Module: ChefZero::RSpec
- Extended by:
- RSpecClassMethods
- Defined in:
- lib/chef_zero/rspec.rb
Defined Under Namespace
Modules: RSpecClassMethods, WhenTheChefServerClassMethods, WhenTheChefServerInstanceMethods
Instance Attribute Summary
Attributes included from RSpecClassMethods
#client_key, #request_log, #server
Instance Method Summary collapse
Methods included from RSpecClassMethods
clear_request_log, set_server_options
Instance Method Details
#when_the_chef_server(description, *tags, &block) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/chef_zero/rspec.rb', line 44 def when_the_chef_server(description, *, &block) context "When the #{ChefZero::Dist::PRODUCT} server #{description}", * do extend WhenTheChefServerClassMethods include WhenTheChefServerInstanceMethods # Take the passed-in options # rubocop:disable Lint/UnderscorePrefixedVariableName define_singleton_method(:chef_server_options) do @chef_server_options ||= begin = { port: 8900, signals: false, log_requests: true } = .merge(.last) if .last.is_a?(Hash) = .freeze end end # rubocop:enable Lint/UnderscorePrefixedVariableName # Merge in chef_server_options from let(:chef_server_options) def # rubocop:disable Lint/NestedMethodDefinition = self.class..dup = .merge(chef_zero_opts) if respond_to?(:chef_zero_opts) end before [:server_scope] do if [:server_scope] != self.class.[:server_scope] raise "server_scope: #{[:server_scope]} will not be honored: it can only be set on when_the_chef_server!" end Log.info("Starting #{ChefZero::Dist::PRODUCT} server with options #{}") ChefZero::RSpec.() if [:organization] organization [:organization] end if defined?(Chef::Config) @old_chef_server_url = Chef::Config.chef_server_url @old_node_name = Chef::Config.node_name @old_client_key = Chef::Config.client_key if [:organization] Chef::Config.chef_server_url = "#{ChefZero::RSpec.server.url}/organizations/#{[:organization]}" else Chef::Config.chef_server_url = ChefZero::RSpec.server.url end Chef::Config.node_name = "admin" Chef::Config.client_key = ChefZero::RSpec.client_key.path Chef::Config.http_retry_count = 0 end end if defined?(Chef::Config) after [:server_scope] do Chef::Config.chef_server_url = @old_chef_server_url Chef::Config.node_name = @old_node_name Chef::Config.client_key = @old_client_key end end instance_eval(&block) end end |