diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2018-07-02 10:29:13 -0700 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2018-07-02 10:29:13 -0700 |
commit | 878560a22f37aec0c2dfe681b3743e027155be88 (patch) | |
tree | 676062be70a45e73a8722c0e6dadd220162fb101 | |
parent | 202887162a22e0c7062064fff0d9462f8c02bf0e (diff) | |
download | chef-878560a22f37aec0c2dfe681b3743e027155be88.tar.gz |
fix Layout/DotPosition
Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
51 files changed, 653 insertions, 653 deletions
diff --git a/lib/chef/chef_fs/chef_fs_data_store.rb b/lib/chef/chef_fs/chef_fs_data_store.rb index 697c2db232..c42f08a462 100644 --- a/lib/chef/chef_fs/chef_fs_data_store.rb +++ b/lib/chef/chef_fs/chef_fs_data_store.rb @@ -537,9 +537,9 @@ class Chef if chef_fs.versioned_cookbooks || path[0] == "cookbook_artifacts" result = with_entry([ path[0] ]) do |entry| # list /cookbooks/name = filter /cookbooks/name-version down to name - entry.children.map { |child| split_name_version(child.name) }. - select { |name, version| name == path[1] }. - map { |name, version| version } + entry.children.map { |child| split_name_version(child.name) } + .select { |name, version| name == path[1] } + .map { |name, version| version } end if result.empty? raise ChefZero::DataStore::DataNotFoundError.new(path) diff --git a/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_entry.rb b/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_entry.rb index 90b8c88cff..c840fad126 100644 --- a/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_entry.rb +++ b/lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_entry.rb @@ -52,9 +52,9 @@ class Chef end def children - entries = Dir.entries(file_path).sort. - map { |child_name| make_child_entry(child_name) }. - select { |child| child && can_have_child?(child.name, child.dir?) } + entries = Dir.entries(file_path).sort + .map { |child_name| make_child_entry(child_name) } + .select { |child| child && can_have_child?(child.name, child.dir?) } entries.select { |entry| !(entry.dir? && entry.children.size == 0 ) } rescue Errno::ENOENT raise Chef::ChefFS::FileSystem::NotFoundError.new(self, $!) diff --git a/lib/chef/chef_fs/file_system/repository/directory.rb b/lib/chef/chef_fs/file_system/repository/directory.rb index 328cf92b03..d3f8d84324 100644 --- a/lib/chef/chef_fs/file_system/repository/directory.rb +++ b/lib/chef/chef_fs/file_system/repository/directory.rb @@ -71,9 +71,9 @@ class Chef def children return FileSystemCache.instance.children(file_path) if FileSystemCache.instance.exist?(file_path) - children = dir_ls.sort. - map { |child_name| make_child_entry(child_name) }. - select { |new_child| new_child.fs_entry_valid? && can_have_child?(new_child.name, new_child.dir?) } + children = dir_ls.sort + .map { |child_name| make_child_entry(child_name) } + .select { |new_child| new_child.fs_entry_valid? && can_have_child?(new_child.name, new_child.dir?) } FileSystemCache.instance.set_children(file_path, children) rescue Errno::ENOENT => e raise Chef::ChefFS::FileSystem::NotFoundError.new(self, e) diff --git a/lib/chef/chef_fs/file_system/repository/file_system_entry.rb b/lib/chef/chef_fs/file_system/repository/file_system_entry.rb index 45ae002521..183fcda26d 100644 --- a/lib/chef/chef_fs/file_system/repository/file_system_entry.rb +++ b/lib/chef/chef_fs/file_system/repository/file_system_entry.rb @@ -80,9 +80,9 @@ class Chef def children # Except cookbooks and data bag dirs, all things must be json files - Dir.entries(file_path).sort. - map { |child_name| make_child_entry(child_name) }. - select { |new_child| new_child.fs_entry_valid? && can_have_child?(new_child.name, new_child.dir?) } + Dir.entries(file_path).sort + .map { |child_name| make_child_entry(child_name) } + .select { |new_child| new_child.fs_entry_valid? && can_have_child?(new_child.name, new_child.dir?) } rescue Errno::ENOENT raise Chef::ChefFS::FileSystem::NotFoundError.new(self, $!) end diff --git a/spec/integration/recipes/lwrp_inline_resources_spec.rb b/spec/integration/recipes/lwrp_inline_resources_spec.rb index dca78e23cc..bda4728449 100644 --- a/spec/integration/recipes/lwrp_inline_resources_spec.rb +++ b/spec/integration/recipes/lwrp_inline_resources_spec.rb @@ -105,9 +105,9 @@ describe "LWRPs with inline resources" do r = lwrp_inline_resources_test2 "hi" do action :b end - end.to have_updated("lwrp_inline_resources_test2[hi]", :b). - and have_updated("ruby_block[run a]", :run). - and have_updated("ruby_block[run b]", :run) + end.to have_updated("lwrp_inline_resources_test2[hi]", :b) + .and have_updated("ruby_block[run a]", :run) + .and have_updated("ruby_block[run b]", :run) expect(r.ran_b).to eq "ran b: ran_a value was \"ran a\"" end end diff --git a/spec/integration/recipes/resource_load_spec.rb b/spec/integration/recipes/resource_load_spec.rb index 4fc14c0687..79df1d6478 100644 --- a/spec/integration/recipes/resource_load_spec.rb +++ b/spec/integration/recipes/resource_load_spec.rb @@ -156,10 +156,10 @@ describe "Resource.load_current_value" do context "And a child resource class with load_current_value" do before do subresource_class.load_current_value do - y "loaded_y #{Namer.incrementing_value} (#{self.class.properties.sort_by { |name, p| name }. - select { |name, p| p.is_set?(self) }. - map { |name, p| "#{name}=#{p.get(self)}" }. - join(", ")})" + y "loaded_y #{Namer.incrementing_value} (#{self.class.properties.sort_by { |name, p| name } + .select { |name, p| p.is_set?(self) } + .map { |name, p| "#{name}=#{p.get(self)}" } + .join(", ")})" end end @@ -174,10 +174,10 @@ describe "Resource.load_current_value" do before do subresource_class.load_current_value do super() - y "loaded_y #{Namer.incrementing_value} (#{self.class.properties.sort_by { |name, p| name }. - select { |name, p| p.is_set?(self) }. - map { |name, p| "#{name}=#{p.get(self)}" }. - join(", ")})" + y "loaded_y #{Namer.incrementing_value} (#{self.class.properties.sort_by { |name, p| name } + .select { |name, p| p.is_set?(self) } + .map { |name, p| "#{name}=#{p.get(self)}" } + .join(", ")})" end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index c9ba059ddb..d900fc2f37 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -50,10 +50,10 @@ end require "chef" require "chef/knife" -Dir["lib/chef/knife/**/*.rb"]. - map { |f| f.gsub("lib/", "") }. - map { |f| f.gsub(%r{\.rb$}, "") }. - each { |f| require f } +Dir["lib/chef/knife/**/*.rb"] + .map { |f| f.gsub("lib/", "") } + .map { |f| f.gsub(%r{\.rb$}, "") } + .each { |f| require f } require "chef/resource_resolver" require "chef/provider_resolver" @@ -90,12 +90,12 @@ require "spec/support/shared/unit/mock_shellout" # Autoloads support files # Excludes support/platforms by default # Do not change the gsub. -Dir["spec/support/**/*.rb"]. - reject { |f| f =~ %r{^spec/support/platforms} }. - reject { |f| f =~ %r{^spec/support/pedant} }. - map { |f| f.gsub(%r{.rb$}, "") }. - map { |f| f.gsub(%r{spec/}, "") }. - each { |f| require f } +Dir["spec/support/**/*.rb"] + .reject { |f| f =~ %r{^spec/support/platforms} } + .reject { |f| f =~ %r{^spec/support/pedant} } + .map { |f| f.gsub(%r{.rb$}, "") } + .map { |f| f.gsub(%r{spec/}, "") } + .each { |f| require f } OHAI_SYSTEM = Ohai::System.new OHAI_SYSTEM.all_plugins(["platform", "hostname", "languages/powershell"]) diff --git a/spec/support/shared/context/client.rb b/spec/support/shared/context/client.rb index 6797a4ad22..0054058d0f 100644 --- a/spec/support/shared/context/client.rb +++ b/spec/support/shared/context/client.rb @@ -87,10 +87,10 @@ shared_context "a client run" do # Make sure Client#register thinks the client key doesn't # exist, so it tries to register and create one. allow(File).to receive(:exists?).and_call_original - expect(File).to receive(:exists?). - with(Chef::Config[:client_key]). - exactly(:once). - and_return(api_client_exists?) + expect(File).to receive(:exists?) + .with(Chef::Config[:client_key]) + .exactly(:once) + .and_return(api_client_exists?) unless api_client_exists? # Client.register will register with the validation client name. @@ -99,21 +99,21 @@ shared_context "a client run" do end def stub_for_data_collector_init - expect(Chef::ServerAPI).to receive(:new). - with(Chef::Config[:data_collector][:server_url], validate_utf8: false). - exactly(:once). - and_return(http_data_collector) + expect(Chef::ServerAPI).to receive(:new) + .with(Chef::Config[:data_collector][:server_url], validate_utf8: false) + .exactly(:once) + .and_return(http_data_collector) end def stub_for_node_load # Client.register will then turn around create another # Chef::ServerAPI object, this time with the client key it got from the # previous step. - expect(Chef::ServerAPI).to receive(:new). - with(Chef::Config[:chef_server_url], client_name: fqdn, - signing_key_filename: Chef::Config[:client_key]). - exactly(:once). - and_return(http_node_load) + expect(Chef::ServerAPI).to receive(:new) + .with(Chef::Config[:chef_server_url], client_name: fqdn, + signing_key_filename: Chef::Config[:client_key]) + .exactly(:once) + .and_return(http_node_load) # --Client#build_node # looks up the node, which we will return, then later saves it. @@ -135,9 +135,9 @@ shared_context "a client run" do # expect_any_instance_of(Chef::CookbookSynchronizer).to receive(:sync_cookbooks) expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url], version_class: Chef::CookbookManifestVersions).and_return(http_cookbook_sync) - expect(http_cookbook_sync).to receive(:post). - with("environments/_default/cookbook_versions", { run_list: [] }). - and_return({}) + expect(http_cookbook_sync).to receive(:post) + .with("environments/_default/cookbook_versions", { run_list: [] }) + .and_return({}) end def stub_for_required_recipe diff --git a/spec/support/shared/unit/provider/useradd_based_user_provider.rb b/spec/support/shared/unit/provider/useradd_based_user_provider.rb index a6301f9ae7..3e48cdf92d 100644 --- a/spec/support/shared/unit/provider/useradd_based_user_provider.rb +++ b/spec/support/shared/unit/provider/useradd_based_user_provider.rb @@ -272,51 +272,51 @@ shared_examples_for "a useradd-based user provider" do |supported_useradd_option end it "should return false if status begins with P" do - expect(provider).to receive(:shell_out). - with("passwd", "-S", @new_resource.username, { returns: [0, 1] }). - and_return(passwd_s_status) + expect(provider).to receive(:shell_out) + .with("passwd", "-S", @new_resource.username, { returns: [0, 1] }) + .and_return(passwd_s_status) expect(provider.check_lock).to eql(false) end it "should return false if status begins with N" do @stdout = "root N" - expect(provider).to receive(:shell_out). - with("passwd", "-S", @new_resource.username, { returns: [0, 1] }). - and_return(passwd_s_status) + expect(provider).to receive(:shell_out) + .with("passwd", "-S", @new_resource.username, { returns: [0, 1] }) + .and_return(passwd_s_status) expect(provider.check_lock).to eql(false) end it "should return true if status begins with L" do @stdout = "root L" - expect(provider).to receive(:shell_out). - with("passwd", "-S", @new_resource.username, { returns: [0, 1] }). - and_return(passwd_s_status) + expect(provider).to receive(:shell_out) + .with("passwd", "-S", @new_resource.username, { returns: [0, 1] }) + .and_return(passwd_s_status) expect(provider.check_lock).to eql(true) end it "should raise a ShellCommandFailed exception if passwd -S exits with something other than 0 or 1" do expect(passwd_s_status).to receive(:error!).and_raise(Mixlib::ShellOut::ShellCommandFailed) - expect(provider).to receive(:shell_out). - with("passwd", "-S", @new_resource.username, { returns: [0, 1] }). - and_return(passwd_s_status) + expect(provider).to receive(:shell_out) + .with("passwd", "-S", @new_resource.username, { returns: [0, 1] }) + .and_return(passwd_s_status) expect { provider.check_lock }.to raise_error(Mixlib::ShellOut::ShellCommandFailed) end it "should raise an error if the output isn't parsable" do expect(passwd_s_status).to receive(:stdout).and_return("") expect(passwd_s_status).to receive(:stderr).and_return("") - expect(provider).to receive(:shell_out). - with("passwd", "-S", @new_resource.username, { returns: [0, 1] }). - and_return(passwd_s_status) + expect(provider).to receive(:shell_out) + .with("passwd", "-S", @new_resource.username, { returns: [0, 1] }) + .and_return(passwd_s_status) expect { provider.check_lock }.to raise_error(Chef::Exceptions::User) end context "when in why run mode" do before do passwd_status = double("Mixlib::ShellOut command", exitstatus: 0, stdout: "", stderr: "passwd: user 'chef-test' does not exist\n") - expect(provider).to receive(:shell_out). - with("passwd", "-S", @new_resource.username, { returns: [0, 1] }). - and_return(passwd_status) + expect(provider).to receive(:shell_out) + .with("passwd", "-S", @new_resource.username, { returns: [0, 1] }) + .and_return(passwd_status) # ubuntu returns 252 on user-does-not-exist so will raise if #error! is called or if # shell_out! is used allow(passwd_status).to receive(:error!).and_raise(Mixlib::ShellOut::ShellCommandFailed) diff --git a/spec/unit/api_client/registration_spec.rb b/spec/unit/api_client/registration_spec.rb index b2b74b1c58..407c2c9f07 100644 --- a/spec/unit/api_client/registration_spec.rb +++ b/spec/unit/api_client/registration_spec.rb @@ -108,28 +108,28 @@ describe Chef::ApiClient::Registration do end it "posts a locally generated public key to the server to create a client" do - expect(http_mock).to receive(:post). - with("clients", expected_post_data). - and_return(create_with_pkey_response) + expect(http_mock).to receive(:post) + .with("clients", expected_post_data) + .and_return(create_with_pkey_response) expect(registration.run.public_key).to eq(create_with_pkey_response["chef_key"]["public_key"]) expect(OpenSSL::PKey::RSA.new(registration.private_key).to_s).to eq(OpenSSL::PKey::RSA.new(generated_private_key_pem).to_s) end it "puts a locally generated public key to the server to update a client" do - expect(http_mock).to receive(:post). - with("clients", expected_post_data). - and_raise(exception_409) - expect(http_mock).to receive(:put). - with("clients/#{client_name}", expected_put_data). - and_return(update_with_pkey_response) + expect(http_mock).to receive(:post) + .with("clients", expected_post_data) + .and_raise(exception_409) + expect(http_mock).to receive(:put) + .with("clients/#{client_name}", expected_put_data) + .and_return(update_with_pkey_response) expect(registration.run.public_key).to eq(update_with_pkey_response["public_key"].to_pem) expect(OpenSSL::PKey::RSA.new(registration.private_key).to_s).to eq(OpenSSL::PKey::RSA.new(generated_private_key_pem).to_s) end it "writes the generated private key to disk" do - expect(http_mock).to receive(:post). - with("clients", expected_post_data). - and_return(create_with_pkey_response) + expect(http_mock).to receive(:post) + .with("clients", expected_post_data) + .and_return(create_with_pkey_response) registration.run expect(OpenSSL::PKey::RSA.new(IO.read(key_location)).to_s).to eq(OpenSSL::PKey::RSA.new(generated_private_key_pem).to_s) end @@ -137,9 +137,9 @@ describe Chef::ApiClient::Registration do context "and the client already exists on a Chef 11 server" do it "requests a new key from the server and saves it" do expect(http_mock).to receive(:post).and_raise(exception_409) - expect(http_mock).to receive(:put). - with("clients/#{client_name}", expected_put_data). - and_return(update_with_pkey_response) + expect(http_mock).to receive(:put) + .with("clients/#{client_name}", expected_put_data) + .and_return(update_with_pkey_response) expect(registration.run.public_key).to eq(update_with_pkey_response["public_key"].to_pem) expect(OpenSSL::PKey::RSA.new(registration.private_key).to_s).to eq(OpenSSL::PKey::RSA.new(generated_private_key_pem).to_s) end @@ -161,9 +161,9 @@ describe Chef::ApiClient::Registration do end it "creates a new ApiClient on the server using the validator identity" do - expect(http_mock).to receive(:post). - with("clients", expected_post_data). - and_return(server_v10_response) + expect(http_mock).to receive(:post) + .with("clients", expected_post_data) + .and_return(server_v10_response) expect(registration.run.private_key).to eq(server_v10_response["private_key"]) expect(registration.private_key).to eq("--begin rsa key etc--") end @@ -171,9 +171,9 @@ describe Chef::ApiClient::Registration do context "and the client already exists on a Chef 11 server" do it "requests a new key from the server and saves it" do expect(http_mock).to receive(:post).and_raise(exception_409) - expect(http_mock).to receive(:put). - with("clients/#{client_name}", expected_put_data). - and_return(server_v11_response) + expect(http_mock).to receive(:put) + .with("clients/#{client_name}", expected_put_data) + .and_return(server_v11_response) expect(registration.run).to eq(server_v11_response) expect(registration.private_key).to eq("--begin rsa key etc--") end @@ -181,11 +181,11 @@ describe Chef::ApiClient::Registration do context "and the client already exists on a Chef 10 server" do it "requests a new key from the server and saves it" do - expect(http_mock).to receive(:post).with("clients", expected_post_data). - and_raise(exception_409) - expect(http_mock).to receive(:put). - with("clients/#{client_name}", expected_put_data). - and_return(server_v10_response) + expect(http_mock).to receive(:post).with("clients", expected_post_data) + .and_raise(exception_409) + expect(http_mock).to receive(:put) + .with("clients/#{client_name}", expected_put_data) + .and_return(server_v10_response) expect(registration.run.private_key).to eq(server_v10_response["private_key"]) expect(registration.private_key).to eq("--begin rsa key etc--") end diff --git a/spec/unit/api_client_spec.rb b/spec/unit/api_client_spec.rb index c3c674ecf7..e83906e712 100644 --- a/spec/unit/api_client_spec.rb +++ b/spec/unit/api_client_spec.rb @@ -302,9 +302,9 @@ describe Chef::ApiClient do @api_client_with_key = Chef::ApiClient.new @api_client_with_key.name("lost-my-key") @api_client_with_key.private_key("the new private key") - expect(@http_client).to receive(:put). - with("clients/lost-my-key", name: "lost-my-key", admin: false, validator: false, private_key: true). - and_return(@api_client_with_key) + expect(@http_client).to receive(:put) + .with("clients/lost-my-key", name: "lost-my-key", admin: false, validator: false, private_key: true) + .and_return(@api_client_with_key) end it "returns an ApiClient with a private key" do @@ -320,9 +320,9 @@ describe Chef::ApiClient do context "and the client exists on a Chef 10-like server" do before do @api_client_with_key = { "name" => "lost-my-key", "private_key" => "the new private key" } - expect(@http_client).to receive(:put). - with("clients/lost-my-key", name: "lost-my-key", admin: false, validator: false, private_key: true). - and_return(@api_client_with_key) + expect(@http_client).to receive(:put) + .with("clients/lost-my-key", name: "lost-my-key", admin: false, validator: false, private_key: true) + .and_return(@api_client_with_key) end it "returns an ApiClient with a private key" do diff --git a/spec/unit/application/apply_spec.rb b/spec/unit/application/apply_spec.rb index b9e474ef08..b659f13fe8 100644 --- a/spec/unit/application/apply_spec.rb +++ b/spec/unit/application/apply_spec.rb @@ -101,8 +101,8 @@ describe Chef::Application::Apply do before do Chef::Config[:json_attribs] = json_source - expect(Chef::ConfigFetcher).to receive(:new).with(json_source). - and_return(config_fetcher) + expect(Chef::ConfigFetcher).to receive(:new).with(json_source) + .and_return(config_fetcher) end it "reads the JSON attributes from the specified source" do diff --git a/spec/unit/application/client_spec.rb b/spec/unit/application/client_spec.rb index a1f96e1d43..40f690abb1 100644 --- a/spec/unit/application/client_spec.rb +++ b/spec/unit/application/client_spec.rb @@ -327,8 +327,8 @@ Enable chef-client interval runs by setting `:client_fork = true` in your config before do allow(app).to receive(:configure_chef).and_return(true) Chef::Config[:json_attribs] = json_source - expect(Chef::ConfigFetcher).to receive(:new).with(json_source). - and_return(config_fetcher) + expect(Chef::ConfigFetcher).to receive(:new).with(json_source) + .and_return(config_fetcher) end it "reads the JSON attributes from the specified source" do diff --git a/spec/unit/application/solo_spec.rb b/spec/unit/application/solo_spec.rb index c4c4c3b252..31114261c8 100644 --- a/spec/unit/application/solo_spec.rb +++ b/spec/unit/application/solo_spec.rb @@ -98,8 +98,8 @@ Enable chef-client interval runs by setting `:client_fork = true` in your config before do Chef::Config[:json_attribs] = json_source - expect(Chef::ConfigFetcher).to receive(:new).with(json_source). - and_return(config_fetcher) + expect(Chef::ConfigFetcher).to receive(:new).with(json_source) + .and_return(config_fetcher) end it "reads the JSON attributes from the specified source" do diff --git a/spec/unit/application_spec.rb b/spec/unit/application_spec.rb index 8b2d0cb114..a342fbd8bf 100644 --- a/spec/unit/application_spec.rb +++ b/spec/unit/application_spec.rb @@ -127,9 +127,9 @@ describe Chef::Application do # force let binding to get evaluated or else we stub Pathname.new before we try to use it. config_location_pathname allow(Pathname).to receive(:new).with(config_location).and_return(config_location_pathname) - expect(File).to receive(:read). - with(config_location). - and_return(config_content) + expect(File).to receive(:read) + .with(config_location) + .and_return(config_content) end it "should configure chef::config from a file" do @@ -393,11 +393,11 @@ describe Chef::Application do def raises_informative_fatals_on_configure_chef config_file_regexp = Regexp.new @app.config[:config_file] - expect(Chef::Log).to receive(:fatal). - with(/Configuration error/) - expect(Chef::Log).to receive(:fatal). - with(config_file_regexp). - at_least(1).times + expect(Chef::Log).to receive(:fatal) + .with(/Configuration error/) + expect(Chef::Log).to receive(:fatal) + .with(config_file_regexp) + .at_least(1).times @app.configure_chef end diff --git a/spec/unit/audit/audit_event_proxy_spec.rb b/spec/unit/audit/audit_event_proxy_spec.rb index ec9960aff4..a9b27f238e 100644 --- a/spec/unit/audit/audit_event_proxy_spec.rb +++ b/spec/unit/audit/audit_event_proxy_spec.rb @@ -44,10 +44,10 @@ describe Chef::Audit::AuditEventProxy do let(:parents) { [double("ExampleGroup")] } it "notifies control_group_started event" do - expect(Chef::Log).to receive(:trace). - with("Entered \`control_group\` block named poots") - expect(events).to receive(:control_group_started). - with(description) + expect(Chef::Log).to receive(:trace) + .with("Entered \`control_group\` block named poots") + expect(events).to receive(:control_group_started) + .with(description) audit_event_proxy.example_group_started(notification) end end @@ -87,14 +87,14 @@ describe Chef::Audit::AuditEventProxy do let(:excpetion) { nil } before do - allow(audit_event_proxy).to receive(:build_control_from). - with(example). - and_return([control_group_name, control_data]) + allow(audit_event_proxy).to receive(:build_control_from) + .with(example) + .and_return([control_group_name, control_data]) end it "notifies events" do - expect(events).to receive(:control_example_success). - with(control_group_name, control_data) + expect(events).to receive(:control_example_success) + .with(control_group_name, control_data) audit_event_proxy.stop(notification) end end @@ -105,14 +105,14 @@ describe Chef::Audit::AuditEventProxy do let(:exception) { double("ExpectationNotMet") } before do - allow(audit_event_proxy).to receive(:build_control_from). - with(example). - and_return([control_group_name, control_data]) + allow(audit_event_proxy).to receive(:build_control_from) + .with(example) + .and_return([control_group_name, control_data]) end it "notifies events" do - expect(events).to receive(:control_example_failure). - with(control_group_name, control_data, exception) + expect(events).to receive(:control_example_failure) + .with(control_group_name, control_data, exception) audit_event_proxy.stop(notification) end end @@ -165,17 +165,17 @@ describe Chef::Audit::AuditEventProxy do before do if described_class - allow(described_class).to receive(:instance_variable_get). - with(:@name). - and_return(resource_name) - allow(described_class.class).to receive(:name). - and_return(described_class.class) + allow(described_class).to receive(:instance_variable_get) + .with(:@name) + .and_return(resource_name) + allow(described_class.class).to receive(:name) + .and_return(described_class.class) end end it "returns the controls block name and example metadata for reporting" do - expect(events).to receive(:control_example_success). - with(control_group_name, control_data) + expect(events).to receive(:control_example_success) + .with(control_group_name, control_data) audit_event_proxy.stop(notification) end end diff --git a/spec/unit/audit/audit_reporter_spec.rb b/spec/unit/audit/audit_reporter_spec.rb index 9f74ba93e1..4c13eca390 100644 --- a/spec/unit/audit/audit_reporter_spec.rb +++ b/spec/unit/audit/audit_reporter_spec.rb @@ -79,8 +79,8 @@ describe Chef::Audit::AuditReporter do "X-Ops-Audit-Report-Protocol-Version" => Chef::Audit::AuditReporter::PROTOCOL_VERSION, } - expect(rest).to receive(:post). - with("controls", run_data, headers) + expect(rest).to receive(:post) + .with("controls", run_data, headers) reporter.run_completed(node) end @@ -145,12 +145,12 @@ EOM shared_examples "non-404 error code" do it "saves the error report" do - expect(Chef::FileCache).to receive(:store). - with("failed-audit-data.json", an_instance_of(String), 0640). - and_return(true) - expect(Chef::FileCache).to receive(:load). - with("failed-audit-data.json", false). - and_return(true) + expect(Chef::FileCache).to receive(:store) + .with("failed-audit-data.json", an_instance_of(String), 0640) + .and_return(true) + expect(Chef::FileCache).to receive(:load) + .with("failed-audit-data.json", false) + .and_return(true) expect(Chef::Log).to receive(:error).with(/Failed to post audit report to server/) reporter.run_completed(node) end @@ -184,9 +184,9 @@ EOM context "when reporting url fatals are enabled" do before do - allow(Chef::Config).to receive(:[]). - with(:enable_reporting_url_fatals). - and_return(true) + allow(Chef::Config).to receive(:[]) + .with(:enable_reporting_url_fatals) + .and_return(true) end it "raises the error" do @@ -353,17 +353,17 @@ EOM metadata: double("metadata")) end before do - allow(Chef::Audit::ControlGroupData).to receive(:new). - with(name, control_group.metadata). - and_return(control_group) + allow(Chef::Audit::ControlGroupData).to receive(:new) + .with(name, control_group.metadata) + .and_return(control_group) end it "stores the control group" do expect(ordered_control_groups).to receive(:has_key?).with(name).and_return(false) allow(run_context.audits).to receive(:[]).with(name).and_return(control_group) - expect(ordered_control_groups).to receive(:store). - with(name, control_group). - and_call_original + expect(ordered_control_groups).to receive(:store) + .with(name, control_group) + .and_call_original reporter.control_group_started(name) # stubbed :has_key? above, which is used by the have_key matcher, # so instead we check the response to Hash's #key? because luckily @@ -400,8 +400,8 @@ EOM let(:error) { double("Exception", message: "oopsie") } it "notifies the control group the example failed" do - expect(control_group_bar).to receive(:example_failure). - with(example_data, error.message) + expect(control_group_bar).to receive(:example_failure) + .with(example_data, error.message) reporter.control_example_failure(name, example_data, error) end end @@ -410,9 +410,9 @@ EOM shared_examples "enabled?" do |true_or_false| it "returns #{true_or_false}" do - expect(Chef::Config).to receive(:[]). - with(:audit_mode). - and_return(audit_setting) + expect(Chef::Config).to receive(:[]) + .with(:audit_mode) + .and_return(audit_setting) expect(reporter.auditing_enabled?).to be true_or_false end end diff --git a/spec/unit/audit/control_group_data_spec.rb b/spec/unit/audit/control_group_data_spec.rb index c56e824d4c..82af77dcea 100644 --- a/spec/unit/audit/control_group_data_spec.rb +++ b/spec/unit/audit/control_group_data_spec.rb @@ -193,11 +193,11 @@ describe Chef::Audit::ControlGroupData do context: context, line_number: line_number) end before do - allow(Chef::Audit::ControlData).to receive(:new). - with(name: name, resource_type: resource_type, + allow(Chef::Audit::ControlData).to receive(:new) + .with(name: name, resource_type: resource_type, resource_name: resource_name, context: context, - line_number: line_number). - and_return(control) + line_number: line_number) + .and_return(control) end end diff --git a/spec/unit/client_spec.rb b/spec/unit/client_spec.rb index 6d94e87e21..b39dde297e 100644 --- a/spec/unit/client_spec.rb +++ b/spec/unit/client_spec.rb @@ -192,9 +192,9 @@ describe Chef::Client do # expect_any_instance_of(Chef::CookbookSynchronizer).to receive(:sync_cookbooks) expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url], version_class: Chef::CookbookManifestVersions).and_return(http_cookbook_sync) - expect(http_cookbook_sync).to receive(:post). - with("environments/_default/cookbook_versions", { run_list: ["override_recipe"] }). - and_return({}) + expect(http_cookbook_sync).to receive(:post) + .with("environments/_default/cookbook_versions", { run_list: ["override_recipe"] }) + .and_return({}) end def stub_for_node_save @@ -226,9 +226,9 @@ describe Chef::Client do # expect_any_instance_of(Chef::CookbookSynchronizer).to receive(:sync_cookbooks) expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url], version_class: Chef::CookbookManifestVersions).and_return(http_cookbook_sync) - expect(http_cookbook_sync).to receive(:post). - with("environments/_default/cookbook_versions", { run_list: ["new_run_list_recipe"] }). - and_return({}) + expect(http_cookbook_sync).to receive(:post) + .with("environments/_default/cookbook_versions", { run_list: ["new_run_list_recipe"] }) + .and_return({}) end before do diff --git a/spec/unit/config_fetcher_spec.rb b/spec/unit/config_fetcher_spec.rb index c91b043160..abaea6b2dc 100644 --- a/spec/unit/config_fetcher_spec.rb +++ b/spec/unit/config_fetcher_spec.rb @@ -16,9 +16,9 @@ describe Chef::ConfigFetcher do let(:config_content) { "# The client.rb content" } it "reads the file from disk" do - expect(::File).to receive(:read). - with(config_location). - and_return(config_content) + expect(::File).to receive(:read) + .with(config_location) + .and_return(config_content) expect(fetcher.read_config).to eq(config_content) end @@ -42,9 +42,9 @@ describe Chef::ConfigFetcher do let(:config_location) { "/etc/chef/first-boot.json" } it "returns the parsed JSON" do - expect(::File).to receive(:read). - with(config_location). - and_return(valid_json) + expect(::File).to receive(:read) + .with(config_location) + .and_return(valid_json) expect(fetcher.fetch_json).to eq({ "a" => "b" }) end @@ -53,12 +53,12 @@ describe Chef::ConfigFetcher do it "reports the JSON error" do - expect(::File).to receive(:read). - with(config_location). - and_return(invalid_json) + expect(::File).to receive(:read) + .with(config_location) + .and_return(invalid_json) - expect(Chef::Application).to receive(:fatal!). - with(invalid_json_error_regex) + expect(Chef::Application).to receive(:fatal!) + .with(invalid_json_error_regex) fetcher.fetch_json end end @@ -78,14 +78,14 @@ describe Chef::ConfigFetcher do describe "reading the file" do before do - expect(Chef::HTTP::Simple).to receive(:new). - with(config_location). - and_return(http) + expect(Chef::HTTP::Simple).to receive(:new) + .with(config_location) + .and_return(http) end it "reads the file over HTTP" do - expect(http).to receive(:get). - with("").and_return(config_content) + expect(http).to receive(:get) + .with("").and_return(config_content) expect(fetcher.read_config).to eq(config_content) end @@ -93,18 +93,18 @@ describe Chef::ConfigFetcher do let(:config_location) { "https://example.com/foo.json" } it "fetches the file and parses it" do - expect(http).to receive(:get). - with("").and_return(valid_json) + expect(http).to receive(:get) + .with("").and_return(valid_json) expect(fetcher.fetch_json).to eq({ "a" => "b" }) end context "and the JSON is invalid" do it "reports the JSON error" do - expect(http).to receive(:get). - with("").and_return(invalid_json) + expect(http).to receive(:get) + .with("").and_return(invalid_json) - expect(Chef::Application).to receive(:fatal!). - with(invalid_json_error_regex) + expect(Chef::Application).to receive(:fatal!) + .with(invalid_json_error_regex) fetcher.fetch_json end end diff --git a/spec/unit/config_spec.rb b/spec/unit/config_spec.rb index 68cb589251..c36f66f18a 100644 --- a/spec/unit/config_spec.rb +++ b/spec/unit/config_spec.rb @@ -7,8 +7,8 @@ RSpec.describe Chef::Config do shared_examples_for "deprecated by ohai but not deprecated" do it "does not emit a deprecation warning when set" do - expect(Chef::Log).to_not receive(:warn). - with(/Ohai::Config\[:#{option}\] is deprecated/) + expect(Chef::Log).to_not receive(:warn) + .with(/Ohai::Config\[:#{option}\] is deprecated/) Chef::Config[option] = value expect(Chef::Config[option]).to eq(value) end diff --git a/spec/unit/cookbook/synchronizer_spec.rb b/spec/unit/cookbook/synchronizer_spec.rb index cabcb57ea4..dce2383a16 100644 --- a/spec/unit/cookbook/synchronizer_spec.rb +++ b/spec/unit/cookbook/synchronizer_spec.rb @@ -218,203 +218,203 @@ describe Chef::CookbookSynchronizer do def setup_common_files_missing_expectations # Files are not in the cache: - expect(file_cache).to receive(:has_key?). - with("cookbooks/cookbook_a/recipes/default.rb"). - and_return(false) - expect(file_cache).to receive(:has_key?). - with("cookbooks/cookbook_a/attributes/default.rb"). - and_return(false) + expect(file_cache).to receive(:has_key?) + .with("cookbooks/cookbook_a/recipes/default.rb") + .and_return(false) + expect(file_cache).to receive(:has_key?) + .with("cookbooks/cookbook_a/attributes/default.rb") + .and_return(false) # Fetch and copy default.rb recipe - expect(server_api).to receive(:streaming_request). - with("http://chef.example.com/abc123"). - and_return(cookbook_a_default_recipe_tempfile) - expect(file_cache).to receive(:move_to). - with("/tmp/cookbook_a_recipes_default_rb", "cookbooks/cookbook_a/recipes/default.rb") - expect(file_cache).to receive(:load). - with("cookbooks/cookbook_a/recipes/default.rb", false). - and_return("/file-cache/cookbooks/cookbook_a/recipes/default.rb") + expect(server_api).to receive(:streaming_request) + .with("http://chef.example.com/abc123") + .and_return(cookbook_a_default_recipe_tempfile) + expect(file_cache).to receive(:move_to) + .with("/tmp/cookbook_a_recipes_default_rb", "cookbooks/cookbook_a/recipes/default.rb") + expect(file_cache).to receive(:load) + .with("cookbooks/cookbook_a/recipes/default.rb", false) + .and_return("/file-cache/cookbooks/cookbook_a/recipes/default.rb") # Fetch and copy default.rb attribute file - expect(server_api).to receive(:streaming_request). - with("http://chef.example.com/abc456"). - and_return(cookbook_a_default_attribute_tempfile) - expect(file_cache).to receive(:move_to). - with("/tmp/cookbook_a_attributes_default_rb", "cookbooks/cookbook_a/attributes/default.rb") - expect(file_cache).to receive(:load). - with("cookbooks/cookbook_a/attributes/default.rb", false). - and_return("/file-cache/cookbooks/cookbook_a/attributes/default.rb") + expect(server_api).to receive(:streaming_request) + .with("http://chef.example.com/abc456") + .and_return(cookbook_a_default_attribute_tempfile) + expect(file_cache).to receive(:move_to) + .with("/tmp/cookbook_a_attributes_default_rb", "cookbooks/cookbook_a/attributes/default.rb") + expect(file_cache).to receive(:load) + .with("cookbooks/cookbook_a/attributes/default.rb", false) + .and_return("/file-cache/cookbooks/cookbook_a/attributes/default.rb") end def setup_no_lazy_files_and_templates_missing_expectations - expect(file_cache).to receive(:has_key?). - with("cookbooks/cookbook_a/files/default/megaman.conf"). - and_return(false) - expect(file_cache).to receive(:has_key?). - with("cookbooks/cookbook_a/templates/default/apache2.conf.erb"). - and_return(false) - - expect(server_api).to receive(:streaming_request). - with("http://chef.example.com/megaman.conf"). - and_return(cookbook_a_file_default_tempfile) - expect(file_cache).to receive(:move_to). - with("/tmp/cookbook_a_file_default_tempfile", "cookbooks/cookbook_a/files/default/megaman.conf") - expect(file_cache).to receive(:load). - with("cookbooks/cookbook_a/files/default/megaman.conf", false). - and_return("/file-cache/cookbooks/cookbook_a/default/megaman.conf") - - expect(server_api).to receive(:streaming_request). - with("http://chef.example.com/ffffff"). - and_return(cookbook_a_template_default_tempfile) - expect(file_cache).to receive(:move_to). - with("/tmp/cookbook_a_template_default_tempfile", "cookbooks/cookbook_a/templates/default/apache2.conf.erb") - expect(file_cache).to receive(:load). - with("cookbooks/cookbook_a/templates/default/apache2.conf.erb", false). - and_return("/file-cache/cookbooks/cookbook_a/templates/default/apache2.conf.erb") + expect(file_cache).to receive(:has_key?) + .with("cookbooks/cookbook_a/files/default/megaman.conf") + .and_return(false) + expect(file_cache).to receive(:has_key?) + .with("cookbooks/cookbook_a/templates/default/apache2.conf.erb") + .and_return(false) + + expect(server_api).to receive(:streaming_request) + .with("http://chef.example.com/megaman.conf") + .and_return(cookbook_a_file_default_tempfile) + expect(file_cache).to receive(:move_to) + .with("/tmp/cookbook_a_file_default_tempfile", "cookbooks/cookbook_a/files/default/megaman.conf") + expect(file_cache).to receive(:load) + .with("cookbooks/cookbook_a/files/default/megaman.conf", false) + .and_return("/file-cache/cookbooks/cookbook_a/default/megaman.conf") + + expect(server_api).to receive(:streaming_request) + .with("http://chef.example.com/ffffff") + .and_return(cookbook_a_template_default_tempfile) + expect(file_cache).to receive(:move_to) + .with("/tmp/cookbook_a_template_default_tempfile", "cookbooks/cookbook_a/templates/default/apache2.conf.erb") + expect(file_cache).to receive(:load) + .with("cookbooks/cookbook_a/templates/default/apache2.conf.erb", false) + .and_return("/file-cache/cookbooks/cookbook_a/templates/default/apache2.conf.erb") end def setup_common_files_chksum_mismatch_expectations # Files are in the cache: - expect(file_cache).to receive(:has_key?). - with("cookbooks/cookbook_a/recipes/default.rb"). - and_return(true) - expect(file_cache).to receive(:has_key?). - with("cookbooks/cookbook_a/attributes/default.rb"). - and_return(true) + expect(file_cache).to receive(:has_key?) + .with("cookbooks/cookbook_a/recipes/default.rb") + .and_return(true) + expect(file_cache).to receive(:has_key?) + .with("cookbooks/cookbook_a/attributes/default.rb") + .and_return(true) # Fetch and copy default.rb recipe - expect(server_api).to receive(:streaming_request). - with("http://chef.example.com/abc123"). - and_return(cookbook_a_default_recipe_tempfile) - expect(file_cache).to receive(:move_to). - with("/tmp/cookbook_a_recipes_default_rb", "cookbooks/cookbook_a/recipes/default.rb") - expect(file_cache).to receive(:load). - with("cookbooks/cookbook_a/recipes/default.rb", false). - twice. - and_return("/file-cache/cookbooks/cookbook_a/recipes/default.rb") + expect(server_api).to receive(:streaming_request) + .with("http://chef.example.com/abc123") + .and_return(cookbook_a_default_recipe_tempfile) + expect(file_cache).to receive(:move_to) + .with("/tmp/cookbook_a_recipes_default_rb", "cookbooks/cookbook_a/recipes/default.rb") + expect(file_cache).to receive(:load) + .with("cookbooks/cookbook_a/recipes/default.rb", false) + .twice + .and_return("/file-cache/cookbooks/cookbook_a/recipes/default.rb") # Current file has fff000, want abc123 - expect(Chef::CookbookVersion).to receive(:checksum_cookbook_file). - with("/file-cache/cookbooks/cookbook_a/recipes/default.rb"). - and_return("fff000").at_least(:once) + expect(Chef::CookbookVersion).to receive(:checksum_cookbook_file) + .with("/file-cache/cookbooks/cookbook_a/recipes/default.rb") + .and_return("fff000").at_least(:once) # Fetch and copy default.rb attribute file - expect(server_api).to receive(:streaming_request). - with("http://chef.example.com/abc456"). - and_return(cookbook_a_default_attribute_tempfile) - expect(file_cache).to receive(:move_to). - with("/tmp/cookbook_a_attributes_default_rb", "cookbooks/cookbook_a/attributes/default.rb") - expect(file_cache).to receive(:load). - with("cookbooks/cookbook_a/attributes/default.rb", false). - twice. - and_return("/file-cache/cookbooks/cookbook_a/attributes/default.rb") + expect(server_api).to receive(:streaming_request) + .with("http://chef.example.com/abc456") + .and_return(cookbook_a_default_attribute_tempfile) + expect(file_cache).to receive(:move_to) + .with("/tmp/cookbook_a_attributes_default_rb", "cookbooks/cookbook_a/attributes/default.rb") + expect(file_cache).to receive(:load) + .with("cookbooks/cookbook_a/attributes/default.rb", false) + .twice + .and_return("/file-cache/cookbooks/cookbook_a/attributes/default.rb") # Current file has fff000, want abc456 - expect(Chef::CookbookVersion).to receive(:checksum_cookbook_file). - with("/file-cache/cookbooks/cookbook_a/attributes/default.rb"). - and_return("fff000").at_least(:once) + expect(Chef::CookbookVersion).to receive(:checksum_cookbook_file) + .with("/file-cache/cookbooks/cookbook_a/attributes/default.rb") + .and_return("fff000").at_least(:once) end def setup_no_lazy_files_and_templates_chksum_mismatch_expectations # Files are in the cache: - expect(file_cache).to receive(:has_key?). - with("cookbooks/cookbook_a/files/default/megaman.conf"). - and_return(true) - expect(file_cache).to receive(:has_key?). - with("cookbooks/cookbook_a/templates/default/apache2.conf.erb"). - and_return(true) + expect(file_cache).to receive(:has_key?) + .with("cookbooks/cookbook_a/files/default/megaman.conf") + .and_return(true) + expect(file_cache).to receive(:has_key?) + .with("cookbooks/cookbook_a/templates/default/apache2.conf.erb") + .and_return(true) # Fetch and copy megaman.conf - expect(server_api).to receive(:streaming_request). - with("http://chef.example.com/megaman.conf"). - and_return(cookbook_a_file_default_tempfile) - expect(file_cache).to receive(:move_to). - with("/tmp/cookbook_a_file_default_tempfile", "cookbooks/cookbook_a/files/default/megaman.conf") - expect(file_cache).to receive(:load). - with("cookbooks/cookbook_a/files/default/megaman.conf", false). - twice. - and_return("/file-cache/cookbooks/cookbook_a/default/megaman.conf") + expect(server_api).to receive(:streaming_request) + .with("http://chef.example.com/megaman.conf") + .and_return(cookbook_a_file_default_tempfile) + expect(file_cache).to receive(:move_to) + .with("/tmp/cookbook_a_file_default_tempfile", "cookbooks/cookbook_a/files/default/megaman.conf") + expect(file_cache).to receive(:load) + .with("cookbooks/cookbook_a/files/default/megaman.conf", false) + .twice + .and_return("/file-cache/cookbooks/cookbook_a/default/megaman.conf") # Fetch and copy apache2.conf template - expect(server_api).to receive(:streaming_request). - with("http://chef.example.com/ffffff"). - and_return(cookbook_a_template_default_tempfile) - expect(file_cache).to receive(:move_to). - with("/tmp/cookbook_a_template_default_tempfile", "cookbooks/cookbook_a/templates/default/apache2.conf.erb") - expect(file_cache).to receive(:load). - with("cookbooks/cookbook_a/templates/default/apache2.conf.erb", false). - twice. - and_return("/file-cache/cookbooks/cookbook_a/templates/default/apache2.conf.erb") + expect(server_api).to receive(:streaming_request) + .with("http://chef.example.com/ffffff") + .and_return(cookbook_a_template_default_tempfile) + expect(file_cache).to receive(:move_to) + .with("/tmp/cookbook_a_template_default_tempfile", "cookbooks/cookbook_a/templates/default/apache2.conf.erb") + expect(file_cache).to receive(:load) + .with("cookbooks/cookbook_a/templates/default/apache2.conf.erb", false) + .twice + .and_return("/file-cache/cookbooks/cookbook_a/templates/default/apache2.conf.erb") # Current file has fff000 - expect(Chef::CookbookVersion).to receive(:checksum_cookbook_file). - with("/file-cache/cookbooks/cookbook_a/default/megaman.conf"). - and_return("fff000") + expect(Chef::CookbookVersion).to receive(:checksum_cookbook_file) + .with("/file-cache/cookbooks/cookbook_a/default/megaman.conf") + .and_return("fff000") # Current file has fff000 - expect(Chef::CookbookVersion).to receive(:checksum_cookbook_file). - with("/file-cache/cookbooks/cookbook_a/templates/default/apache2.conf.erb"). - and_return("fff000") + expect(Chef::CookbookVersion).to receive(:checksum_cookbook_file) + .with("/file-cache/cookbooks/cookbook_a/templates/default/apache2.conf.erb") + .and_return("fff000") end def setup_common_files_present_expectations # Files are in the cache: - expect(file_cache).to receive(:has_key?). - with("cookbooks/cookbook_a/recipes/default.rb"). - and_return(true) - expect(file_cache).to receive(:has_key?). - with("cookbooks/cookbook_a/attributes/default.rb"). - and_return(true) + expect(file_cache).to receive(:has_key?) + .with("cookbooks/cookbook_a/recipes/default.rb") + .and_return(true) + expect(file_cache).to receive(:has_key?) + .with("cookbooks/cookbook_a/attributes/default.rb") + .and_return(true) # Current file has abc123, want abc123 - expect(Chef::CookbookVersion).to receive(:checksum_cookbook_file). - with("/file-cache/cookbooks/cookbook_a/recipes/default.rb"). - and_return("abc123").at_least(:once) + expect(Chef::CookbookVersion).to receive(:checksum_cookbook_file) + .with("/file-cache/cookbooks/cookbook_a/recipes/default.rb") + .and_return("abc123").at_least(:once) # Current file has abc456, want abc456 - expect(Chef::CookbookVersion).to receive(:checksum_cookbook_file). - with("/file-cache/cookbooks/cookbook_a/attributes/default.rb"). - and_return("abc456").at_least(:once) + expect(Chef::CookbookVersion).to receive(:checksum_cookbook_file) + .with("/file-cache/cookbooks/cookbook_a/attributes/default.rb") + .and_return("abc456").at_least(:once) # :load called twice - expect(file_cache).to receive(:load). - with("cookbooks/cookbook_a/recipes/default.rb", false). - twice. - and_return("/file-cache/cookbooks/cookbook_a/recipes/default.rb") - expect(file_cache).to receive(:load). - with("cookbooks/cookbook_a/attributes/default.rb", false). - twice. - and_return("/file-cache/cookbooks/cookbook_a/attributes/default.rb") + expect(file_cache).to receive(:load) + .with("cookbooks/cookbook_a/recipes/default.rb", false) + .twice + .and_return("/file-cache/cookbooks/cookbook_a/recipes/default.rb") + expect(file_cache).to receive(:load) + .with("cookbooks/cookbook_a/attributes/default.rb", false) + .twice + .and_return("/file-cache/cookbooks/cookbook_a/attributes/default.rb") end def setup_no_lazy_files_and_templates_present_expectations # Files are in the cache: - expect(file_cache).to receive(:has_key?). - with("cookbooks/cookbook_a/files/default/megaman.conf"). - and_return(true) - expect(file_cache).to receive(:has_key?). - with("cookbooks/cookbook_a/templates/default/apache2.conf.erb"). - and_return(true) + expect(file_cache).to receive(:has_key?) + .with("cookbooks/cookbook_a/files/default/megaman.conf") + .and_return(true) + expect(file_cache).to receive(:has_key?) + .with("cookbooks/cookbook_a/templates/default/apache2.conf.erb") + .and_return(true) # Current file has abc124, want abc124 - expect(Chef::CookbookVersion).to receive(:checksum_cookbook_file). - with("/file-cache/cookbooks/cookbook_a/default/megaman.conf"). - and_return("abc124") + expect(Chef::CookbookVersion).to receive(:checksum_cookbook_file) + .with("/file-cache/cookbooks/cookbook_a/default/megaman.conf") + .and_return("abc124") # Current file has abc125, want abc125 - expect(Chef::CookbookVersion).to receive(:checksum_cookbook_file). - with("/file-cache/cookbooks/cookbook_a/templates/default/apache2.conf.erb"). - and_return("abc125") + expect(Chef::CookbookVersion).to receive(:checksum_cookbook_file) + .with("/file-cache/cookbooks/cookbook_a/templates/default/apache2.conf.erb") + .and_return("abc125") # :load called twice - expect(file_cache).to receive(:load). - with("cookbooks/cookbook_a/files/default/megaman.conf", false). - twice. - and_return("/file-cache/cookbooks/cookbook_a/default/megaman.conf") - expect(file_cache).to receive(:load). - with("cookbooks/cookbook_a/templates/default/apache2.conf.erb", false). - twice. - and_return("/file-cache/cookbooks/cookbook_a/templates/default/apache2.conf.erb") + expect(file_cache).to receive(:load) + .with("cookbooks/cookbook_a/files/default/megaman.conf", false) + .twice + .and_return("/file-cache/cookbooks/cookbook_a/default/megaman.conf") + expect(file_cache).to receive(:load) + .with("cookbooks/cookbook_a/templates/default/apache2.conf.erb", false) + .twice + .and_return("/file-cache/cookbooks/cookbook_a/templates/default/apache2.conf.erb") end describe "#server_api" do @@ -451,8 +451,8 @@ describe Chef::CookbookSynchronizer do it "does not fetch templates or cookbook files" do # Implicitly tested in previous test; this test is just for behavior specification. - expect(server_api).not_to receive(:streaming_request). - with("http://chef.example.com/ffffff") + expect(server_api).not_to receive(:streaming_request) + .with("http://chef.example.com/ffffff") synchronizer.sync_cookbooks end @@ -531,25 +531,25 @@ describe Chef::CookbookSynchronizer do let(:skip_cookbook_sync) { true } it "loads the cookbook files and warns the user that this isn't supported" do - expect(file_cache).to receive(:load). - with("cookbooks/cookbook_a/recipes/default.rb", false). - once. - and_return("/file-cache/cookbooks/cookbook_a/recipes/default.rb") - expect(file_cache).to receive(:load). - with("cookbooks/cookbook_a/attributes/default.rb", false). - once. - and_return("/file-cache/cookbooks/cookbook_a/attributes/default.rb") - expect(file_cache).to receive(:load). - with("cookbooks/cookbook_a/templates/default/apache2.conf.erb", false). - once. - and_return("/file-cache/cookbooks/cookbook_a/templates/default/apache2.conf.erb") - expect(file_cache).to receive(:load). - with("cookbooks/cookbook_a/files/default/megaman.conf", false). - once. - and_return("/file-cache/cookbooks/cookbook_a/files/default/megaman.conf") - expect(Chef::Log).to receive(:warn). - with("skipping cookbook synchronization! DO NOT LEAVE THIS ENABLED IN PRODUCTION!!!"). - once + expect(file_cache).to receive(:load) + .with("cookbooks/cookbook_a/recipes/default.rb", false) + .once + .and_return("/file-cache/cookbooks/cookbook_a/recipes/default.rb") + expect(file_cache).to receive(:load) + .with("cookbooks/cookbook_a/attributes/default.rb", false) + .once + .and_return("/file-cache/cookbooks/cookbook_a/attributes/default.rb") + expect(file_cache).to receive(:load) + .with("cookbooks/cookbook_a/templates/default/apache2.conf.erb", false) + .once + .and_return("/file-cache/cookbooks/cookbook_a/templates/default/apache2.conf.erb") + expect(file_cache).to receive(:load) + .with("cookbooks/cookbook_a/files/default/megaman.conf", false) + .once + .and_return("/file-cache/cookbooks/cookbook_a/files/default/megaman.conf") + expect(Chef::Log).to receive(:warn) + .with("skipping cookbook synchronization! DO NOT LEAVE THIS ENABLED IN PRODUCTION!!!") + .once synchronizer.sync_cookbooks end end diff --git a/spec/unit/cookbook_loader_spec.rb b/spec/unit/cookbook_loader_spec.rb index 8bc215360a..6553dad433 100644 --- a/spec/unit/cookbook_loader_spec.rb +++ b/spec/unit/cookbook_loader_spec.rb @@ -44,10 +44,10 @@ describe Chef::CookbookLoader do cookbook_paths.delete_if { |path| File.basename(path) == "chefignore" } cookbook_paths.each do |cookbook_path| - expect(Chef::Cookbook::CookbookVersionLoader).to receive(:new). - with(cookbook_path, anything). - once. - and_call_original + expect(Chef::Cookbook::CookbookVersionLoader).to receive(:new) + .with(cookbook_path, anything) + .once + .and_call_original end expect(Chef::Log).to receive(:deprecation).with(/The cookbook\(s\): openldap exist in multiple places in your cookbook_path./) cookbook_loader.load_cookbooks diff --git a/spec/unit/cookbook_uploader_spec.rb b/spec/unit/cookbook_uploader_spec.rb index 0c4fb6cda7..26e8d28454 100644 --- a/spec/unit/cookbook_uploader_spec.rb +++ b/spec/unit/cookbook_uploader_spec.rb @@ -85,9 +85,9 @@ describe Chef::CookbookUploader do end def expect_sandbox_create - expect(http_client).to receive(:post). - with("sandboxes", { checksums: checksums_set }). - and_return(sandbox_response) + expect(http_client).to receive(:post) + .with("sandboxes", { checksums: checksums_set }) + .and_return(sandbox_response) end def expect_checksum_upload @@ -100,8 +100,8 @@ describe Chef::CookbookUploader do "accept" => "application/json", } - expect(http_client).to receive(:put). - with(url_for(md5), IO.binread(file_path), upload_headers) + expect(http_client).to receive(:put) + .with(url_for(md5), IO.binread(file_path), upload_headers) end end @@ -117,8 +117,8 @@ describe Chef::CookbookUploader do def expect_cookbook_create cookbooks_to_upload.each do |cookbook| - expect(http_client).to receive(:put). - with(expected_save_url(cookbook), cookbook) + expect(http_client).to receive(:put) + .with(expected_save_url(cookbook), cookbook) end end diff --git a/spec/unit/file_content_management/deploy/mv_windows_spec.rb b/spec/unit/file_content_management/deploy/mv_windows_spec.rb index 456e7a2e3c..80155f131c 100644 --- a/spec/unit/file_content_management/deploy/mv_windows_spec.rb +++ b/spec/unit/file_content_management/deploy/mv_windows_spec.rb @@ -59,10 +59,10 @@ describe Chef::FileContentManagement::Deploy::MvWindows do end before do - allow(Chef::ReservedNames::Win32::Security::SecurableObject). - to receive(:new). - with(target_file_path). - and_return(target_file_security_object, updated_target_security_object) + allow(Chef::ReservedNames::Win32::Security::SecurableObject) + .to receive(:new) + .with(target_file_path) + .and_return(target_file_security_object, updated_target_security_object) end @@ -147,19 +147,19 @@ describe Chef::FileContentManagement::Deploy::MvWindows do allow(target_file_security_descriptor).to receive(:dacl_inherits?).and_return(false) allow(target_file_security_descriptor).to receive(:dacl).and_return(original_target_file_dacl) - expect(Chef::ReservedNames::Win32::Security::ACL). - to receive(:create). - with([]). - and_return(empty_dacl) + expect(Chef::ReservedNames::Win32::Security::ACL) + .to receive(:create) + .with([]) + .and_return(empty_dacl) allow(target_file_security_descriptor).to receive(:sacl_present?).and_return(true) allow(target_file_security_descriptor).to receive(:sacl_inherits?).and_return(false) allow(target_file_security_descriptor).to receive(:sacl).and_return(original_target_file_sacl) - expect(Chef::ReservedNames::Win32::Security::ACL). - to receive(:create). - with([]). - and_return(empty_sacl) + expect(Chef::ReservedNames::Win32::Security::ACL) + .to receive(:create) + .with([]) + .and_return(empty_sacl) expect(updated_target_security_object).to receive(:set_dacl).with(empty_dacl, false) expect(updated_target_security_object).to receive(:set_sacl).with(empty_sacl, false) @@ -188,19 +188,19 @@ describe Chef::FileContentManagement::Deploy::MvWindows do allow(target_file_security_descriptor).to receive(:dacl_inherits?).and_return(dacl_inherits?) allow(target_file_security_descriptor).to receive(:dacl).and_return(original_target_file_dacl) - expect(Chef::ReservedNames::Win32::Security::ACL). - to receive(:create). - with([not_inherited_dacl_ace]). - and_return(custom_dacl) + expect(Chef::ReservedNames::Win32::Security::ACL) + .to receive(:create) + .with([not_inherited_dacl_ace]) + .and_return(custom_dacl) allow(target_file_security_descriptor).to receive(:sacl_present?).and_return(true) allow(target_file_security_descriptor).to receive(:sacl_inherits?).and_return(sacl_inherits?) allow(target_file_security_descriptor).to receive(:sacl).and_return(original_target_file_sacl) - expect(Chef::ReservedNames::Win32::Security::ACL). - to receive(:create). - with([not_inherited_sacl_ace]). - and_return(custom_sacl) + expect(Chef::ReservedNames::Win32::Security::ACL) + .to receive(:create) + .with([not_inherited_sacl_ace]) + .and_return(custom_sacl) expect(updated_target_security_object).to receive(:set_dacl).with(custom_dacl, dacl_inherits?) expect(updated_target_security_object).to receive(:set_sacl).with(custom_sacl, sacl_inherits?) diff --git a/spec/unit/http/authenticator_spec.rb b/spec/unit/http/authenticator_spec.rb index 4502bb651c..4a919ad492 100644 --- a/spec/unit/http/authenticator_spec.rb +++ b/spec/unit/http/authenticator_spec.rb @@ -34,8 +34,8 @@ describe Chef::HTTP::Authenticator do it "merges the default version of X-Ops-Server-API-Version into the headers" do # headers returned - expect(class_instance.handle_request(method, url, headers, data)[2]). - to include({ "X-Ops-Server-API-Version" => Chef::HTTP::Authenticator::DEFAULT_SERVER_API_VERSION }) + expect(class_instance.handle_request(method, url, headers, data)[2]) + .to include({ "X-Ops-Server-API-Version" => Chef::HTTP::Authenticator::DEFAULT_SERVER_API_VERSION }) end context "when version_class is provided" do @@ -53,8 +53,8 @@ describe Chef::HTTP::Authenticator do it "uses it to select the correct http version" do Chef::ServerAPIVersions.instance.reset! expect(AuthFactoryClass).to receive(:best_request_version).and_call_original - expect(class_instance.handle_request(method, url, headers, data)[2]). - to include({ "X-Ops-Server-API-Version" => "2" }) + expect(class_instance.handle_request(method, url, headers, data)[2]) + .to include({ "X-Ops-Server-API-Version" => "2" }) end end @@ -62,8 +62,8 @@ describe Chef::HTTP::Authenticator do let(:class_instance) { Chef::HTTP::Authenticator.new({ api_version: "-10" }) } it "merges the requested version of X-Ops-Server-API-Version into the headers" do - expect(class_instance.handle_request(method, url, headers, data)[2]). - to include({ "X-Ops-Server-API-Version" => "-10" }) + expect(class_instance.handle_request(method, url, headers, data)[2]) + .to include({ "X-Ops-Server-API-Version" => "-10" }) end end end diff --git a/spec/unit/knife/configure_client_spec.rb b/spec/unit/knife/configure_client_spec.rb index 0f83897564..c83ceed6cb 100644 --- a/spec/unit/knife/configure_client_spec.rb +++ b/spec/unit/knife/configure_client_spec.rb @@ -43,10 +43,10 @@ describe Chef::Knife::ConfigureClient do @knife.name_args = ["/home/bob/.chef"] @client_file = StringIO.new @validation_file = StringIO.new - expect(File).to receive(:open).with("/home/bob/.chef/client.rb", "w"). - and_yield(@client_file) - expect(File).to receive(:open).with("/home/bob/.chef/validation.pem", "w"). - and_yield(@validation_file) + expect(File).to receive(:open).with("/home/bob/.chef/client.rb", "w") + .and_yield(@client_file) + expect(File).to receive(:open).with("/home/bob/.chef/validation.pem", "w") + .and_yield(@validation_file) expect(IO).to receive(:read).and_return("foo_bar_baz") end diff --git a/spec/unit/knife/cookbook_delete_spec.rb b/spec/unit/knife/cookbook_delete_spec.rb index 9bf4c81a73..7277b63c28 100644 --- a/spec/unit/knife/cookbook_delete_spec.rb +++ b/spec/unit/knife/cookbook_delete_spec.rb @@ -62,8 +62,8 @@ describe Chef::Knife::CookbookDelete do describe "with -p or --purge" do it "should prompt to purge the files" do @knife.config[:purge] = true - expect(@knife).to receive(:confirm). - with(/.+Are you sure you want to purge files.+/) + expect(@knife).to receive(:confirm) + .with(/.+Are you sure you want to purge files.+/) expect(@knife).to receive(:delete_without_explicit_version) @knife.run end @@ -146,8 +146,8 @@ describe Chef::Knife::CookbookDelete do describe "if the cookbook can't be found" do before(:each) do - expect(@rest_mock).to receive(:get). - and_raise(Net::HTTPServerException.new("404 Not Found", "404")) + expect(@rest_mock).to receive(:get) + .and_raise(Net::HTTPServerException.new("404 Not Found", "404")) end it "should print an error" do diff --git a/spec/unit/knife/cookbook_download_spec.rb b/spec/unit/knife/cookbook_download_spec.rb index af0b839cd6..122c284b93 100644 --- a/spec/unit/knife/cookbook_download_spec.rb +++ b/spec/unit/knife/cookbook_download_spec.rb @@ -47,8 +47,8 @@ describe Chef::Knife::CookbookDownload do @rest_mock = double("rest") allow(@knife).to receive(:rest).and_return(@rest_mock) - expect(Chef::CookbookVersion).to receive(:load).with("foobar", "1.0.0"). - and_return(cookbook) + expect(Chef::CookbookVersion).to receive(:load).with("foobar", "1.0.0") + .and_return(cookbook) end let(:manifest_data) do @@ -119,18 +119,18 @@ describe Chef::Knife::CookbookDownload do describe "when downloading the cookbook" do before(:each) do @files.map { |f| File.dirname(f) }.flatten.uniq.each do |dir| - expect(FileUtils).to receive(:mkdir_p).with("/var/tmp/chef/foobar-1.0.0/#{dir}"). - at_least(:once) + expect(FileUtils).to receive(:mkdir_p).with("/var/tmp/chef/foobar-1.0.0/#{dir}") + .at_least(:once) end @files_mocks.each_pair do |file, mock| - expect(@rest_mock).to receive(:streaming_request).with("http://example.org/files/#{file}"). - and_return(mock) + expect(@rest_mock).to receive(:streaming_request).with("http://example.org/files/#{file}") + .and_return(mock) end @files.each do |f| - expect(FileUtils).to receive(:mv). - with("/var/tmp/#{File.basename(f)}", "/var/tmp/chef/foobar-1.0.0/#{f}") + expect(FileUtils).to receive(:mv) + .with("/var/tmp/#{File.basename(f)}", "/var/tmp/chef/foobar-1.0.0/#{f}") end end @@ -182,8 +182,8 @@ describe Chef::Knife::CookbookDownload do describe "with -N or --latest" do it "should return and set the version to the latest version" do @knife.config[:latest] = true - expect(@knife).to receive(:available_versions).at_least(:once). - and_return(["1.0.0", "1.1.0", "2.0.0"]) + expect(@knife).to receive(:available_versions).at_least(:once) + .and_return(["1.0.0", "1.1.0", "2.0.0"]) @knife.determine_version expect(@knife.version.to_s).to eq("2.0.0") end @@ -196,26 +196,26 @@ describe Chef::Knife::CookbookDownload do end it "should return nil if there are no versions" do - expect(Chef::CookbookVersion).to receive(:available_versions). - with("foobar"). - and_return(nil) + expect(Chef::CookbookVersion).to receive(:available_versions) + .with("foobar") + .and_return(nil) expect(@knife.available_versions).to eq(nil) end it "should return the available versions" do - expect(Chef::CookbookVersion).to receive(:available_versions). - with("foobar"). - and_return(["1.1.0", "2.0.0", "1.0.0"]) + expect(Chef::CookbookVersion).to receive(:available_versions) + .with("foobar") + .and_return(["1.1.0", "2.0.0", "1.0.0"]) expect(@knife.available_versions).to eq([Chef::Version.new("1.0.0"), Chef::Version.new("1.1.0"), Chef::Version.new("2.0.0")]) end it "should avoid multiple API calls to the server" do - expect(Chef::CookbookVersion).to receive(:available_versions). - once. - with("foobar"). - and_return(["1.1.0", "2.0.0", "1.0.0"]) + expect(Chef::CookbookVersion).to receive(:available_versions) + .once + .with("foobar") + .and_return(["1.1.0", "2.0.0", "1.0.0"]) @knife.available_versions @knife.available_versions end diff --git a/spec/unit/knife/cookbook_list_spec.rb b/spec/unit/knife/cookbook_list_spec.rb index fce6bc9593..e34b58b672 100644 --- a/spec/unit/knife/cookbook_list_spec.rb +++ b/spec/unit/knife/cookbook_list_spec.rb @@ -37,8 +37,8 @@ describe Chef::Knife::CookbookList do describe "run" do it "should display the latest version of the cookbooks" do - expect(@rest_mock).to receive(:get).with("/cookbooks?num_versions=1"). - and_return(@cookbook_data) + expect(@rest_mock).to receive(:get).with("/cookbooks?num_versions=1") + .and_return(@cookbook_data) @knife.run @cookbook_names.each do |item| expect(@stdout.string).to match /#{item}\s+1\.0\.1/ @@ -47,9 +47,9 @@ describe Chef::Knife::CookbookList do it "should query cookbooks for the configured environment" do @knife.config[:environment] = "production" - expect(@rest_mock).to receive(:get). - with("/environments/production/cookbooks?num_versions=1"). - and_return(@cookbook_data) + expect(@rest_mock).to receive(:get) + .with("/environments/production/cookbooks?num_versions=1") + .and_return(@cookbook_data) @knife.run end @@ -75,8 +75,8 @@ describe Chef::Knife::CookbookList do it "should display all versions of the cookbooks" do @knife.config[:all_versions] = true - expect(@rest_mock).to receive(:get).with("/cookbooks?num_versions=all"). - and_return(@cookbook_data) + expect(@rest_mock).to receive(:get).with("/cookbooks?num_versions=all") + .and_return(@cookbook_data) @knife.run @cookbook_names.each do |item| expect(@stdout.string).to match /#{item}\s+1\.0\.1\s+1\.0\.0/ diff --git a/spec/unit/knife/cookbook_site_download_spec.rb b/spec/unit/knife/cookbook_site_download_spec.rb index 0e2798f374..9bf10859c0 100644 --- a/spec/unit/knife/cookbook_site_download_spec.rb +++ b/spec/unit/knife/cookbook_site_download_spec.rb @@ -35,9 +35,9 @@ describe Chef::Knife::CookbookSiteDownload do allow(@knife.ui).to receive(:stderr).and_return(@stderr) allow(@knife).to receive(:noauth_rest).and_return(@noauth_rest) - expect(@noauth_rest).to receive(:get). - with("#{@cookbook_api_url}/apache2"). - and_return(@current_data) + expect(@noauth_rest).to receive(:get) + .with("#{@cookbook_api_url}/apache2") + .and_return(@current_data) @knife.configure_chef end @@ -47,10 +47,10 @@ describe Chef::Knife::CookbookSiteDownload do end it "should warn with info about the replacement" do - expect(@knife.ui).to receive(:warn). - with(/.+deprecated.+replaced by other_apache2.+/i) - expect(@knife.ui).to receive(:warn). - with(/use --force.+download.+/i) + expect(@knife.ui).to receive(:warn) + .with(/.+deprecated.+replaced by other_apache2.+/i) + expect(@knife.ui).to receive(:warn) + .with(/use --force.+download.+/i) @knife.run end end @@ -65,12 +65,12 @@ describe Chef::Knife::CookbookSiteDownload do context "downloading the latest version" do before do - expect(@noauth_rest).to receive(:get). - with(@current_data["latest_version"]). - and_return(@cookbook_data) - expect(@noauth_rest).to receive(:streaming_request). - with(@cookbook_data["file"]). - and_return(@temp_file) + expect(@noauth_rest).to receive(:get) + .with(@current_data["latest_version"]) + .and_return(@cookbook_data) + expect(@noauth_rest).to receive(:streaming_request) + .with(@cookbook_data["file"]) + .and_return(@temp_file) end context "and it is deprecated and with --force" do @@ -80,8 +80,8 @@ describe Chef::Knife::CookbookSiteDownload do end it "should download the latest version" do - expect(@knife.ui).to receive(:warn). - with(/.+deprecated.+replaced by other_apache2.+/i) + expect(@knife.ui).to receive(:warn) + .with(/.+deprecated.+replaced by other_apache2.+/i) expect(FileUtils).to receive(:cp).with(@temp_file.path, @file) @knife.run expect(@stderr.string).to match /downloading apache2.+version.+#{Regexp.escape(@version)}/i @@ -130,12 +130,12 @@ describe Chef::Knife::CookbookSiteDownload do end it "should download the desired version" do - expect(@noauth_rest).to receive(:get). - with("#{@cookbook_api_url}/apache2/versions/#{@version_us}"). - and_return(@cookbook_data) - expect(@noauth_rest).to receive(:streaming_request). - with(@cookbook_data["file"]). - and_return(@temp_file) + expect(@noauth_rest).to receive(:get) + .with("#{@cookbook_api_url}/apache2/versions/#{@version_us}") + .and_return(@cookbook_data) + expect(@noauth_rest).to receive(:streaming_request) + .with(@cookbook_data["file"]) + .and_return(@temp_file) expect(FileUtils).to receive(:cp).with(@temp_file.path, @file) @knife.run expect(@stderr.string).to match /downloading apache2.+version.+#{Regexp.escape(@version)}/i diff --git a/spec/unit/knife/cookbook_upload_spec.rb b/spec/unit/knife/cookbook_upload_spec.rb index 7f890534bc..3110ba7496 100644 --- a/spec/unit/knife/cookbook_upload_spec.rb +++ b/spec/unit/knife/cookbook_upload_spec.rb @@ -61,9 +61,9 @@ describe Chef::Knife::CookbookUpload do test_cookbook = Chef::CookbookVersion.new("test_cookbook", "/tmp/blah") allow(cookbook_loader).to receive(:each).and_yield("test_cookbook", test_cookbook) allow(cookbook_loader).to receive(:cookbook_names).and_return(["test_cookbook"]) - expect(Chef::CookbookUploader).to receive(:new). - with( kind_of(Array), { force: nil, concurrency: 3 }). - and_return(double("Chef::CookbookUploader", upload_cookbooks: true)) + expect(Chef::CookbookUploader).to receive(:new) + .with( kind_of(Array), { force: nil, concurrency: 3 }) + .and_return(double("Chef::CookbookUploader", upload_cookbooks: true)) knife.run end end @@ -106,8 +106,8 @@ describe Chef::Knife::CookbookUpload do before do allow(cookbook_loader).to receive(:merged_cookbooks).and_return(["test_cookbook"]) - allow(cookbook_loader).to receive(:merged_cookbook_paths). - and_return({ "test_cookbook" => %w{/path/one/test_cookbook /path/two/test_cookbook} }) + allow(cookbook_loader).to receive(:merged_cookbook_paths) + .and_return({ "test_cookbook" => %w{/path/one/test_cookbook /path/two/test_cookbook} }) end it "emits a warning" do @@ -310,8 +310,8 @@ E describe "when a frozen cookbook exists on the server" do it "should fail to replace it" do exception = Chef::Exceptions::CookbookFrozen.new - expect(cookbook_uploader).to receive(:upload_cookbooks). - and_raise(exception) + expect(cookbook_uploader).to receive(:upload_cookbooks) + .and_raise(exception) allow(knife.ui).to receive(:error) expect(knife.ui).to receive(:error).with(exception) expect { knife.run }.to raise_error(SystemExit) diff --git a/spec/unit/knife/key_create_spec.rb b/spec/unit/knife/key_create_spec.rb index 5b00c6ea31..2d882b87e0 100644 --- a/spec/unit/knife/key_create_spec.rb +++ b/spec/unit/knife/key_create_spec.rb @@ -44,9 +44,9 @@ describe "key create commands that inherit knife" do context "when the service object is called" do it "creates a new instance of Chef::Knife::KeyCreate with the correct args" do - expect(Chef::Knife::KeyCreate).to receive(:new). - with("charmander", command.actor_field_name, command.ui, command.config). - and_return(service_object) + expect(Chef::Knife::KeyCreate).to receive(:new) + .with("charmander", command.actor_field_name, command.ui, command.config) + .and_return(service_object) command.service_object end end # when the service object is called diff --git a/spec/unit/knife/key_delete_spec.rb b/spec/unit/knife/key_delete_spec.rb index 0176f3c71e..87969198dc 100644 --- a/spec/unit/knife/key_delete_spec.rb +++ b/spec/unit/knife/key_delete_spec.rb @@ -44,9 +44,9 @@ describe "key delete commands that inherit knife" do context "when the service object is called" do it "creates a new instance of Chef::Knife::KeyDelete with the correct args" do - expect(Chef::Knife::KeyDelete).to receive(:new). - with("charmander-key", "charmander", command.actor_field_name, command.ui). - and_return(service_object) + expect(Chef::Knife::KeyDelete).to receive(:new) + .with("charmander-key", "charmander", command.actor_field_name, command.ui) + .and_return(service_object) command.service_object end end # when the service object is called diff --git a/spec/unit/knife/key_edit_spec.rb b/spec/unit/knife/key_edit_spec.rb index 244d8bdcc7..1650386da6 100644 --- a/spec/unit/knife/key_edit_spec.rb +++ b/spec/unit/knife/key_edit_spec.rb @@ -44,9 +44,9 @@ describe "key edit commands that inherit knife" do context "when the service object is called" do it "creates a new instance of Chef::Knife::KeyEdit with the correct args" do - expect(Chef::Knife::KeyEdit).to receive(:new). - with("charmander-key", "charmander", command.actor_field_name, command.ui, command.config). - and_return(service_object) + expect(Chef::Knife::KeyEdit).to receive(:new) + .with("charmander-key", "charmander", command.actor_field_name, command.ui, command.config) + .and_return(service_object) command.service_object end end # when the service object is called diff --git a/spec/unit/knife/key_list_spec.rb b/spec/unit/knife/key_list_spec.rb index 82fd1e4a09..e221a4da72 100644 --- a/spec/unit/knife/key_list_spec.rb +++ b/spec/unit/knife/key_list_spec.rb @@ -44,9 +44,9 @@ describe "key list commands that inherit knife" do context "when the service object is called" do it "creates a new instance of Chef::Knife::KeyList with the correct args" do - expect(Chef::Knife::KeyList).to receive(:new). - with("charmander", command.list_method, command.ui, command.config). - and_return(service_object) + expect(Chef::Knife::KeyList).to receive(:new) + .with("charmander", command.list_method, command.ui, command.config) + .and_return(service_object) command.service_object end end # when the service object is called diff --git a/spec/unit/knife/key_show_spec.rb b/spec/unit/knife/key_show_spec.rb index 139d4f91a2..f2eb244b23 100644 --- a/spec/unit/knife/key_show_spec.rb +++ b/spec/unit/knife/key_show_spec.rb @@ -44,9 +44,9 @@ describe "key show commands that inherit knife" do context "when the service object is called" do it "creates a new instance of Chef::Knife::KeyShow with the correct args" do - expect(Chef::Knife::KeyShow).to receive(:new). - with("charmander-key", "charmander", command.load_method, command.ui). - and_return(service_object) + expect(Chef::Knife::KeyShow).to receive(:new) + .with("charmander-key", "charmander", command.load_method, command.ui) + .and_return(service_object) command.service_object end end # when the service object is called diff --git a/spec/unit/knife/ssh_spec.rb b/spec/unit/knife/ssh_spec.rb index ec345d5aff..9cefcba84f 100644 --- a/spec/unit/knife/ssh_spec.rb +++ b/spec/unit/knife/ssh_spec.rb @@ -290,28 +290,28 @@ describe Chef::Knife::Ssh do let(:command) { "false" } before do - expect(execution_channel). - to receive(:on_request). - and_yield(nil, double(:data_stream, read_long: exit_status)) - - expect(session_channel). - to receive(:exec). - with(command). - and_yield(execution_channel, true) - - expect(execution_channel2). - to receive(:on_request). - and_yield(nil, double(:data_stream, read_long: exit_status2)) - - expect(session_channel2). - to receive(:exec). - with(command). - and_yield(execution_channel2, true) - - expect(session). - to receive(:open_channel). - and_yield(session_channel). - and_yield(session_channel2) + expect(execution_channel) + .to receive(:on_request) + .and_yield(nil, double(:data_stream, read_long: exit_status)) + + expect(session_channel) + .to receive(:exec) + .with(command) + .and_yield(execution_channel, true) + + expect(execution_channel2) + .to receive(:on_request) + .and_yield(nil, double(:data_stream, read_long: exit_status2)) + + expect(session_channel2) + .to receive(:exec) + .with(command) + .and_yield(execution_channel2, true) + + expect(session) + .to receive(:open_channel) + .and_yield(session_channel) + .and_yield(session_channel2) end context "both connections return 0" do diff --git a/spec/unit/knife/ssl_check_spec.rb b/spec/unit/knife/ssl_check_spec.rb index 9f0c191323..a25c8b759c 100644 --- a/spec/unit/knife/ssl_check_spec.rb +++ b/spec/unit/knife/ssl_check_spec.rb @@ -199,12 +199,12 @@ E before do @old_signal = trap(:INT, "DEFAULT") - expect(ssl_check).to receive(:proxified_socket). - with("foo.example.com", 8443). - and_return(tcp_socket_for_debug) - expect(OpenSSL::SSL::SSLSocket).to receive(:new). - with(tcp_socket_for_debug, ssl_check.noverify_peer_ssl_context). - and_return(ssl_socket_for_debug) + expect(ssl_check).to receive(:proxified_socket) + .with("foo.example.com", 8443) + .and_return(tcp_socket_for_debug) + expect(OpenSSL::SSL::SSLSocket).to receive(:new) + .with(tcp_socket_for_debug, ssl_check.noverify_peer_ssl_context) + .and_return(ssl_socket_for_debug) end after do @@ -215,9 +215,9 @@ E before do expect(ssl_check).to receive(:verify_X509).and_return(true) # X509 valid certs expect(ssl_socket).to receive(:connect) # no error - expect(ssl_socket).to receive(:post_connection_check). - with("foo.example.com"). - and_raise(OpenSSL::SSL::SSLError) + expect(ssl_socket).to receive(:post_connection_check) + .with("foo.example.com") + .and_raise(OpenSSL::SSL::SSLError) expect(ssl_socket).to receive(:hostname=).with("foo.example.com") # no error expect(ssl_socket_for_debug).to receive(:connect) expect(ssl_socket_for_debug).to receive(:peer_cert).and_return(self_signed_crt) @@ -235,10 +235,10 @@ E context "when the cert is not signed by any trusted authority" do before do expect(ssl_check).to receive(:verify_X509).and_return(true) # X509 valid certs - expect(ssl_socket).to receive(:connect). - and_raise(OpenSSL::SSL::SSLError) - expect(ssl_socket).to receive(:hostname=). - with("foo.example.com") # no error + expect(ssl_socket).to receive(:connect) + .and_raise(OpenSSL::SSL::SSLError) + expect(ssl_socket).to receive(:hostname=) + .with("foo.example.com") # no error expect(ssl_socket_for_debug).to receive(:connect) expect(ssl_socket_for_debug).to receive(:peer_cert).and_return(self_signed_crt) end diff --git a/spec/unit/mixin/api_version_request_handling_spec.rb b/spec/unit/mixin/api_version_request_handling_spec.rb index 5cbad7efa0..cabc85439c 100644 --- a/spec/unit/mixin/api_version_request_handling_spec.rb +++ b/spec/unit/mixin/api_version_request_handling_spec.rb @@ -30,8 +30,8 @@ describe Chef::Mixin::ApiVersionRequestHandling do let(:exception) { Net::HTTPServerException.new("405 Something Else", response) } it "returns nil" do - expect(object.server_client_api_version_intersection(exception, default_supported_client_versions)). - to be_nil + expect(object.server_client_api_version_intersection(exception, default_supported_client_versions)) + .to be_nil end end # when the response code is not 406 @@ -42,8 +42,8 @@ describe Chef::Mixin::ApiVersionRequestHandling do context "when x-ops-server-api-version header does not exist" do it "returns nil" do - expect(object.server_client_api_version_intersection(exception, default_supported_client_versions)). - to be_nil + expect(object.server_client_api_version_intersection(exception, default_supported_client_versions)) + .to be_nil end end # when x-ops-server-api-version header does not exist @@ -64,13 +64,13 @@ describe Chef::Mixin::ApiVersionRequestHandling do context "when there is no intersection between client and server versions" do shared_examples_for "no intersection between client and server versions" do it "return an array" do - expect(object.server_client_api_version_intersection(exception, supported_client_versions)). - to be_a_kind_of(Array) + expect(object.server_client_api_version_intersection(exception, supported_client_versions)) + .to be_a_kind_of(Array) end it "returns an empty array" do - expect(object.server_client_api_version_intersection(exception, supported_client_versions).length). - to eq(0) + expect(object.server_client_api_version_intersection(exception, supported_client_versions).length) + .to eq(0) end end @@ -94,8 +94,8 @@ describe Chef::Mixin::ApiVersionRequestHandling do let(:supported_client_versions) { [1, 2, 3, 4, 5] } it "includes all of the intersection" do - expect(object.server_client_api_version_intersection(exception, supported_client_versions)). - to eq([2, 3, 4]) + expect(object.server_client_api_version_intersection(exception, supported_client_versions)) + .to eq([2, 3, 4]) end end # when multiple versions intersect @@ -103,8 +103,8 @@ describe Chef::Mixin::ApiVersionRequestHandling do let(:supported_client_versions) { [0, 1, 2] } it "includes the intersection" do - expect(object.server_client_api_version_intersection(exception, supported_client_versions)). - to eq([2]) + expect(object.server_client_api_version_intersection(exception, supported_client_versions)) + .to eq([2]) end end # when only the min client version intersects @@ -112,8 +112,8 @@ describe Chef::Mixin::ApiVersionRequestHandling do let(:supported_client_versions) { [4, 5, 6] } it "includes the intersection" do - expect(object.server_client_api_version_intersection(exception, supported_client_versions)). - to eq([4]) + expect(object.server_client_api_version_intersection(exception, supported_client_versions)) + .to eq([4]) end end # when only the max client version intersects diff --git a/spec/unit/platform/query_helpers_spec.rb b/spec/unit/platform/query_helpers_spec.rb index ac5158e913..82ed4de9c6 100644 --- a/spec/unit/platform/query_helpers_spec.rb +++ b/spec/unit/platform/query_helpers_spec.rb @@ -51,9 +51,9 @@ describe "Chef::Platform#windows_nano_server?" do it "returns true when the registry value is 1" do allow(ChefConfig).to receive(:windows?).and_return(true) allow(Chef::Platform).to receive(:require).with("win32/registry") - expect(Win32::Registry::HKEY_LOCAL_MACHINE).to receive(:open). - with(key, access). - and_yield(registry) + expect(Win32::Registry::HKEY_LOCAL_MACHINE).to receive(:open) + .with(key, access) + .and_yield(registry) expect(registry).to receive(:[]).with("NanoServer").and_return(1) expect(Chef::Platform.windows_nano_server?).to be true end @@ -61,9 +61,9 @@ describe "Chef::Platform#windows_nano_server?" do it "returns false when the registry value is not 1" do allow(ChefConfig).to receive(:windows?).and_return(true) allow(Chef::Platform).to receive(:require).with("win32/registry") - expect(Win32::Registry::HKEY_LOCAL_MACHINE).to receive(:open). - with(key, access). - and_yield(registry) + expect(Win32::Registry::HKEY_LOCAL_MACHINE).to receive(:open) + .with(key, access) + .and_yield(registry) expect(registry).to receive(:[]).with("NanoServer").and_return(0) expect(Chef::Platform.windows_nano_server?).to be false end @@ -71,20 +71,20 @@ describe "Chef::Platform#windows_nano_server?" do it "returns false when the registry value does not exist" do allow(ChefConfig).to receive(:windows?).and_return(true) allow(Chef::Platform).to receive(:require).with("win32/registry") - expect(Win32::Registry::HKEY_LOCAL_MACHINE).to receive(:open). - with(key, access). - and_yield(registry) - expect(registry).to receive(:[]).with("NanoServer"). - and_raise(Win32::Registry::Error, "The system cannot find the file specified.") + expect(Win32::Registry::HKEY_LOCAL_MACHINE).to receive(:open) + .with(key, access) + .and_yield(registry) + expect(registry).to receive(:[]).with("NanoServer") + .and_raise(Win32::Registry::Error, "The system cannot find the file specified.") expect(Chef::Platform.windows_nano_server?).to be false end it "returns false when the registry key does not exist" do allow(ChefConfig).to receive(:windows?).and_return(true) allow(Chef::Platform).to receive(:require).with("win32/registry") - expect(Win32::Registry::HKEY_LOCAL_MACHINE).to receive(:open). - with(key, access). - and_raise(Win32::Registry::Error, "The system cannot find the file specified.") + expect(Win32::Registry::HKEY_LOCAL_MACHINE).to receive(:open) + .with(key, access) + .and_raise(Win32::Registry::Error, "The system cannot find the file specified.") expect(Chef::Platform.windows_nano_server?).to be false end end @@ -122,18 +122,18 @@ describe "Chef::Platform#supports_msi?" do it "returns true when the registry key exists" do allow(ChefConfig).to receive(:windows?).and_return(true) allow(Chef::Platform).to receive(:require).with("win32/registry") - expect(Win32::Registry::HKEY_LOCAL_MACHINE).to receive(:open). - with(key, access). - and_yield(registry) + expect(Win32::Registry::HKEY_LOCAL_MACHINE).to receive(:open) + .with(key, access) + .and_yield(registry) expect(Chef::Platform.supports_msi?).to be true end it "returns false when the registry key does not exist" do allow(ChefConfig).to receive(:windows?).and_return(true) allow(Chef::Platform).to receive(:require).with("win32/registry") - expect(Win32::Registry::HKEY_LOCAL_MACHINE).to receive(:open). - with(key, access). - and_raise(Win32::Registry::Error, "The system cannot find the file specified.") + expect(Win32::Registry::HKEY_LOCAL_MACHINE).to receive(:open) + .with(key, access) + .and_raise(Win32::Registry::Error, "The system cannot find the file specified.") expect(Chef::Platform.supports_msi?).to be false end end @@ -188,18 +188,18 @@ describe "Chef::Platform#dsc_refresh_mode_disabled?" do let(:cmdlet_result) { instance_double("Chef::Util::Powershell::CmdletResult") } it "returns true when RefreshMode is Disabled" do - expect(Chef::Util::Powershell::Cmdlet).to receive(:new). - with(node, "Get-DscLocalConfigurationManager", :object). - and_return(cmdlet) + expect(Chef::Util::Powershell::Cmdlet).to receive(:new) + .with(node, "Get-DscLocalConfigurationManager", :object) + .and_return(cmdlet) expect(cmdlet).to receive(:run!).and_return(cmdlet_result) expect(cmdlet_result).to receive(:return_value).and_return({ "RefreshMode" => "Disabled" }) expect(Chef::Platform.dsc_refresh_mode_disabled?(node)).to be true end it "returns false when RefreshMode is not Disabled" do - expect(Chef::Util::Powershell::Cmdlet).to receive(:new). - with(node, "Get-DscLocalConfigurationManager", :object). - and_return(cmdlet) + expect(Chef::Util::Powershell::Cmdlet).to receive(:new) + .with(node, "Get-DscLocalConfigurationManager", :object) + .and_return(cmdlet) expect(cmdlet).to receive(:run!).and_return(cmdlet_result) expect(cmdlet_result).to receive(:return_value).and_return({ "RefreshMode" => "LaLaLa" }) expect(Chef::Platform.dsc_refresh_mode_disabled?(node)).to be false diff --git a/spec/unit/policy_builder/policyfile_spec.rb b/spec/unit/policy_builder/policyfile_spec.rb index 260b99c89c..ab2fdecfe7 100644 --- a/spec/unit/policy_builder/policyfile_spec.rb +++ b/spec/unit/policy_builder/policyfile_spec.rb @@ -221,9 +221,9 @@ describe Chef::PolicyBuilder::Policyfile do let(:error404) { Net::HTTPServerException.new("404 message", :body) } before do - expect(api_service).to receive(:get). - with("data/policyfiles/example-policy-stage"). - and_raise(error404) + expect(api_service).to receive(:get) + .with("data/policyfiles/example-policy-stage") + .and_raise(error404) end it "raises an error" do @@ -744,8 +744,8 @@ describe Chef::PolicyBuilder::Policyfile do policy_builder.finish_load_node(node) policy_builder.build_node - expect(api_service).to receive(:get).with(cookbook1_url). - and_raise(error404) + expect(api_service).to receive(:get).with(cookbook1_url) + .and_raise(error404) end it "raises an error indicating which cookbook is missing" do @@ -763,9 +763,9 @@ describe Chef::PolicyBuilder::Policyfile do policy_builder.finish_load_node(node) policy_builder.build_node - allow(Chef::CookbookSynchronizer).to receive(:new). - with(expected_cookbook_hash, events). - and_return(cookbook_synchronizer) + allow(Chef::CookbookSynchronizer).to receive(:new) + .with(expected_cookbook_hash, events) + .and_return(cookbook_synchronizer) end after do @@ -814,15 +814,15 @@ describe Chef::PolicyBuilder::Policyfile do context "when the cookbooks exist on the server" do before do - expect(api_service).to receive(:get).with(cookbook1_url). - and_return(example1_cookbook_data) - expect(api_service).to receive(:get).with(cookbook2_url). - and_return(example2_cookbook_data) + expect(api_service).to receive(:get).with(cookbook1_url) + .and_return(example1_cookbook_data) + expect(api_service).to receive(:get).with(cookbook2_url) + .and_return(example2_cookbook_data) - expect(Chef::CookbookVersion).to receive(:from_cb_artifact_data).with(example1_cookbook_data). - and_return(example1_cookbook_object) - expect(Chef::CookbookVersion).to receive(:from_cb_artifact_data).with(example2_cookbook_data). - and_return(example2_cookbook_object) + expect(Chef::CookbookVersion).to receive(:from_cb_artifact_data).with(example1_cookbook_data) + .and_return(example1_cookbook_object) + expect(Chef::CookbookVersion).to receive(:from_cb_artifact_data).with(example2_cookbook_data) + .and_return(example2_cookbook_object) end include_examples "fetching cookbooks when they exist" @@ -847,15 +847,15 @@ describe Chef::PolicyBuilder::Policyfile do context "when the cookbooks exist on the server" do before do - expect(api_service).to receive(:get).with(cookbook1_url). - and_return(example1_cookbook_data) - expect(api_service).to receive(:get).with(cookbook2_url). - and_return(example2_cookbook_data) - - expect(Chef::CookbookVersion).to receive(:from_cb_artifact_data).with(example1_cookbook_data). - and_return(example1_cookbook_object) - expect(Chef::CookbookVersion).to receive(:from_cb_artifact_data).with(example2_cookbook_data). - and_return(example2_cookbook_object) + expect(api_service).to receive(:get).with(cookbook1_url) + .and_return(example1_cookbook_data) + expect(api_service).to receive(:get).with(cookbook2_url) + .and_return(example2_cookbook_data) + + expect(Chef::CookbookVersion).to receive(:from_cb_artifact_data).with(example1_cookbook_data) + .and_return(example1_cookbook_object) + expect(Chef::CookbookVersion).to receive(:from_cb_artifact_data).with(example2_cookbook_data) + .and_return(example2_cookbook_object) end include_examples "fetching cookbooks when they exist" diff --git a/spec/unit/provider/dsc_resource_spec.rb b/spec/unit/provider/dsc_resource_spec.rb index ab675c4ddd..411dc50cc9 100644 --- a/spec/unit/provider/dsc_resource_spec.rb +++ b/spec/unit/provider/dsc_resource_spec.rb @@ -103,8 +103,8 @@ describe Chef::Provider::DscResource do it "flags the resource as reboot required when required" do expect(provider).to receive(:test_resource).and_return(false) - expect(provider).to receive(:invoke_resource). - and_return(double(stdout: "", return_value: nil)) + expect(provider).to receive(:invoke_resource) + .and_return(double(stdout: "", return_value: nil)) expect(provider).to receive(:add_dsc_verbose_log) expect(provider).to receive(:return_dsc_resource_result).and_return(true) expect(provider).to receive(:create_reboot_resource) @@ -113,8 +113,8 @@ describe Chef::Provider::DscResource do it "does not flag the resource as reboot required when not required" do expect(provider).to receive(:test_resource).and_return(false) - expect(provider).to receive(:invoke_resource). - and_return(double(stdout: "", return_value: nil)) + expect(provider).to receive(:invoke_resource) + .and_return(double(stdout: "", return_value: nil)) expect(provider).to receive(:add_dsc_verbose_log) expect(provider).to receive(:return_dsc_resource_result).and_return(false) expect(provider).to_not receive(:create_reboot_resource) diff --git a/spec/unit/provider/launchd_spec.rb b/spec/unit/provider/launchd_spec.rb index 97883fc04c..3031ea36c3 100644 --- a/spec/unit/provider/launchd_spec.rb +++ b/spec/unit/provider/launchd_spec.rb @@ -112,14 +112,14 @@ XML describe "agent" do it "path should be /Library/LaunchAgents/call.mom.weekly.plist" do new_resource.type "agent" - expect(provider.gen_path_from_type). - to eq("/Library/LaunchAgents/call.mom.weekly.plist") + expect(provider.gen_path_from_type) + .to eq("/Library/LaunchAgents/call.mom.weekly.plist") end end describe "daemon" do it "path should be /Library/LaunchDaemons/call.mom.weekly.plist" do - expect(provider.gen_path_from_type). - to eq("/Library/LaunchDaemons/call.mom.weekly.plist") + expect(provider.gen_path_from_type) + .to eq("/Library/LaunchDaemons/call.mom.weekly.plist") end end end diff --git a/spec/unit/provider/package/freebsd/pkgng_spec.rb b/spec/unit/provider/package/freebsd/pkgng_spec.rb index a4da5bb235..13e5dd17fd 100644 --- a/spec/unit/provider/package/freebsd/pkgng_spec.rb +++ b/spec/unit/provider/package/freebsd/pkgng_spec.rb @@ -99,30 +99,30 @@ describe Chef::Provider::Package::Freebsd::Port do it "should handle package source from file" do @provider.new_resource.source("/nas/pkg/repo/zsh-5.0.1.txz") - expect(@provider).to receive(:shell_out_compacted!). - with("pkg", "add", "/nas/pkg/repo/zsh-5.0.1.txz", env: { "LC_ALL" => nil }, timeout: 900). - and_return(@install_result) + expect(@provider).to receive(:shell_out_compacted!) + .with("pkg", "add", "/nas/pkg/repo/zsh-5.0.1.txz", env: { "LC_ALL" => nil }, timeout: 900) + .and_return(@install_result) @provider.install_package("zsh", "5.0.1") end it "should handle package source over ftp or http" do @provider.new_resource.source("http://repo.example.com/zsh-5.0.1.txz") - expect(@provider).to receive(:shell_out_compacted!). - with("pkg", "add", "http://repo.example.com/zsh-5.0.1.txz", env: { "LC_ALL" => nil }, timeout: 900). - and_return(@install_result) + expect(@provider).to receive(:shell_out_compacted!) + .with("pkg", "add", "http://repo.example.com/zsh-5.0.1.txz", env: { "LC_ALL" => nil }, timeout: 900) + .and_return(@install_result) @provider.install_package("zsh", "5.0.1") end it "should handle a package name" do - expect(@provider).to receive(:shell_out_compacted!). - with("pkg", "install", "-y", "zsh", env: { "LC_ALL" => nil }, timeout: 900).and_return(@install_result) + expect(@provider).to receive(:shell_out_compacted!) + .with("pkg", "install", "-y", "zsh", env: { "LC_ALL" => nil }, timeout: 900).and_return(@install_result) @provider.install_package("zsh", "5.0.1") end it "should handle a package name with a specified repo" do @provider.new_resource.options("-r LocalMirror") # This requires LocalMirror repo configuration. - expect(@provider).to receive(:shell_out_compacted!). - with("pkg", "install", "-y", "-r", "LocalMirror", "zsh", env: { "LC_ALL" => nil }, timeout: 900).and_return(@install_result) + expect(@provider).to receive(:shell_out_compacted!) + .with("pkg", "install", "-y", "-r", "LocalMirror", "zsh", env: { "LC_ALL" => nil }, timeout: 900).and_return(@install_result) @provider.install_package("zsh", "5.0.1") end end @@ -133,15 +133,15 @@ describe Chef::Provider::Package::Freebsd::Port do end it "should call pkg delete" do - expect(@provider).to receive(:shell_out_compacted!). - with("pkg", "delete", "-y", "zsh-5.0.1", env: nil, timeout: 900).and_return(@install_result) + expect(@provider).to receive(:shell_out_compacted!) + .with("pkg", "delete", "-y", "zsh-5.0.1", env: nil, timeout: 900).and_return(@install_result) @provider.remove_package("zsh", "5.0.1") end it "should not include repo option in pkg delete" do @provider.new_resource.options("-r LocalMirror") # This requires LocalMirror repo configuration. - expect(@provider).to receive(:shell_out_compacted!). - with("pkg", "delete", "-y", "zsh-5.0.1", env: nil, timeout: 900).and_return(@install_result) + expect(@provider).to receive(:shell_out_compacted!) + .with("pkg", "delete", "-y", "zsh-5.0.1", env: nil, timeout: 900).and_return(@install_result) @provider.remove_package("zsh", "5.0.1") end end diff --git a/spec/unit/provider/package/freebsd/port_spec.rb b/spec/unit/provider/package/freebsd/port_spec.rb index 1406235725..af5216dc04 100644 --- a/spec/unit/provider/package/freebsd/port_spec.rb +++ b/spec/unit/provider/package/freebsd/port_spec.rb @@ -98,8 +98,8 @@ describe Chef::Provider::Package::Freebsd::Port do it "should return candidate version if port exists" do allow(::File).to receive(:exist?).with("/usr/ports/Makefile").and_return(true) allow(@provider).to receive(:port_dir).and_return("/usr/ports/shells/zsh") - expect(@provider).to receive(:shell_out_compacted!).with("make", "-V", "PORTVERSION", cwd: "/usr/ports/shells/zsh", env: nil, returns: [0, 1], timeout: 900). - and_return(@port_version) + expect(@provider).to receive(:shell_out_compacted!).with("make", "-V", "PORTVERSION", cwd: "/usr/ports/shells/zsh", env: nil, returns: [0, 1], timeout: 900) + .and_return(@port_version) expect(@provider.candidate_version).to eq("5.0.5") end @@ -140,9 +140,9 @@ describe Chef::Provider::Package::Freebsd::Port do it "should run make install in port directory" do allow(@provider).to receive(:port_dir).and_return("/usr/ports/shells/zsh") - expect(@provider).to receive(:shell_out_compacted!). - with("make", "-DBATCH", "install", "clean", timeout: 1800, cwd: "/usr/ports/shells/zsh", env: nil). - and_return(@install_result) + expect(@provider).to receive(:shell_out_compacted!) + .with("make", "-DBATCH", "install", "clean", timeout: 1800, cwd: "/usr/ports/shells/zsh", env: nil) + .and_return(@install_result) @provider.install_package("zsh", "5.0.5") end end @@ -154,9 +154,9 @@ describe Chef::Provider::Package::Freebsd::Port do it "should run make deinstall in port directory" do allow(@provider).to receive(:port_dir).and_return("/usr/ports/shells/zsh") - expect(@provider).to receive(:shell_out_compacted!). - with("make", "deinstall", timeout: 300, cwd: "/usr/ports/shells/zsh", env: nil). - and_return(@install_result) + expect(@provider).to receive(:shell_out_compacted!) + .with("make", "deinstall", timeout: 300, cwd: "/usr/ports/shells/zsh", env: nil) + .and_return(@install_result) @provider.remove_package("zsh", "5.0.5") end end diff --git a/spec/unit/provider/package/rpm_spec.rb b/spec/unit/provider/package/rpm_spec.rb index 91d4ca69b4..3682043dcd 100644 --- a/spec/unit/provider/package/rpm_spec.rb +++ b/spec/unit/provider/package/rpm_spec.rb @@ -85,13 +85,13 @@ describe Chef::Provider::Package::Rpm do describe "when the package source is valid" do before do - expect(provider).to receive(:shell_out_compacted!). - with("rpm", "-qp", "--queryformat", "%{NAME} %{VERSION}-%{RELEASE}\n", package_source, timeout: 900). - and_return(rpm_qp_status) + expect(provider).to receive(:shell_out_compacted!) + .with("rpm", "-qp", "--queryformat", "%{NAME} %{VERSION}-%{RELEASE}\n", package_source, timeout: 900) + .and_return(rpm_qp_status) - expect(provider).to receive(:shell_out_compacted). - with("rpm", "-q", "--queryformat", "%{NAME} %{VERSION}-%{RELEASE}\n", package_name, timeout: 900). - and_return(rpm_q_status) + expect(provider).to receive(:shell_out_compacted) + .with("rpm", "-q", "--queryformat", "%{NAME} %{VERSION}-%{RELEASE}\n", package_name, timeout: 900) + .and_return(rpm_q_status) end context "when rpm fails when querying package installed state" do diff --git a/spec/unit/provider/package/smartos_spec.rb b/spec/unit/provider/package/smartos_spec.rb index 172bfbac84..cd85e1b3d9 100644 --- a/spec/unit/provider/package/smartos_spec.rb +++ b/spec/unit/provider/package/smartos_spec.rb @@ -76,9 +76,9 @@ describe Chef::Provider::Package::SmartOS, "load_current_resource" do it "should lookup the candidate_version if the variable is not already set (pkgin separated by spaces)" do search = double() - expect(search).to receive(:each_line). - and_yield("something-varnish-1.1.1 something varnish like\n"). - and_yield("varnish-2.3.4 actual varnish\n") + expect(search).to receive(:each_line) + .and_yield("something-varnish-1.1.1 something varnish like\n") + .and_yield("varnish-2.3.4 actual varnish\n") @shell_out = double("shell_out!", stdout: search) expect(@provider).to receive(:shell_out_compacted!).with("/opt/local/bin/pkgin", "se", "varnish", env: nil, returns: [0, 1], timeout: 900).and_return(@shell_out) expect(@provider.candidate_version).to eq("2.3.4") @@ -86,9 +86,9 @@ describe Chef::Provider::Package::SmartOS, "load_current_resource" do it "should lookup the candidate_version if the variable is not already set (pkgin separated by semicolons)" do search = double() - expect(search).to receive(:each_line). - and_yield("something-varnish-1.1.1;;something varnish like\n"). - and_yield("varnish-2.3.4;;actual varnish\n") + expect(search).to receive(:each_line) + .and_yield("something-varnish-1.1.1;;something varnish like\n") + .and_yield("varnish-2.3.4;;actual varnish\n") @shell_out = double("shell_out!", stdout: search) expect(@provider).to receive(:shell_out_compacted!).with("/opt/local/bin/pkgin", "se", "varnish", env: nil, returns: [0, 1], timeout: 900).and_return(@shell_out) expect(@provider.candidate_version).to eq("2.3.4") diff --git a/spec/unit/provider/service/macosx_spec.rb b/spec/unit/provider/service/macosx_spec.rb index 0c71eb604f..d6aeed2daf 100644 --- a/spec/unit/provider/service/macosx_spec.rb +++ b/spec/unit/provider/service/macosx_spec.rb @@ -82,14 +82,14 @@ XML allow(Etc).to receive(:getpwuid).and_return(@getpwuid) allow(node).to receive(:[]).with("platform_version").and_return(platform_version) cmd = "launchctl list #{service_label}" - allow(provider).to receive(:shell_out). - with(/(#{su_cmd} '#{cmd}'|#{cmd})/, default_env: false). - and_return(double("Status", + allow(provider).to receive(:shell_out) + .with(/(#{su_cmd} '#{cmd}'|#{cmd})/, default_env: false) + .and_return(double("Status", stdout: launchctl_stdout, exitstatus: 0)) allow(File).to receive(:exists?).and_return([true], []) - allow(provider).to receive(:shell_out!). - with(/plutil -convert xml1 -o/, default_env: false). - and_return(double("Status", stdout: plutil_stdout)) + allow(provider).to receive(:shell_out!) + .with(/plutil -convert xml1 -o/, default_env: false) + .and_return(double("Status", stdout: plutil_stdout)) end context "#{service_name} that is a #{service_type} running Osx #{platform_version}" do @@ -113,9 +113,9 @@ XML before do allow(Dir).to receive(:glob).and_return([]) allow(File).to receive(:exists?).and_return([true], []) - allow(provider).to receive(:shell_out!). - with(/plutil -convert xml1 -o/). - and_raise(Mixlib::ShellOut::ShellCommandFailed) + allow(provider).to receive(:shell_out!) + .with(/plutil -convert xml1 -o/) + .and_raise(Mixlib::ShellOut::ShellCommandFailed) end it "works for action :nothing" do @@ -269,9 +269,9 @@ SVC_LIST it "starts service via launchctl if service found" do cmd = "launchctl load -w " + session + plist - expect(provider).to receive(:shell_out). - with(/(#{su_cmd} .#{cmd}.|#{cmd})/, default_env: false). - and_return(0) + expect(provider).to receive(:shell_out) + .with(/(#{su_cmd} .#{cmd}.|#{cmd})/, default_env: false) + .and_return(0) provider.start_service end @@ -301,9 +301,9 @@ SVC_LIST it "stops the service via launchctl if service found" do cmd = "launchctl unload -w " + plist - expect(provider).to receive(:shell_out). - with(/(#{su_cmd} .#{cmd}.|#{cmd})/, default_env: false). - and_return(0) + expect(provider).to receive(:shell_out) + .with(/(#{su_cmd} .#{cmd}.|#{cmd})/, default_env: false) + .and_return(0) provider.stop_service end diff --git a/spec/unit/provider/subversion_spec.rb b/spec/unit/provider/subversion_spec.rb index 8f364aa8c8..5233ecb229 100644 --- a/spec/unit/provider/subversion_spec.rb +++ b/spec/unit/provider/subversion_spec.rb @@ -74,8 +74,8 @@ describe Chef::Provider::Subversion do "Last Changed Date: 2009-03-25 06:09:56 -0600 (Wed, 25 Mar 2009)\n\n" expect(::File).to receive(:exist?).at_least(1).times.with("/my/deploy/dir/.svn").and_return(true) expected_command = ["svn info", { cwd: "/my/deploy/dir", returns: [0, 1] }] - expect(@provider).to receive(:shell_out!).with(*expected_command). - and_return(double("ShellOut result", stdout: example_svn_info, stderr: "")) + expect(@provider).to receive(:shell_out!).with(*expected_command) + .and_return(double("ShellOut result", stdout: example_svn_info, stderr: "")) expect(@provider.find_current_revision).to eql("11410") end @@ -83,8 +83,8 @@ describe Chef::Provider::Subversion do example_svn_info = "svn: '/tmp/deploydir' is not a working copy\n" expect(::File).to receive(:exist?).with("/my/deploy/dir/.svn").and_return(true) expected_command = ["svn info", { cwd: "/my/deploy/dir", returns: [0, 1] }] - expect(@provider).to receive(:shell_out!).with(*expected_command). - and_return(double("ShellOut result", stdout: example_svn_info, stderr: "")) + expect(@provider).to receive(:shell_out!).with(*expected_command) + .and_return(double("ShellOut result", stdout: example_svn_info, stderr: "")) expect(@provider.find_current_revision).to be_nil end @@ -129,8 +129,8 @@ describe Chef::Provider::Subversion do "Last Changed Date: 2009-03-25 06:09:56 -0600 (Wed, 25 Mar 2009)\n\n" @resource.revision "HEAD" expected_command = ["svn info http://svn.example.org/trunk/ --no-auth-cache -rHEAD", { cwd: "/my/deploy/dir", returns: [0, 1] }] - expect(@provider).to receive(:shell_out!).with(*expected_command). - and_return(double("ShellOut result", stdout: example_svn_info, stderr: "")) + expect(@provider).to receive(:shell_out!).with(*expected_command) + .and_return(double("ShellOut result", stdout: example_svn_info, stderr: "")) expect(@provider.revision_int).to eql("11410") end @@ -138,8 +138,8 @@ describe Chef::Provider::Subversion do example_svn_info = "some random text from an error message\n" @resource.revision "HEAD" expected_command = ["svn info http://svn.example.org/trunk/ --no-auth-cache -rHEAD", { cwd: "/my/deploy/dir", returns: [0, 1] }] - expect(@provider).to receive(:shell_out!).with(*expected_command). - and_return(double("ShellOut result", stdout: example_svn_info, stderr: "")) + expect(@provider).to receive(:shell_out!).with(*expected_command) + .and_return(double("ShellOut result", stdout: example_svn_info, stderr: "")) expect { @provider.revision_int }.to raise_error(RuntimeError, "Could not parse `svn info` data: some random text from an error message\n") end diff --git a/spec/unit/resource_reporter_spec.rb b/spec/unit/resource_reporter_spec.rb index 042b09659c..0c4942f319 100644 --- a/spec/unit/resource_reporter_spec.rb +++ b/spec/unit/resource_reporter_spec.rb @@ -616,11 +616,11 @@ describe Chef::ResourceReporter do # 404 getting the run_id @response = Net::HTTPNotFound.new("a response body", "404", "Not Found") @error = Net::HTTPServerException.new("404 message", @response) - expect(@rest_client).to receive(:post). - with("reports/nodes/spitfire/runs", { action: :start, run_id: @run_id, + expect(@rest_client).to receive(:post) + .with("reports/nodes/spitfire/runs", { action: :start, run_id: @run_id, start_time: @start_time.to_s }, - { "X-Ops-Reporting-Protocol-Version" => Chef::ResourceReporter::PROTOCOL_VERSION }). - and_raise(@error) + { "X-Ops-Reporting-Protocol-Version" => Chef::ResourceReporter::PROTOCOL_VERSION }) + .and_raise(@error) end it "assumes the feature is not enabled" do @@ -646,10 +646,10 @@ describe Chef::ResourceReporter do # 500 getting the run_id @response = Net::HTTPInternalServerError.new("a response body", "500", "Internal Server Error") @error = Net::HTTPServerException.new("500 message", @response) - expect(@rest_client).to receive(:post). - with("reports/nodes/spitfire/runs", { action: :start, run_id: @run_id, start_time: @start_time.to_s }, - { "X-Ops-Reporting-Protocol-Version" => Chef::ResourceReporter::PROTOCOL_VERSION }). - and_raise(@error) + expect(@rest_client).to receive(:post) + .with("reports/nodes/spitfire/runs", { action: :start, run_id: @run_id, start_time: @start_time.to_s }, + { "X-Ops-Reporting-Protocol-Version" => Chef::ResourceReporter::PROTOCOL_VERSION }) + .and_raise(@error) end it "assumes the feature is not enabled" do @@ -676,10 +676,10 @@ describe Chef::ResourceReporter do # 500 getting the run_id @response = Net::HTTPInternalServerError.new("a response body", "500", "Internal Server Error") @error = Net::HTTPServerException.new("500 message", @response) - expect(@rest_client).to receive(:post). - with("reports/nodes/spitfire/runs", { action: :start, run_id: @run_id, start_time: @start_time.to_s }, - { "X-Ops-Reporting-Protocol-Version" => Chef::ResourceReporter::PROTOCOL_VERSION }). - and_raise(@error) + expect(@rest_client).to receive(:post) + .with("reports/nodes/spitfire/runs", { action: :start, run_id: @run_id, start_time: @start_time.to_s }, + { "X-Ops-Reporting-Protocol-Version" => Chef::ResourceReporter::PROTOCOL_VERSION }) + .and_raise(@error) end after do @@ -697,10 +697,10 @@ describe Chef::ResourceReporter do context "after creating the run history document" do before do response = { "uri" => "https://example.com/reports/nodes/spitfire/runs/@run_id" } - expect(@rest_client).to receive(:post). - with("reports/nodes/spitfire/runs", { action: :start, run_id: @run_id, start_time: @start_time.to_s }, - { "X-Ops-Reporting-Protocol-Version" => Chef::ResourceReporter::PROTOCOL_VERSION }). - and_return(response) + expect(@rest_client).to receive(:post) + .with("reports/nodes/spitfire/runs", { action: :start, run_id: @run_id, start_time: @start_time.to_s }, + { "X-Ops-Reporting-Protocol-Version" => Chef::ResourceReporter::PROTOCOL_VERSION }) + .and_return(response) @resource_reporter.run_started(@run_status) end |