diff options
Diffstat (limited to 'spec')
142 files changed, 1045 insertions, 1045 deletions
diff --git a/spec/functional/dsl/reboot_pending_spec.rb b/spec/functional/dsl/reboot_pending_spec.rb index 89701802b3..1bd1ce3328 100644 --- a/spec/functional/dsl/reboot_pending_spec.rb +++ b/spec/functional/dsl/reboot_pending_spec.rb @@ -36,9 +36,9 @@ describe Chef::DSL::RebootPending, :windows_only do let(:reg_key) { nil } let(:original_set) { false } - before(:all) { @any_flag = {} } + before(:all) do @any_flag = {} end - after { @any_flag[reg_key] = original_set } + after do @any_flag[reg_key] = original_set end describe 'HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\PendingFileRenameOperations' do let(:reg_key) { 'HKLM\SYSTEM\CurrentControlSet\Control\Session Manager' } diff --git a/spec/functional/event_loggers/windows_eventlog_spec.rb b/spec/functional/event_loggers/windows_eventlog_spec.rb index ca15d3e38d..311fc691a2 100644 --- a/spec/functional/event_loggers/windows_eventlog_spec.rb +++ b/spec/functional/event_loggers/windows_eventlog_spec.rb @@ -48,37 +48,37 @@ describe Chef::EventLoggers::WindowsEventLogger, :windows_only do it "writes run_start event with event_id 10000 and contains version" do logger.run_start(version, run_status) - expect(event_log.read(flags, offset).any? do |e| + expect(event_log.read(flags, offset).any? { |e| e.source == Chef::Dist::PRODUCT && e.event_id == 10000 && e.string_inserts[0].include?(version) - end ).to be_truthy + } ).to be_truthy end it "writes run_started event with event_id 10001 and contains the run_id" do logger.run_started(run_status) - expect(event_log.read(flags, offset).any? do |e| + expect(event_log.read(flags, offset).any? { |e| e.source == Chef::Dist::PRODUCT && e.event_id == 10001 && e.string_inserts[0].include?(run_id) - end ).to be_truthy + } ).to be_truthy end it "writes run_completed event with event_id 10002 and contains the run_id and elapsed time" do logger.run_started(run_status) logger.run_completed(node) - expect(event_log.read(flags, offset).any? do |e| + expect(event_log.read(flags, offset).any? { |e| e.source == Chef::Dist::PRODUCT && e.event_id == 10002 && e.string_inserts[0].include?(run_id) && e.string_inserts[1].include?(elapsed_time.to_s) - end).to be_truthy + }).to be_truthy end it "writes run_failed event with event_id 10003 and contains the run_id, elapsed time, and exception info" do logger.run_started(run_status) logger.run_failed(mock_exception) - expect(event_log.read(flags, offset).any? do |e| + expect(event_log.read(flags, offset).any? { |e| e.source == Chef::Dist::PRODUCT && e.event_id == 10003 && e.string_inserts[0].include?(run_id) && e.string_inserts[1].include?(elapsed_time.to_s) && @@ -86,13 +86,13 @@ describe Chef::EventLoggers::WindowsEventLogger, :windows_only do e.string_inserts[3].include?(mock_exception.message) && e.string_inserts[4].include?(mock_exception.backtrace[0]) && e.string_inserts[4].include?(mock_exception.backtrace[1]) - end).to be_truthy + }).to be_truthy end it "writes run_failed event with event_id 10003 even when run_status is not set" do logger.run_failed(mock_exception) - expect(event_log.read(flags, offset).any? do |e| + expect(event_log.read(flags, offset).any? { |e| e.source == Chef::Dist::PRODUCT && e.event_id == 10003 && e.string_inserts[0].include?("UNKNOWN") && e.string_inserts[1].include?("UNKNOWN") && @@ -100,7 +100,7 @@ describe Chef::EventLoggers::WindowsEventLogger, :windows_only do e.string_inserts[3].include?(mock_exception.message) && e.string_inserts[4].include?(mock_exception.backtrace[0]) && e.string_inserts[4].include?(mock_exception.backtrace[1]) - end).to be_truthy + }).to be_truthy end end diff --git a/spec/functional/file_content_management/deploy_strategies_spec.rb b/spec/functional/file_content_management/deploy_strategies_spec.rb index 07991aa8bd..75d2422454 100644 --- a/spec/functional/file_content_management/deploy_strategies_spec.rb +++ b/spec/functional/file_content_management/deploy_strategies_spec.rb @@ -72,9 +72,9 @@ shared_examples_for "a content deploy strategy" do end let(:parent_inheritable_aces) do - inheritable_aces = parent_security_descriptor.dacl.select do |ace| + inheritable_aces = parent_security_descriptor.dacl.select { |ace| ace_inherits?(ace) - end + } end it "touches the file to create it (Windows)", :windows_only do @@ -91,9 +91,9 @@ shared_examples_for "a content deploy strategy" do # On certain windows systems like 2003 and Azure VMs there are some default # ACEs that are not inherited from parents. So filter out the parents before # comparing the aces - self_aces = security_descriptor.dacl.select do |ace| + self_aces = security_descriptor.dacl.select { |ace| ace_inherits?(ace) - end + } self_aces.each_with_index do |ace, index| expect(ace.mask).to eq(parent_aces[index].mask) @@ -109,7 +109,7 @@ shared_examples_for "a content deploy strategy" do let(:staging_file_path) do path = File.join(staging_dir, "cp-deploy-strategy-staging-file.txt") - File.open(path, "w+", 0600) { |f| f.print(staging_file_content) } + File.open(path, "w+", 0600) do |f| f.print(staging_file_content) end path end diff --git a/spec/functional/http/simple_spec.rb b/spec/functional/http/simple_spec.rb index 313fed064b..1ef809abfa 100644 --- a/spec/functional/http/simple_spec.rb +++ b/spec/functional/http/simple_spec.rb @@ -118,9 +118,9 @@ describe Chef::HTTP::Simple do end it "Logs the request and response and bodies for 400 response" do - expect do + expect { http_client.get("http://localhost:9000/bad_request") - end.to raise_error(Net::HTTPClientException) + }.to raise_error(Net::HTTPClientException) expect(@debug_log).to match(/400/) expect(@debug_log).to match(/HTTP Request Header Data/) expect(@debug_log).to match(/HTTP Status and Header Data/) @@ -131,9 +131,9 @@ describe Chef::HTTP::Simple do end it "Logs the request and response and bodies for 400 POST response" do - expect do + expect { http_client.post("http://localhost:9000/bad_request", "hithere") - end.to raise_error(Net::HTTPClientException) + }.to raise_error(Net::HTTPClientException) expect(@debug_log).to match(/400/) expect(@debug_log).to match(/HTTP Request Header Data/) expect(@debug_log).to match(/HTTP Status and Header Data/) diff --git a/spec/functional/knife/cookbook_delete_spec.rb b/spec/functional/knife/cookbook_delete_spec.rb index 7438ef9841..9b1ac93794 100644 --- a/spec/functional/knife/cookbook_delete_spec.rb +++ b/spec/functional/knife/cookbook_delete_spec.rb @@ -70,7 +70,7 @@ describe Chef::Knife::CookbookDelete do allow(knife.ui).to receive(:stdout).and_return(stdout) cb100_deleted = false - api.delete("/cookbooks/obsolete-cookbook/1.0.0", 200) { cb100_deleted = true; "[\"true\"]" } + api.delete("/cookbooks/obsolete-cookbook/1.0.0", 200) do cb100_deleted = true; "[\"true\"]" end knife.run @@ -86,7 +86,7 @@ describe Chef::Knife::CookbookDelete do allow(knife.ui).to receive(:stdout).and_return(stdout) cb100_deleted = false - api.delete("/cookbooks/obsolete-cookbook/1.0.0?purge=true", 200) { cb100_deleted = true; "[\"true\"]" } + api.delete("/cookbooks/obsolete-cookbook/1.0.0?purge=true", 200) do cb100_deleted = true; "[\"true\"]" end knife.run @@ -111,9 +111,9 @@ describe Chef::Knife::CookbookDelete do knife.config[:all] = true knife.config[:yes] = true cb100_deleted = cb110_deleted = cb120_deleted = nil - api.delete("/cookbooks/obsolete-cookbook/1.0.0", 200) { cb100_deleted = true; "[\"true\"]" } - api.delete("/cookbooks/obsolete-cookbook/1.1.0", 200) { cb110_deleted = true; "[\"true\"]" } - api.delete("/cookbooks/obsolete-cookbook/1.2.0", 200) { cb120_deleted = true; "[\"true\"]" } + api.delete("/cookbooks/obsolete-cookbook/1.0.0", 200) do cb100_deleted = true; "[\"true\"]" end + api.delete("/cookbooks/obsolete-cookbook/1.1.0", 200) do cb110_deleted = true; "[\"true\"]" end + api.delete("/cookbooks/obsolete-cookbook/1.2.0", 200) do cb120_deleted = true; "[\"true\"]" end knife.run expect(cb100_deleted).to be_truthy @@ -123,7 +123,7 @@ describe Chef::Knife::CookbookDelete do it "asks which version to delete and deletes that when not given the -a flag" do cb100_deleted = cb110_deleted = cb120_deleted = nil - api.delete("/cookbooks/obsolete-cookbook/1.0.0", 200) { cb100_deleted = true; "[\"true\"]" } + api.delete("/cookbooks/obsolete-cookbook/1.0.0", 200) do cb100_deleted = true; "[\"true\"]" end stdin, stdout = StringIO.new, StringIO.new allow(knife.ui).to receive(:stdin).and_return(stdin) allow(knife.ui).to receive(:stdout).and_return(stdout) @@ -136,9 +136,9 @@ describe Chef::Knife::CookbookDelete do it "deletes all versions of the cookbook when not given the -a flag and the user chooses to delete all" do cb100_deleted = cb110_deleted = cb120_deleted = nil - api.delete("/cookbooks/obsolete-cookbook/1.0.0", 200) { cb100_deleted = true; "[\"true\"]" } - api.delete("/cookbooks/obsolete-cookbook/1.1.0", 200) { cb110_deleted = true; "[\"true\"]" } - api.delete("/cookbooks/obsolete-cookbook/1.2.0", 200) { cb120_deleted = true; "[\"true\"]" } + api.delete("/cookbooks/obsolete-cookbook/1.0.0", 200) do cb100_deleted = true; "[\"true\"]" end + api.delete("/cookbooks/obsolete-cookbook/1.1.0", 200) do cb110_deleted = true; "[\"true\"]" end + api.delete("/cookbooks/obsolete-cookbook/1.2.0", 200) do cb120_deleted = true; "[\"true\"]" end stdin, stdout = StringIO.new("4\n"), StringIO.new allow(knife.ui).to receive(:stdin).and_return(stdin) diff --git a/spec/functional/mixin/from_file_spec.rb b/spec/functional/mixin/from_file_spec.rb index d8519b4185..8d3b7162c6 100644 --- a/spec/functional/mixin/from_file_spec.rb +++ b/spec/functional/mixin/from_file_spec.rb @@ -70,9 +70,9 @@ describe Chef::Mixin::FromFile do it "should fail on invalid data" do datum = TestData.new - expect do + expect { datum.from_file(INVALID_DATA) - end.to raise_error(NoMethodError) + }.to raise_error(NoMethodError) end it "should fail on nonexistant data" do diff --git a/spec/functional/notifications_spec.rb b/spec/functional/notifications_spec.rb index 87afbd8359..3d2c4c7026 100644 --- a/spec/functional/notifications_spec.rb +++ b/spec/functional/notifications_spec.rb @@ -32,15 +32,15 @@ describe "Notifications" do end it "should subscribe from one resource to another" do - log_resource = recipe.declare_resource(:log, "subscribed-log") do + log_resource = recipe.declare_resource(:log, "subscribed-log") { message "This is a log message" action :nothing subscribes :write, "package[vim]", :immediately - end + } - package_resource = recipe.declare_resource(:package, "vim") do + package_resource = recipe.declare_resource(:package, "vim") { action :install - end + } expect(log_resource).to receive(:run_action).with(:nothing, nil, nil).and_call_original @@ -53,15 +53,15 @@ describe "Notifications" do end it "should notify from one resource to another immediately" do - log_resource = recipe.declare_resource(:log, "log") do + log_resource = recipe.declare_resource(:log, "log") { message "This is a log message" action :write notifies :install, "package[vim]", :immediately - end + } - package_resource = recipe.declare_resource(:package, "vim") do + package_resource = recipe.declare_resource(:package, "vim") { action :nothing - end + } expect(log_resource).to receive(:run_action).with(:write, nil, nil).and_call_original update_action(log_resource) @@ -74,16 +74,16 @@ describe "Notifications" do end it "should notify from one resource to another before" do - log_resource = recipe.declare_resource(:log, "log") do + log_resource = recipe.declare_resource(:log, "log") { message "This is a log message" action :write notifies :install, "package[vim]", :before - end + } update_action(log_resource, 2) - package_resource = recipe.declare_resource(:package, "vim") do + package_resource = recipe.declare_resource(:package, "vim") { action :nothing - end + } actions = [] [ log_resource, package_resource ].each do |resource| @@ -110,15 +110,15 @@ describe "Notifications" do end it "should not notify from one resource to another before if the resource is not updated" do - log_resource = recipe.declare_resource(:log, "log") do + log_resource = recipe.declare_resource(:log, "log") { message "This is a log message" action :write notifies :install, "package[vim]", :before - end + } - package_resource = recipe.declare_resource(:package, "vim") do + package_resource = recipe.declare_resource(:package, "vim") { action :nothing - end + } actions = [] [ log_resource, package_resource ].each do |resource| @@ -144,15 +144,15 @@ describe "Notifications" do end it "should notify from one resource to another delayed" do - log_resource = recipe.declare_resource(:log, "log") do + log_resource = recipe.declare_resource(:log, "log") { message "This is a log message" action :write notifies :install, "package[vim]", :delayed - end + } - package_resource = recipe.declare_resource(:package, "vim") do + package_resource = recipe.declare_resource(:package, "vim") { action :nothing - end + } expect(log_resource).to receive(:run_action).with(:write, nil, nil).and_call_original update_action(log_resource) @@ -169,21 +169,21 @@ describe "Notifications" do it "subscribes to a resource defined in a ruby block" do r = recipe t = self - ruby_block = recipe.declare_resource(:ruby_block, "rblock") do + ruby_block = recipe.declare_resource(:ruby_block, "rblock") { block do - log_resource = r.declare_resource(:log, "log") do + log_resource = r.declare_resource(:log, "log") { message "This is a log message" action :write - end + } t.expect(log_resource).to t.receive(:run_action).with(:write, nil, nil).and_call_original t.update_action(log_resource) end - end + } - package_resource = recipe.declare_resource(:package, "vim") do + package_resource = recipe.declare_resource(:package, "vim") { action :nothing subscribes :install, "log[log]", :delayed - end + } # RubyBlock needs to be able to run for our lazy examples to work - and it alone cannot affect the system expect(ruby_block).to receive(:provider_for_action).and_call_original @@ -198,21 +198,21 @@ describe "Notifications" do it "notifies from inside a ruby_block to a resource defined outside" do r = recipe t = self - ruby_block = recipe.declare_resource(:ruby_block, "rblock") do + ruby_block = recipe.declare_resource(:ruby_block, "rblock") { block do - log_resource = r.declare_resource(:log, "log") do + log_resource = r.declare_resource(:log, "log") { message "This is a log message" action :write notifies :install, "package[vim]", :immediately - end + } t.expect(log_resource).to t.receive(:run_action).with(:write, nil, nil).and_call_original t.update_action(log_resource) end - end + } - package_resource = recipe.declare_resource(:package, "vim") do + package_resource = recipe.declare_resource(:package, "vim") { action :nothing - end + } # RubyBlock needs to be able to run for our lazy examples to work - and it alone cannot affect the system expect(ruby_block).to receive(:provider_for_action).and_call_original diff --git a/spec/functional/provider/remote_file/cache_control_data_spec.rb b/spec/functional/provider/remote_file/cache_control_data_spec.rb index c56787e7e5..a5d938418e 100755 --- a/spec/functional/provider/remote_file/cache_control_data_spec.rb +++ b/spec/functional/provider/remote_file/cache_control_data_spec.rb @@ -81,9 +81,9 @@ describe Chef::Provider::RemoteFile::CacheControlData do let(:uri) { uri_exceeds_file_system_limit } it "writes data to the cache" do - expect do + expect { cache_control_data.save - end.not_to raise_error + }.not_to raise_error end it "writes the data to the cache and the same data can be read back" do diff --git a/spec/functional/provider/whyrun_safe_ruby_block_spec.rb b/spec/functional/provider/whyrun_safe_ruby_block_spec.rb index 1bb36f2cf6..409b084186 100644 --- a/spec/functional/provider/whyrun_safe_ruby_block_spec.rb +++ b/spec/functional/provider/whyrun_safe_ruby_block_spec.rb @@ -38,12 +38,12 @@ describe Chef::Resource::WhyrunSafeRubyBlock do describe "when testing the resource" do let(:new_resource) do r = Chef::Resource::WhyrunSafeRubyBlock.new("reload all", run_context) - r.block { $evil_global_evil_laugh = :mwahahaha } + r.block do $evil_global_evil_laugh = :mwahahaha end r end it "updates the evil laugh, even in why-run mode" do - Array(new_resource.action).each { |action| new_resource.run_action(action) } + Array(new_resource.action).each do |action| new_resource.run_action(action) end expect($evil_global_evil_laugh).to eq(:mwahahaha) expect(new_resource).to be_updated end diff --git a/spec/functional/resource/apt_package_spec.rb b/spec/functional/resource/apt_package_spec.rb index ad4378b83a..6145ea598d 100644 --- a/spec/functional/resource/apt_package_spec.rb +++ b/spec/functional/resource/apt_package_spec.rb @@ -187,9 +187,9 @@ describe Chef::Resource::AptPackage, metadata do end it "raises a reasonable error for action :install" do - expect do + expect { package_resource.run_action(:install) - end.to raise_error(Mixlib::ShellOut::ShellCommandFailed) + }.to raise_error(Mixlib::ShellOut::ShellCommandFailed) end end diff --git a/spec/functional/resource/chocolatey_package_spec.rb b/spec/functional/resource/chocolatey_package_spec.rb index c5590b2d88..eccea739e6 100644 --- a/spec/functional/resource/chocolatey_package_spec.rb +++ b/spec/functional/resource/chocolatey_package_spec.rb @@ -33,7 +33,7 @@ describe Chef::Resource::ChocolateyPackage, :windows_only, :choco_installed do end context "installing a package" do - after { remove_package } + after do remove_package end it "installs the latest version" do subject.run_action(:install) @@ -78,7 +78,7 @@ describe Chef::Resource::ChocolateyPackage, :windows_only, :choco_installed do end context "upgrading a package" do - after { remove_package } + after do remove_package end it "upgrades to a specific version" do subject.version "1.0" diff --git a/spec/functional/resource/cron_spec.rb b/spec/functional/resource/cron_spec.rb index 16b0d2645c..e5bc166958 100644 --- a/spec/functional/resource/cron_spec.rb +++ b/spec/functional/resource/cron_spec.rb @@ -86,7 +86,7 @@ describe Chef::Resource::Cron, :requires_root, :unix_only do end it "should create exactly one crontab entry" do - 5.times { new_resource.run_action(:create) } + 5.times do new_resource.run_action(:create) end cron_should_exists(new_resource.name, new_resource.command) end end diff --git a/spec/functional/resource/dsc_resource_spec.rb b/spec/functional/resource/dsc_resource_spec.rb index 8f5ba5fd9e..58b915f802 100644 --- a/spec/functional/resource/dsc_resource_spec.rb +++ b/spec/functional/resource/dsc_resource_spec.rb @@ -67,9 +67,9 @@ describe Chef::Resource::DscResource, :windows_powershell_dsc_only do it "converges the resource if it is not converged" do new_resource.run_action(:run) - contents = File.open(tmp_file_name, "rb:bom|UTF-16LE") do |f| + contents = File.open(tmp_file_name, "rb:bom|UTF-16LE") { |f| f.read.encode("UTF-8") - end + } expect(contents).to eq(test_text) expect(new_resource).to be_updated end diff --git a/spec/functional/resource/execute_spec.rb b/spec/functional/resource/execute_spec.rb index 3e57795f73..bec056fed2 100644 --- a/spec/functional/resource/execute_spec.rb +++ b/spec/functional/resource/execute_spec.rb @@ -29,7 +29,7 @@ describe Chef::Resource::Execute do describe "when guard is ruby block" do it "guard can still run" do - resource.only_if { true } + resource.only_if do true end resource.run_action(:run) expect(resource).to be_updated_by_last_action end diff --git a/spec/functional/resource/file_spec.rb b/spec/functional/resource/file_spec.rb index 291311f3e2..197e8c1469 100644 --- a/spec/functional/resource/file_spec.rb +++ b/spec/functional/resource/file_spec.rb @@ -140,7 +140,7 @@ describe Chef::Resource::File do context "and the target file exists and has the correct content" do before(:each) do - File.open(path, "w") { |f| f.print expected_content } + File.open(path, "w") do |f| f.print expected_content end @expected_checksum = sha256_checksum(path) diff --git a/spec/functional/resource/git_spec.rb b/spec/functional/resource/git_spec.rb index e978041038..a10bcad2e3 100644 --- a/spec/functional/resource/git_spec.rb +++ b/spec/functional/resource/git_spec.rb @@ -76,7 +76,7 @@ describe Chef::Resource::Git, requires_git: true do Chef::Log.level = :warn # silence git command live streams @old_file_cache_path = Chef::Config[:file_cache_path] shell_out!("git clone \"#{git_bundle_repo}\" example", cwd: origin_repo_dir) - File.open("#{origin_repo}/.git/config", "a+") { |f| f.print(git_user_config) } + File.open("#{origin_repo}/.git/config", "a+") do |f| f.print(git_user_config) end Chef::Config[:file_cache_path] = file_cache_path end diff --git a/spec/functional/resource/link_spec.rb b/spec/functional/resource/link_spec.rb index 4593dc1971..996047e342 100644 --- a/spec/functional/resource/link_spec.rb +++ b/spec/functional/resource/link_spec.rb @@ -281,7 +281,7 @@ describe Chef::Resource::Link do # Writing to one hardlinked file should cause both # to have the new value. expect(IO.read(to)).to eq(IO.read(target_file)) - File.open(to, "w") { |file| file.write("wowzers") } + File.open(to, "w") do |file| file.write("wowzers") end expect(IO.read(target_file)).to eq("wowzers") end it "marks the resource updated" do @@ -306,7 +306,7 @@ describe Chef::Resource::Link do # Writing to one hardlinked file should cause both # to have the new value. expect(IO.read(to)).to eq(IO.read(target_file)) - File.open(to, "w") { |file| file.write("wowzers") } + File.open(to, "w") do |file| file.write("wowzers") end expect(IO.read(target_file)).to eq("wowzers") end it "does not mark the resource updated" do @@ -355,7 +355,7 @@ describe Chef::Resource::Link do before(:each) do resource.owner(test_user) @other_target = File.join(test_file_dir, make_tmpname("other_spec")) - File.open(@other_target, "w") { |file| file.write("eek") } + File.open(@other_target, "w") do |file| file.write("eek") end symlink(@other_target, target_file) chown(target_file, test_user) expect(symlink?(target_file)).to be_truthy @@ -465,7 +465,7 @@ describe Chef::Resource::Link do context "to a file that exists" do before(:each) do @other_target = File.join(test_file_dir, make_tmpname("other_spec")) - File.open(@other_target, "w") { |file| file.write("eek") } + File.open(@other_target, "w") do |file| file.write("eek") end symlink(@other_target, to) expect(symlink?(to)).to be_truthy expect(readlink(to)).to eq(canonicalize(@other_target)) @@ -646,7 +646,7 @@ describe Chef::Resource::Link do context "to a real file" do before(:each) do @other_target = File.join(test_file_dir, make_tmpname("other_spec")) - File.open(@other_target, "w") { |file| file.write("eek") } + File.open(@other_target, "w") do |file| file.write("eek") end symlink(@other_target, to) expect(symlink?(to)).to be_truthy expect(readlink(to)).to eq(canonicalize(@other_target)) diff --git a/spec/functional/resource/msu_package_spec.rb b/spec/functional/resource/msu_package_spec.rb index d6811d99e7..8f28def693 100644 --- a/spec/functional/resource/msu_package_spec.rb +++ b/spec/functional/resource/msu_package_spec.rb @@ -40,7 +40,7 @@ describe Chef::Resource::MsuPackage, :win2012r2_only do end context "installing package" do - after { remove_package } + after do remove_package end it "installs the package successfully" do subject.run_action(:install) diff --git a/spec/functional/resource/powershell_script_spec.rb b/spec/functional/resource/powershell_script_spec.rb index 74ece0d33c..39c614ab91 100644 --- a/spec/functional/resource/powershell_script_spec.rb +++ b/spec/functional/resource/powershell_script_spec.rb @@ -255,7 +255,7 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do it "raises an error when given a block and a guard_interpreter" do resource.guard_interpreter :sh - resource.only_if { true } + resource.only_if do true end expect { resource.should_skip?(:run) }.to raise_error(ArgumentError, /guard_interpreter does not support blocks/) end diff --git a/spec/functional/resource/reboot_spec.rb b/spec/functional/resource/reboot_spec.rb index 5489dc1c72..5b8752f06f 100644 --- a/spec/functional/resource/reboot_spec.rb +++ b/spec/functional/resource/reboot_spec.rb @@ -80,9 +80,9 @@ describe Chef::Resource::Reboot do it "should have modified the run context correctly" do # this doesn't actually test the flow of Chef::Client#do_run, unfortunately. - expect do + expect { resource.run_action(:reboot_now) - end.to throw_symbol(:end_client_run_early) + }.to throw_symbol(:end_client_run_early) test_reboot_action(resource) end diff --git a/spec/functional/resource/remote_directory_spec.rb b/spec/functional/resource/remote_directory_spec.rb index c25e51cf2a..58b2ed70ec 100644 --- a/spec/functional/resource/remote_directory_spec.rb +++ b/spec/functional/resource/remote_directory_spec.rb @@ -136,8 +136,8 @@ describe Chef::Resource::RemoteDirectory do FileUtils.mkdir_p(File.join(path, "remotesubdir")) modified_file = File.join(path, "remote_dir_file1.txt") modified_subdir_file = File.join(path, "remotesubdir", "remote_subdir_file1.txt") - File.open(modified_file, "a") { |f| f.puts "santa is real" } - File.open(modified_subdir_file, "a") { |f| f.puts "so is rudolph" } + File.open(modified_file, "a") do |f| f.puts "santa is real" end + File.open(modified_subdir_file, "a") do |f| f.puts "so is rudolph" end modified_file_checksum = sha256_checksum(modified_file) modified_subdir_file_checksum = sha256_checksum(modified_subdir_file) diff --git a/spec/functional/resource/windows_certificate_spec.rb b/spec/functional/resource/windows_certificate_spec.rb index 9b79de6a77..fa14c5b59b 100644 --- a/spec/functional/resource/windows_certificate_spec.rb +++ b/spec/functional/resource/windows_certificate_spec.rb @@ -93,7 +93,7 @@ describe Chef::Resource::WindowsCertificate, :windows_only, :appveyor_only do end end - after { cleanup(store) } + after do cleanup(store) end subject(:win_certificate) do new_resource.store_name = store @@ -453,7 +453,7 @@ describe Chef::Resource::WindowsCertificate, :windows_only, :appveyor_only do win_certificate.source = cer_path win_certificate.run_action(:create) end - before { win_certificate.source = tests_thumbprint } + before do win_certificate.source = tests_thumbprint end it "Initial check if certificate is present" do expect(no_of_certificates).to eq(1) end diff --git a/spec/functional/resource/windows_package_spec.rb b/spec/functional/resource/windows_package_spec.rb index bc508dc526..faad96e9e1 100644 --- a/spec/functional/resource/windows_package_spec.rb +++ b/spec/functional/resource/windows_package_spec.rb @@ -70,7 +70,7 @@ describe Chef::Resource::WindowsPackage, :windows_only, :volatile do subject { Chef::Resource::WindowsPackage.new(pkg_name, run_context) } context "multiple versions and a version given to remove" do - before { subject.version("8.0.56336") } + before do subject.version("8.0.56336") end it "removes specified version" do subject.run_action(:remove) @@ -121,7 +121,7 @@ describe Chef::Resource::WindowsPackage, :windows_only, :volatile do end describe "package version and installer type" do - after { subject.run_action(:remove) } + after do subject.run_action(:remove) end context "null soft" do let(:pkg_name) { "Ultra Defragmenter" } diff --git a/spec/functional/resource/windows_path_spec.rb b/spec/functional/resource/windows_path_spec.rb index 912abe6b24..1d08d6113c 100644 --- a/spec/functional/resource/windows_path_spec.rb +++ b/spec/functional/resource/windows_path_spec.rb @@ -35,7 +35,7 @@ describe Chef::Resource::WindowsPath, :windows_only do end describe "adding path" do - after { remove_path } + after do remove_path end it "appends the user given path in the Environment variable Path" do subject.run_action(:add) @@ -44,7 +44,7 @@ describe Chef::Resource::WindowsPath, :windows_only do end describe "removing path" do - before { add_path } + before do add_path end it "removes the user given path from the Environment variable Path" do subject.run_action(:remove) diff --git a/spec/functional/resource/windows_service_spec.rb b/spec/functional/resource/windows_service_spec.rb index 999b235df1..9d5459caac 100644 --- a/spec/functional/resource/windows_service_spec.rb +++ b/spec/functional/resource/windows_service_spec.rb @@ -59,7 +59,7 @@ describe Chef::Resource::WindowsService, :windows_only, :system_windows_service_ let(:service_resource) do r = Chef::Resource::WindowsService.new(service_params[:service_name], run_context) - %i{run_as_user run_as_password}.each { |prop| r.send(prop, service_params[prop]) } + %i{run_as_user run_as_password}.each do |prop| r.send(prop, service_params[prop]) end r end diff --git a/spec/functional/resource/windows_task_spec.rb b/spec/functional/resource/windows_task_spec.rb index fa51ad3f8a..3365d37a34 100644 --- a/spec/functional/resource/windows_task_spec.rb +++ b/spec/functional/resource/windows_task_spec.rb @@ -32,7 +32,7 @@ describe Chef::Resource::WindowsTask, :windows_only do end describe "action :create" do - after { delete_task } + after do delete_task end context "when command is with arguments" do subject do new_resource = Chef::Resource::WindowsTask.new(task_name, run_context) @@ -1340,7 +1340,7 @@ describe Chef::Resource::WindowsTask, :windows_only do context "task_name with parent folder" do describe "task_name with path '\\foo\\chef-client-functional-test' " do let(:task_name) { "\\foo\\chef-client-functional-test" } - after { delete_task } + after do delete_task end subject do new_resource = Chef::Resource::WindowsTask.new(task_name, run_context) new_resource.command task_name @@ -1366,7 +1366,7 @@ describe Chef::Resource::WindowsTask, :windows_only do describe "task_name with path '\\foo\\bar\\chef-client-functional-test' " do let(:task_name) { "\\foo\\bar\\chef-client-functional-test" } - after { delete_task } + after do delete_task end subject do new_resource = Chef::Resource::WindowsTask.new(task_name, run_context) new_resource.command task_name @@ -1392,7 +1392,7 @@ describe Chef::Resource::WindowsTask, :windows_only do end describe "priority" do - after { delete_task } + after do delete_task end subject do new_resource = Chef::Resource::WindowsTask.new(task_name, run_context) new_resource.command task_name @@ -1494,7 +1494,7 @@ describe Chef::Resource::WindowsTask, :windows_only do end describe "Examples of idempotent checks for each frequency" do - after { delete_task } + after do delete_task end context "For frequency :once" do subject do new_resource = Chef::Resource::WindowsTask.new(task_name, run_context) @@ -1853,7 +1853,7 @@ describe Chef::Resource::WindowsTask, :windows_only do end describe "action :run" do - after { delete_task } + after do delete_task end subject do new_resource = Chef::Resource::WindowsTask.new(task_name, run_context) @@ -1873,7 +1873,7 @@ describe Chef::Resource::WindowsTask, :windows_only do end describe "action :end", :volatile do - after { delete_task } + after do delete_task end subject do new_resource = Chef::Resource::WindowsTask.new(task_name, run_context) @@ -1894,7 +1894,7 @@ describe Chef::Resource::WindowsTask, :windows_only do describe "action :enable" do let(:task_name) { "chef-client-functional-test-enable" } - after { delete_task } + after do delete_task end subject do new_resource = Chef::Resource::WindowsTask.new(task_name, run_context) @@ -1917,7 +1917,7 @@ describe Chef::Resource::WindowsTask, :windows_only do describe "action :disable" do let(:task_name) { "chef-client-functional-test-disable" } - after { delete_task } + after do delete_task end subject do new_resource = Chef::Resource::WindowsTask.new(task_name, run_context) @@ -1936,7 +1936,7 @@ describe Chef::Resource::WindowsTask, :windows_only do end describe "action :change" do - after { delete_task } + after do delete_task end subject do new_resource = Chef::Resource::WindowsTask.new(task_name, run_context) new_resource.command task_name diff --git a/spec/functional/resource/zypper_package_spec.rb b/spec/functional/resource/zypper_package_spec.rb index c95c3575ca..f7067aad81 100644 --- a/spec/functional/resource/zypper_package_spec.rb +++ b/spec/functional/resource/zypper_package_spec.rb @@ -64,7 +64,7 @@ describe Chef::Resource::ZypperPackage, :requires_root, :suse_only do end context "installing a package" do - after { remove_package } + after do remove_package end it "installs the latest version" do zypper_package.run_action(:install) expect(zypper_package.updated_by_last_action?).to be true diff --git a/spec/functional/run_lock_spec.rb b/spec/functional/run_lock_spec.rb index d9a8bd2d0e..d368d837cf 100644 --- a/spec/functional/run_lock_spec.rb +++ b/spec/functional/run_lock_spec.rb @@ -34,8 +34,8 @@ describe Chef::RunLock do let(:lockfile) { "#{random_temp_root}/this/long/path/does/not/exist/chef-client-running.pid" } # make sure to start with a clean slate. - before(:each) { log_event("rm -rf before"); FileUtils.rm_r(random_temp_root) if File.exist?(random_temp_root) } - after(:each) { log_event("rm -rf after"); FileUtils.rm_r(random_temp_root) if File.exist?(random_temp_root) } + before(:each) do log_event("rm -rf before"); FileUtils.rm_r(random_temp_root) if File.exist?(random_temp_root) end + after(:each) do log_event("rm -rf after"); FileUtils.rm_r(random_temp_root) if File.exist?(random_temp_root) end def log_event(message, time = Time.now.strftime("%H:%M:%S.%L")) events << [ message, time ] @@ -85,7 +85,7 @@ describe Chef::RunLock do context "when the lockfile does not already exist" do context "when a client creates the lockfile but has not yet acquired the lock" do - before { p1.run_to("created lock") } + before do p1.run_to("created lock") end shared_context "second client gets the lock" do it "the lockfile is created" do log_event("lockfile exists? #{File.exist?(lockfile)}") @@ -106,7 +106,7 @@ describe Chef::RunLock do end context "and a second client gets the lock" do - before { p2.run_to("acquired lock") } + before do p2.run_to("acquired lock") end it "the first client does not get the lock until the second finishes" do p1.run_to("acquired lock") do p2.run_to_completion @@ -128,13 +128,13 @@ describe Chef::RunLock do end context "and the second client has created the lockfile but not yet acquired the lock" do - before { p2.run_to("created lock") } + before do p2.run_to("created lock") end include_context "second client gets the lock" end end context "when a client acquires the lock but has not yet saved the pid" do - before { p1.run_to("acquired lock") } + before do p1.run_to("acquired lock") end it "the lockfile is created" do log_event("lockfile exists? #{File.exist?(lockfile)}") @@ -182,7 +182,7 @@ describe Chef::RunLock do end context "when a client acquires the lock and saves the pid" do - before { p1.run_to("saved pid") } + before do p1.run_to("saved pid") end it "the lockfile is created" do expect(File.exist?(lockfile)).to be_truthy @@ -229,7 +229,7 @@ describe Chef::RunLock do end context "when a client acquires a lock and exits normally" do - before { p1.run_to_completion } + before do p1.run_to_completion end it "the lockfile remains" do expect(File.exist?(lockfile)).to be_truthy @@ -258,20 +258,20 @@ describe Chef::RunLock do run_lock = Chef::RunLock.new(lockfile) from_tests, to_fork = IO.pipe from_fork, to_tests = IO.pipe - p1 = fork do + p1 = fork { expect(run_lock.test).to eq(true) to_tests.puts "lock acquired" # Wait for the test to tell us we can exit before exiting from_tests.readline exit! 0 - end + } wait_on_lock(from_fork) - p2 = fork do + p2 = fork { expect(run_lock.test).to eq(false) exit! 0 - end + } pid, exit_status = Process.waitpid2(p2) expect(exit_status).to eq(0) @@ -284,13 +284,13 @@ describe Chef::RunLock do run_lock = Chef::RunLock.new(lockfile) from_tests, to_fork = IO.pipe from_fork, to_tests = IO.pipe - p1 = fork do + p1 = fork { run_lock.acquire to_tests.puts "lock acquired" # Wait for the test to tell us we can exit before exiting from_tests.readline exit! 0 - end + } wait_on_lock(from_fork) expect(run_lock.test).to eq(false) @@ -437,7 +437,7 @@ describe Chef::RunLock do def start example.log_event("#{name}.start") - @pid = fork do + @pid = fork { begin Timeout.timeout(CLIENT_PROCESS_TIMEOUT) do run_lock = TestRunLock.new(example.lockfile) @@ -453,7 +453,7 @@ describe Chef::RunLock do fire_event($!.message.lines.join(" // ")) raise end - end + } example.log_event("#{name}.start forked (pid #{pid})") end diff --git a/spec/functional/shell_spec.rb b/spec/functional/shell_spec.rb index dd0455fc9e..b68fef023a 100644 --- a/spec/functional/shell_spec.rb +++ b/spec/functional/shell_spec.rb @@ -105,11 +105,11 @@ describe Shell do end it "sets the log_level from the command line" do - output, exitstatus = run_chef_shell_with("-lfatal") do |out, keyboard| + output, exitstatus = run_chef_shell_with("-lfatal") { |out, keyboard| show_log_level_code = %q[puts "===#{Chef::Log.level}==="] keyboard.puts(show_log_level_code) read_until(out, show_log_level_code) - end + } expect(output).to include("===fatal===") expect(exitstatus).to eq(0) end @@ -122,22 +122,22 @@ describe Shell do end it "should be able to use the API" do - output, exitstatus = run_chef_shell_with("-s") do |out, keyboard| + output, exitstatus = run_chef_shell_with("-s") { |out, keyboard| simple_api_get = "api.get('data')" keyboard.puts(simple_api_get) read_until(out, simple_api_get) - end + } expect(output).to include("{}") expect(exitstatus).to eq(0) end end it "sets the override_runlist from the command line" do - output, exitstatus = run_chef_shell_with("-o 'override::foo,override::bar'") do |out, keyboard| + output, exitstatus = run_chef_shell_with("-o 'override::foo,override::bar'") { |out, keyboard| show_recipes_code = %q[puts "#{node["recipes"].inspect}"] keyboard.puts(show_recipes_code) read_until(out, show_recipes_code) - end + } expect(output).to include(%q{["override::foo", "override::bar"]}) expect(exitstatus).to eq(0) end diff --git a/spec/functional/tiny_server_spec.rb b/spec/functional/tiny_server_spec.rb index 1ec56bd490..eb6483a859 100644 --- a/spec/functional/tiny_server_spec.rb +++ b/spec/functional/tiny_server_spec.rb @@ -44,7 +44,7 @@ describe TinyServer::API do it "creates a route for a request with a block" do block_called = false - @api.get("/bar/baz", 200) { block_called = true; "hello barbaz" } + @api.get("/bar/baz", 200) do block_called = true; "hello barbaz" end response = @api.call("REQUEST_METHOD" => "GET", "REQUEST_URI" => "http://localhost:1974/bar/baz") expect(response).to eq([200, { "Content-Type" => "application/json" }, [ "hello barbaz" ]]) expect(block_called).to be_truthy diff --git a/spec/functional/win32/security_spec.rb b/spec/functional/win32/security_spec.rb index a72088a079..c38d1d9571 100644 --- a/spec/functional/win32/security_spec.rb +++ b/spec/functional/win32/security_spec.rb @@ -51,9 +51,9 @@ describe "Chef::Win32::Security", :windows_only do end it "has_admin_privileges? returns false" do - has_admin_privileges = with_user_context(user, password, domain, :local) do + has_admin_privileges = with_user_context(user, password, domain, :local) { Chef::ReservedNames::Win32::Security.has_admin_privileges? - end + } expect(has_admin_privileges).to eq(false) end end diff --git a/spec/functional/win32/versions_spec.rb b/spec/functional/win32/versions_spec.rb index 19bd0e3875..2fee52449f 100644 --- a/spec/functional/win32/versions_spec.rb +++ b/spec/functional/win32/versions_spec.rb @@ -59,7 +59,7 @@ describe "Chef::ReservedNames::Win32::Version", :windows_only do context "Win32 version object" do it "should have have one method for each marketing version" do versions = 0 - for_each_windows_version { versions += 1 } + for_each_windows_version do versions += 1 end expect(versions).to be > 0 expect(versions).to eq(Chef::ReservedNames::Win32::Version::WIN_VERSIONS.length) end diff --git a/spec/integration/client/client_spec.rb b/spec/integration/client/client_spec.rb index 68cfd015ab..a6930e8231 100644 --- a/spec/integration/client/client_spec.rb +++ b/spec/integration/client/client_spec.rb @@ -48,7 +48,7 @@ describe "chef-client" do let(:chef_solo) { "bundle exec #{Chef::Dist::SOLOEXEC} --legacy-mode --minimal-ohai" } when_the_repository "has a cookbook with a no-op recipe" do - before { file "cookbooks/x/recipes/default.rb", "" } + before do file "cookbooks/x/recipes/default.rb", "" end it "should complete with success" do file "config/client.rb", <<~EOM @@ -93,7 +93,7 @@ describe "chef-client" do end context "and a config file under .chef/knife.rb" do - before { file ".chef/knife.rb", "xxx.xxx" } + before do file ".chef/knife.rb", "xxx.xxx" end it "should load .chef/knife.rb when -z is specified" do result = shell_out("#{chef_client} -z -o 'x::default'", cwd: path_to("")) diff --git a/spec/integration/client/exit_code_spec.rb b/spec/integration/client/exit_code_spec.rb index 37999ab431..18f44a3e34 100644 --- a/spec/integration/client/exit_code_spec.rb +++ b/spec/integration/client/exit_code_spec.rb @@ -57,7 +57,7 @@ describe "chef-client" do context "with a recipe" do context "which throws an error" do - before { file "cookbooks/x/recipes/default.rb", "raise 'BOOM'" } + before do file "cookbooks/x/recipes/default.rb", "raise 'BOOM'" end it "exits with GENERIC_FAILURE, 1" do setup_client_rb @@ -66,7 +66,7 @@ describe "chef-client" do end context "with a recipe which calls Chef::Application.fatal with a non-RFC exit code" do - before { file "cookbooks/x/recipes/default.rb", "Chef::Application.fatal!('BOOM', 123)" } + before do file "cookbooks/x/recipes/default.rb", "Chef::Application.fatal!('BOOM', 123)" end it "exits with the GENERIC_FAILURE exit code, 1" do setup_client_rb @@ -75,7 +75,7 @@ describe "chef-client" do end context "with a recipe which calls Chef::Application.exit with a non-RFC exit code" do - before { file "cookbooks/x/recipes/default.rb", "Chef::Application.exit!('BOOM', 231)" } + before do file "cookbooks/x/recipes/default.rb", "Chef::Application.exit!('BOOM', 231)" end it "exits with the GENERIC_FAILURE exit code, 1" do setup_client_rb diff --git a/spec/integration/knife/chef_repo_path_spec.rb b/spec/integration/knife/chef_repo_path_spec.rb index 919741f930..852438d4db 100644 --- a/spec/integration/knife/chef_repo_path_spec.rb +++ b/spec/integration/knife/chef_repo_path_spec.rb @@ -178,21 +178,21 @@ describe "chef_repo_path tests", :workstation do end context "when cwd is at the top level" do - before { cwd "." } + before do cwd "." end it "knife list --local -Rfp fails" do knife("list --local -Rfp").should_fail(error_rel_path_outside_repo) end end context "when cwd is inside the data_bags directory" do - before { cwd "data_bags" } + before do cwd "data_bags" end it "knife list --local -Rfp fails" do knife("list --local -Rfp").should_fail(error_rel_path_outside_repo) end end context "when cwd is inside chef_repo2" do - before { cwd "chef_repo2" } + before do cwd "chef_repo2" end it "knife list --local -Rfp lists everything" do knife("list --local -Rfp").should_succeed <<~EOM clients/ @@ -216,7 +216,7 @@ describe "chef_repo_path tests", :workstation do end context "when cwd is inside data_bags2" do - before { cwd "data_bags2" } + before do cwd "data_bags2" end it "knife list --local -Rfp lists data bags" do knife("list --local -Rfp").should_succeed <<~EOM bag2/ @@ -237,7 +237,7 @@ describe "chef_repo_path tests", :workstation do end context "when cwd is at the top level" do - before { cwd "." } + before do cwd "." end it "knife list --local -Rfp lists everything" do knife("list --local -Rfp").should_succeed <<~EOM clients/ @@ -261,21 +261,21 @@ describe "chef_repo_path tests", :workstation do end context "when cwd is inside the data_bags directory" do - before { cwd "data_bags" } + before do cwd "data_bags" end it "knife list --local -Rfp fails" do knife("list --local -Rfp").should_fail(error_rel_path_outside_repo) end end context "when cwd is inside chef_repo2" do - before { cwd "chef_repo2" } + before do cwd "chef_repo2" end it "knife list -Rfp fails" do knife("list --local -Rfp").should_fail(error_rel_path_outside_repo) end end context "when cwd is inside data_bags2" do - before { cwd "data_bags2" } + before do cwd "data_bags2" end it "knife list --local -Rfp lists data bags" do knife("list --local -Rfp").should_succeed <<~EOM bag2/ @@ -294,21 +294,21 @@ describe "chef_repo_path tests", :workstation do end context "when cwd is at the top level" do - before { cwd "." } + before do cwd "." end it "knife list --local -Rfp fails" do knife("list --local -Rfp").should_fail(error_rel_path_outside_repo) end end context "when cwd is inside the data_bags directory" do - before { cwd "data_bags" } + before do cwd "data_bags" end it "knife list --local -Rfp fails" do knife("list --local -Rfp").should_fail(error_rel_path_outside_repo) end end context "when cwd is inside chef_repo2" do - before { cwd "chef_repo2" } + before do cwd "chef_repo2" end it "knife list --local -Rfp lists everything" do knife("list --local -Rfp").should_succeed <<~EOM clients/ @@ -332,7 +332,7 @@ describe "chef_repo_path tests", :workstation do end context "when cwd is inside chef_repo2/data_bags" do - before { cwd "chef_repo2/data_bags" } + before do cwd "chef_repo2/data_bags" end it "knife list --local -Rfp lists data bags" do knife("list --local -Rfp").should_succeed <<~EOM bag3/ @@ -514,14 +514,14 @@ describe "chef_repo_path tests", :workstation do end context "when cwd is at the top level" do - before { cwd "." } + before do cwd "." end it "knife list --local -Rfp fails" do knife("list --local -Rfp").should_fail(error_rel_path_outside_repo) end end context "when cwd is inside the data_bags directory" do - before { cwd "data_bags" } + before do cwd "data_bags" end it "knife list --local -Rfp lists data bags" do knife("list --local -Rfp").should_succeed <<~EOM bag/ @@ -533,7 +533,7 @@ describe "chef_repo_path tests", :workstation do end context "when cwd is inside chef_repo2" do - before { cwd "chef_repo2" } + before do cwd "chef_repo2" end it "knife list --local -Rfp lists everything" do knife("list --local -Rfp").should_succeed <<~EOM clients/ @@ -566,7 +566,7 @@ describe "chef_repo_path tests", :workstation do end context "when cwd is inside data_bags2" do - before { cwd "data_bags2" } + before do cwd "data_bags2" end it "knife list --local -Rfp lists data bags" do knife("list --local -Rfp").should_succeed <<~EOM bag/ @@ -590,7 +590,7 @@ describe "chef_repo_path tests", :workstation do end context "when cwd is at the top level" do - before { cwd "." } + before do cwd "." end it "knife list --local -Rfp lists everything" do knife("list --local -Rfp").should_succeed <<~EOM clients/ @@ -623,7 +623,7 @@ describe "chef_repo_path tests", :workstation do end context "when cwd is inside the data_bags directory" do - before { cwd "data_bags" } + before do cwd "data_bags" end it "knife list --local -Rfp lists data bags" do knife("list --local -Rfp").should_succeed <<~EOM bag/ @@ -635,7 +635,7 @@ describe "chef_repo_path tests", :workstation do end context "when cwd is inside chef_repo2" do - before { cwd "chef_repo2" } + before do cwd "chef_repo2" end it "knife list --local -Rfp lists everything" do knife("list --local -Rfp").should_succeed <<~EOM clients/ @@ -668,7 +668,7 @@ describe "chef_repo_path tests", :workstation do end context "when cwd is inside chef_repo2/data_bags" do - before { cwd "chef_repo2/data_bags" } + before do cwd "chef_repo2/data_bags" end it "knife list --local -Rfp lists data bags" do knife("list --local -Rfp").should_succeed <<~EOM bag/ @@ -690,21 +690,21 @@ describe "chef_repo_path tests", :workstation do end context "when cwd is at the top level" do - before { cwd "." } + before do cwd "." end it "knife list --local -Rfp fails" do knife("list --local -Rfp").should_fail(error_rel_path_outside_repo) end end context "when cwd is inside the data_bags directory" do - before { cwd "data_bags" } + before do cwd "data_bags" end it "knife list --local -Rfp fails" do knife("list --local -Rfp").should_fail(error_rel_path_outside_repo) end end context "when cwd is inside chef_repo2" do - before { cwd "chef_repo2" } + before do cwd "chef_repo2" end it "knife list --local -Rfp lists everything" do knife("list --local -Rfp").should_succeed <<~EOM clients/ @@ -728,7 +728,7 @@ describe "chef_repo_path tests", :workstation do end context "when cwd is inside chef_repo2/data_bags" do - before { cwd "chef_repo2/data_bags" } + before do cwd "chef_repo2/data_bags" end it "knife list --local -Rfp lists data bags" do knife("list --local -Rfp").should_succeed <<~EOM bag3/ @@ -751,7 +751,7 @@ describe "chef_repo_path tests", :workstation do end context "when cwd is at the top level" do - before { cwd "." } + before do cwd "." end it "knife list --local -Rfp lists everything" do knife("list --local -Rfp").should_succeed <<~EOM clients/ @@ -784,7 +784,7 @@ describe "chef_repo_path tests", :workstation do end context "when cwd is inside the data_bags directory" do - before { cwd "data_bags" } + before do cwd "data_bags" end it "knife list --local -Rfp lists data bags" do knife("list --local -Rfp").should_succeed <<~EOM bag/ @@ -796,7 +796,7 @@ describe "chef_repo_path tests", :workstation do end context "when cwd is inside chef_repo2" do - before { cwd "chef_repo2" } + before do cwd "chef_repo2" end it "knife list --local -Rfp lists everything" do knife("list --local -Rfp").should_succeed <<~EOM clients/ @@ -829,7 +829,7 @@ describe "chef_repo_path tests", :workstation do end context "when cwd is inside chef_repo2/data_bags" do - before { cwd "chef_repo2/data_bags" } + before do cwd "chef_repo2/data_bags" end it "knife list --local -Rfp lists data bags" do knife("list --local -Rfp").should_succeed <<~EOM bag/ @@ -851,14 +851,14 @@ describe "chef_repo_path tests", :workstation do end context "when cwd is at the top level" do - before { cwd "." } + before do cwd "." end it "knife list --local -Rfp fails" do knife("list --local -Rfp").should_fail(error_rel_path_outside_repo) end end context "when cwd is inside the data_bags directory" do - before { cwd "data_bags" } + before do cwd "data_bags" end it "knife list --local -Rfp lists data bags" do knife("list --local -Rfp").should_succeed <<~EOM bag/ @@ -868,7 +868,7 @@ describe "chef_repo_path tests", :workstation do end context "when cwd is inside chef_repo2" do - before { cwd "chef_repo2" } + before do cwd "chef_repo2" end it "knife list --local -Rfp lists everything" do knife("list --local -Rfp").should_succeed <<~EOM clients/ @@ -892,7 +892,7 @@ describe "chef_repo_path tests", :workstation do end context "when cwd is inside chef_repo2/data_bags" do - before { cwd "chef_repo2/data_bags" } + before do cwd "chef_repo2/data_bags" end it "knife list --local -Rfp fails" do knife("list --local -Rfp").should_fail(error_rel_path_outside_repo) end @@ -926,7 +926,7 @@ describe "chef_repo_path tests", :workstation do end context "when cwd is inside the data_bags directory" do - before { cwd "data_bags" } + before do cwd "data_bags" end it "knife list --local -Rfp lists data bags" do knife("list --local -Rfp").should_succeed <<~EOM bag/ diff --git a/spec/integration/knife/chef_repository_file_system_spec.rb b/spec/integration/knife/chef_repository_file_system_spec.rb index 6e9c4611e2..04584e1fb4 100644 --- a/spec/integration/knife/chef_repository_file_system_spec.rb +++ b/spec/integration/knife/chef_repository_file_system_spec.rb @@ -42,7 +42,7 @@ describe "General chef_repo file system checks", :workstation do end when_the_repository "has an empty data_bags directory" do - before { directory "data_bags" } + before do directory "data_bags" end it "knife list --local / returns it" do knife("list --local /").should_succeed "/data_bags\n" @@ -50,7 +50,7 @@ describe "General chef_repo file system checks", :workstation do end when_the_repository "has an empty cookbook directory" do - before { directory "cookbooks/cookbook1" } + before do directory "cookbooks/cookbook1" end it "knife list --local -Rfp / does not return it" do knife("list --local -Rfp /").should_succeed(<<~EOM, stderr: "WARN: Cookbook 'cookbook1' is empty or entirely chefignored at #{Chef::Config.chef_repo_path}/cookbooks/cookbook1\n") @@ -60,7 +60,7 @@ describe "General chef_repo file system checks", :workstation do end when_the_repository "has only empty cookbook subdirectories" do - before { directory "cookbooks/cookbook1/recipes" } + before do directory "cookbooks/cookbook1/recipes" end it "knife list --local -Rfp / does not return it" do knife("list --local -Rfp /").should_succeed(<<~EOM, stderr: "WARN: Cookbook 'cookbook1' is empty or entirely chefignored at #{Chef::Config.chef_repo_path}/cookbooks/cookbook1\n") @@ -87,7 +87,7 @@ describe "General chef_repo file system checks", :workstation do end when_the_repository "has only empty cookbook sub-sub-directories" do - before { directory "cookbooks/cookbook1/templates/default" } + before do directory "cookbooks/cookbook1/templates/default" end it "knife list --local -Rfp / does not return it" do knife("list --local -Rfp /").should_succeed(<<~EOM, stderr: "WARN: Cookbook 'cookbook1' is empty or entirely chefignored at #{Chef::Config.chef_repo_path}/cookbooks/cookbook1\n") @@ -159,7 +159,7 @@ describe "General chef_repo file system checks", :workstation do end when_the_repository "has a file in cookbooks/" do - before { file "cookbooks/file", "" } + before do file "cookbooks/file", "" end it "does not show up in list -Rfp" do knife("list --local -Rfp /").should_succeed <<~EOM /cookbooks/ @@ -168,7 +168,7 @@ describe "General chef_repo file system checks", :workstation do end when_the_repository "has a file in data_bags/" do - before { file "data_bags/file", "" } + before do file "data_bags/file", "" end it "does not show up in list -Rfp" do knife("list --local -Rfp /").should_succeed <<~EOM /data_bags/ diff --git a/spec/integration/knife/chefignore_spec.rb b/spec/integration/knife/chefignore_spec.rb index b92fb1f485..b022f1a842 100644 --- a/spec/integration/knife/chefignore_spec.rb +++ b/spec/integration/knife/chefignore_spec.rb @@ -84,7 +84,7 @@ describe "chefignore tests", :workstation do end context "and has a chefignore with filenames" do - before { file "cookbooks/chefignore", "x.json\n" } + before do file "cookbooks/chefignore", "x.json\n" end it "matching files and directories get ignored in all cookbooks" do knife("list --local -Rfp /").should_succeed <<~EOM diff --git a/spec/integration/knife/client_create_spec.rb b/spec/integration/knife/client_create_spec.rb index 505358923b..2a5420cc46 100644 --- a/spec/integration/knife/client_create_spec.rb +++ b/spec/integration/knife/client_create_spec.rb @@ -57,7 +57,7 @@ describe "knife client create", :workstation do it "reads the public key from a file" do Dir.mktmpdir do |tgt| key = OpenSSL::PKey::RSA.generate(1024) - File.open("#{tgt}/public.pem", "w") { |pub| pub.write(key.public_key.to_pem) } + File.open("#{tgt}/public.pem", "w") do |pub| pub.write(key.public_key.to_pem) end knife("client create -p #{tgt}/public.pem bah").should_succeed stderr: out end end diff --git a/spec/integration/knife/client_key_create_spec.rb b/spec/integration/knife/client_key_create_spec.rb index 7ccec8bffd..dc3fbd236d 100644 --- a/spec/integration/knife/client_key_create_spec.rb +++ b/spec/integration/knife/client_key_create_spec.rb @@ -56,7 +56,7 @@ describe "knife client key create", :workstation do it "reads the public key from a file" do Dir.mktmpdir do |tgt| key = OpenSSL::PKey::RSA.generate(1024) - File.open("#{tgt}/public.pem", "w") { |pub| pub.write(key.public_key.to_pem) } + File.open("#{tgt}/public.pem", "w") do |pub| pub.write(key.public_key.to_pem) end knife("client key create -p #{tgt}/public.pem -k new bah").should_succeed stderr: /^#{out}/ end end diff --git a/spec/integration/knife/common_options_spec.rb b/spec/integration/knife/common_options_spec.rb index 5eac571a85..d92c51955b 100644 --- a/spec/integration/knife/common_options_spec.rb +++ b/spec/integration/knife/common_options_spec.rb @@ -31,7 +31,7 @@ describe "knife common options", :workstation do let(:local_listen_warning) { /\Awarn:.*local.*listen.*$/im } when_the_repository "has a node" do - before { file "nodes/x.json", {} } + before do file "nodes/x.json", {} end context "When chef_zero.enabled is true" do before(:each) do @@ -48,7 +48,7 @@ describe "knife common options", :workstation do end context "And chef_zero.port is 9999" do - before(:each) { Chef::Config.chef_zero.port = 9999 } + before(:each) do Chef::Config.chef_zero.port = 9999 end it "knife raw /nodes/x should retrieve the node" do knife("raw --listen /nodes/x").should_succeed( /"name": "x"/, stderr: local_listen_warning ) @@ -58,7 +58,7 @@ describe "knife common options", :workstation do # 0.0.0.0 is not a valid address to bind to on windows. context "And chef_zero.host is 0.0.0.0", :unix_only do - before(:each) { Chef::Config.chef_zero.host = "0.0.0.0" } + before(:each) do Chef::Config.chef_zero.host = "0.0.0.0" end it "knife raw /nodes/x should retrieve the role" do knife("raw --listen /nodes/x").should_succeed( /"name": "x"/, stderr: local_listen_warning ) diff --git a/spec/integration/knife/config_get_profile_spec.rb b/spec/integration/knife/config_get_profile_spec.rb index e97b24b869..214413f548 100644 --- a/spec/integration/knife/config_get_profile_spec.rb +++ b/spec/integration/knife/config_get_profile_spec.rb @@ -41,7 +41,7 @@ describe "knife config get-profile", :workstation do old_wd = Dir.pwd ChefConfig::PathHelper.per_tool_home_environment = "KNIFE_HOME" # Clear these out because they are cached permanently. - ChefConfig::PathHelper.class_exec { remove_class_variable(:@@home_dir) } + ChefConfig::PathHelper.class_exec do remove_class_variable(:@@home_dir) end Chef::Knife::ConfigGetProfile.reset_config_loader! begin ex.run @@ -88,7 +88,7 @@ describe "knife config get-profile", :workstation do end context "with a context file" do - before { file(".chef/context", "development\n") } + before do file(".chef/context", "development\n") end it { is_expected.to eq "development\n" } end diff --git a/spec/integration/knife/config_get_spec.rb b/spec/integration/knife/config_get_spec.rb index 98fefd729f..d2e1461a2a 100644 --- a/spec/integration/knife/config_get_spec.rb +++ b/spec/integration/knife/config_get_spec.rb @@ -45,7 +45,7 @@ describe "knife config get", :workstation do old_wd = Dir.pwd ChefConfig::PathHelper.per_tool_home_environment = "KNIFE_HOME" # Clear these out because they are cached permanently. - ChefConfig::PathHelper.class_exec { remove_class_variable(:@@home_dir) } + ChefConfig::PathHelper.class_exec do remove_class_variable(:@@home_dir) end Chef::Knife::ConfigGet.reset_config_loader! begin ex.run @@ -69,14 +69,14 @@ describe "knife config get", :workstation do end context "with a global knife.rb" do - before { file(".chef/knife.rb", "node_name 'one'\n") } + before do file(".chef/knife.rb", "node_name 'one'\n") end it { is_expected.to match(%r{^Loading from configuration file .*/#{File.basename(path_to("."))}/.chef/knife.rb$}) } it { is_expected.to match(/^node_name:\s+one$/) } end context "with a repo knife.rb" do - before { file("repo/.chef/knife.rb", "node_name 'two'\n") } + before do file("repo/.chef/knife.rb", "node_name 'two'\n") end it { is_expected.to match(%r{^Loading from configuration file .*/#{File.basename(path_to("."))}/repo/.chef/knife.rb$}) } it { is_expected.to match(/^node_name:\s+two$/) } @@ -93,7 +93,7 @@ describe "knife config get", :workstation do end context "with a credentials file" do - before { file(".chef/credentials", "[default]\nclient_name = \"three\"\n") } + before do file(".chef/credentials", "[default]\nclient_name = \"three\"\n") end it { is_expected.to match(%r{^Loading from credentials file .*/#{File.basename(path_to("."))}/.chef/credentials$}) } it { is_expected.to match(/^node_name:\s+three$/) } @@ -134,49 +134,49 @@ describe "knife config get", :workstation do context "with single argument" do let(:cmd_args) { %w{node_name} } - before { file(".chef/credentials", "[default]\nclient_name = \"three\"\n") } + before do file(".chef/credentials", "[default]\nclient_name = \"three\"\n") end it { is_expected.to match(/^node_name:\s+three\Z/) } end context "with two arguments" do let(:cmd_args) { %w{node_name client_key} } - before { file(".chef/credentials", "[default]\nclient_name = \"three\"\nclient_key = \"three.pem\"") } + before do file(".chef/credentials", "[default]\nclient_name = \"three\"\nclient_key = \"three.pem\"") end it { is_expected.to match(%r{^client_key:\s+\S*/.chef/three.pem\nnode_name:\s+three\Z}) } end context "with a dotted argument" do let(:cmd_args) { %w{knife.ssh_user} } - before { file(".chef/credentials", "[default]\nclient_name = \"three\"\n[default.knife]\nssh_user = \"foo\"\n") } + before do file(".chef/credentials", "[default]\nclient_name = \"three\"\n[default.knife]\nssh_user = \"foo\"\n") end it { is_expected.to match(/^knife.ssh_user:\s+foo\Z/) } end context "with regex argument" do let(:cmd_args) { %w{/name/} } - before { file(".chef/credentials", "[default]\nclient_name = \"three\"\n") } + before do file(".chef/credentials", "[default]\nclient_name = \"three\"\n") end it { is_expected.to match(/^node_name:\s+three\Z/) } end context "with --all" do let(:cmd_args) { %w{-a /key_contents/} } - before { file(".chef/credentials", "[default]\nclient_name = \"three\"\n") } + before do file(".chef/credentials", "[default]\nclient_name = \"three\"\n") end it { is_expected.to match(/^client_key_contents:\s+\nvalidation_key_contents:\s+\Z/) } end context "with --raw" do let(:cmd_args) { %w{-r node_name} } - before { file(".chef/credentials", "[default]\nclient_name = \"three\"\n") } + before do file(".chef/credentials", "[default]\nclient_name = \"three\"\n") end it { is_expected.to eq("three\n") } end context "with --format=json" do let(:cmd_args) { %w{--format=json node_name} } - before { file(".chef/credentials", "[default]\nclient_name = \"three\"\n") } + before do file(".chef/credentials", "[default]\nclient_name = \"three\"\n") end it { expect(JSON.parse(subject)).to eq({ "node_name" => "three" }) } end diff --git a/spec/integration/knife/config_list_profiles_spec.rb b/spec/integration/knife/config_list_profiles_spec.rb index 044b50b5be..3f7dd33c9c 100644 --- a/spec/integration/knife/config_list_profiles_spec.rb +++ b/spec/integration/knife/config_list_profiles_spec.rb @@ -37,7 +37,7 @@ describe "knife config list-profiles", :workstation do old_home = ENV["HOME"] old_wd = Dir.pwd # Clear these out because they are cached permanently. - ChefConfig::PathHelper.class_exec { remove_class_variable(:@@home_dir) } + ChefConfig::PathHelper.class_exec do remove_class_variable(:@@home_dir) end Chef::Knife::ConfigListProfiles.reset_config_loader! begin ex.run @@ -67,13 +67,13 @@ describe "knife config list-profiles", :workstation do end context "with an empty credentials file" do - before { file(".chef/credentials", "") } + before do file(".chef/credentials", "") end subject { knife_list_profiles.stderr } it { is_expected.to eq "FATAL: No profiles found, #{path_to(".chef/credentials")} does not exist or is empty\n" } end context "with a simple default profile" do - before { file(".chef/credentials", <<~EOH) } + before do file(".chef/credentials", <<~EOH) end [default] client_name = "testuser" client_key = "testkey.pem" @@ -87,7 +87,7 @@ describe "knife config list-profiles", :workstation do end context "with multiple profiles" do - before { file(".chef/credentials", <<~EOH) } + before do file(".chef/credentials", <<~EOH) end [default] client_name = "testuser" client_key = "testkey.pem" @@ -114,7 +114,7 @@ describe "knife config list-profiles", :workstation do context "with a non-default active profile" do let(:cmd_args) { %w{--profile prod} } - before { file(".chef/credentials", <<~EOH) } + before do file(".chef/credentials", <<~EOH) end [default] client_name = "testuser" client_key = "testkey.pem" @@ -140,7 +140,7 @@ describe "knife config list-profiles", :workstation do end context "with a minimal profile" do - before { file(".chef/credentials", <<~EOH) } + before do file(".chef/credentials", <<~EOH) end [default] chef_server_url = "https://example.com/organizations/testorg" EOH @@ -149,7 +149,7 @@ describe "knife config list-profiles", :workstation do context "with -i" do let(:cmd_args) { %w{-i} } - before { file(".chef/credentials", <<~EOH) } + before do file(".chef/credentials", <<~EOH) end [default] chef_server_url = "https://example.com/organizations/testorg" EOH @@ -162,7 +162,7 @@ describe "knife config list-profiles", :workstation do context "with --format=json" do let(:cmd_args) { %w{--format=json node_name} } - before { file(".chef/credentials", <<~EOH) } + before do file(".chef/credentials", <<~EOH) end [default] client_name = "testuser" client_key = "testkey.pem" diff --git a/spec/integration/knife/config_use_profile_spec.rb b/spec/integration/knife/config_use_profile_spec.rb index a021dbbe6f..4c52d1c4bd 100644 --- a/spec/integration/knife/config_use_profile_spec.rb +++ b/spec/integration/knife/config_use_profile_spec.rb @@ -42,7 +42,7 @@ describe "knife config use-profile", :workstation do old_wd = Dir.pwd ChefConfig::PathHelper.per_tool_home_environment = "KNIFE_HOME" # Clear these out because they are cached permanently. - ChefConfig::PathHelper.class_exec { remove_class_variable(:@@home_dir) } + ChefConfig::PathHelper.class_exec do remove_class_variable(:@@home_dir) end Chef::Knife::ConfigUseProfile.reset_config_loader! begin ex.run @@ -80,7 +80,7 @@ describe "knife config use-profile", :workstation do context "with $CHEF_HOME" do let(:cmd_args) { %w{staging} } - before { ENV["CHEF_HOME"] = path_to("chefhome"); file("chefhome/tmp", "") } + before do ENV["CHEF_HOME"] = path_to("chefhome"); file("chefhome/tmp", "") end it do is_expected.to eq "Set default profile to staging\n" expect(File.read(path_to("chefhome/.chef/context"))).to eq "staging\n" @@ -90,7 +90,7 @@ describe "knife config use-profile", :workstation do context "with $KNIFE_HOME" do let(:cmd_args) { %w{development} } - before { ENV["KNIFE_HOME"] = path_to("knifehome"); file("knifehome/tmp", "") } + before do ENV["KNIFE_HOME"] = path_to("knifehome"); file("knifehome/tmp", "") end it do is_expected.to eq "Set default profile to development\n" expect(File.read(path_to("knifehome/.chef/context"))).to eq "development\n" diff --git a/spec/integration/knife/delete_spec.rb b/spec/integration/knife/delete_spec.rb index fd5853dfef..440be05878 100644 --- a/spec/integration/knife/delete_spec.rb +++ b/spec/integration/knife/delete_spec.rb @@ -641,7 +641,7 @@ describe "knife delete", :workstation do end context "and cwd is at the top level" do - before { cwd "." } + before do cwd "." end it "knife delete fails" do knife("delete").should_fail "FATAL: You must specify at least one argument. If you want to delete everything in this directory, run \"knife delete --recurse .\"\n", stdout: /USAGE/ knife("list -Rf /").should_succeed <<~EOM @@ -854,7 +854,7 @@ describe "knife delete", :workstation do end context "and cwd is at the top level" do - before { cwd "." } + before do cwd "." end it "knife delete fails" do knife("delete").should_fail "FATAL: You must specify at least one argument. If you want to delete everything in this directory, run \"knife delete --recurse .\"\n", stdout: /USAGE/ knife("list -Rf /").should_succeed <<~EOM @@ -928,7 +928,7 @@ describe "knife delete", :workstation do end when_the_chef_server "has a later version for the cookbook, and no current version" do - before { cookbook "x", "1.0.1", { "onlyin1.0.1.rb" => "hi" } } + before do cookbook "x", "1.0.1", { "onlyin1.0.1.rb" => "hi" } end it "knife delete --both /cookbooks/x deletes the server and client version of the cookbook" do knife("delete --both -r /cookbooks/x").should_succeed "Deleted /cookbooks/x\n" @@ -938,7 +938,7 @@ describe "knife delete", :workstation do end when_the_chef_server "has an earlier version for the cookbook, and no current version" do - before { cookbook "x", "0.9.9", { "onlyin0.9.9.rb" => "hi" } } + before do cookbook "x", "0.9.9", { "onlyin0.9.9.rb" => "hi" } end it "knife delete --both /cookbooks/x deletes the server and client version of the cookbook" do knife("delete --both -r /cookbooks/x").should_succeed "Deleted /cookbooks/x\n" diff --git a/spec/integration/knife/deps_spec.rb b/spec/integration/knife/deps_spec.rb index 4dfccf38de..0c0e441966 100644 --- a/spec/integration/knife/deps_spec.rb +++ b/spec/integration/knife/deps_spec.rb @@ -25,7 +25,7 @@ describe "knife deps", :workstation do context "local" do when_the_repository "has a role with no run_list" do - before { file "roles/starring.json", {} } + before do file "roles/starring.json", {} end it "knife deps reports no dependencies" do knife("deps /roles/starring.json").should_succeed "/roles/starring.json\n" end @@ -70,7 +70,7 @@ describe "knife deps", :workstation do end when_the_repository "has a node with no environment or run_list" do - before { file "nodes/mort.json", {} } + before do file "nodes/mort.json", {} end it "knife deps reports just the node" do knife("deps /nodes/mort.json").should_succeed "/nodes/mort.json\n" end @@ -123,13 +123,13 @@ depends "kettle"' end end when_the_repository "has a data bag" do - before { file "data_bags/bag/item.json", {} } + before do file "data_bags/bag/item.json", {} end it "knife deps reports just the data bag" do knife("deps /data_bags/bag/item.json").should_succeed "/data_bags/bag/item.json\n" end end when_the_repository "has an environment" do - before { file "environments/desert.json", {} } + before do file "environments/desert.json", {} end it "knife deps reports just the environment" do knife("deps /environments/desert.json").should_succeed "/environments/desert.json\n" end @@ -344,13 +344,13 @@ depends "foo"' end end when_the_repository "has a data bag" do - before { file "data_bags/bag/item.json", "" } + before do file "data_bags/bag/item.json", "" end it "knife deps /data_bags/bag shows no dependencies" do knife("deps /data_bags/bag").should_succeed("/data_bags/bag\n") end end when_the_repository "has a cookbook" do - before { file "cookbooks/blah/metadata.rb", 'name "blah"' } + before do file "cookbooks/blah/metadata.rb", 'name "blah"' end it "knife deps on a cookbook file shows no dependencies" do knife("deps /cookbooks/blah/metadata.rb").should_succeed( "/cookbooks/blah/metadata.rb\n" @@ -364,7 +364,7 @@ depends "foo"' include_context "default config options" when_the_chef_server "has a role with no run_list" do - before { role "starring", {} } + before do role "starring", {} end it "knife deps reports no dependencies" do knife("deps --remote /roles/starring.json").should_succeed "/roles/starring.json\n" end @@ -405,7 +405,7 @@ depends "foo"' end when_the_chef_server "has a node with no environment or run_list" do - before { node "mort", {} } + before do node "mort", {} end it "knife deps reports just the node" do knife("deps --remote /nodes/mort.json").should_succeed "/nodes/mort.json\n" end @@ -454,13 +454,13 @@ depends "kettle"', "recipes" => { "default.rb" => "" } } end end when_the_chef_server "has a data bag" do - before { data_bag "bag", { "item" => {} } } + before do data_bag "bag", { "item" => {} } end it "knife deps reports just the data bag" do knife("deps --remote /data_bags/bag/item.json").should_succeed "/data_bags/bag/item.json\n" end end when_the_chef_server "has an environment" do - before { environment "desert", {} } + before do environment "desert", {} end it "knife deps reports just the environment" do knife("deps --remote /environments/desert.json").should_succeed "/environments/desert.json\n" end @@ -678,7 +678,7 @@ depends "self"' } end end when_the_chef_server "has a data bag" do - before { data_bag "bag", { "item" => {} } } + before do data_bag "bag", { "item" => {} } end it "knife deps /data_bags/bag shows no dependencies" do knife("deps --remote /data_bags/bag").should_succeed("/data_bags/bag\n") end diff --git a/spec/integration/knife/diff_spec.rb b/spec/integration/knife/diff_spec.rb index 87cbd1559d..944666ccc7 100644 --- a/spec/integration/knife/diff_spec.rb +++ b/spec/integration/knife/diff_spec.rb @@ -134,7 +134,7 @@ describe "knife diff", :workstation do end context "when cwd is the data_bags directory" do - before { cwd "data_bags" } + before do cwd "data_bags" end it "knife diff reports different data bags" do knife("diff --name-status").should_succeed <<~EOM A\tx/z.json @@ -240,13 +240,13 @@ describe "knife diff", :workstation do end when_the_chef_server "has an empty environment" do - before { environment "x", {} } + before do environment "x", {} end it "knife diff returns no differences" do knife("diff /environments/x.json").should_succeed "" end end when_the_chef_server "has an environment with a different value" do - before { environment "x", { "description" => "hi" } } + before do environment "x", { "description" => "hi" } end it "knife diff reports the difference" do knife("diff /environments/x.json").should_succeed(/ { @@ -305,9 +305,9 @@ describe "knife diff", :workstation do end when_the_chef_server "has an environment" do - before { environment "x", {} } + before do environment "x", {} end when_the_repository "has an environment with bad JSON" do - before { file "environments/x.json", "{" } + before do file "environments/x.json", "{" end it "knife diff reports an error and does a textual diff" do error_text = "WARN: Parse error reading #{path_to("environments/x.json")} as JSON: parse error: premature EOF" error_match = Regexp.new(Regexp.escape(error_text)) @@ -430,7 +430,7 @@ describe "knife diff", :workstation do end context "when cwd is the data_bags directory" do - before { cwd "data_bags" } + before do cwd "data_bags" end it "knife diff reports different data bags" do knife("diff --name-status").should_succeed <<~EOM A\tx/z.json @@ -524,15 +524,15 @@ describe "knife diff", :workstation do context "json diff tests" do when_the_repository "has an empty environment file" do - before { file "environments/x.json", {} } + before do file "environments/x.json", {} end when_the_chef_server "has an empty environment" do - before { environment "x", {} } + before do environment "x", {} end it "knife diff returns no differences" do knife("diff /environments/x.json").should_succeed "" end end when_the_chef_server "has an environment with a different value" do - before { environment "x", { "description" => "hi" } } + before do environment "x", { "description" => "hi" } end it "knife diff reports the difference" do knife("diff /environments/x.json").should_succeed(/ { @@ -559,7 +559,7 @@ describe "knife diff", :workstation do end end when_the_chef_server "has an environment with no value" do - before { environment "x", {} } + before do environment "x", {} end it "knife diff reports the difference" do knife("diff /environments/x.json").should_succeed(/ { @@ -588,9 +588,9 @@ describe "knife diff", :workstation do end when_the_chef_server "has an environment" do - before { environment "x", {} } + before do environment "x", {} end when_the_repository "has an environment with bad JSON" do - before { file "environments/x.json", "{" } + before do file "environments/x.json", "{" end it "knife diff reports an error and does a textual diff" do error_text = "WARN: Parse error reading #{path_to("environments/x.json")} as JSON: parse error: premature EOF" error_match = Regexp.new(Regexp.escape(error_text)) diff --git a/spec/integration/knife/list_spec.rb b/spec/integration/knife/list_spec.rb index 830dd0e428..fb62c69ec7 100644 --- a/spec/integration/knife/list_spec.rb +++ b/spec/integration/knife/list_spec.rb @@ -314,7 +314,7 @@ describe "knife list", :workstation do context "symlink tests" do when_the_repository "is empty" do context "when cwd is at the top of the repository" do - before { cwd "." } + before do cwd "." end it "knife list -Rfp returns everything" do knife("list -Rfp").should_succeed <<~EOM @@ -357,9 +357,9 @@ describe "knife list", :workstation do end when_the_repository "has a cookbooks directory" do - before { directory "cookbooks" } + before do directory "cookbooks" end context "when cwd is in cookbooks/" do - before { cwd "cookbooks" } + before do cwd "cookbooks" end it "knife list -Rfp / returns everything" do knife("list -Rfp /").should_succeed <<~EOM @@ -451,10 +451,10 @@ describe "knife list", :workstation do end when_the_repository "has a cookbooks/cookbook2 directory" do - before { directory "cookbooks/cookbook2" } + before do directory "cookbooks/cookbook2" end context "when cwd is in cookbooks/cookbook2" do - before { cwd "cookbooks/cookbook2" } + before do cwd "cookbooks/cookbook2" end it "knife list -Rfp returns cookbooks" do knife("list -Rfp").should_succeed <<~EOM @@ -473,7 +473,7 @@ describe "knife list", :workstation do end context "when cwd is in cookbooks/" do - before { cwd "cookbooks" } + before do cwd "cookbooks" end it "knife list -Rfp returns cookbooks" do knife("list -Rfp").should_succeed <<~EOM @@ -488,7 +488,7 @@ describe "knife list", :workstation do end context "when cwd is in symlinked/" do - before { cwd "symlinked" } + before do cwd "symlinked" end it "knife list -Rfp returns cookbooks" do knife("list -Rfp").should_succeed <<~EOM @@ -510,7 +510,7 @@ describe "knife list", :workstation do end context "when cwd is in real_cookbooks/" do - before { cwd "real_cookbooks" } + before do cwd "real_cookbooks" end it "knife list -Rfp returns cookbooks" do knife("list -Rfp").should_succeed <<~EOM @@ -525,7 +525,7 @@ describe "knife list", :workstation do end context "when cwd is in cookbooks/" do - before { cwd "cookbooks" } + before do cwd "cookbooks" end it "knife list -Rfp returns cookbooks" do knife("list -Rfp").should_succeed <<~EOM diff --git a/spec/integration/knife/redirection_spec.rb b/spec/integration/knife/redirection_spec.rb index 5e5ef27b9a..7bf7b772cd 100644 --- a/spec/integration/knife/redirection_spec.rb +++ b/spec/integration/knife/redirection_spec.rb @@ -27,7 +27,7 @@ describe "redirection", :workstation do include_context "default config options" when_the_chef_server "has a role" do - before { role "x", {} } + before do role "x", {} end context "and another server redirects to it with 302" do before :each do diff --git a/spec/integration/knife/show_spec.rb b/spec/integration/knife/show_spec.rb index dd83475b8c..a237603ceb 100644 --- a/spec/integration/knife/show_spec.rb +++ b/spec/integration/knife/show_spec.rb @@ -156,7 +156,7 @@ describe "knife show", :workstation do end when_the_repository "has an environment with bad JSON" do - before { file "environments/x.json", "{" } + before do file "environments/x.json", "{" end it "knife show succeeds" do knife("show --local /environments/x.json").should_succeed <<~EOM /environments/x.json: diff --git a/spec/integration/recipes/lwrp_inline_resources_spec.rb b/spec/integration/recipes/lwrp_inline_resources_spec.rb index b96fa1d67d..e732da9f69 100644 --- a/spec/integration/recipes/lwrp_inline_resources_spec.rb +++ b/spec/integration/recipes/lwrp_inline_resources_spec.rb @@ -37,9 +37,9 @@ describe "LWRPs with inline resources" do it "this is totally a bug, but for backcompat purposes, it adds the resources to the main resource collection and does not get marked updated" do r = nil - expect_recipe do + expect_recipe { r = lwrp_inline_resources_test "hi" - end.to have_updated("ruby_block[run a]", :run) + }.to have_updated("ruby_block[run a]", :run) expect(r.ran_a).to eq "ran a" end end @@ -58,7 +58,7 @@ describe "LWRPs with inline resources" do end end - after { File.delete(LwrpShadowedPropertyTest::PATH) if File.exists?(LwrpShadowedPropertyTest::PATH) } + after do File.delete(LwrpShadowedPropertyTest::PATH) if File.exists?(LwrpShadowedPropertyTest::PATH) end # https://github.com/chef/chef/issues/4334 it "does not warn spuriously" do @@ -101,11 +101,11 @@ describe "LWRPs with inline resources" do it "resources declared in b are executed immediately inline" do r = nil - expect_recipe do + expect_recipe { r = lwrp_inline_resources_test2 "hi" do action :b end - end.to have_updated("lwrp_inline_resources_test2[hi]", :b) + }.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\"" diff --git a/spec/integration/recipes/noop_resource_spec.rb b/spec/integration/recipes/noop_resource_spec.rb index db6b668553..2f2c6e7ae4 100644 --- a/spec/integration/recipes/noop_resource_spec.rb +++ b/spec/integration/recipes/noop_resource_spec.rb @@ -13,11 +13,11 @@ describe "Resources with a no-op provider" do end it "does not blow up a run with a noop'd resource" do - recipe = converge do + recipe = converge { hi_there "blah" do action :update end - end + } expect(recipe.logged_warnings).to eq "" end end diff --git a/spec/integration/recipes/provider_choice.rb b/spec/integration/recipes/provider_choice.rb index dea58230db..3f9e87eb77 100644 --- a/spec/integration/recipes/provider_choice.rb +++ b/spec/integration/recipes/provider_choice.rb @@ -25,9 +25,9 @@ describe "Recipe DSL methods" do end it "provider_thingy 'blah' runs the provider and warns" do - recipe = converge do + recipe = converge { provider_thingy("blah") {} - end + } expect(recipe.logged_warnings).to match /hello from Chef::Provider::ProviderThingy/ expect(recipe.logged_warnings).to match /you must use 'provides' to provide DSL/i end diff --git a/spec/integration/recipes/recipe_dsl_spec.rb b/spec/integration/recipes/recipe_dsl_spec.rb index 766752ac13..75670722a4 100644 --- a/spec/integration/recipes/recipe_dsl_spec.rb +++ b/spec/integration/recipes/recipe_dsl_spec.rb @@ -8,8 +8,8 @@ describe "Recipe DSL methods" do attr_accessor :current_index end - before(:all) { Namer.current_index = 1 } - before { Namer.current_index += 1 } + before(:all) do Namer.current_index = 1 end + before do Namer.current_index += 1 end context "with resource 'base_thingy' declared as BaseThingy" do before(:each) do @@ -50,18 +50,18 @@ describe "Recipe DSL methods" do end it "creates base_thingy when you call base_thingy in a recipe" do - recipe = converge do + recipe = converge { base_thingy("blah") {} - end + } expect(recipe.logged_warnings).to eq "" expect(BaseThingy.created_name).to eq "blah" expect(BaseThingy.created_resource).to eq BaseThingy end it "errors when you call base_thingy do ... end in a recipe" do - expect_converge do + expect_converge { base_thingy { ; } - end.to raise_error(Chef::Exceptions::ValidationFailed) + }.to raise_error(Chef::Exceptions::ValidationFailed) end context "nameless resources" do @@ -75,9 +75,9 @@ describe "Recipe DSL methods" do end it "does not error when not given a name" do - recipe = converge do + recipe = converge { nameless_thingy {} - end + } expect(recipe.logged_warnings).to eq "" expect(BaseThingy.created_name).to eq "" expect(BaseThingy.created_resource).to eq NamelessThingy @@ -98,9 +98,9 @@ describe "Recipe DSL methods" do end it "bar_thingy does not work" do - expect_converge do + expect_converge { bar_thingy("blah") {} - end.to raise_error(NoMethodError) + }.to raise_error(NoMethodError) end end @@ -114,9 +114,9 @@ describe "Recipe DSL methods" do end it "no_name_thingy does not work" do - expect_converge do + expect_converge { no_name_thingy("blah") {} - end.to raise_error(NoMethodError) + }.to raise_error(NoMethodError) end end @@ -130,15 +130,15 @@ describe "Recipe DSL methods" do end it "another_no_name_thingy does not work" do - expect_converge do + expect_converge { another_no_name_thingy("blah") {} - end.to raise_error(NoMethodError) + }.to raise_error(NoMethodError) end it "another_thingy_name works" do - recipe = converge do + recipe = converge { another_thingy_name("blah") {} - end + } expect(recipe.logged_warnings).to eq "" expect(BaseThingy.created_resource).to eq(AnotherNoNameThingy) end @@ -155,21 +155,21 @@ describe "Recipe DSL methods" do end it "another_no_name_thingy does not work" do - expect_converge do + expect_converge { another_no_name_thingy2("blah") {} - end.to raise_error(NoMethodError) + }.to raise_error(NoMethodError) end it "another_thingy_name2 does not work" do - expect_converge do + expect_converge { another_thingy_name2("blah") {} - end.to raise_error(NoMethodError) + }.to raise_error(NoMethodError) end it "yet_another_thingy_name3 works" do - recipe = converge do + recipe = converge { another_thingy_name3("blah") {} - end + } expect(recipe.logged_warnings).to eq "" expect(BaseThingy.created_resource).to eq(AnotherNoNameThingy2) end @@ -187,19 +187,19 @@ describe "Recipe DSL methods" do end it "and os = linux, another_no_name_thingy3 does not work" do - expect_converge do + expect_converge { # TODO this is an ugly way to test, make Cheffish expose node attrs run_context.node.automatic[:os] = "linux" another_no_name_thingy3("blah") {} - end.to raise_error(Chef::Exceptions::NoSuchResourceType) + }.to raise_error(Chef::Exceptions::NoSuchResourceType) end it "and os = blarghle, another_no_name_thingy3 works" do - recipe = converge do + recipe = converge { # TODO this is an ugly way to test, make Cheffish expose node attrs run_context.node.automatic[:os] = "blarghle" another_no_name_thingy3("blah") {} - end + } expect(recipe.logged_warnings).to eq "" expect(BaseThingy.created_resource).to eq (AnotherNoNameThingy3) end @@ -217,29 +217,29 @@ describe "Recipe DSL methods" do end it "and os = linux, another_no_name_thingy4 does not work" do - expect_converge do + expect_converge { # TODO this is an ugly way to test, make Cheffish expose node attrs run_context.node.automatic[:os] = "linux" another_no_name_thingy4("blah") {} - end.to raise_error(Chef::Exceptions::NoSuchResourceType) + }.to raise_error(Chef::Exceptions::NoSuchResourceType) end it "and os = blarghle, another_no_name_thingy4 works" do - recipe = converge do + recipe = converge { # TODO this is an ugly way to test, make Cheffish expose node attrs run_context.node.automatic[:os] = "blarghle" another_no_name_thingy4("blah") {} - end + } expect(recipe.logged_warnings).to eq "" expect(BaseThingy.created_resource).to eq (AnotherNoNameThingy4) end it "and platform_family = foo, another_no_name_thingy4 works" do - recipe = converge do + recipe = converge { # TODO this is an ugly way to test, make Cheffish expose node attrs run_context.node.automatic[:platform_family] = "foo" another_no_name_thingy4("blah") {} - end + } expect(recipe.logged_warnings).to eq "" expect(BaseThingy.created_resource).to eq (AnotherNoNameThingy4) end @@ -256,27 +256,27 @@ describe "Recipe DSL methods" do end it "and os = linux, another_no_name_thingy5 does not work" do - expect_converge do + expect_converge { # this is an ugly way to test, make Cheffish expose node attrs run_context.node.automatic[:os] = "linux" another_no_name_thingy5("blah") {} - end.to raise_error(Chef::Exceptions::NoSuchResourceType) + }.to raise_error(Chef::Exceptions::NoSuchResourceType) end it "and os = blarghle, another_no_name_thingy5 works" do - recipe = converge do + recipe = converge { # this is an ugly way to test, make Cheffish expose node attrs run_context.node.automatic[:os] = "blarghle" another_no_name_thingy5("blah") {} - end + } expect(recipe.logged_warnings).to eq "" expect(BaseThingy.created_resource).to eq (AnotherNoNameThingy5) end it "the new resource name can be used in a recipe" do - recipe = converge do + recipe = converge { another_thingy_name_for_another_no_name_thingy5("blah") {} - end + } expect(recipe.logged_warnings).to eq "" expect(BaseThingy.created_resource).to eq (AnotherNoNameThingy5) end @@ -293,27 +293,27 @@ describe "Recipe DSL methods" do end it "and os = linux, another_no_name_thingy6 does not work" do - expect_converge do + expect_converge { # this is an ugly way to test, make Cheffish expose node attrs run_context.node.automatic[:os] = "linux" another_no_name_thingy6("blah") {} - end.to raise_error(Chef::Exceptions::NoSuchResourceType) + }.to raise_error(Chef::Exceptions::NoSuchResourceType) end it "and os = blarghle, another_no_name_thingy6 works" do - recipe = converge do + recipe = converge { # this is an ugly way to test, make Cheffish expose node attrs run_context.node.automatic[:os] = "blarghle" another_no_name_thingy6("blah") {} - end + } expect(recipe.logged_warnings).to eq "" expect(BaseThingy.created_resource).to eq (AnotherNoNameThingy6) end it "the new resource name can be used in a recipe" do - recipe = converge do + recipe = converge { another_thingy_name_for_another_no_name_thingy6("blah") {} - end + } expect(recipe.logged_warnings).to eq "" expect(BaseThingy.created_resource).to eq (AnotherNoNameThingy6) end @@ -330,29 +330,29 @@ describe "Recipe DSL methods" do end it "and os = linux, another_thingy_name_for_another_no_name_thingy7 does not work" do - expect_converge do + expect_converge { # this is an ugly way to test, make Cheffish expose node attrs run_context.node.automatic[:os] = "linux" another_thingy_name_for_another_no_name_thingy7("blah") {} - end.to raise_error(Chef::Exceptions::NoSuchResourceType) + }.to raise_error(Chef::Exceptions::NoSuchResourceType) end it "and os = blarghle, another_thingy_name_for_another_no_name_thingy7 works" do - recipe = converge do + recipe = converge { # this is an ugly way to test, make Cheffish expose node attrs run_context.node.automatic[:os] = "blarghle" another_thingy_name_for_another_no_name_thingy7("blah") {} - end + } expect(recipe.logged_warnings).to eq "" expect(BaseThingy.created_resource).to eq (AnotherNoNameThingy7) end it "the old resource name does not work" do - expect_converge do + expect_converge { # this is an ugly way to test, make Cheffish expose node attrs run_context.node.automatic[:os] = "linux" another_no_name_thingy_7("blah") {} - end.to raise_error(NoMethodError) + }.to raise_error(NoMethodError) end end @@ -368,29 +368,29 @@ describe "Recipe DSL methods" do end it "and os = linux, another_thingy_name_for_another_no_name_thingy8 does not work" do - expect_converge do + expect_converge { # this is an ugly way to test, make Cheffish expose node attrs run_context.node.automatic[:os] = "linux" another_thingy_name_for_another_no_name_thingy8("blah") {} - end.to raise_error(Chef::Exceptions::NoSuchResourceType) + }.to raise_error(Chef::Exceptions::NoSuchResourceType) end it "and os = blarghle, another_thingy_name_for_another_no_name_thingy8 works" do - recipe = converge do + recipe = converge { # this is an ugly way to test, make Cheffish expose node attrs run_context.node.automatic[:os] = "blarghle" another_thingy_name_for_another_no_name_thingy8("blah") {} - end + } expect(recipe.logged_warnings).to eq "" expect(BaseThingy.created_resource).to eq (AnotherNoNameThingy8) end it "the old resource name does not work" do - expect_converge do + expect_converge { # this is an ugly way to test, make Cheffish expose node attrs run_context.node.automatic[:os] = "linux" another_thingy_name8("blah") {} - end.to raise_error(NoMethodError) + }.to raise_error(NoMethodError) end end end @@ -407,15 +407,15 @@ describe "Recipe DSL methods" do end it "my_supplier does not work in a recipe" do - expect_converge do + expect_converge { my_supplier("blah") {} - end.to raise_error(NoMethodError) + }.to raise_error(NoMethodError) end it "hemlock works in a recipe" do - expect_recipe do + expect_recipe { hemlock("blah") {} - end.to emit_no_warnings_or_errors + }.to emit_no_warnings_or_errors expect(BaseThingy.created_resource).to eq RecipeDSLSpecNamespace::MySupplier end end @@ -430,9 +430,9 @@ describe "Recipe DSL methods" do end it "thingy3 works in a recipe" do - expect_recipe do + expect_recipe { thingy3("blah") {} - end.to emit_no_warnings_or_errors + }.to emit_no_warnings_or_errors expect(BaseThingy.created_resource).to eq RecipeDSLSpecNamespace::Thingy3 end @@ -446,16 +446,16 @@ describe "Recipe DSL methods" do end it "thingy3 works in a recipe and yields Thingy4 (the last one)" do - recipe = converge do + recipe = converge { thingy3("blah") {} - end + } expect(BaseThingy.created_resource).to eq RecipeDSLSpecNamespace::Thingy4 end it "thingy4 does not work in a recipe" do - expect_converge do + expect_converge { thingy4("blah") {} - end.to raise_error(NoMethodError) + }.to raise_error(NoMethodError) end it "resource_matching_short_name returns Thingy4" do @@ -477,9 +477,9 @@ describe "Recipe DSL methods" do end it "thingy5 works in a recipe" do - expect_recipe do + expect_recipe { thingy5("blah") {} - end.to emit_no_warnings_or_errors + }.to emit_no_warnings_or_errors expect(BaseThingy.created_resource).to eq RecipeDSLSpecNamespace::Thingy5 end @@ -494,16 +494,16 @@ describe "Recipe DSL methods" do end it "thingy6 works in a recipe and yields Thingy6" do - recipe = converge do + recipe = converge { thingy6("blah") {} - end + } expect(BaseThingy.created_resource).to eq RecipeDSLSpecNamespace::Thingy6 end it "thingy5 works in a recipe and yields Foo::Thingy6 (the last one)" do - recipe = converge do + recipe = converge { thingy5("blah") {} - end + } expect(BaseThingy.created_resource).to eq RecipeDSLSpecNamespace::Thingy6 end @@ -521,9 +521,9 @@ describe "Recipe DSL methods" do end it "thingy5reverse works in a recipe and yields AThingy5 (the alphabetical one)" do - recipe = converge do + recipe = converge { thingy5reverse("blah") {} - end + } expect(BaseThingy.created_resource).to eq RecipeDSLSpecNamespace::AThingy5 end end @@ -540,9 +540,9 @@ describe "Recipe DSL methods" do end it "thingy5_2 works in a recipe and yields the ZRecipeDSLSpaceNamespace one (the last one)" do - recipe = converge do + recipe = converge { thingy5_2("blah") {} - end + } expect(BaseThingy.created_resource).to eq ZRecipeDSLSpecNamespace::Thingy5 end end @@ -559,9 +559,9 @@ describe "Recipe DSL methods" do end it "thingy5_2reverse works in a recipe and yields the ARecipeDSLSpaceNamespace one (the alphabetical one)" do - recipe = converge do + recipe = converge { thingy5_2reverse("blah") {} - end + } expect(BaseThingy.created_resource).to eq ARecipeDSLSpecNamespace::Thingy5 end end @@ -577,9 +577,9 @@ describe "Recipe DSL methods" do end it "thingy3 works in a recipe" do - expect_recipe do + expect_recipe { thingy3("blah") {} - end.to emit_no_warnings_or_errors + }.to emit_no_warnings_or_errors expect(BaseThingy.created_resource).to eq RecipeDSLSpecNamespace::Thingy3 end @@ -593,16 +593,16 @@ describe "Recipe DSL methods" do end it "thingy3 works in a recipe and yields Thingy4 (the last one)" do - recipe = converge do + recipe = converge { thingy3("blah") {} - end + } expect(BaseThingy.created_resource).to eq RecipeDSLSpecNamespace::Thingy4 end it "thingy4 does not work in a recipe" do - expect_converge do + expect_converge { thingy4("blah") {} - end.to raise_error(NoMethodError) + }.to raise_error(NoMethodError) end it "resource_matching_short_name returns Thingy4" do @@ -620,16 +620,16 @@ describe "Recipe DSL methods" do end it "thingy3 works in a recipe and yields Thingy4 (the last one)" do - recipe = converge do + recipe = converge { thingy3("blah") {} - end + } expect(BaseThingy.created_resource).to eq RecipeDSLSpecNamespace::Thingy4 end it "thingy4 does not work in a recipe" do - expect_converge do + expect_converge { thingy4("blah") {} - end.to raise_error(NoMethodError) + }.to raise_error(NoMethodError) end it "resource_matching_short_name returns Thingy4" do @@ -660,16 +660,16 @@ describe "Recipe DSL methods" do end it "thingy7 works in a recipe and yields Thingy7" do - recipe = converge do + recipe = converge { thingy7("blah") {} - end + } expect(BaseThingy.created_resource).to eq RecipeDSLSpecNamespace::Thingy7 end it "thingy8 works in a recipe and yields Thingy7 (last)" do - recipe = converge do + recipe = converge { thingy8("blah") {} - end + } expect(BaseThingy.created_resource).to eq RecipeDSLSpecNamespace::Thingy8 end @@ -691,23 +691,23 @@ describe "Recipe DSL methods" do end it "thingy12 works in a recipe and yields Thingy12" do - expect_recipe do + expect_recipe { thingy12("blah") {} - end.to emit_no_warnings_or_errors + }.to emit_no_warnings_or_errors expect(BaseThingy.created_resource).to eq RecipeDSLSpecNamespace::Thingy12 end it "twizzle works in a recipe and yields Thingy12" do - expect_recipe do + expect_recipe { twizzle("blah") {} - end.to emit_no_warnings_or_errors + }.to emit_no_warnings_or_errors expect(BaseThingy.created_resource).to eq RecipeDSLSpecNamespace::Thingy12 end it "twizzle2 works in a recipe and yields Thingy12" do - expect_recipe do + expect_recipe { twizzle2("blah") {} - end.to emit_no_warnings_or_errors + }.to emit_no_warnings_or_errors expect(BaseThingy.created_resource).to eq RecipeDSLSpecNamespace::Thingy12 end end @@ -750,11 +750,11 @@ describe "Recipe DSL methods" do it "A run with platform 'x' reports that my_super_thingy is not supported" do r = Cheffish::ChefRun.new(chef_config) r.client.run_context.node.automatic["platform"] = "x" - expect do + expect { r.compile_recipe do my_super_thingy("blah") {} end - end.to raise_error(Chef::Exceptions::NoSuchResourceType) + }.to raise_error(Chef::Exceptions::NoSuchResourceType) end end @@ -804,7 +804,7 @@ describe "Recipe DSL methods" do result.resource_name two_classes_one_dsl result end - before { resource_class } # pull on it so it gets defined before the recipe runs + before do resource_class end # pull on it so it gets defined before the recipe runs context "and another resource named 'A' with resource_name :two_classes_one_dsl" do let(:resource_class_a) do @@ -820,13 +820,13 @@ describe "Recipe DSL methods" do result.resource_name two_classes_one_dsl result end - before { resource_class_a } # pull on it so it gets defined before the recipe runs + before do resource_class_a end # pull on it so it gets defined before the recipe runs it "two_classes_one_dsl resolves to A (alphabetically earliest)" do temp_two_classes_one_dsl = two_classes_one_dsl - recipe = converge do + recipe = converge { instance_eval("#{temp_two_classes_one_dsl} 'blah'") - end + } expect(recipe.logged_warnings).to eq "" expect(BaseThingy.created_resource).to eq resource_class_a end @@ -850,13 +850,13 @@ describe "Recipe DSL methods" do result.resource_name two_classes_one_dsl result end - before { resource_class_z } # pull on it so it gets defined before the recipe runs + before do resource_class_z end # pull on it so it gets defined before the recipe runs it "two_classes_one_dsl resolves to Z (last)" do temp_two_classes_one_dsl = two_classes_one_dsl - recipe = converge do + recipe = converge { instance_eval("#{temp_two_classes_one_dsl} 'blah'") - end + } expect(recipe.logged_warnings).to eq "" expect(BaseThingy.created_resource).to eq resource_class_z end @@ -872,9 +872,9 @@ describe "Recipe DSL methods" do it "two_classes_one_dsl resolves to Z (respects the priority array)" do temp_two_classes_one_dsl = two_classes_one_dsl - recipe = converge do + recipe = converge { instance_eval("#{temp_two_classes_one_dsl} 'blah'") - end + } expect(recipe.logged_warnings).to eq "" expect(BaseThingy.created_resource).to eq resource_class_z end @@ -890,9 +890,9 @@ describe "Recipe DSL methods" do it "two_classes_one_dsl resolves to B (picks the next thing in the priority array)" do temp_two_classes_one_dsl = two_classes_one_dsl - recipe = converge do + recipe = converge { instance_eval("#{temp_two_classes_one_dsl} 'blah'") - end + } expect(recipe.logged_warnings).to eq "" expect(BaseThingy.created_resource).to eq resource_class end @@ -911,9 +911,9 @@ describe "Recipe DSL methods" do it "two_classes_one_dsl resolves to Z (respects the most recent priority array)" do temp_two_classes_one_dsl = two_classes_one_dsl - recipe = converge do + recipe = converge { instance_eval("#{temp_two_classes_one_dsl} 'blah'") - end + } expect(recipe.logged_warnings).to eq "" expect(BaseThingy.created_resource).to eq resource_class_z end @@ -929,9 +929,9 @@ describe "Recipe DSL methods" do it "two_classes_one_dsl resolves to B (picks the first match from the other priority array)" do temp_two_classes_one_dsl = two_classes_one_dsl - recipe = converge do + recipe = converge { instance_eval("#{temp_two_classes_one_dsl} 'blah'") - end + } expect(recipe.logged_warnings).to eq "" expect(BaseThingy.created_resource).to eq resource_class end @@ -954,9 +954,9 @@ describe "Recipe DSL methods" do it "two_classes_one_dsl resolves to B (picks the first match outside the priority array)" do temp_two_classes_one_dsl = two_classes_one_dsl - recipe = converge do + recipe = converge { instance_eval("#{temp_two_classes_one_dsl} 'blah'") - end + } expect(recipe.logged_warnings).to eq "" expect(BaseThingy.created_resource).to eq resource_class end @@ -987,7 +987,7 @@ describe "Recipe DSL methods" do result.provides two_classes_one_dsl result end - before { provider_class } # pull on it so it gets defined before the recipe runs + before do provider_class end # pull on it so it gets defined before the recipe runs context "and another provider named 'A'" do let(:provider_class_a) do @@ -1003,25 +1003,25 @@ describe "Recipe DSL methods" do result end context "which provides :two_classes_one_dsl" do - before { provider_class_a.provides two_classes_one_dsl } + before do provider_class_a.provides two_classes_one_dsl end it "two_classes_one_dsl resolves to A (alphabetically earliest)" do temp_two_classes_one_dsl = two_classes_one_dsl - recipe = converge do + recipe = converge { instance_eval("#{temp_two_classes_one_dsl} 'blah'") - end + } expect(recipe.logged_warnings).to eq "" expect(BaseThingy.created_provider).to eq provider_class_a end end context "which provides(:two_classes_one_dsl) { false }" do - before { provider_class_a.provides(two_classes_one_dsl) { false } } + before do provider_class_a.provides(two_classes_one_dsl) { false } end it "two_classes_one_dsl resolves to B (since A declined)" do temp_two_classes_one_dsl = two_classes_one_dsl - recipe = converge do + recipe = converge { instance_eval("#{temp_two_classes_one_dsl} 'blah'") - end + } expect(recipe.logged_warnings).to eq "" expect(BaseThingy.created_provider).to eq provider_class end @@ -1041,28 +1041,28 @@ describe "Recipe DSL methods" do end result end - before { provider_class_z } # pull on it so it gets defined before the recipe runs + before do provider_class_z end # pull on it so it gets defined before the recipe runs context "which provides :two_classes_one_dsl" do - before { provider_class_z.provides two_classes_one_dsl } + before do provider_class_z.provides two_classes_one_dsl end it "two_classes_one_dsl resolves to Z (last)" do temp_two_classes_one_dsl = two_classes_one_dsl - recipe = converge do + recipe = converge { instance_eval("#{temp_two_classes_one_dsl} 'blah'") - end + } expect(recipe.logged_warnings).to eq "" expect(BaseThingy.created_provider).to eq provider_class_z end context "with a priority array [ Z, B ]" do - before { Chef.set_provider_priority_array two_classes_one_dsl, [ provider_class_z, provider_class ] } + before do Chef.set_provider_priority_array two_classes_one_dsl, [ provider_class_z, provider_class ] end it "two_classes_one_dsl resolves to Z (respects the priority map)" do temp_two_classes_one_dsl = two_classes_one_dsl - recipe = converge do + recipe = converge { instance_eval("#{temp_two_classes_one_dsl} 'blah'") - end + } expect(recipe.logged_warnings).to eq "" expect(BaseThingy.created_provider).to eq provider_class_z end @@ -1070,30 +1070,30 @@ describe "Recipe DSL methods" do end context "which provides(:two_classes_one_dsl) { false }" do - before { provider_class_z.provides(two_classes_one_dsl) { false } } + before do provider_class_z.provides(two_classes_one_dsl) { false } end context "with a priority array [ Z, B ]" do - before { Chef.set_provider_priority_array two_classes_one_dsl, [ provider_class_z, provider_class ] } + before do Chef.set_provider_priority_array two_classes_one_dsl, [ provider_class_z, provider_class ] end it "two_classes_one_dsl resolves to B (the next one in the priority map)" do temp_two_classes_one_dsl = two_classes_one_dsl - recipe = converge do + recipe = converge { instance_eval("#{temp_two_classes_one_dsl} 'blah'") - end + } expect(recipe.logged_warnings).to eq "" expect(BaseThingy.created_provider).to eq provider_class end end context "with priority arrays [ B ] and [ Z ]" do - before { Chef.set_provider_priority_array two_classes_one_dsl, [ provider_class_z ] } - before { Chef.set_provider_priority_array two_classes_one_dsl, [ provider_class ] } + before do Chef.set_provider_priority_array two_classes_one_dsl, [ provider_class_z ] end + before do Chef.set_provider_priority_array two_classes_one_dsl, [ provider_class ] end it "two_classes_one_dsl resolves to B (the one in the next priority map)" do temp_two_classes_one_dsl = two_classes_one_dsl - recipe = converge do + recipe = converge { instance_eval("#{temp_two_classes_one_dsl} 'blah'") - end + } expect(recipe.logged_warnings).to eq "" expect(BaseThingy.created_provider).to eq provider_class end @@ -1117,26 +1117,26 @@ describe "Recipe DSL methods" do result.provides two_classes_one_dsl, os: "blarghle" result end - before { resource_class_blarghle } # pull on it so it gets defined before the recipe runs + before do resource_class_blarghle end # pull on it so it gets defined before the recipe runs it "on os = blarghle, two_classes_one_dsl resolves to Blarghle" do temp_two_classes_one_dsl = two_classes_one_dsl - recipe = converge do + recipe = converge { # this is an ugly way to test, make Cheffish expose node attrs run_context.node.automatic[:os] = "blarghle" instance_eval("#{temp_two_classes_one_dsl} 'blah' do; end") - end + } expect(recipe.logged_warnings).to eq "" expect(BaseThingy.created_resource).to eq resource_class_blarghle end it "on os = linux, two_classes_one_dsl resolves to B" do temp_two_classes_one_dsl = two_classes_one_dsl - recipe = converge do + recipe = converge { # this is an ugly way to test, make Cheffish expose node attrs run_context.node.automatic[:os] = "linux" instance_eval("#{temp_two_classes_one_dsl} 'blah' do; end") - end + } expect(recipe.logged_warnings).to eq "" expect(BaseThingy.created_resource).to eq resource_class end @@ -1174,9 +1174,9 @@ describe "Recipe DSL methods" do it "my_resource returns the resource and calls provides?, but does not emit a warning" do dsl_name = my_resource - recipe = converge do + recipe = converge { instance_eval("#{dsl_name} 'foo'") - end + } expect(recipe.logged_warnings).to eq "" expect(BaseThingy.created_resource).to eq resource_class expect(resource_class.called_provides).to be_truthy @@ -1216,9 +1216,9 @@ describe "Recipe DSL methods" do it "my_resource runs the provider and does not emit a warning" do temp_my_resource = my_resource - recipe = converge do + recipe = converge { instance_eval("#{temp_my_resource} 'foo'") - end + } expect(recipe.logged_warnings).to eq "" expect(BaseThingy.created_provider).to eq provider_class end @@ -1246,9 +1246,9 @@ describe "Recipe DSL methods" do it "my_resource runs the first provider" do temp_my_resource = my_resource - recipe = converge do + recipe = converge { instance_eval("#{temp_my_resource} 'foo'") - end + } expect(recipe.logged_warnings).to eq "" expect(BaseThingy.created_provider).to eq provider_class end @@ -1263,9 +1263,9 @@ describe "Recipe DSL methods" do # TODO no warning? ick it "my_resource runs the provider anyway" do temp_my_resource = my_resource - recipe = converge do + recipe = converge { instance_eval("#{temp_my_resource} 'foo'") - end + } expect(recipe.logged_warnings).to eq "" expect(BaseThingy.created_provider).to eq provider_class end @@ -1291,13 +1291,13 @@ describe "Recipe DSL methods" do end end end - before { provider_class2 } # make sure the provider class shows up + before do provider_class2 end # make sure the provider class shows up it "my_resource runs the other provider" do temp_my_resource = my_resource - recipe = converge do + recipe = converge { instance_eval("#{temp_my_resource} 'foo'") - end + } expect(recipe.logged_warnings).to eq "" expect(BaseThingy.created_provider).to eq provider_class2 end @@ -1317,17 +1317,17 @@ describe "Recipe DSL methods" do end it "utf-8 dsl names work" do - recipe = converge do + recipe = converge { Straße("blah") {} - end + } expect(recipe.logged_warnings).to eq "" expect(BaseThingy.created_resource).to eq(UTF8Thingy) end end end - before(:all) { Namer.current_index = 0 } - before { Namer.current_index += 1 } + before(:all) do Namer.current_index = 0 end + before do Namer.current_index += 1 end context "with an LWRP that declares actions" do let(:resource_class) do diff --git a/spec/integration/recipes/resource_action_spec.rb b/spec/integration/recipes/resource_action_spec.rb index c8da9196ca..f2f9936f9b 100644 --- a/spec/integration/recipes/resource_action_spec.rb +++ b/spec/integration/recipes/resource_action_spec.rb @@ -103,14 +103,14 @@ module ResourceActionSpec end it "the action cannot access private methods" do - expect do + expect { converge(<<-EOM, __FILE__, __LINE__ + 1) #{resource_dsl} "hi" do foo "foo!" action :access_private_method end EOM - end.to raise_error(NameError) + }.to raise_error(NameError) expect(ActionJackson.ran_action).to eq :access_private_method end @@ -249,7 +249,7 @@ module ResourceActionSpec end it "Can retrieve ancestors of action class without crashing" do - converge { action_jackson "hi" } + converge do action_jackson "hi" end expect { ActionJackson.action_class.ancestors.join(",") }.not_to raise_error end @@ -371,9 +371,9 @@ module ResourceActionSpec context "With a resource with a UTF-8 action" do it "Running the action works" do - expect_recipe do + expect_recipe { weird_action_jackson "hi" - end.to be_up_to_date + }.to be_up_to_date expect(WeirdActionJackson.action_was).to eq :Straße end end @@ -398,11 +398,11 @@ module ResourceActionSpec end it "Setting group to nil in an action does not emit a warning about it being defined in two places" do - expect_recipe do + expect_recipe { resource_action_spec_set_group_to_nil "hi" do action :set_group_to_nil end - end.to emit_no_warnings_or_errors + }.to emit_no_warnings_or_errors end end @@ -444,9 +444,9 @@ module ResourceActionSpec it "the methods are available to the action" do r = nil - expect_recipe do + expect_recipe { r = declares_action_class_methods "hi" - end.to emit_no_warnings_or_errors + }.to emit_no_warnings_or_errors expect(r.x).to eq(4) end @@ -467,9 +467,9 @@ module ResourceActionSpec it "the methods are available to the action" do r = nil - expect_recipe do + expect_recipe { r = declares_action_class_methods_too "hi" - end.to emit_no_warnings_or_errors + }.to emit_no_warnings_or_errors expect(r.x).to eq(8) end end @@ -492,9 +492,9 @@ module ResourceActionSpec it "the methods are available to the action" do r = nil - expect_recipe do + expect_recipe { r = declares_action_class_methods_too "hi" - end.to emit_no_warnings_or_errors + }.to emit_no_warnings_or_errors expect(r.x).to eq(8) end end diff --git a/spec/integration/recipes/resource_converge_if_changed_spec.rb b/spec/integration/recipes/resource_converge_if_changed_spec.rb index 605cb2c941..2cb3b5fc3a 100644 --- a/spec/integration/recipes/resource_converge_if_changed_spec.rb +++ b/spec/integration/recipes/resource_converge_if_changed_spec.rb @@ -13,9 +13,9 @@ describe "Resource::ActionClass#converge_if_changed" do attr_writer :incrementing_value end - before(:all) { Namer.current_index = 1 } - before { Namer.current_index += 1 } - before { Namer.incrementing_value = 0 } + before(:all) do Namer.current_index = 1 end + before do Namer.current_index += 1 end + before do Namer.incrementing_value = 0 end context "when the resource has identity, state, control, and sensitive properties" do let(:resource_name) { :"converge_if_changed_dsl#{Namer.current_index}" } diff --git a/spec/integration/recipes/resource_load_spec.rb b/spec/integration/recipes/resource_load_spec.rb index 79df1d6478..860f4b0080 100644 --- a/spec/integration/recipes/resource_load_spec.rb +++ b/spec/integration/recipes/resource_load_spec.rb @@ -13,9 +13,9 @@ describe "Resource.load_current_value" do attr_writer :incrementing_value end - before(:all) { Namer.current_index = 1 } - before { Namer.current_index += 1 } - before { Namer.incrementing_value = 0 } + before(:all) do Namer.current_index = 1 end + before do Namer.current_index += 1 end + before do Namer.incrementing_value = 0 end let(:resource_name) { :"load_current_value_dsl#{Namer.current_index}" } let(:resource_class) do @@ -40,7 +40,7 @@ describe "Resource.load_current_value" do end # Pull on resource_class to initialize it - before { resource_class } + before do resource_class end context "with a resource with load_current_value" do before :each do @@ -57,9 +57,9 @@ describe "Resource.load_current_value" do e = self r = nil converge do - r = public_send(e.resource_name, "blah") do + r = public_send(e.resource_name, "blah") { x "desired" - end + } end r end @@ -131,15 +131,15 @@ describe "Resource.load_current_value" do end # Pull on subresource_class to initialize it - before { subresource_class } + before do subresource_class end let(:subresource) do e = self r = nil converge do - r = public_send(e.subresource_name, "blah") do + r = public_send(e.subresource_name, "blah") { x "desired" - end + } end r end diff --git a/spec/integration/solo/solo_spec.rb b/spec/integration/solo/solo_spec.rb index 451943e225..f19cc682c4 100644 --- a/spec/integration/solo/solo_spec.rb +++ b/spec/integration/solo/solo_spec.rb @@ -180,7 +180,7 @@ describe Chef::Dist::SOLOEXEC do EOM # We have a timeout protection here so that if due to some bug # run_lock gets stuck we can discover it. - expect do + expect { Timeout.timeout(120) do chef_dir = File.join(File.dirname(__FILE__), "..", "..", "..") @@ -200,7 +200,7 @@ describe Chef::Dist::SOLOEXEC do threads.each(&:join) end - end.not_to raise_error + }.not_to raise_error # Unfortunately file / directory helpers in integration tests # are implemented using before(:each) so we need to do all below diff --git a/spec/scripts/ssl-serve.rb b/spec/scripts/ssl-serve.rb index e9f645416c..fc5f273af0 100644 --- a/spec/scripts/ssl-serve.rb +++ b/spec/scripts/ssl-serve.rb @@ -42,6 +42,6 @@ webrick_opts = DEFAULT_OPTIONS.merge(server_opts) pp webrick_opts: webrick_opts server = WEBrick::HTTPServer.new(webrick_opts) -trap("INT") { server.shutdown } +trap("INT") do server.shutdown end server.start diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 5ab97a8320..4d42cd29e2 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -53,7 +53,7 @@ require "chef/knife" Dir["lib/chef/knife/**/*.rb"] .map { |f| f.gsub("lib/", "") } .map { |f| f.gsub(/\.rb$/, "") } - .each { |f| require f } + .each do |f| require f end require "chef/resource_resolver" require "chef/provider_resolver" @@ -95,7 +95,7 @@ Dir["spec/support/**/*.rb"] .reject { |f| f =~ %r{^spec/support/pedant} } .map { |f| f.gsub(/.rb$/, "") } .map { |f| f.gsub(%r{spec/}, "") } - .each { |f| require f } + .each do |f| require f end OHAI_SYSTEM = Ohai::System.new OHAI_SYSTEM.all_plugins(["platform", "hostname", "languages/powershell"]) @@ -271,11 +271,11 @@ RSpec.configure do |config| if Process.euid == 0 && Process.uid == 0 config.after(:each) do if Process.uid != 0 - RSpec.configure { |c| c.fail_fast = true } + RSpec.configure do |c| c.fail_fast = true end raise "rspec was invoked as root, but the last test dropped real uid to #{Process.uid}" end if Process.euid != 0 - RSpec.configure { |c| c.fail_fast = true } + RSpec.configure do |c| c.fail_fast = true end raise "rspec was invoked as root, but the last test dropped effective uid to #{Process.euid}" end end diff --git a/spec/stress/win32/security_spec.rb b/spec/stress/win32/security_spec.rb index 8929a2ff74..0f9da86a9b 100644 --- a/spec/stress/win32/security_spec.rb +++ b/spec/stress/win32/security_spec.rb @@ -49,21 +49,21 @@ describe "Chef::ReservedNames::Win32::Security", :windows_only do end it "should not leak when retrieving and reading the ACE from a file", :volatile do - expect do + expect { sids = Chef::ReservedNames::Win32::Security::SecurableObject.new(@monkeyfoo).security_descriptor.dacl.select(&:sid) GC.start - end.not_to leak_memory(warmup: 50, iterations: 100) + }.not_to leak_memory(warmup: 50, iterations: 100) end it "should not leak when creating a new ACL and setting it on a file", :volatile do securable_object = Security::SecurableObject.new(@monkeyfoo) - expect do + expect { securable_object.dacl = Chef::ReservedNames::Win32::Security::ACL.create([ Chef::ReservedNames::Win32::Security::ACE.access_allowed(Chef::ReservedNames::Win32::Security::SID.Everyone, Chef::ReservedNames::Win32::API::Security::GENERIC_READ), Chef::ReservedNames::Win32::Security::ACE.access_denied(Chef::ReservedNames::Win32::Security::SID.from_account("Users"), Chef::ReservedNames::Win32::API::Security::GENERIC_ALL), ]) GC.start - end.not_to leak_memory(warmup: 50, iterations: 100) + }.not_to leak_memory(warmup: 50, iterations: 100) end end diff --git a/spec/support/shared/functional/file_resource.rb b/spec/support/shared/functional/file_resource.rb index 114971641d..bb6a68e946 100644 --- a/spec/support/shared/functional/file_resource.rb +++ b/spec/support/shared/functional/file_resource.rb @@ -149,7 +149,7 @@ shared_examples_for "a file with the wrong content" do end context "when set" do - before { resource.sensitive(true) } + before do resource.sensitive(true) end it "should be set on the resource" do expect(resource.sensitive).to(be_truthy) @@ -917,7 +917,7 @@ shared_examples_for "a configured file resource" do context "when the target file has the wrong content" do before(:each) do - File.open(path, "wb") { |f| f.print "This is so wrong!!!" } + File.open(path, "wb") do |f| f.print "This is so wrong!!!" end now = Time.now.to_i File.utime(now - 9000, now - 9000, path) @@ -944,7 +944,7 @@ shared_examples_for "a configured file resource" do context "when the target file has the correct content" do before(:each) do - File.open(path, "wb") { |f| f.print expected_content } + File.open(path, "wb") do |f| f.print expected_content end now = Time.now.to_i File.utime(now - 9000, now - 9000, path) @@ -981,7 +981,7 @@ shared_examples_for "a configured file resource" do end before do - File.open(path, "wb") { |f| f.print expected_content } + File.open(path, "wb") do |f| f.print expected_content end now = Time.now.to_i File.utime(now - 9000, now - 9000, path) diff --git a/spec/support/shared/integration/integration_helper.rb b/spec/support/shared/integration/integration_helper.rb index 6c0eca98be..42f63e7c05 100644 --- a/spec/support/shared/integration/integration_helper.rb +++ b/spec/support/shared/integration/integration_helper.rb @@ -142,13 +142,13 @@ module IntegrationSupport # Versioned cookbooks RSpec.shared_context "with versioned cookbooks", versioned_cookbooks: true do - before(:each) { Chef::Config[:versioned_cookbooks] = true } + before(:each) do Chef::Config[:versioned_cookbooks] = true end after(:each) { Chef::Config.delete(:versioned_cookbooks) } end RSpec.shared_context "without versioned cookbooks", versioned_cookbooks: false do # Just make sure this goes back to default - before(:each) { Chef::Config[:versioned_cookbooks] = false } + before(:each) do Chef::Config[:versioned_cookbooks] = false end after(:each) { Chef::Config.delete(:versioned_cookbooks) } end diff --git a/spec/support/shared/unit/file_system_support.rb b/spec/support/shared/unit/file_system_support.rb index 957479f149..0ecbff1eda 100644 --- a/spec/support/shared/unit/file_system_support.rb +++ b/spec/support/shared/unit/file_system_support.rb @@ -64,7 +64,7 @@ module FileSystemSupport def list_should_yield_paths(fs, pattern_str, *expected_paths) result_paths = [] - Chef::ChefFS::FileSystem.list(fs, pattern(pattern_str)).each { |result| result_paths << result.path } + Chef::ChefFS::FileSystem.list(fs, pattern(pattern_str)).each do |result| result_paths << result.path end expect(result_paths).to match_array(expected_paths) end end diff --git a/spec/support/shared/unit/provider/file.rb b/spec/support/shared/unit/provider/file.rb index 2771a371d4..820b4bb887 100644 --- a/spec/support/shared/unit/provider/file.rb +++ b/spec/support/shared/unit/provider/file.rb @@ -415,7 +415,7 @@ shared_examples_for Chef::Provider::File do context "define_resource_requirements" do context "when the enclosing directory does not exist" do - before { setup_missing_enclosing_directory } + before do setup_missing_enclosing_directory end %i{create create_if_missing touch}.each do |action| context "action #{action}" do @@ -433,7 +433,7 @@ shared_examples_for Chef::Provider::File do end context "when the file exists but is not deletable" do - before { setup_unwritable_file } + before do setup_unwritable_file end it "action delete raises InsufficientPermissions" do expect { provider.run_action(:delete) }.to raise_error(Chef::Exceptions::InsufficientPermissions) @@ -458,7 +458,7 @@ shared_examples_for Chef::Provider::File do end context "do_validate_content" do - before { setup_normal_file } + before do setup_normal_file end let(:tempfile) do t = double("Tempfile", path: "/tmp/foo-bar-baz", closed?: true) @@ -492,7 +492,7 @@ shared_examples_for Chef::Provider::File do context "do_create_file" do context "when the file exists" do - before { setup_normal_file } + before do setup_normal_file end it "should not create the file" do provider.load_current_resource expect(provider.deployment_strategy).not_to receive(:create).with(resource_path) @@ -501,7 +501,7 @@ shared_examples_for Chef::Provider::File do end end context "when the file does not exist" do - before { setup_missing_file } + before do setup_missing_file end it "should create the file" do provider.load_current_resource expect(provider.deployment_strategy).to receive(:create).with(resource_path) @@ -540,7 +540,7 @@ shared_examples_for Chef::Provider::File do expect(provider.deployment_strategy).to receive(:deploy).with(tempfile_path, normalized_path) end context "when the file was created" do - before { expect(provider).to receive(:needs_creating?).at_least(:once).and_return(true) } + before do expect(provider).to receive(:needs_creating?).at_least(:once).and_return(true) end it "does not backup the file" do expect(provider).not_to receive(:do_backup) provider.send(:do_contents_changes) @@ -693,8 +693,8 @@ shared_examples_for Chef::Provider::File do end context "in why run mode" do - before { Chef::Config[:why_run] = true } - after { Chef::Config[:why_run] = false } + before do Chef::Config[:why_run] = true end + after do Chef::Config[:why_run] = false end it "does not modify new_resource" do setup_missing_file @@ -708,7 +708,7 @@ shared_examples_for Chef::Provider::File do context "when the file exists" do context "when the file is writable" do context "when the file is not a symlink" do - before { setup_normal_file } + before do setup_normal_file end it "should backup and delete the file and be updated by the last action" do expect(provider).to receive(:do_backup).at_least(:once).and_return(true) expect(File).to receive(:delete).with(resource_path).and_return(true) @@ -717,7 +717,7 @@ shared_examples_for Chef::Provider::File do end end context "when the file is a symlink" do - before { setup_symlink } + before do setup_symlink end it "should not backup the symlink" do expect(provider).not_to receive(:do_backup) expect(File).to receive(:delete).with(resource_path).and_return(true) @@ -727,7 +727,7 @@ shared_examples_for Chef::Provider::File do end end context "when the file is not writable" do - before { setup_unwritable_file } + before do setup_unwritable_file end it "should not try to backup or delete the file, and should not be updated by last action" do expect(provider).not_to receive(:do_backup) expect(File).not_to receive(:delete) @@ -738,7 +738,7 @@ shared_examples_for Chef::Provider::File do end context "when the file does not exist" do - before { setup_missing_file } + before do setup_missing_file end it "should not try to backup or delete the file, and should not be updated by last action" do expect(provider).not_to receive(:do_backup) @@ -751,7 +751,7 @@ shared_examples_for Chef::Provider::File do context "action touch" do context "when the file does not exist" do - before { setup_missing_file } + before do setup_missing_file end it "should update the atime/mtime on action_touch" do expect(File).to receive(:utime).once expect(provider).to receive(:action_create) @@ -760,7 +760,7 @@ shared_examples_for Chef::Provider::File do end end context "when the file exists" do - before { setup_normal_file } + before do setup_normal_file end it "should update the atime/mtime on action_touch" do expect(File).to receive(:utime).once expect(provider).to receive(:action_create) @@ -772,7 +772,7 @@ shared_examples_for Chef::Provider::File do context "action create_if_missing" do context "when the file does not exist" do - before { setup_missing_file } + before do setup_missing_file end it "should call action_create" do expect(provider).to receive(:action_create) provider.run_action(:create_if_missing) @@ -780,7 +780,7 @@ shared_examples_for Chef::Provider::File do end context "when the file exists" do - before { setup_normal_file } + before do setup_normal_file end it "should not call action_create" do expect(provider).not_to receive(:action_create) provider.run_action(:create_if_missing) diff --git a/spec/support/shared/unit/windows_script_resource.rb b/spec/support/shared/unit/windows_script_resource.rb index 29238a3917..48974b2387 100644 --- a/spec/support/shared/unit/windows_script_resource.rb +++ b/spec/support/shared/unit/windows_script_resource.rb @@ -57,13 +57,13 @@ shared_examples_for "a Windows script resource" do describe "when the guard is given a ruby block" do it "should evaluate the guard if the guard_interpreter is set to its default value" do - @resource.only_if { true } + @resource.only_if do true end expect(@resource.should_skip?(:run)).to eq(nil) end it "should raise an exception if the guard_interpreter is overridden from its default value" do @resource.guard_interpreter :bash - @resource.only_if { true } + @resource.only_if do true end expect { @resource.should_skip?(:run) }.to raise_error(ArgumentError) end end diff --git a/spec/unit/application/client_spec.rb b/spec/unit/application/client_spec.rb index 0773fc70fd..316dbea17c 100644 --- a/spec/unit/application/client_spec.rb +++ b/spec/unit/application/client_spec.rb @@ -392,10 +392,10 @@ Enable .* interval runs by setting `:client_fork = true` in your config file or end it "sleeps for the amount of time passed" do - pid = fork do + pid = fork { expect(@app).to receive(:interval_sleep).with(wait_secs) @app.run_application - end + } _pid, result = Process.waitpid2(pid) expect(result.exitstatus).to eq 0 @@ -523,18 +523,18 @@ describe Chef::Application::Client, "run_application", :unix_only do end it "should exit hard with exitstatus 3", :volatile do - pid = fork do + pid = fork { @app.run_application - end + } Process.kill("TERM", pid) _pid, result = Process.waitpid2(pid) expect(result.exitstatus).to eq(3) end it "should allow child to finish converging" do - pid = fork do + pid = fork { @app.run_application - end + } expect(@pipe[0].gets).to eq("started\n") Process.kill("TERM", pid) Process.wait(pid) @@ -551,9 +551,9 @@ describe Chef::Application::Client, "run_application", :unix_only do end it "should exit gracefully when sent during converge" do - pid = fork do + pid = fork { @app.run_application - end + } expect(@pipe[0].gets).to eq("started\n") Process.kill("TERM", pid) _pid, result = Process.waitpid2(pid) @@ -563,10 +563,10 @@ describe Chef::Application::Client, "run_application", :unix_only do end it "should exit hard when sent before converge" do - pid = fork do + pid = fork { sleep 3 @app.run_application - end + } Process.kill("TERM", pid) _pid, result = Process.waitpid2(pid) expect(result.exitstatus).to eq(3) @@ -585,9 +585,9 @@ describe Chef::Application::Client, "run_application", :unix_only do it "shouldn't sleep when sent USR1" do allow(@app).to receive(:interval_sleep).and_return true allow(@app).to receive(:interval_sleep).with(0).and_call_original - pid = fork do + pid = fork { @app.run_application - end + } _pid, result = Process.waitpid2(pid) expect(result.exitstatus).to eq(0) end diff --git a/spec/unit/chef_class_spec.rb b/spec/unit/chef_class_spec.rb index d862273f52..b0f08e260a 100644 --- a/spec/unit/chef_class_spec.rb +++ b/spec/unit/chef_class_spec.rb @@ -99,18 +99,18 @@ describe "Chef class" do end it "raise error if unknown event type is passed" do - expect do + expect { Chef.event_handler do on :yolo do end end - end.to raise_error(Chef::Exceptions::InvalidEventType) + }.to raise_error(Chef::Exceptions::InvalidEventType) end end describe "Deprecation system" do context "with treat_deprecation_warnings_as_errors false" do - before { Chef::Config[:treat_deprecation_warnings_as_errors] = false } + before do Chef::Config[:treat_deprecation_warnings_as_errors] = false end it "displays a simple deprecation warning" do expect(Chef::Log).to receive(:warn).with(%r{spec/unit/chef_class_spec\.rb.*?I'm a little teapot.*?Please see}m) @@ -229,7 +229,7 @@ describe "Chef class" do context "with treat_deprecation_warnings_as_errors true" do # This is already turned on globally for Chef's unit tests, but just for clarity do it here too. - before { Chef::Config[:treat_deprecation_warnings_as_errors] = true } + before do Chef::Config[:treat_deprecation_warnings_as_errors] = true end it "displays a simple deprecation error" do expect(Chef::Log).to receive(:error).with(%r{spec/unit/chef_class_spec\.rb.*?I'm a little teapot.*?Please see}m) diff --git a/spec/unit/chef_fs/file_system/operation_failed_error_spec.rb b/spec/unit/chef_fs/file_system/operation_failed_error_spec.rb index 661994337b..2bda2b75c9 100644 --- a/spec/unit/chef_fs/file_system/operation_failed_error_spec.rb +++ b/spec/unit/chef_fs/file_system/operation_failed_error_spec.rb @@ -30,17 +30,17 @@ describe Chef::ChefFS::FileSystem::OperationFailedError do allow(@response).to receive(:code).and_return("400") allow(@response).to receive(:body).and_return(response_body) exception = Net::HTTPClientException.new("(exception) unauthorized", @response) - expect do + expect { raise Chef::ChefFS::FileSystem::OperationFailedError.new(:write, self, exception), error_message - end.to raise_error(Chef::ChefFS::FileSystem::OperationFailedError, "#{error_message} cause: #{response_body}") + }.to raise_error(Chef::ChefFS::FileSystem::OperationFailedError, "#{error_message} cause: #{response_body}") end end context "does not have a cause attribute" do it "does not include error cause" do - expect do + expect { raise Chef::ChefFS::FileSystem::OperationFailedError.new(:write, self), error_message - end.to raise_error(Chef::ChefFS::FileSystem::OperationFailedError, error_message) + }.to raise_error(Chef::ChefFS::FileSystem::OperationFailedError, error_message) end end end diff --git a/spec/unit/chef_fs/parallelizer.rb b/spec/unit/chef_fs/parallelizer.rb index d43e48b7bc..541ce2593e 100644 --- a/spec/unit/chef_fs/parallelizer.rb +++ b/spec/unit/chef_fs/parallelizer.rb @@ -35,29 +35,29 @@ describe Chef::ChefFS::Parallelizer do context "With :ordered => false (unordered output)" do it "An empty input produces an empty output" do - expect(parallelize([], ordered: false) do + expect(parallelize([], ordered: false) { sleep 10 - end.to_a).to eql([]) + }.to_a).to eql([]) expect(elapsed_time).to be < 0.1 end it "10 sleep(0.2)s complete within 0.5 seconds" do - expect(parallelize(1.upto(10), ordered: false) do |i| + expect(parallelize(1.upto(10), ordered: false) { |i| sleep 0.2 "x" - end.to_a).to eq(%w{x x x x x x x x x x}) + }.to_a).to eq(%w{x x x x x x x x x x}) expect(elapsed_time).to be < 0.5 end it "The output comes as soon as it is available" do - enum = parallelize([0.5, 0.3, 0.1], ordered: false) do |val| + enum = parallelize([0.5, 0.3, 0.1], ordered: false) { |val| sleep val val - end - expect(enum.map do |value| + } + expect(enum.map { |value| expect(elapsed_time).to be < value + 0.1 value - end).to eq([ 0.1, 0.3, 0.5 ]) + }).to eq([ 0.1, 0.3, 0.5 ]) end it "An exception in input is passed through but does NOT stop processing" do @@ -73,7 +73,7 @@ describe Chef::ChefFS::Parallelizer do it "Exceptions in output are raised after all processing is done" do processed = 0 - enum = parallelize([1, 2, "x", 3], ordered: false) do |x| + enum = parallelize([1, 2, "x", 3], ordered: false) { |x| if x == "x" sleep 0.1 raise "hi" @@ -81,7 +81,7 @@ describe Chef::ChefFS::Parallelizer do sleep 0.2 processed += 1 x - end + } results = [] expect { enum.each { |value| results << value } }.to raise_error "hi" expect(results.sort).to eq([ 1, 2, 3 ]) @@ -91,7 +91,7 @@ describe Chef::ChefFS::Parallelizer do it "Exceptions with :stop_on_exception are raised after all processing is done" do processed = 0 - parallelized = parallelize([0.3, 0.3, "x", 0.3, 0.3, 0.3, 0.3, 0.3], ordered: false, stop_on_exception: true) do |x| + parallelized = parallelize([0.3, 0.3, "x", 0.3, 0.3, 0.3, 0.3, 0.3], ordered: false, stop_on_exception: true) { |x| if x == "x" sleep(0.1) raise "hi" @@ -99,7 +99,7 @@ describe Chef::ChefFS::Parallelizer do sleep(x) processed += 1 x - end + } expect { parallelized.to_a }.to raise_error "hi" expect(processed).to eq(4) end @@ -107,25 +107,25 @@ describe Chef::ChefFS::Parallelizer do context "With :ordered => true (ordered output)" do it "An empty input produces an empty output" do - expect(parallelize([]) do + expect(parallelize([]) { sleep 10 - end.to_a).to eql([]) + }.to_a).to eql([]) expect(elapsed_time).to be < 0.1 end it "10 sleep(0.2)s complete within 0.5 seconds" do - expect(parallelize(1.upto(10), ordered: true) do |i| + expect(parallelize(1.upto(10), ordered: true) { |i| sleep 0.2 "x" - end.to_a).to eq(%w{x x x x x x x x x x}) + }.to_a).to eq(%w{x x x x x x x x x x}) expect(elapsed_time).to be < 0.5 end it "Output comes in the order of the input" do - enum = parallelize([0.5, 0.3, 0.1]) do |val| + enum = parallelize([0.5, 0.3, 0.1]) { |val| sleep val val - end.enum_for(:each_with_index) + }.enum_for(:each_with_index) expect(enum.next).to eq([ 0.5, 0 ]) expect(enum.next).to eq([ 0.3, 1 ]) expect(enum.next).to eq([ 0.1, 2 ]) @@ -145,7 +145,7 @@ describe Chef::ChefFS::Parallelizer do it "Exceptions in output are raised in the correct sequence and running processes do NOT stop processing" do processed = 0 - enum = parallelize([1, 2, "x", 3]) do |x| + enum = parallelize([1, 2, "x", 3]) { |x| if x == "x" sleep(0.1) raise "hi" @@ -153,7 +153,7 @@ describe Chef::ChefFS::Parallelizer do sleep(0.2) processed += 1 x - end + } results = [] expect { enum.each { |value| results << value } }.to raise_error "hi" expect(results).to eq([ 1, 2 ]) @@ -163,7 +163,7 @@ describe Chef::ChefFS::Parallelizer do it "Exceptions with :stop_on_exception are raised after all processing is done" do processed = 0 - parallelized = parallelize([0.3, 0.3, "x", 0.3, 0.3, 0.3, 0.3, 0.3], ordered: false, stop_on_exception: true) do |x| + parallelized = parallelize([0.3, 0.3, "x", 0.3, 0.3, 0.3, 0.3, 0.3], ordered: false, stop_on_exception: true) { |x| if x == "x" sleep(0.1) raise "hi" @@ -171,7 +171,7 @@ describe Chef::ChefFS::Parallelizer do sleep(x) processed += 1 x - end + } expect { parallelized.to_a }.to raise_error "hi" expect(processed).to eq(4) end @@ -187,10 +187,10 @@ describe Chef::ChefFS::Parallelizer do sleep 0.1 end enum = parallelize(input) { |x| x } - expect(enum.map do |value| + expect(enum.map { |value| expect(elapsed_time).to be < (value + 1) * 0.1 value - end).to eq([ 1, 2, 3 ]) + }).to eq([ 1, 2, 3 ]) end end @@ -205,11 +205,11 @@ describe Chef::ChefFS::Parallelizer do started = false @occupying_job_finished = occupying_job_finished = [ false ] @thread = Thread.new do - parallelizer.parallelize([0], main_thread_processing: false) do |x| + parallelizer.parallelize([0], main_thread_processing: false) { |x| started = true sleep(0.3) occupying_job_finished[0] = true - end.wait + }.wait end sleep(0.01) until started end @@ -219,18 +219,18 @@ describe Chef::ChefFS::Parallelizer do end it "parallelize with :main_thread_processing = true does not block" do - expect(parallelizer.parallelize([1]) do |x| + expect(parallelizer.parallelize([1]) { |x| sleep(0.1) x - end.to_a).to eq([ 1 ]) + }.to_a).to eq([ 1 ]) expect(elapsed_time).to be < 0.2 end it "parallelize with :main_thread_processing = false waits for the job to finish" do - expect(parallelizer.parallelize([1], main_thread_processing: false) do |x| + expect(parallelizer.parallelize([1], main_thread_processing: false) { |x| sleep(0.1) x + 1 - end.to_a).to eq([ 2 ]) + }.to_a).to eq([ 2 ]) expect(elapsed_time).to be > 0.3 end @@ -264,11 +264,11 @@ describe Chef::ChefFS::Parallelizer do it ".count does not process anything" do outputs_processed = 0 input_mapper = TestEnumerable.new(1, 2, 3, 4, 5, 6) - enum = parallelizer.parallelize(input_mapper) do |x| + enum = parallelizer.parallelize(input_mapper) { |x| outputs_processed += 1 sleep(0.05) # Just enough to yield and get other inputs in the queue x - end + } expect(enum.count).to eq(6) expect(outputs_processed).to eq(0) expect(input_mapper.num_processed).to eq(6) @@ -277,10 +277,10 @@ describe Chef::ChefFS::Parallelizer do it ".count with arguments works normally" do outputs_processed = 0 input_mapper = TestEnumerable.new(1, 1, 1, 1, 2, 2, 2, 3, 3, 4) - enum = parallelizer.parallelize(input_mapper) do |x| + enum = parallelizer.parallelize(input_mapper) { |x| outputs_processed += 1 x - end + } expect(enum.count { |x| x > 1 }).to eq(6) expect(enum.count(2)).to eq(3) expect(outputs_processed).to eq(20) @@ -290,11 +290,11 @@ describe Chef::ChefFS::Parallelizer do it ".first does not enumerate anything other than the first result(s)" do outputs_processed = 0 input_mapper = TestEnumerable.new(1, 2, 3, 4, 5, 6) - enum = parallelizer.parallelize(input_mapper) do |x| + enum = parallelizer.parallelize(input_mapper) { |x| outputs_processed += 1 sleep(0.05) # Just enough to yield and get other inputs in the queue x - end + } expect(enum.first).to eq(1) expect(enum.first(2)).to eq([1, 2]) expect(outputs_processed).to eq(3) @@ -304,11 +304,11 @@ describe Chef::ChefFS::Parallelizer do it ".take does not enumerate anything other than the first result(s)" do outputs_processed = 0 input_mapper = TestEnumerable.new(1, 2, 3, 4, 5, 6) - enum = parallelizer.parallelize(input_mapper) do |x| + enum = parallelizer.parallelize(input_mapper) { |x| outputs_processed += 1 sleep(0.05) # Just enough to yield and get other inputs in the queue x - end + } expect(enum.take(2)).to eq([1, 2]) expect(outputs_processed).to eq(2) expect(input_mapper.num_processed).to eq(2) @@ -317,11 +317,11 @@ describe Chef::ChefFS::Parallelizer do it ".drop does not process anything other than the last result(s)" do outputs_processed = 0 input_mapper = TestEnumerable.new(1, 2, 3, 4, 5, 6) - enum = parallelizer.parallelize(input_mapper) do |x| + enum = parallelizer.parallelize(input_mapper) { |x| outputs_processed += 1 sleep(0.05) # Just enough to yield and get other inputs in the queue x - end + } expect(enum.drop(2)).to eq([3, 4, 5, 6]) expect(outputs_processed).to eq(4) expect(input_mapper.num_processed).to eq(6) @@ -331,11 +331,11 @@ describe Chef::ChefFS::Parallelizer do it ".lazy.take does not enumerate anything other than the first result(s)" do outputs_processed = 0 input_mapper = TestEnumerable.new(1, 2, 3, 4, 5, 6) - enum = parallelizer.parallelize(input_mapper) do |x| + enum = parallelizer.parallelize(input_mapper) { |x| outputs_processed += 1 sleep(0.05) # Just enough to yield and get other inputs in the queue x - end + } expect(enum.lazy.take(2).to_a).to eq([1, 2]) expect(outputs_processed).to eq(2) expect(input_mapper.num_processed).to eq(2) @@ -344,11 +344,11 @@ describe Chef::ChefFS::Parallelizer do it ".drop does not process anything other than the last result(s)" do outputs_processed = 0 input_mapper = TestEnumerable.new(1, 2, 3, 4, 5, 6) - enum = parallelizer.parallelize(input_mapper) do |x| + enum = parallelizer.parallelize(input_mapper) { |x| outputs_processed += 1 sleep(0.05) # Just enough to yield and get other inputs in the queue x - end + } expect(enum.lazy.drop(2).to_a).to eq([3, 4, 5, 6]) expect(outputs_processed).to eq(4) expect(input_mapper.num_processed).to eq(6) @@ -357,11 +357,11 @@ describe Chef::ChefFS::Parallelizer do it "lazy enumerable is actually lazy" do outputs_processed = 0 input_mapper = TestEnumerable.new(1, 2, 3, 4, 5, 6) - enum = parallelizer.parallelize(input_mapper) do |x| + enum = parallelizer.parallelize(input_mapper) { |x| outputs_processed += 1 sleep(0.05) # Just enough to yield and get other inputs in the queue x - end + } enum.lazy.take(2) enum.lazy.drop(2) sleep(0.1) @@ -375,10 +375,10 @@ describe Chef::ChefFS::Parallelizer do it ".map twice on the same parallel enumerable returns the correct results and re-processes the input" do outputs_processed = 0 input_mapper = TestEnumerable.new(1, 2, 3) - enum = parallelizer.parallelize(input_mapper) do |x| + enum = parallelizer.parallelize(input_mapper) { |x| outputs_processed += 1 x - end + } expect(enum.map { |x| x }).to eq([1, 2, 3]) expect(enum.map { |x| x }).to eq([1, 2, 3]) expect(outputs_processed).to eq(6) @@ -388,10 +388,10 @@ describe Chef::ChefFS::Parallelizer do it ".first and then .map on the same parallel enumerable returns the correct results and re-processes the input" do outputs_processed = 0 input_mapper = TestEnumerable.new(1, 2, 3) - enum = parallelizer.parallelize(input_mapper) do |x| + enum = parallelizer.parallelize(input_mapper) { |x| outputs_processed += 1 x - end + } expect(enum.first).to eq(1) expect(enum.map { |x| x }).to eq([1, 2, 3]) expect(outputs_processed).to be >= 4 @@ -402,10 +402,10 @@ describe Chef::ChefFS::Parallelizer do enum = parallelizer.parallelize([1, 2, 3]) { |x| x } a = enum.enum_for(:each) a.next - expect do + expect { b = enum.enum_for(:each) b.next - end.to raise_error + }.to raise_error end end end @@ -436,13 +436,13 @@ describe Chef::ChefFS::Parallelizer do end it "does not have contention issues with large numbers of jobs and inputs with ordering off" do - parallelizers = 0.upto(99).map do + parallelizers = 0.upto(99).map { parallelizer.parallelize(1.upto(500)) { |x| x + 1 } - end + } outputs = [] - threads = 0.upto(99).map do |i| + threads = 0.upto(99).map { |i| Thread.new { outputs[i] = parallelizers[i].to_a } - end + } threads.each(&:join) outputs.each { |output| expect(output.sort).to eq(2.upto(501).to_a) } end diff --git a/spec/unit/client_spec.rb b/spec/unit/client_spec.rb index 5182717af8..eae1b6a400 100644 --- a/spec/unit/client_spec.rb +++ b/spec/unit/client_spec.rb @@ -733,9 +733,9 @@ describe Chef::Client do context "when any directory of cookbook_path contains no cookbook" do it "raises CookbookNotFound error" do - expect do + expect { client.send(:assert_cookbook_path_not_empty, nil) - end.to raise_error(Chef::Exceptions::CookbookNotFound, 'None of the cookbook paths set in Chef::Config[:cookbook_path], ["/path/to/invalid/cookbook_path"], contain any cookbooks') + }.to raise_error(Chef::Exceptions::CookbookNotFound, 'None of the cookbook paths set in Chef::Config[:cookbook_path], ["/path/to/invalid/cookbook_path"], contain any cookbooks') end end end diff --git a/spec/unit/cookbook/syntax_check_spec.rb b/spec/unit/cookbook/syntax_check_spec.rb index a24fa3ab2a..18b2227bee 100644 --- a/spec/unit/cookbook/syntax_check_spec.rb +++ b/spec/unit/cookbook/syntax_check_spec.rb @@ -208,7 +208,7 @@ describe Chef::Cookbook::SyntaxCheck do describe "and the files have been syntax checked previously" do before do - syntax_check.untested_ruby_files.each { |f| syntax_check.validated(f) } + syntax_check.untested_ruby_files.each do |f| syntax_check.validated(f) end syntax_check.untested_template_files.each { |f| syntax_check.validated(f) } end diff --git a/spec/unit/cookbook_loader_spec.rb b/spec/unit/cookbook_loader_spec.rb index c747f14dd0..c6bcb60d57 100644 --- a/spec/unit/cookbook_loader_spec.rb +++ b/spec/unit/cookbook_loader_spec.rb @@ -40,7 +40,7 @@ describe Chef::CookbookLoader do cookbook_paths |= Dir[File.join(repo_path, "*")] end - cookbook_paths.delete_if { |path| File.basename(path) == "chefignore" } + cookbook_paths.delete_if do |path| File.basename(path) == "chefignore" end cookbook_paths.each do |cookbook_path| expect(Chef::Cookbook::CookbookVersionLoader).to receive(:new) @@ -112,30 +112,30 @@ describe Chef::CookbookLoader do end it "should load different attribute files from deeper paths" do - expect(full_paths_for_part(:openldap, "attributes").detect do |f| + expect(full_paths_for_part(:openldap, "attributes").detect { |f| f =~ %r{cookbooks/openldap/attributes/smokey.rb} - end).not_to eql(nil) + }).not_to eql(nil) end it "should load definition files from deeper paths" do - expect(full_paths_for_part(:openldap, "definitions").detect do |f| + expect(full_paths_for_part(:openldap, "definitions").detect { |f| f =~ %r{cookbooks/openldap/definitions/server.rb} - end).not_to eql(nil) + }).not_to eql(nil) end it "should load recipe files from deeper paths" do - expect(full_paths_for_part(:openldap, "recipes").detect do |f| + expect(full_paths_for_part(:openldap, "recipes").detect { |f| f =~ %r{cookbooks/openldap/recipes/one.rb} - end).not_to eql(nil) + }).not_to eql(nil) end it "should find files that start with a ." do - expect(full_paths_for_part(:openldap, "files").detect do |f| + expect(full_paths_for_part(:openldap, "files").detect { |f| f =~ /\.dotfile$/ - end).to match(/\.dotfile$/) - expect(full_paths_for_part(:openldap, "files").detect do |f| + }).to match(/\.dotfile$/) + expect(full_paths_for_part(:openldap, "files").detect { |f| f =~ %r{\.ssh/id_rsa$} - end).to match(%r{\.ssh/id_rsa$}) + }).to match(%r{\.ssh/id_rsa$}) end it "should load the metadata for the cookbook" do diff --git a/spec/unit/cookbook_uploader_spec.rb b/spec/unit/cookbook_uploader_spec.rb index 2adecfaa82..6dc2f6563b 100644 --- a/spec/unit/cookbook_uploader_spec.rb +++ b/spec/unit/cookbook_uploader_spec.rb @@ -77,10 +77,10 @@ describe Chef::CookbookUploader do end let(:sandbox_response) do - sandbox_checksums = cksums_not_on_remote.inject({}) do |cksum_map, cksum| + sandbox_checksums = cksums_not_on_remote.inject({}) { |cksum_map, cksum| cksum_map[cksum] = { "needs_upload" => true, "url" => url_for(cksum) } cksum_map - end + } { "checksums" => sandbox_checksums, "uri" => sandbox_commit_uri } end diff --git a/spec/unit/cookbook_version_file_specificity_spec.rb b/spec/unit/cookbook_version_file_specificity_spec.rb index 4d0c8c62f1..b562eb53c2 100644 --- a/spec/unit/cookbook_version_file_specificity_spec.rb +++ b/spec/unit/cookbook_version_file_specificity_spec.rb @@ -338,24 +338,24 @@ describe Chef::CookbookVersion, "file specificity" do it "should raise a FileNotFound exception without match" do node = Chef::Node.new - expect do + expect { @cookbook.preferred_manifest_record(node, :files, "doesn't_exist.rb") - end.to raise_error(Chef::Exceptions::FileNotFound) + }.to raise_error(Chef::Exceptions::FileNotFound) end it "should raise a FileNotFound exception consistently without match" do node = Chef::Node.new - expect do + expect { @cookbook.preferred_manifest_record(node, :files, "doesn't_exist.rb") - end.to raise_error(Chef::Exceptions::FileNotFound) + }.to raise_error(Chef::Exceptions::FileNotFound) - expect do + expect { @cookbook.preferred_manifest_record(node, :files, "doesn't_exist.rb") - end.to raise_error(Chef::Exceptions::FileNotFound) + }.to raise_error(Chef::Exceptions::FileNotFound) - expect do + expect { @cookbook.preferred_manifest_record(node, :files, "doesn't_exist.rb") - end.to raise_error(Chef::Exceptions::FileNotFound) + }.to raise_error(Chef::Exceptions::FileNotFound) end describe "when fetching the contents of a directory by file specificity" do diff --git a/spec/unit/data_bag_spec.rb b/spec/unit/data_bag_spec.rb index 4b0ba42172..80d901bdb7 100644 --- a/spec/unit/data_bag_spec.rb +++ b/spec/unit/data_bag_spec.rb @@ -241,9 +241,9 @@ describe Chef::DataBag do it "should raise an error if the configured data_bag_path is invalid" do file_dir_stub(@paths.first, false) - expect do + expect { Chef::DataBag.load("foo") - end.to raise_error Chef::Exceptions::InvalidDataBagPath, "Data bag path '/var/chef/data_bags' is invalid" + }.to raise_error Chef::Exceptions::InvalidDataBagPath, "Data bag path '/var/chef/data_bags' is invalid" end end diff --git a/spec/unit/decorator/lazy_array_spec.rb b/spec/unit/decorator/lazy_array_spec.rb index 0c5c2eeee0..61465c027f 100644 --- a/spec/unit/decorator/lazy_array_spec.rb +++ b/spec/unit/decorator/lazy_array_spec.rb @@ -51,7 +51,7 @@ describe Chef::Decorator::LazyArray do it "if we loop over the elements and do nothing then its not lazy" do # we don't know how many elements there are unless we evaluate the proc - decorator.each { |i| } + decorator.each do |i| end expect(@foo).to equal(1) expect(@bar).to equal(2) end diff --git a/spec/unit/dsl/declare_resource_spec.rb b/spec/unit/dsl/declare_resource_spec.rb index ead0be2967..80b9ffae5f 100644 --- a/spec/unit/dsl/declare_resource_spec.rb +++ b/spec/unit/dsl/declare_resource_spec.rb @@ -59,36 +59,36 @@ describe Chef::ResourceCollection do describe "#edit_resource!" do it "raises if nothing is found" do - expect do + expect { recipe.edit_resource!(:zen_master, "monkey") do something true end - end.to raise_error(Chef::Exceptions::ResourceNotFound) + }.to raise_error(Chef::Exceptions::ResourceNotFound) end it "raises if nothing is found and no block is given" do - expect do + expect { recipe.edit_resource!(:zen_master, "monkey") - end.to raise_error(Chef::Exceptions::ResourceNotFound) + }.to raise_error(Chef::Exceptions::ResourceNotFound) end it "edits the resource if it finds one" do - resource = recipe.declare_resource(:zen_master, "monkey") do + resource = recipe.declare_resource(:zen_master, "monkey") { something false - end + } expect( - recipe.edit_resource!(:zen_master, "monkey") do + recipe.edit_resource!(:zen_master, "monkey") { something true - end + } ).to eql(resource) expect(run_context.resource_collection.all_resources.size).to eql(1) expect(run_context.resource_collection.first.something).to be true end it "acts like find_resource! if not given a block and the resource exists" do - resource = recipe.declare_resource(:zen_master, "monkey") do + resource = recipe.declare_resource(:zen_master, "monkey") { something false - end + } expect( recipe.edit_resource!(:zen_master, "monkey") ).to eql(resource) @@ -99,9 +99,9 @@ describe Chef::ResourceCollection do describe "#edit_resource" do it "inserts a resource if nothing is found" do - resource = recipe.edit_resource(:zen_master, "monkey") do + resource = recipe.edit_resource(:zen_master, "monkey") { something true - end + } expect(run_context.resource_collection.all_resources.size).to eql(1) expect(run_context.resource_collection.first).to eql(resource) expect(run_context.resource_collection.first.something).to be true @@ -114,22 +114,22 @@ describe Chef::ResourceCollection do end it "edits the resource if it finds one" do - resource = recipe.declare_resource(:zen_master, "monkey") do + resource = recipe.declare_resource(:zen_master, "monkey") { something false - end + } expect( - recipe.edit_resource(:zen_master, "monkey") do + recipe.edit_resource(:zen_master, "monkey") { something true - end + } ).to eql(resource) expect(run_context.resource_collection.all_resources.size).to eql(1) expect(run_context.resource_collection.first.something).to be true end it "acts like find_resource if not given a block and the resource exists" do - resource = recipe.declare_resource(:zen_master, "monkey") do + resource = recipe.declare_resource(:zen_master, "monkey") { something false - end + } expect( recipe.edit_resource(:zen_master, "monkey") ).to eql(resource) @@ -140,26 +140,26 @@ describe Chef::ResourceCollection do describe "#find_resource!" do it "raises if nothing is found" do - expect do + expect { recipe.find_resource!(:zen_master, "monkey") - end.to raise_error(Chef::Exceptions::ResourceNotFound) + }.to raise_error(Chef::Exceptions::ResourceNotFound) end it "raises if given a block" do - resource = recipe.declare_resource(:zen_master, "monkey") do + resource = recipe.declare_resource(:zen_master, "monkey") { something false - end - expect do + } + expect { recipe.find_resource!(:zen_master, "monkey") do something false end - end.to raise_error(ArgumentError) + }.to raise_error(ArgumentError) end it "returns the resource if it finds one" do - resource = recipe.declare_resource(:zen_master, "monkey") do + resource = recipe.declare_resource(:zen_master, "monkey") { something false - end + } expect( recipe.find_resource!(:zen_master, "monkey") ).to eql(resource) @@ -175,9 +175,9 @@ describe Chef::ResourceCollection do end it "returns the resource if it finds one" do - resource = recipe.declare_resource(:zen_master, "monkey") do + resource = recipe.declare_resource(:zen_master, "monkey") { something false - end + } expect( recipe.find_resource(:zen_master, "monkey") ).to eql(resource) @@ -188,22 +188,22 @@ describe Chef::ResourceCollection do describe "#find_resource with block" do it "inserts a resource if nothing is found" do - resource = recipe.find_resource(:zen_master, "monkey") do + resource = recipe.find_resource(:zen_master, "monkey") { something true - end + } expect(run_context.resource_collection.all_resources.size).to eql(1) expect(run_context.resource_collection.first).to eql(resource) expect(run_context.resource_collection.first.something).to be true end it "returns the resource if it finds one" do - resource = recipe.declare_resource(:zen_master, "monkey") do + resource = recipe.declare_resource(:zen_master, "monkey") { something false - end + } expect( - recipe.find_resource(:zen_master, "monkey") do + recipe.find_resource(:zen_master, "monkey") { something true - end + } ).to eql(resource) expect(run_context.resource_collection.all_resources.size).to eql(1) expect(run_context.resource_collection.first.something).to be false @@ -218,9 +218,9 @@ describe Chef::ResourceCollection do end it "deletes and returns the resource if it finds one" do - resource = recipe.declare_resource(:zen_master, "monkey") do + resource = recipe.declare_resource(:zen_master, "monkey") { something false - end + } expect( recipe.delete_resource(:zen_master, "monkey") ).to eql(resource) @@ -230,15 +230,15 @@ describe Chef::ResourceCollection do describe "#delete_resource!" do it "raises if nothing is found" do - expect do + expect { recipe.delete_resource!(:zen_master, "monkey") - end.to raise_error(Chef::Exceptions::ResourceNotFound) + }.to raise_error(Chef::Exceptions::ResourceNotFound) end it "deletes and returns the resource if it finds one" do - resource = recipe.declare_resource(:zen_master, "monkey") do + resource = recipe.declare_resource(:zen_master, "monkey") { something false - end + } expect( recipe.delete_resource!(:zen_master, "monkey") ).to eql(resource) @@ -300,15 +300,15 @@ describe Chef::ResourceCollection do end it "our tests have correct separation" do - child_resource = child_recipe.declare_resource(:zen_master, "child") do + child_resource = child_recipe.declare_resource(:zen_master, "child") { something false - end - parent_resource = parent_recipe.declare_resource(:zen_master, "parent") do + } + parent_resource = parent_recipe.declare_resource(:zen_master, "parent") { something false - end - root_resource = recipe.declare_resource(:zen_master, "root") do + } + root_resource = recipe.declare_resource(:zen_master, "root") { something false - end + } expect(run_context.resource_collection.first).to eql(root_resource) expect(run_context.resource_collection.first.to_s).to eql("zen_master[root]") expect(run_context.resource_collection.all_resources.size).to eql(1) @@ -364,9 +364,9 @@ describe Chef::ResourceCollection do it "with_run_context returns the return value of the block" do child_recipe.instance_eval do - ret = with_run_context(:root) do + ret = with_run_context(:root) { "return value" - end + } raise "failed" unless ret == "return value" end end diff --git a/spec/unit/environment_spec.rb b/spec/unit/environment_spec.rb index 42906ef772..c62774dbbe 100644 --- a/spec/unit/environment_spec.rb +++ b/spec/unit/environment_spec.rb @@ -296,9 +296,9 @@ describe Chef::Environment do end it "should raise an exception" do - expect do + expect { Chef::Environment.validate_cookbook_version("= 1.2.3.4") - end.to raise_error Chef::Exceptions::IllegalVersionConstraint, + }.to raise_error Chef::Exceptions::IllegalVersionConstraint, /Environment cookbook version constraints not allowed in .*/ end end @@ -452,9 +452,9 @@ describe Chef::Environment do it "should raise an error if the configured environment_path is invalid" do expect(File).to receive(:directory?).with(Chef::Config[:environment_path]).and_return(false) - expect do + expect { Chef::Environment.load("foo") - end.to raise_error Chef::Exceptions::InvalidEnvironmentPath, "Environment path '/var/chef/environments' is invalid" + }.to raise_error Chef::Exceptions::InvalidEnvironmentPath, "Environment path '/var/chef/environments' is invalid" end it "should raise an error if the file does not exist" do @@ -462,9 +462,9 @@ describe Chef::Environment do expect(File).to receive(:exists?).with(File.join(Chef::Config[:environment_path], "foo.json")).and_return(false) expect(File).to receive(:exists?).with(File.join(Chef::Config[:environment_path], "foo.rb")).and_return(false) - expect do + expect { Chef::Environment.load("foo") - end.to raise_error Chef::Exceptions::EnvironmentNotFound, "Environment 'foo' could not be loaded from disk" + }.to raise_error Chef::Exceptions::EnvironmentNotFound, "Environment 'foo' could not be loaded from disk" end end end diff --git a/spec/unit/event_dispatch/dsl_spec.rb b/spec/unit/event_dispatch/dsl_spec.rb index 009242f4fb..2896ce4610 100644 --- a/spec/unit/event_dispatch/dsl_spec.rb +++ b/spec/unit/event_dispatch/dsl_spec.rb @@ -35,18 +35,18 @@ describe Chef::EventDispatch::DSL do subject { described_class.new("test") } it "set handler name" do - subject.on(:run_started) {} + subject.on(:run_started) do end expect(events.subscribers.first.name).to eq("test") end it "raise error when invalid event type is supplied" do - expect do + expect { subject.on(:foo_bar) {} - end.to raise_error(Chef::Exceptions::InvalidEventType) + }.to raise_error(Chef::Exceptions::InvalidEventType) end it "register user hooks against valid event type" do - subject.on(:run_failed) { "testhook" } + subject.on(:run_failed) do "testhook" end expect(events.subscribers.first.run_failed).to eq("testhook") end @@ -61,7 +61,7 @@ describe Chef::EventDispatch::DSL do end end resource = Chef::Resource::RubyBlock.new("foo", run_context) - resource.block {} + resource.block do end resource.run_action(:run) expect(calls).to eq(%i{started updated}) end @@ -76,7 +76,7 @@ describe Chef::EventDispatch::DSL do end end resource = Chef::Resource::RubyBlock.new("foo", run_context) - resource.block {} + resource.block do end resource.run_action(:run) expect(events.subscribers.first.instance_variable_get(:@ivar)).to eq([1, 2]) end diff --git a/spec/unit/file_cache_spec.rb b/spec/unit/file_cache_spec.rb index 388b0e746a..60a0ff2c80 100644 --- a/spec/unit/file_cache_spec.rb +++ b/spec/unit/file_cache_spec.rb @@ -57,7 +57,7 @@ describe Chef::FileCache do describe "when loading cached files" do it "finds and reads the cached file" do FileUtils.mkdir_p(File.join(@file_cache_path, "whiz")) - File.open(File.join(@file_cache_path, "whiz", "bang"), "w") { |f| f.print("borkborkbork") } + File.open(File.join(@file_cache_path, "whiz", "bang"), "w") do |f| f.print("borkborkbork") end expect(Chef::FileCache.load("whiz/bang")).to eq("borkborkbork") end diff --git a/spec/unit/formatters/error_inspectors/resource_failure_inspector_spec.rb b/spec/unit/formatters/error_inspectors/resource_failure_inspector_spec.rb index 7add65150a..7de11a4c75 100644 --- a/spec/unit/formatters/error_inspectors/resource_failure_inspector_spec.rb +++ b/spec/unit/formatters/error_inspectors/resource_failure_inspector_spec.rb @@ -47,7 +47,7 @@ describe Chef::Formatters::ErrorInspectors::ResourceFailureInspector do describe "when explaining an error converging a resource" do before do - @resource = package("non-existing-package") do + @resource = package("non-existing-package") { only_if do true @@ -55,7 +55,7 @@ describe Chef::Formatters::ErrorInspectors::ResourceFailureInspector do not_if("/bin/false") action :upgrade - end + } @trace = [ "/var/chef/cache/cookbooks/syntax-err/recipes/default.rb:14:in `from_file'", @@ -89,9 +89,9 @@ describe Chef::Formatters::ErrorInspectors::ResourceFailureInspector do @context = Chef::Mixin::Template::TemplateContext.new({}) @context[:chef] = "cool" - @resource = template("/tmp/foo.txt") do + @resource = template("/tmp/foo.txt") { mode "0644" - end + } @error = begin @context.render_template_from_string("foo\nbar\nbaz\n<%= this_is_not_defined %>\nquin\nqunx\ndunno") diff --git a/spec/unit/http/ssl_policies_spec.rb b/spec/unit/http/ssl_policies_spec.rb index b67ecc84de..49b55a18e4 100644 --- a/spec/unit/http/ssl_policies_spec.rb +++ b/spec/unit/http/ssl_policies_spec.rb @@ -85,7 +85,7 @@ describe "HTTP SSL Policy" do end describe "when configured with a client certificate" do - before { @url = URI.parse("https://chef.example.com:4443/") } + before do @url = URI.parse("https://chef.example.com:4443/") end it "raises ConfigurationError if the certificate file doesn't exist" do Chef::Config[:ssl_client_cert] = "/dev/null/nothing_here" diff --git a/spec/unit/json_compat_spec.rb b/spec/unit/json_compat_spec.rb index 38c2c60b2e..1218f2e20d 100644 --- a/spec/unit/json_compat_spec.rb +++ b/spec/unit/json_compat_spec.rb @@ -20,7 +20,7 @@ require File.expand_path("../../spec_helper", __FILE__) require "chef/json_compat" describe Chef::JSONCompat do - before { Chef::Config[:treat_deprecation_warnings_as_errors] = false } + before do Chef::Config[:treat_deprecation_warnings_as_errors] = false end describe "#parse with JSON containing comments" do let(:json) { %Q{{\n/* comment */\n// comment 2\n"json_class": "Chef::Role"}} } @@ -57,9 +57,9 @@ describe Chef::JSONCompat do end it "should has 'test' as a 252 nested value" do - v = 252.times.inject(hash) do |memo, _| + v = 252.times.inject(hash) { |memo, _| memo["key"] - end + } expect(v).to eq("test") end end diff --git a/spec/unit/knife/bootstrap_spec.rb b/spec/unit/knife/bootstrap_spec.rb index 5f4be8dfa2..bc54bdfe7b 100644 --- a/spec/unit/knife/bootstrap_spec.rb +++ b/spec/unit/knife/bootstrap_spec.rb @@ -321,7 +321,7 @@ describe Chef::Knife::Bootstrap do context "with bootstrap_attribute options" do let(:jsonfile) do file = Tempfile.new (["node", ".json"]) - File.open(file.path, "w") { |f| f.puts '{"foo":{"bar":"baz"}}' } + File.open(file.path, "w") do |f| f.puts '{"foo":{"bar":"baz"}}' end file end diff --git a/spec/unit/knife/configure_client_spec.rb b/spec/unit/knife/configure_client_spec.rb index be76250e7c..2f1df09e46 100644 --- a/spec/unit/knife/configure_client_spec.rb +++ b/spec/unit/knife/configure_client_spec.rb @@ -33,9 +33,9 @@ describe Chef::Knife::ConfigureClient do it "should print usage and exit when a directory is not provided" do expect(@knife).to receive(:show_usage) expect(@knife.ui).to receive(:fatal).with(/must provide the directory/) - expect do + expect { @knife.run - end.to raise_error SystemExit + }.to raise_error SystemExit end describe "when specifing a directory" do diff --git a/spec/unit/knife/cookbook_upload_spec.rb b/spec/unit/knife/cookbook_upload_spec.rb index 9c371c4140..e4af9a5b4f 100644 --- a/spec/unit/knife/cookbook_upload_spec.rb +++ b/spec/unit/knife/cookbook_upload_spec.rb @@ -158,11 +158,11 @@ describe Chef::Knife::CookbookUpload do knife.config[:depends] = true allow(knife).to receive(:cookbook_names).and_return(%w{test_cookbook1 test_cookbook2 test_cookbook3}) expect(knife).to receive(:upload).exactly(3).times - expect do + expect { Timeout.timeout(5) do knife.run end - end.not_to raise_error + }.not_to raise_error end end diff --git a/spec/unit/knife/core/node_editor_spec.rb b/spec/unit/knife/core/node_editor_spec.rb index 493de3c5b1..5ddc2d0067 100644 --- a/spec/unit/knife/core/node_editor_spec.rb +++ b/spec/unit/knife/core/node_editor_spec.rb @@ -44,10 +44,10 @@ describe Chef::Knife::NodeEditor do describe "#view" do it "returns a Hash with only the name, chef_environment, normal, " + "policy_name, policy_group, and run_list properties" do - expected = node_data.select do |key,| + expected = node_data.select { |key,| %w{ name chef_environment normal policy_name policy_group run_list }.include?(key) - end + } expect(subject.view).to eq(expected) end diff --git a/spec/unit/knife/core/ui_spec.rb b/spec/unit/knife/core/ui_spec.rb index e5f19a4837..245411f524 100644 --- a/spec/unit/knife/core/ui_spec.rb +++ b/spec/unit/knife/core/ui_spec.rb @@ -541,9 +541,9 @@ describe Chef::Knife::UI do shared_examples_for "confirm with negative answer" do it "confirm should exit 3" do - expect do + expect { run_confirm - end.to raise_error(SystemExit) { |e| expect(e.status).to eq(3) } + }.to raise_error(SystemExit) { |e| expect(e.status).to eq(3) } end it "confirm_without_exit should return false" do diff --git a/spec/unit/knife/node_bulk_delete_spec.rb b/spec/unit/knife/node_bulk_delete_spec.rb index db9e2caab1..5b7054a6b3 100644 --- a/spec/unit/knife/node_bulk_delete_spec.rb +++ b/spec/unit/knife/node_bulk_delete_spec.rb @@ -36,10 +36,10 @@ describe Chef::Knife::NodeBulkDelete do describe "when creating the list of nodes" do it "fetches the node list" do - expected = @nodes.inject({}) do |inflatedish, (name, uri)| + expected = @nodes.inject({}) { |inflatedish, (name, uri)| inflatedish[name] = Chef::Node.new.tap { |n| n.name(name) } inflatedish - end + } expect(Chef::Node).to receive(:list).and_return(@nodes) # I hate not having == defined for anything :( actual = @knife.all_nodes @@ -50,13 +50,13 @@ describe Chef::Knife::NodeBulkDelete do describe "run" do before do - @inflatedish_list = @nodes.keys.inject({}) do |nodes_by_name, name| + @inflatedish_list = @nodes.keys.inject({}) { |nodes_by_name, name| node = Chef::Node.new node.name(name) allow(node).to receive(:destroy).and_return(true) nodes_by_name[name] = node nodes_by_name - end + } allow(@knife).to receive(:all_nodes).and_return(@inflatedish_list) end diff --git a/spec/unit/lwrp_spec.rb b/spec/unit/lwrp_spec.rb index def981801e..b84f611a15 100644 --- a/spec/unit/lwrp_spec.rb +++ b/spec/unit/lwrp_spec.rb @@ -229,9 +229,9 @@ describe "LWRP" do end it "allows to user to user the resource_name" do - expect do + expect { klass.resource_name(:foo) - end.to_not raise_error + }.to_not raise_error end it "returns the set value for the resource" do diff --git a/spec/unit/mixin/openssl_helper_spec.rb b/spec/unit/mixin/openssl_helper_spec.rb index a6a6fb0e71..d68fcb71eb 100644 --- a/spec/unit/mixin/openssl_helper_spec.rb +++ b/spec/unit/mixin/openssl_helper_spec.rb @@ -32,9 +32,9 @@ describe Chef::Mixin::OpenSSLHelper do describe "#get_key_filename" do context "When the input is not a string" do it "Throws a TypeError" do - expect do + expect { instance.get_key_filename(33) - end.to raise_error(TypeError) + }.to raise_error(TypeError) end end @@ -89,11 +89,11 @@ describe Chef::Mixin::OpenSSLHelper do context "When the dhparam.pem file does exist, but does not contain a valid dhparam key" do it "Throws an OpenSSL::PKey::DHError exception" do - expect do + expect { @dhparam_file.puts("I_am_not_a_key_I_am_a_free_man") @dhparam_file.close instance.dhparam_pem_valid?(@dhparam_file.path) - end.to raise_error(::OpenSSL::PKey::DHError) + }.to raise_error(::OpenSSL::PKey::DHError) end end @@ -225,17 +225,17 @@ describe Chef::Mixin::OpenSSLHelper do describe "#gen_dhparam" do context "When given an invalid key length" do it "Throws an ArgumentError" do - expect do + expect { instance.gen_dhparam(2046, 2) - end.to raise_error(ArgumentError) + }.to raise_error(ArgumentError) end end context "When given an invalid generator id" do it "Throws a TypeError" do - expect do + expect { instance.gen_dhparam(2048, "bob") - end.to raise_error(TypeError) + }.to raise_error(TypeError) end end @@ -249,9 +249,9 @@ describe Chef::Mixin::OpenSSLHelper do describe "#gen_rsa_priv_key" do context "When given an invalid key length" do it "Throws an ArgumentError" do - expect do + expect { instance.gen_rsa_priv_key(4093) - end.to raise_error(ArgumentError) + }.to raise_error(ArgumentError) end end @@ -269,33 +269,33 @@ describe Chef::Mixin::OpenSSLHelper do context "When given anything other than an RSA key object to encrypt" do it "Raises a TypeError" do - expect do + expect { instance.encrypt_rsa_key("abcd", "efgh", "des3") - end.to raise_error(TypeError) + }.to raise_error(TypeError) end end context "When given anything other than a string as the passphrase" do it "Raises a TypeError" do - expect do + expect { instance.encrypt_rsa_key(@rsa_key, 1234, "des3") - end.to raise_error(TypeError) + }.to raise_error(TypeError) end end context "When given anything other than a string as the cipher" do it "Raises a TypeError" do - expect do + expect { instance.encrypt_rsa_key(@rsa_key, "1234", 1234) - end.to raise_error(TypeError) + }.to raise_error(TypeError) end end context "When given an invalid cipher string" do it "Raises an ArgumentError" do - expect do + expect { instance.encrypt_rsa_key(@rsa_key, "1234", "des3_bogus") - end.to raise_error(ArgumentError) + }.to raise_error(ArgumentError) end end @@ -311,15 +311,15 @@ describe Chef::Mixin::OpenSSLHelper do describe "#gen_ec_priv_key" do context "When given an invalid curve" do it "Raises a TypeError" do - expect do + expect { instance.gen_ec_priv_key(2048) - end.to raise_error(TypeError) + }.to raise_error(TypeError) end it "Throws an ArgumentError" do - expect do + expect { instance.gen_ec_priv_key("primeFromTheFuture") - end.to raise_error(ArgumentError) + }.to raise_error(ArgumentError) end end @@ -337,33 +337,33 @@ describe Chef::Mixin::OpenSSLHelper do context "When given anything other than an EC key object to encrypt" do it "Raises a TypeError" do - expect do + expect { instance.encrypt_ec_key("abcd", "efgh", "des3") - end.to raise_error(TypeError) + }.to raise_error(TypeError) end end context "When given anything other than a string as the passphrase" do it "Raises a TypeError" do - expect do + expect { instance.encrypt_ec_key(@ec_key, 1234, "des3") - end.to raise_error(TypeError) + }.to raise_error(TypeError) end end context "When given anything other than a string as the cipher" do it "Raises a TypeError" do - expect do + expect { instance.encrypt_ec_key(@ec_key, "1234", 1234) - end.to raise_error(TypeError) + }.to raise_error(TypeError) end end context "When given an invalid cipher string" do it "Raises an ArgumentError" do - expect do + expect { instance.encrypt_ec_key(@ec_key, "1234", "des3_bogus") - end.to raise_error(ArgumentError) + }.to raise_error(ArgumentError) end end @@ -385,17 +385,17 @@ describe Chef::Mixin::OpenSSLHelper do context "When given anything other than an RSA/EC key object" do it "Raises a TypeError" do - expect do + expect { instance.gen_x509_request(@subject, "abc") - end.to raise_error(TypeError) + }.to raise_error(TypeError) end end context "When given anything other than an X509 Name object" do it "Raises a TypeError" do - expect do + expect { instance.gen_x509_request("abc", @key) - end.to raise_error(TypeError) + }.to raise_error(TypeError) end end @@ -419,35 +419,35 @@ describe Chef::Mixin::OpenSSLHelper do describe "#gen_x509_extensions" do context "When given anything other than an Ruby Hash object" do it "Raises a TypeError" do - expect do + expect { instance.gen_x509_extensions("abc") - end.to raise_error(TypeError) + }.to raise_error(TypeError) end end context "When a misformatted ruby Hash is given" do it "Raises a TypeError" do - expect do + expect { instance.gen_x509_extensions("pouet" => "plop") - end.to raise_error(TypeError) + }.to raise_error(TypeError) end it "Raises a ArgumentError" do - expect do + expect { instance.gen_x509_extensions("pouet" => { "values" => [ "keyCertSign" ], "wrong_key" => true }) - end.to raise_error(ArgumentError) + }.to raise_error(ArgumentError) end it "Raises a TypeError" do - expect do + expect { instance.gen_x509_extensions("keyUsage" => { "values" => "keyCertSign", "critical" => true }) - end.to raise_error(TypeError) + }.to raise_error(TypeError) end it "Raises a TypeError" do - expect do + expect { instance.gen_x509_extensions("keyUsage" => { "values" => [ "keyCertSign" ], "critical" => "yes" }) - end.to raise_error(TypeError) + }.to raise_error(TypeError) end end @@ -496,33 +496,33 @@ describe Chef::Mixin::OpenSSLHelper do context "When the request given is anything other then a Ruby OpenSSL::X509::Request" do it "Raises a TypeError" do - expect do + expect { @instance.gen_x509_cert("abc", @x509_extension, @info_without_issuer, @rsa_key) - end.to raise_error(TypeError) + }.to raise_error(TypeError) end end context "When the extension given is anything other then a Ruby Array" do it "Raises a TypeError" do - expect do + expect { @instance.gen_x509_cert(@rsa_request, "abc", @info_without_issuer, @rsa_key) - end.to raise_error(TypeError) + }.to raise_error(TypeError) end end context "When the info given is anything other then a Ruby Hash" do it "Raises a TypeError" do - expect do + expect { @instance.gen_x509_cert(@rsa_request, @x509_extension, "abc", @rsa_key) - end.to raise_error(TypeError) + }.to raise_error(TypeError) end end context "When the key given is anything other then a Ruby OpenSSL::Pkey::EC or OpenSSL::Pkey::RSA object" do it "Raises a TypeError" do - expect do + expect { @instance.gen_x509_cert(@rsa_request, @x509_extension, @info_without_issuer, "abc") - end.to raise_error(TypeError) + }.to raise_error(TypeError) end end @@ -550,9 +550,9 @@ describe Chef::Mixin::OpenSSLHelper do context "When the CRL given is anything other then a Ruby OpenSSL::X509::CRL object" do it "Raises a TypeError" do - expect do + expect { instance.get_next_crl_number("abc") - end.to raise_error(TypeError) + }.to raise_error(TypeError) end end @@ -572,17 +572,17 @@ describe Chef::Mixin::OpenSSLHelper do context "When the CRL given is anything other then a Ruby OpenSSL::X509::CRL object" do it "Raises a TypeError" do - expect do + expect { instance.serial_revoked?("abc", "C7BCB6602A2E4251EF4E2827A228CB52BC0CEA2F") - end.to raise_error(TypeError) + }.to raise_error(TypeError) end end context "When the serial given is anything other then a Ruby String or Integer object" do it "Raises a TypeError" do - expect do + expect { instance.serial_revoked?(@crl, []) - end.to raise_error(TypeError) + }.to raise_error(TypeError) end end @@ -621,37 +621,37 @@ describe Chef::Mixin::OpenSSLHelper do context "When the CA private key given is anything other then a Ruby OpenSSL::PKey::EC object or a OpenSSL::PKey::RSA object" do it "Raises a TypeError" do - expect do + expect { instance.gen_x509_crl("abc", @info) - end.to raise_error(TypeError) + }.to raise_error(TypeError) end end context "When the info given is anything other then a Ruby Hash" do it "Raises a TypeError" do - expect do + expect { instance.gen_x509_crl(@ca_key, "abc") - end.to raise_error(TypeError) + }.to raise_error(TypeError) end end context "When a misformatted info Ruby Hash is given" do it "Raises a ArgumentError" do - expect do + expect { instance.gen_x509_crl(@ca_key, "abc" => "def", "validity" => 8) - end.to raise_error(ArgumentError) + }.to raise_error(ArgumentError) end it "Raises a TypeError" do - expect do + expect { instance.gen_x509_crl(@ca_key, "issuer" => "abc", "validity" => 8) - end.to raise_error(TypeError) + }.to raise_error(TypeError) end it "Raises a TypeError" do - expect do + expect { instance.gen_x509_crl(@ca_key, "issuer" => @ca_cert, "validity" => "abc") - end.to raise_error(TypeError) + }.to raise_error(TypeError) end end @@ -693,45 +693,45 @@ describe Chef::Mixin::OpenSSLHelper do context "When the CRL given is anything other then a Ruby OpenSSL::X509::CRL object" do it "Raises a TypeError" do - expect do + expect { instance.renew_x509_crl("abc", @ca_key, @info) - end.to raise_error(TypeError) + }.to raise_error(TypeError) end end context "When the CA private key given is anything other then a Ruby OpenSSL::PKey::EC object or a OpenSSL::PKey::RSA object" do it "Raises a TypeError" do - expect do + expect { instance.renew_x509_crl(@crl, "abc", @info) - end.to raise_error(TypeError) + }.to raise_error(TypeError) end end context "When the info given is anything other then a Ruby Hash" do it "Raises a TypeError" do - expect do + expect { instance.renew_x509_crl(@crl, @ca_key, "abc") - end.to raise_error(TypeError) + }.to raise_error(TypeError) end end context "When a misformatted info Ruby Hash is given" do it "Raises a ArgumentError" do - expect do + expect { instance.renew_x509_crl(@crl, @ca_key, "abc" => "def", "validity" => 8) - end.to raise_error(ArgumentError) + }.to raise_error(ArgumentError) end it "Raises a TypeError" do - expect do + expect { instance.renew_x509_crl(@crl, @ca_key, "issuer" => "abc", "validity" => 8) - end.to raise_error(TypeError) + }.to raise_error(TypeError) end it "Raises a TypeError" do - expect do + expect { instance.renew_x509_crl(@crl, @ca_key, "issuer" => @ca_cert, "validity" => "abc") - end.to raise_error(TypeError) + }.to raise_error(TypeError) end end @@ -775,73 +775,73 @@ describe Chef::Mixin::OpenSSLHelper do context "When the revoke_info given is anything other then a Ruby Hash" do it "Raises a TypeError" do - expect do + expect { instance.revoke_x509_crl("abc", @crl, @ca_key, @info) - end.to raise_error(TypeError) + }.to raise_error(TypeError) end end context "When the CRL given is anything other then a Ruby OpenSSL::X509::CRL object" do it "Raises a TypeError" do - expect do + expect { instance.revoke_x509_crl(@revoke_info, "abc", @ca_key, @info) - end.to raise_error(TypeError) + }.to raise_error(TypeError) end end context "When the CA private key given is anything other then a Ruby OpenSSL::PKey::EC object or a OpenSSL::PKey::RSA object" do it "Raises a TypeError" do - expect do + expect { instance.revoke_x509_crl(@revoke_info, @crl, "abc", @info) - end.to raise_error(TypeError) + }.to raise_error(TypeError) end end context "When the info given is anything other then a Ruby Hash" do it "Raises a TypeError" do - expect do + expect { instance.revoke_x509_crl(@revoke_info, @crl, @ca_key, "abc") - end.to raise_error(TypeError) + }.to raise_error(TypeError) end end context "When a misformatted revoke_info Ruby Hash is given" do it "Raises a ArgumentError" do - expect do + expect { instance.revoke_x509_crl({ "abc" => "def", "ghi" => "jkl" }, @crl, @ca_key, @info) - end.to raise_error(ArgumentError) + }.to raise_error(ArgumentError) end it "Raises a TypeError" do - expect do + expect { instance.revoke_x509_crl({ "serial" => [], "reason" => 0 }, @crl, @ca_key, @info) - end.to raise_error(TypeError) + }.to raise_error(TypeError) end it "Raises a TypeError" do - expect do + expect { instance.revoke_x509_crl({ "serial" => 1, "reason" => "abc" }, @crl, @ca_key, @info) - end.to raise_error(TypeError) + }.to raise_error(TypeError) end end context "When a misformatted info Ruby Hash is given" do it "Raises a ArgumentError" do - expect do + expect { instance.revoke_x509_crl(@revoke_info, @crl, @ca_key, "abc" => "def", "validity" => 8) - end.to raise_error(ArgumentError) + }.to raise_error(ArgumentError) end it "Raises a TypeError" do - expect do + expect { instance.revoke_x509_crl(@revoke_info, @crl, @ca_key, "issuer" => "abc", "validity" => 8) - end.to raise_error(TypeError) + }.to raise_error(TypeError) end it "Raises a TypeError" do - expect do + expect { instance.revoke_x509_crl(@revoke_info, @crl, @ca_key, "issuer" => @ca_cert, "validity" => "abc") - end.to raise_error(TypeError) + }.to raise_error(TypeError) end end diff --git a/spec/unit/mixin/params_validate_spec.rb b/spec/unit/mixin/params_validate_spec.rb index 489742cb7d..3e7a5969f1 100644 --- a/spec/unit/mixin/params_validate_spec.rb +++ b/spec/unit/mixin/params_validate_spec.rb @@ -56,7 +56,7 @@ describe Chef::Mixin::ParamsValidate do end it "should allow you to check what kind_of? thing an argument is with kind_of" do - expect do + expect { @vo.validate( { one: "string" }, { @@ -65,9 +65,9 @@ describe Chef::Mixin::ParamsValidate do }, } ) - end.not_to raise_error + }.not_to raise_error - expect do + expect { @vo.validate( { one: "string" }, { @@ -76,11 +76,11 @@ describe Chef::Mixin::ParamsValidate do }, } ) - end.to raise_error(ArgumentError) + }.to raise_error(ArgumentError) end it "should allow you to specify an argument is required with required" do - expect do + expect { @vo.validate( { one: "string" }, { @@ -89,9 +89,9 @@ describe Chef::Mixin::ParamsValidate do }, } ) - end.not_to raise_error + }.not_to raise_error - expect do + expect { @vo.validate( { two: "string" }, { @@ -100,9 +100,9 @@ describe Chef::Mixin::ParamsValidate do }, } ) - end.to raise_error(ArgumentError) + }.to raise_error(ArgumentError) - expect do + expect { @vo.validate( { two: "string" }, { @@ -111,11 +111,11 @@ describe Chef::Mixin::ParamsValidate do }, } ) - end.not_to raise_error + }.not_to raise_error end it "should allow you to specify whether an object has a method with respond_to" do - expect do + expect { @vo.validate( { one: @vo }, { @@ -124,9 +124,9 @@ describe Chef::Mixin::ParamsValidate do }, } ) - end.not_to raise_error + }.not_to raise_error - expect do + expect { @vo.validate( { one: @vo }, { @@ -135,11 +135,11 @@ describe Chef::Mixin::ParamsValidate do }, } ) - end.to raise_error(ArgumentError) + }.to raise_error(ArgumentError) end it "should allow you to specify whether an object has all the given methods with respond_to and an array" do - expect do + expect { @vo.validate( { one: @vo }, { @@ -148,9 +148,9 @@ describe Chef::Mixin::ParamsValidate do }, } ) - end.not_to raise_error + }.not_to raise_error - expect do + expect { @vo.validate( { one: @vo }, { @@ -159,7 +159,7 @@ describe Chef::Mixin::ParamsValidate do }, } ) - end.to raise_error(ArgumentError) + }.to raise_error(ArgumentError) end it "should let you set a default value with default => value" do @@ -173,7 +173,7 @@ describe Chef::Mixin::ParamsValidate do end it "should let you check regular expressions" do - expect do + expect { @vo.validate( { one: "is good" }, { @@ -182,9 +182,9 @@ describe Chef::Mixin::ParamsValidate do }, } ) - end.not_to raise_error + }.not_to raise_error - expect do + expect { @vo.validate( { one: "is good" }, { @@ -193,11 +193,11 @@ describe Chef::Mixin::ParamsValidate do }, } ) - end.to raise_error(ArgumentError) + }.to raise_error(ArgumentError) end it "should let you specify your own callbacks" do - expect do + expect { @vo.validate( { one: "is good" }, { @@ -210,9 +210,9 @@ describe Chef::Mixin::ParamsValidate do }, } ) - end.not_to raise_error + }.not_to raise_error - expect do + expect { @vo.validate( { one: "is bad" }, { @@ -225,12 +225,12 @@ describe Chef::Mixin::ParamsValidate do }, } ) - end.to raise_error(ArgumentError) + }.to raise_error(ArgumentError) end it "should let you combine checks" do args = { one: "is good", two: "is bad" } - expect do + expect { @vo.validate( args, { @@ -252,9 +252,9 @@ describe Chef::Mixin::ParamsValidate do three: { default: "neato mosquito" }, } ) - end.not_to raise_error + }.not_to raise_error expect(args[:three]).to eq("neato mosquito") - expect do + expect { @vo.validate( args, { @@ -276,11 +276,11 @@ describe Chef::Mixin::ParamsValidate do three: { default: "neato mosquito" }, } ) - end.to raise_error(ArgumentError) + }.to raise_error(ArgumentError) end it "should raise an ArgumentError if the validation map has an unknown check" do - expect do + expect { @vo.validate( { one: "two" }, { @@ -289,17 +289,17 @@ describe Chef::Mixin::ParamsValidate do }, } ) - end.to raise_error(ArgumentError) + }.to raise_error(ArgumentError) end it "should accept keys that are strings in the options" do - expect do + expect { @vo.validate({ "one" => "two" }, { one: { regex: /^two$/ } }) - end.not_to raise_error + }.not_to raise_error end it "should allow an array to kind_of" do - expect do + expect { @vo.validate( { one: "string" }, { @@ -308,8 +308,8 @@ describe Chef::Mixin::ParamsValidate do }, } ) - end.not_to raise_error - expect do + }.not_to raise_error + expect { @vo.validate( { one: ["string"] }, { @@ -318,8 +318,8 @@ describe Chef::Mixin::ParamsValidate do }, } ) - end.not_to raise_error - expect do + }.not_to raise_error + expect { @vo.validate( { one: {} }, { @@ -328,29 +328,29 @@ describe Chef::Mixin::ParamsValidate do }, } ) - end.to raise_error(ArgumentError) + }.to raise_error(ArgumentError) end it "asserts that a value returns false from a predicate method" do - expect do + expect { @vo.validate({ not_blank: "should pass" }, { not_blank: { cannot_be: %i{nil empty} } }) - end.not_to raise_error - expect do + }.not_to raise_error + expect { @vo.validate({ not_blank: "" }, { not_blank: { cannot_be: %i{nil empty} } }) - end.to raise_error(Chef::Exceptions::ValidationFailed) + }.to raise_error(Chef::Exceptions::ValidationFailed) end it "allows a custom validation message" do - expect do + expect { @vo.validate({ not_blank: "should pass" }, { not_blank: { cannot_be: %i{nil empty}, validation_message: "my validation message" } }) - end.not_to raise_error - expect do + }.not_to raise_error + expect { @vo.validate({ not_blank: "" }, { not_blank: { cannot_be: %i{nil empty}, validation_message: "my validation message" } }) - end.to raise_error(Chef::Exceptions::ValidationFailed, "my validation message") + }.to raise_error(Chef::Exceptions::ValidationFailed, "my validation message") end it "should set and return a value, then return the same value" do @@ -366,15 +366,15 @@ describe Chef::Mixin::ParamsValidate do end it "should raise an ArgumentError when argument is nil and required is true" do - expect do + expect { @vo.set_or_return(:test, nil, { required: true }) - end.to raise_error(ArgumentError) + }.to raise_error(ArgumentError) end it "should not raise an error when argument is nil and required is false" do - expect do + expect { @vo.set_or_return(:test, nil, { required: false }) - end.not_to raise_error + }.not_to raise_error end it "should set and return @name, then return @name for foo when argument is nil" do @@ -391,9 +391,9 @@ describe Chef::Mixin::ParamsValidate do it "should raise an error when delayed evaluated attribute is not valid" do value = Chef::DelayedEvaluator.new { "test" } @vo.set_or_return(:test, value, { kind_of: Numeric }) - expect do + expect { @vo.set_or_return(:test, nil, { kind_of: Numeric }) - end.to raise_error(Chef::Exceptions::ValidationFailed) + }.to raise_error(Chef::Exceptions::ValidationFailed) end it "should create DelayedEvaluator instance when #lazy is used" do diff --git a/spec/unit/node/vivid_mash_spec.rb b/spec/unit/node/vivid_mash_spec.rb index 575d8c3321..93fc919fa1 100644 --- a/spec/unit/node/vivid_mash_spec.rb +++ b/spec/unit/node/vivid_mash_spec.rb @@ -226,7 +226,7 @@ describe Chef::Node::VividMash do it "writes with a block" do expect(root).to receive(:reset_cache).at_least(:once).with("one") - vivid.write("one", "five") { "six" } + vivid.write("one", "five") do "six" end expect(vivid["one"]["five"]).to eql("six") end end @@ -282,7 +282,7 @@ describe Chef::Node::VividMash do it "writes with a block" do expect(root).to receive(:reset_cache).at_least(:once).with("one") - vivid.write!("one", "five") { "six" } + vivid.write!("one", "five") do "six" end expect(vivid["one"]["five"]).to eql("six") end end @@ -406,14 +406,14 @@ describe Chef::Node::AttrArray do context "#collect!" do it "converts Hashes" do - array.collect! { |x| { "zero" => "zero2" } } + array.collect! do |x| { "zero" => "zero2" } end expect(array[1].class).to eql(Chef::Node::VividMash) end end context "#map!" do it "converts Hashes" do - array.map! { |x| { "zero" => "zero2" } } + array.map! do |x| { "zero" => "zero2" } end expect(array[1].class).to eql(Chef::Node::VividMash) end end diff --git a/spec/unit/policy_builder/policyfile_spec.rb b/spec/unit/policy_builder/policyfile_spec.rb index d08a9f5b33..760eef3194 100644 --- a/spec/unit/policy_builder/policyfile_spec.rb +++ b/spec/unit/policy_builder/policyfile_spec.rb @@ -151,7 +151,7 @@ describe Chef::PolicyBuilder::Policyfile do end context "chef-solo" do - before { Chef::Config[:solo_legacy_mode] = true } + before do Chef::Config[:solo_legacy_mode] = true end it "errors on create" do expect { initialize_pb }.to raise_error(err_namespace::UnsupportedFeature) @@ -175,7 +175,7 @@ describe Chef::PolicyBuilder::Policyfile do end context "when an environment is configured" do - before { Chef::Config[:environment] = "blurch" } + before do Chef::Config[:environment] = "blurch" end it "errors when an environment is configured" do expect { initialize_pb }.to raise_error(err_namespace::UnsupportedFeature) diff --git a/spec/unit/property/validation_spec.rb b/spec/unit/property/validation_spec.rb index dab2be8000..240555a783 100644 --- a/spec/unit/property/validation_spec.rb +++ b/spec/unit/property/validation_spec.rb @@ -84,7 +84,7 @@ describe "Chef::Resource.property validation" do end success_values.each do |v| it "value #{v.inspect} is valid" do - resource.instance_eval { @x = "default" } + resource.instance_eval do @x = "default" end expect(resource.x v).to eq v expect(resource.x).to eq v end @@ -92,7 +92,7 @@ describe "Chef::Resource.property validation" do failure_values.each do |v| it "value #{v.inspect} is invalid" do expect { resource.x v }.to raise_error Chef::Exceptions::ValidationFailed - resource.instance_eval { @x = "default" } + resource.instance_eval do @x = "default" end expect { resource.x v }.to raise_error Chef::Exceptions::ValidationFailed end end @@ -102,7 +102,7 @@ describe "Chef::Resource.property validation" do end unless tags.include?(:nillable) it "changing x to nil does a set" do - resource.instance_eval { @x = "default" } + resource.instance_eval do @x = "default" end expect(resource.x nil).to eq nil expect(resource.x).to eq nil end @@ -115,7 +115,7 @@ describe "Chef::Resource.property validation" do expect(resource.x).to be_nil end it "changing x to nil does a set" do - resource.instance_eval { @x = "default" } + resource.instance_eval do @x = "default" end expect(resource.x nil).to eq nil expect(resource.x).to eq nil end @@ -123,7 +123,7 @@ describe "Chef::Resource.property validation" do elsif tags.include?(:nillable) with_property ":x, #{validation}, nillable: true" do it "changing x to nil with nillable true overwrites defaults and just works" do - resource.instance_eval { @x = "default" } + resource.instance_eval do @x = "default" end expect { resource.x nil }.not_to raise_error expect(resource.x nil).to eq nil expect(resource.x).to eq nil diff --git a/spec/unit/property_spec.rb b/spec/unit/property_spec.rb index 1fcbb77e8e..c24b442d1a 100644 --- a/spec/unit/property_spec.rb +++ b/spec/unit/property_spec.rb @@ -493,7 +493,7 @@ describe "Chef::Resource.property" do expect(resource.state_for_resource_reporter).to eq({}) end it "when x is set to nil, it returns nil" do - resource.instance_eval { @x = nil } + resource.instance_eval do @x = nil end expect(resource.x).to be_nil end @@ -1083,18 +1083,18 @@ describe "Chef::Resource.property" do context "property_type" do it "property_types validate their defaults" do - expect do + expect { module ::PropertySpecPropertyTypes include Chef::Mixin::Properties property_type(is: %i{a b}, default: :c) end - end.to raise_error(Chef::Exceptions::ValidationFailed) - expect do + }.to raise_error(Chef::Exceptions::ValidationFailed) + expect { module ::PropertySpecPropertyTypes include Chef::Mixin::Properties property_type(is: %i{a b}, default: :b) end - end.not_to raise_error + }.not_to raise_error end context "With property_type ABType (is: [:a, :b]) and CDType (is: [:c, :d])" do @@ -1161,7 +1161,7 @@ describe "Chef::Resource.property" do with_property ":real, Integer" do it "should set the real property and emit a deprecation message" do expect(Chef).to receive(:deprecated).with(:property, "we don't like the deprecated property no more") - resource_class.class_eval { deprecated_property_alias :deprecated, :real, "we don't like the deprecated property no more" } + resource_class.class_eval do deprecated_property_alias :deprecated, :real, "we don't like the deprecated property no more" end resource.deprecated 10 expect(resource.real).to eq 10 end diff --git a/spec/unit/provider/cron/unix_spec.rb b/spec/unit/provider/cron/unix_spec.rb index c8ef82e37a..3bff44f2de 100644 --- a/spec/unit/provider/cron/unix_spec.rb +++ b/spec/unit/provider/cron/unix_spec.rb @@ -96,9 +96,9 @@ describe Chef::Provider::Cron::Unix do let (:exitstatus) { 2 } it "should raise an exception if another error occurs" do - expect do + expect { provider.send(:read_crontab) - end.to raise_error(Chef::Exceptions::Cron, "Error determining state of #{new_resource.name}, exit: 2") + }.to raise_error(Chef::Exceptions::Cron, "Error determining state of #{new_resource.name}, exit: 2") end it "logs the crontab output to debug" do @@ -135,9 +135,9 @@ describe Chef::Provider::Cron::Unix do context "when writing the crontab fails" do let(:exitstatus) { 1 } it "should raise an exception if the command returns non-zero" do - expect do + expect { provider.send(:write_crontab, "Foo") - end.to raise_error(Chef::Exceptions::Cron, /Error updating state of #{new_resource.name}, exit: 1/) + }.to raise_error(Chef::Exceptions::Cron, /Error updating state of #{new_resource.name}, exit: 1/) end end end diff --git a/spec/unit/provider/cron_spec.rb b/spec/unit/provider/cron_spec.rb index 4cd8a140af..c3a2409d82 100644 --- a/spec/unit/provider/cron_spec.rb +++ b/spec/unit/provider/cron_spec.rb @@ -194,9 +194,9 @@ describe Chef::Provider::Cron do # Chef Name: foo[bar] (baz) 21 */4 * * * some_prog 1234567 CRONTAB - expect do + expect { @provider.load_current_resource - end.not_to raise_error + }.not_to raise_error end end @@ -799,9 +799,9 @@ describe Chef::Provider::Cron do it "should throw an error" do @new_resource.shell "/bash" @new_resource.environment "SHELL" => "/bash" - expect do + expect { @provider.run_action(:create) - end.to raise_error(Chef::Exceptions::Cron, /cronhole some stuff: the 'SHELL' property is set and environment property also contains the 'SHELL' variable. Remove the variable from the environment property./) + }.to raise_error(Chef::Exceptions::Cron, /cronhole some stuff: the 'SHELL' property is set and environment property also contains the 'SHELL' variable. Remove the variable from the environment property./) end end @@ -1034,9 +1034,9 @@ describe Chef::Provider::Cron do it "should raise an exception if the command returns non-zero" do @status = double("Status", exitstatus: 1) allow(@provider).to receive(:shell_out!).and_raise(Mixlib::ShellOut::ShellCommandFailed) - expect do + expect { @provider.send(:write_crontab, "Foo") - end.to raise_error(Chef::Exceptions::Cron) + }.to raise_error(Chef::Exceptions::Cron) end end diff --git a/spec/unit/provider/directory_spec.rb b/spec/unit/provider/directory_spec.rb index 4672db7d8d..18b7108209 100644 --- a/spec/unit/provider/directory_spec.rb +++ b/spec/unit/provider/directory_spec.rb @@ -150,8 +150,8 @@ describe Chef::Provider::Directory do end context "in why run mode" do - before { Chef::Config[:why_run] = true } - after { Chef::Config[:why_run] = false } + before do Chef::Config[:why_run] = true end + after do Chef::Config[:why_run] = false end it "does not modify new_resource" do expect(directory).not_to receive(:load_resource_attributes_from_file).with(new_resource) diff --git a/spec/unit/provider/dsc_script_spec.rb b/spec/unit/provider/dsc_script_spec.rb index a1115150e8..138c55c3c8 100644 --- a/spec/unit/provider/dsc_script_spec.rb +++ b/spec/unit/provider/dsc_script_spec.rb @@ -156,16 +156,16 @@ describe Chef::Provider::DscScript do it "raises an exception for powershell version '#{version}'" do node.automatic[:languages][:powershell][:version] = version - expect do + expect { provider.run_action(:run) - end.to raise_error(Chef::Exceptions::ProviderNotFound) + }.to raise_error(Chef::Exceptions::ProviderNotFound) end end it "raises an exception if PowerShell is not present" do - expect do + expect { provider.run_action(:run) - end.to raise_error(Chef::Exceptions::ProviderNotFound) + }.to raise_error(Chef::Exceptions::ProviderNotFound) end end diff --git a/spec/unit/provider/execute_spec.rb b/spec/unit/provider/execute_spec.rb index 11eb70e396..c4f7c2c254 100644 --- a/spec/unit/provider/execute_spec.rb +++ b/spec/unit/provider/execute_spec.rb @@ -159,9 +159,9 @@ describe Chef::Provider::Execute do opts.delete(:live_stream) new_resource.sensitive true expect(provider).to receive(:shell_out!).and_raise(Mixlib::ShellOut::ShellCommandFailed) - expect do + expect { provider.run_action(:run) - end.to raise_error(Mixlib::ShellOut::ShellCommandFailed, /suppressed for sensitive resource/) + }.to raise_error(Mixlib::ShellOut::ShellCommandFailed, /suppressed for sensitive resource/) end describe "streaming output" do diff --git a/spec/unit/provider/git_spec.rb b/spec/unit/provider/git_spec.rb index 9a6ae31397..50a337ec8a 100644 --- a/spec/unit/provider/git_spec.rb +++ b/spec/unit/provider/git_spec.rb @@ -294,7 +294,7 @@ describe Chef::Provider::Git do end context "with a timeout set" do let (:seconds) { 10 } - before { @resource.timeout(seconds) } + before do @resource.timeout(seconds) end it "clones a repo with amended git options" do expect(@provider).to receive(:shell_out!).with(expected_cmd, default_options.merge(timeout: seconds)) @provider.clone @@ -314,7 +314,7 @@ describe Chef::Provider::Git do before do @resource.environment(override_home) end - before { @resource.environment(override_home) } + before do @resource.environment(override_home) end it "clones a repo with amended git options with specific home" do expect(@provider).to receive(:shell_out!).with(expected_cmd, overrided_options) @provider.clone @@ -350,7 +350,7 @@ describe Chef::Provider::Git do before do @resource.environment(override_home) end - before { @resource.environment(override_home) } + before do @resource.environment(override_home) end it "clones a repo with amended git options with specific home" do expect(@provider).to receive(:shell_out!).with(expected_cmd, hash_including(overrided_options)) @provider.clone diff --git a/spec/unit/provider/group/groupadd_spec.rb b/spec/unit/provider/group/groupadd_spec.rb index 79586eac71..0b25c40017 100644 --- a/spec/unit/provider/group/groupadd_spec.rb +++ b/spec/unit/provider/group/groupadd_spec.rb @@ -85,7 +85,7 @@ describe Chef::Provider::Group::Groupadd do end context "on Solaris" do - before { node.automatic["platform"] = "solaris2" } + before do node.automatic["platform"] = "solaris2" end it "should not set groupadd -r if system is true" do new_resource.system(true) expect(provider.groupadd_options).to eql([]) diff --git a/spec/unit/provider/group_spec.rb b/spec/unit/provider/group_spec.rb index d7fdfb299c..18597659c7 100644 --- a/spec/unit/provider/group_spec.rb +++ b/spec/unit/provider/group_spec.rb @@ -119,7 +119,7 @@ describe Chef::Provider::User do end it "should return true if the append is true and excluded_members include an existing user" do - @new_resource.members.each { |m| @new_resource.excluded_members << m } + @new_resource.members.each do |m| @new_resource.excluded_members << m end @new_resource.members.clear @new_resource.append(true) expect(@provider.compare_group).to be_truthy diff --git a/spec/unit/provider/http_request_spec.rb b/spec/unit/provider/http_request_spec.rb index 8b5ae02b3c..47d270d5e1 100644 --- a/spec/unit/provider/http_request_spec.rb +++ b/spec/unit/provider/http_request_spec.rb @@ -52,7 +52,7 @@ describe Chef::Provider::HttpRequest do describe "action_get" do it "should inflate a message block at runtime" do - @new_resource.message { "return" } + @new_resource.message do "return" end expect(@http).to receive(:get).with("http://www.opscode.com/", {}) @provider.run_action(:get) expect(@new_resource).to be_updated @@ -88,7 +88,7 @@ describe Chef::Provider::HttpRequest do end it "should inflate a message block at runtime" do - @new_resource.message { "return" } + @new_resource.message do "return" end expect(@http).to receive(:post).with("http://www.opscode.com/", "return", {}) @provider.run_action(:post) expect(@new_resource).to be_updated @@ -111,7 +111,7 @@ describe Chef::Provider::HttpRequest do end it "should inflate a message block at runtime" do - @new_resource.message { "return" } + @new_resource.message do "return" end expect(@http).to receive(:head).with("http://www.opscode.com/", {}).and_return(nil) @provider.run_action(:head) expect(@new_resource).to be_updated diff --git a/spec/unit/provider/launchd_spec.rb b/spec/unit/provider/launchd_spec.rb index 53b56b4960..e5e3435450 100644 --- a/spec/unit/provider/launchd_spec.rb +++ b/spec/unit/provider/launchd_spec.rb @@ -138,12 +138,12 @@ describe Chef::Provider::Launchd do describe "start_calendar_interval is passed" do it "should allow array of Hashes" do - allowed = (1..2).collect do |num| + allowed = (1..2).collect { |num| { "Hour" => 10 + num, "Weekday" => num, } - end + } new_resource.program "/Library/scripts/call_mom.sh" new_resource.time_out 300 new_resource.start_calendar_interval allowed @@ -171,17 +171,17 @@ describe Chef::Provider::Launchd do it "should not allow invalid ShowCalendarInterval keys" do new_resource.program "/Library/scripts/call_mom.sh" new_resource.time_out 300 - expect do + expect { new_resource.start_calendar_interval "Hourly" => 1 - end.to raise_error(/Hourly are invalid/) + }.to raise_error(/Hourly are invalid/) end it "should not allow non-integer values" do new_resource.program "/Library/scripts/call_mom.sh" new_resource.time_out 300 - expect do + expect { new_resource.start_calendar_interval "Weekday" => "1-2" - end.to raise_error(/Invalid value.*\(1-2\)/) + }.to raise_error(/Invalid value.*\(1-2\)/) end end diff --git a/spec/unit/provider/package/rubygems_spec.rb b/spec/unit/provider/package/rubygems_spec.rb index 1bafefe5e8..dde9efc2a6 100644 --- a/spec/unit/provider/package/rubygems_spec.rb +++ b/spec/unit/provider/package/rubygems_spec.rb @@ -33,7 +33,7 @@ class RspecVersionString def self.rspec_version_string @rspec_version_string ||= begin stubs = Gem::Specification.send(:installed_stubs, Gem::Specification.dirs, "rspec-core-*.gemspec") - stubs.select! { |stub| stub.name == "rspec-core" && Gem::Dependency.new("rspec-core", ">= 0").requirement.satisfied_by?(stub.version) } + stubs.select! do |stub| stub.name == "rspec-core" && Gem::Dependency.new("rspec-core", ">= 0").requirement.satisfied_by?(stub.version) end stubs.max_by(&:version).version.to_s end end diff --git a/spec/unit/provider/package/windows/exe_spec.rb b/spec/unit/provider/package/windows/exe_spec.rb index 6fa1747b03..67365660fb 100644 --- a/spec/unit/provider/package/windows/exe_spec.rb +++ b/spec/unit/provider/package/windows/exe_spec.rb @@ -87,7 +87,7 @@ describe Chef::Provider::Package::Windows::Exe do end describe "package_version" do - before { new_resource.version(nil) } + before do new_resource.version(nil) end context "source file does not exist" do before do diff --git a/spec/unit/provider/package/windows/msi_spec.rb b/spec/unit/provider/package/windows/msi_spec.rb index d2902e1bb1..f162ae678c 100644 --- a/spec/unit/provider/package/windows/msi_spec.rb +++ b/spec/unit/provider/package/windows/msi_spec.rb @@ -147,7 +147,7 @@ describe Chef::Provider::Package::Windows::MSI do end context "custom options includes /Q" do - before { new_resource.options("/Q") } + before do new_resource.options("/Q") end it "does not duplicate quiet switch" do expect(provider).to receive(:shell_out!).with(%r{msiexec /x {guid} /Q}, kind_of(Hash)) @@ -156,7 +156,7 @@ describe Chef::Provider::Package::Windows::MSI do end context "custom options includes /qn" do - before { new_resource.options("/qn") } + before do new_resource.options("/qn") end it "does not duplicate quiet switch" do expect(provider).to receive(:shell_out!).with(%r{msiexec /x {guid} /qn}, kind_of(Hash)) diff --git a/spec/unit/provider/package/windows_spec.rb b/spec/unit/provider/package/windows_spec.rb index 2fafb3bd0e..0549048d2b 100644 --- a/spec/unit/provider/package/windows_spec.rb +++ b/spec/unit/provider/package/windows_spec.rb @@ -225,7 +225,7 @@ describe Chef::Provider::Package::Windows, :windows_only do end context "uninstall entries is empty" do - before { allow(Chef::Provider::Package::Windows::RegistryUninstallEntry).to receive(:find_entries).and_return([]) } + before do allow(Chef::Provider::Package::Windows::RegistryUninstallEntry).to receive(:find_entries).and_return([]) end it "returns nil" do expect(provider.installer_type).to eql(nil) @@ -326,7 +326,7 @@ describe Chef::Provider::Package::Windows, :windows_only do end context "no version given or discovered but package is installed" do - before { allow(provider).to receive(:current_version_array).and_return(["5.5.5"]) } + before do allow(provider).to receive(:current_version_array).and_return(["5.5.5"]) end it "does not install" do expect(provider).not_to receive(:install_package) @@ -335,7 +335,7 @@ describe Chef::Provider::Package::Windows, :windows_only do end context "a version is given and none is installed" do - before { new_resource.version("5.5.5") } + before do new_resource.version("5.5.5") end it "installs given version" do expect(provider).to receive(:install_package).with("blah", "5.5.5") diff --git a/spec/unit/provider/remote_directory_spec.rb b/spec/unit/provider/remote_directory_spec.rb index f9559d8827..c4648ec064 100644 --- a/spec/unit/provider/remote_directory_spec.rb +++ b/spec/unit/provider/remote_directory_spec.rb @@ -125,7 +125,7 @@ describe Chef::Provider::RemoteDirectory do @resource.path(@destination_dir) end - after { FileUtils.rm_rf(@destination_dir) } + after do FileUtils.rm_rf(@destination_dir) end # CHEF-3552 it "creates the toplevel directory without error " do @@ -149,8 +149,8 @@ describe Chef::Provider::RemoteDirectory do @resource.overwrite(true) @provider.run_action(:create) - File.open(@destination_dir + "/remote_dir_file1.txt", "a") { |f| f.puts "blah blah blah" } - File.open(@destination_dir + "/remotesubdir/remote_subdir_file1.txt", "a") { |f| f.puts "blah blah blah" } + File.open(@destination_dir + "/remote_dir_file1.txt", "a") do |f| f.puts "blah blah blah" end + File.open(@destination_dir + "/remotesubdir/remote_subdir_file1.txt", "a") do |f| f.puts "blah blah blah" end file1md5 = Digest::MD5.hexdigest(File.read(@destination_dir + "/remote_dir_file1.txt")) subdirfile1md5 = Digest::MD5.hexdigest(File.read(@destination_dir + "/remotesubdir/remote_subdir_file1.txt")) @@ -162,7 +162,7 @@ describe Chef::Provider::RemoteDirectory do end describe "with purging enabled" do - before { @resource.purge(true) } + before do @resource.purge(true) end it "removes existing files if purge is true" do @provider.run_action(:create) @@ -217,13 +217,13 @@ describe Chef::Provider::RemoteDirectory do end describe "with overwrite disabled" do - before { @resource.purge(false) } - before { @resource.overwrite(false) } + before do @resource.purge(false) end + before do @resource.overwrite(false) end it "leaves modifications alone" do @provider.run_action(:create) - ::File.open(@destination_dir + "/remote_dir_file1.txt", "a") { |f| f.puts "blah blah blah" } - ::File.open(@destination_dir + "/remotesubdir/remote_subdir_file1.txt", "a") { |f| f.puts "blah blah blah" } + ::File.open(@destination_dir + "/remote_dir_file1.txt", "a") do |f| f.puts "blah blah blah" end + ::File.open(@destination_dir + "/remotesubdir/remote_subdir_file1.txt", "a") do |f| f.puts "blah blah blah" end file1md5 = Digest::MD5.hexdigest(::File.read(@destination_dir + "/remote_dir_file1.txt")) subdirfile1md5 = Digest::MD5.hexdigest(::File.read(@destination_dir + "/remotesubdir/remote_subdir_file1.txt")) @provider.run_action(:create) diff --git a/spec/unit/provider/ruby_block_spec.rb b/spec/unit/provider/ruby_block_spec.rb index b49aef9243..35fa0b8a26 100644 --- a/spec/unit/provider/ruby_block_spec.rb +++ b/spec/unit/provider/ruby_block_spec.rb @@ -25,7 +25,7 @@ describe Chef::Provider::RubyBlock, "initialize" do @events = Chef::EventDispatch::Dispatcher.new @run_context = Chef::RunContext.new(@node, {}, @events) @new_resource = Chef::Resource::RubyBlock.new("bloc party") - @new_resource.block { $evil_global_evil_laugh = :mwahahaha } + @new_resource.block do $evil_global_evil_laugh = :mwahahaha end @provider = Chef::Provider::RubyBlock.new(@new_resource, @run_context) end diff --git a/spec/unit/provider/service/debian_service_spec.rb b/spec/unit/provider/service/debian_service_spec.rb index 5f89605b2e..3119cd0bf5 100644 --- a/spec/unit/provider/service/debian_service_spec.rb +++ b/spec/unit/provider/service/debian_service_spec.rb @@ -50,9 +50,9 @@ describe Chef::Provider::Service::Debian do expect(File).to receive(:exists?).with("/usr/sbin/update-rc.d") .and_return(false) @provider.define_resource_requirements - expect do + expect { @provider.process_resource_requirements - end.to raise_error(Chef::Exceptions::Service) + }.to raise_error(Chef::Exceptions::Service) end context "when update-rc.d shows init linked to rc*.d/" do diff --git a/spec/unit/provider/service/gentoo_service_spec.rb b/spec/unit/provider/service/gentoo_service_spec.rb index bc3d0b5c04..b0e956cfaf 100644 --- a/spec/unit/provider/service/gentoo_service_spec.rb +++ b/spec/unit/provider/service/gentoo_service_spec.rb @@ -124,7 +124,7 @@ describe Chef::Provider::Service::Gentoo do end describe "action_methods" do - before(:each) { allow(@provider).to receive(:load_current_resource).and_return(@current_resource) } + before(:each) do allow(@provider).to receive(:load_current_resource).and_return(@current_resource) end describe Chef::Provider::Service::Gentoo, "enable_service" do it "should call rc-update add *service* default" do diff --git a/spec/unit/provider/user/aix_spec.rb b/spec/unit/provider/user/aix_spec.rb index f8b5b8a324..4aab195cd2 100644 --- a/spec/unit/provider/user/aix_spec.rb +++ b/spec/unit/provider/user/aix_spec.rb @@ -58,7 +58,7 @@ describe Chef::Provider::User::Aix do describe "#create_user" do context "with a system user" do - before { new_resource.system(true) } + before do new_resource.system(true) end it "should add the user to the system group" do expect(provider).to receive(:shell_out_compacted!).with("useradd", "-g", "system", "adam") provider.create_user diff --git a/spec/unit/provider/user/solaris_spec.rb b/spec/unit/provider/user/solaris_spec.rb index 11c8656a5c..aae4a686f1 100644 --- a/spec/unit/provider/user/solaris_spec.rb +++ b/spec/unit/provider/user/solaris_spec.rb @@ -81,7 +81,7 @@ describe Chef::Provider::User::Solaris do describe "#create_user" do context "with a system user" do - before { new_resource.system(true) } + before do new_resource.system(true) end it "should not pass -r" do expect(provider).to receive(:shell_out_compacted!).with( "useradd", "adam") provider.create_user @@ -89,7 +89,7 @@ describe Chef::Provider::User::Solaris do end context "with manage_home" do - before { new_resource.manage_home(true) } + before do new_resource.manage_home(true) end it "should not pass -r" do expect(provider).to receive(:shell_out_compacted!).with( "useradd", "-m", "adam") provider.create_user diff --git a/spec/unit/provider/whyrun_safe_ruby_block_spec.rb b/spec/unit/provider/whyrun_safe_ruby_block_spec.rb index 29d49ff90b..3fbc940cbe 100644 --- a/spec/unit/provider/whyrun_safe_ruby_block_spec.rb +++ b/spec/unit/provider/whyrun_safe_ruby_block_spec.rb @@ -25,7 +25,7 @@ describe Chef::Provider::WhyrunSafeRubyBlock, "initialize" do @events = Chef::EventDispatch::Dispatcher.new @run_context = Chef::RunContext.new(@node, {}, @events) @new_resource = Chef::Resource::WhyrunSafeRubyBlock.new("bloc party") - @new_resource.block { $evil_global_evil_laugh = :mwahahaha } + @new_resource.block do $evil_global_evil_laugh = :mwahahaha end @provider = Chef::Provider::WhyrunSafeRubyBlock.new(@new_resource, @run_context) end diff --git a/spec/unit/provider_resolver_spec.rb b/spec/unit/provider_resolver_spec.rb index 94e0d6074b..358030e75a 100644 --- a/spec/unit/provider_resolver_spec.rb +++ b/spec/unit/provider_resolver_spec.rb @@ -91,10 +91,10 @@ describe Chef::ProviderResolver do let(:platform_family) { platform_family } let(:platform_version) { platform_version } - define_singleton_method(:os) { os } - define_singleton_method(:platform) { platform } - define_singleton_method(:platform_family) { platform_family } - define_singleton_method(:platform_version) { platform_version } + define_singleton_method(:os) do os end + define_singleton_method(:platform) do platform end + define_singleton_method(:platform_family) do platform_family end + define_singleton_method(:platform_version) do platform_version end instance_eval(&block) end diff --git a/spec/unit/recipe_spec.rb b/spec/unit/recipe_spec.rb index f2ec175243..9d14216cb1 100644 --- a/spec/unit/recipe_spec.rb +++ b/spec/unit/recipe_spec.rb @@ -47,27 +47,27 @@ describe Chef::Recipe do describe "method_missing" do describe "resources" do it "should load a two word (zen_master) resource" do - expect do + expect { recipe.zen_master "monkey" do peace true end - end.not_to raise_error + }.not_to raise_error end it "should load a one word (cat) resource" do - expect do + expect { recipe.cat "loulou" do pretty_kitty true end - end.not_to raise_error + }.not_to raise_error end it "should load a four word (one_two_three_four) resource" do - expect do + expect { recipe.one_two_three_four "numbers" do i_can_count true end - end.not_to raise_error + }.not_to raise_error end it "should throw an error if you access a resource that we can't find" do @@ -75,9 +75,9 @@ describe Chef::Recipe do end it "should allow regular errors (not NameErrors) to pass unchanged" do - expect do + expect { recipe.cat("felix") { raise ArgumentError, "You Suck" } - end.to raise_error(ArgumentError) + }.to raise_error(ArgumentError) end it "should add our zen_master to the collection" do @@ -299,18 +299,18 @@ describe Chef::Recipe do describe "when attempting to create a resource of an invalid type" do it "gives a sane error message when using method_missing" do - expect do + expect { recipe.no_such_resource("foo") - end.to raise_error(NoMethodError, /undefined method `no_such_resource' for cookbook: hjk, recipe: test :Chef::Recipe/) + }.to raise_error(NoMethodError, /undefined method `no_such_resource' for cookbook: hjk, recipe: test :Chef::Recipe/) end it "gives a sane error message when using method_missing 'bare'" do - expect do + expect { recipe.instance_eval do # Giving an argument will change this from NameError to NoMethodError no_such_resource end - end.to raise_error(NameError, /undefined local variable or method `no_such_resource' for cookbook: hjk, recipe: test :Chef::Recipe/) + }.to raise_error(NameError, /undefined local variable or method `no_such_resource' for cookbook: hjk, recipe: test :Chef::Recipe/) end it "gives a sane error message when using build_resource" do @@ -326,11 +326,11 @@ describe Chef::Recipe do describe "when creating a resource that contains an error in the attributes block" do it "does not obfuscate the error source" do - expect do + expect { recipe.zen_master("klopp") do this_method_doesnt_exist end - end.to raise_error(NoMethodError, "undefined method `this_method_doesnt_exist' for Chef::Resource::ZenMaster") + }.to raise_error(NoMethodError, "undefined method `this_method_doesnt_exist' for Chef::Resource::ZenMaster") end diff --git a/spec/unit/resource/dsc_resource_spec.rb b/spec/unit/resource/dsc_resource_spec.rb index e0beb309ab..661f9fa3c2 100644 --- a/spec/unit/resource/dsc_resource_spec.rb +++ b/spec/unit/resource/dsc_resource_spec.rb @@ -77,9 +77,9 @@ describe Chef::Resource::DscResource do end it "raises a TypeError if property_name is not a symbol" do - expect do + expect { dsc_test_resource.property("Foo", dsc_test_property_value) - end.to raise_error(TypeError) + }.to raise_error(TypeError) end context "when using DelayedEvaluators" do diff --git a/spec/unit/resource/file/verification_spec.rb b/spec/unit/resource/file/verification_spec.rb index 57c58249eb..cb60c9d917 100644 --- a/spec/unit/resource/file/verification_spec.rb +++ b/spec/unit/resource/file/verification_spec.rb @@ -88,16 +88,16 @@ describe Chef::Resource::File::Verification do it "raises an error when \%{file} is used" do test_command = platform_specific_verify_command("file") - expect do + expect { Chef::Resource::File::Verification.new(parent_resource, test_command, {}).verify(temp_path) - end.to raise_error(ArgumentError) + }.to raise_error(ArgumentError) end it "does not raise an error when \%{file} is not used" do test_command = platform_specific_verify_command("path") - expect do + expect { Chef::Resource::File::Verification.new(parent_resource, test_command, {}).verify(temp_path) - end.to_not raise_error + }.to_not raise_error end it "substitutes \%{path} with the path" do diff --git a/spec/unit/resource/remote_file_spec.rb b/spec/unit/resource/remote_file_spec.rb index 39d34d9a96..ae7f38af83 100644 --- a/spec/unit/resource/remote_file_spec.rb +++ b/spec/unit/resource/remote_file_spec.rb @@ -99,15 +99,15 @@ describe Chef::Resource::RemoteFile do end it "only accept a single argument if a delayed evalutor is used" do - expect do + expect { resource.source("http://opscode.com/", Chef::DelayedEvaluator.new { "http://opscode.com/" }) - end.to raise_error(Chef::Exceptions::InvalidRemoteFileURI) + }.to raise_error(Chef::Exceptions::InvalidRemoteFileURI) end it "only accept a single array item if a delayed evalutor is used" do - expect do + expect { resource.source(["http://opscode.com/", Chef::DelayedEvaluator.new { "http://opscode.com/" }]) - end.to raise_error(Chef::Exceptions::InvalidRemoteFileURI) + }.to raise_error(Chef::Exceptions::InvalidRemoteFileURI) end it "does not accept a non-URI as the source" do @@ -115,10 +115,10 @@ describe Chef::Resource::RemoteFile do end it "does not accept a non-URI as the source when read from a delayed evaluator" do - expect do + expect { resource.source(Chef::DelayedEvaluator.new { "not-a-uri" }) resource.source - end.to raise_error(Chef::Exceptions::InvalidRemoteFileURI) + }.to raise_error(Chef::Exceptions::InvalidRemoteFileURI) end it "raises an exception when source is an empty array" do diff --git a/spec/unit/resource/rhsm_errata_level_spec.rb b/spec/unit/resource/rhsm_errata_level_spec.rb index 8d0de18f98..eb67f3278e 100644 --- a/spec/unit/resource/rhsm_errata_level_spec.rb +++ b/spec/unit/resource/rhsm_errata_level_spec.rb @@ -43,8 +43,8 @@ describe Chef::Resource::RhsmErrataLevel do end it "raises an exception if invalid errata_level is passed" do - expect do + expect { resource.errata_level "FOO" - end.to raise_error(Chef::Exceptions::ValidationFailed) + }.to raise_error(Chef::Exceptions::ValidationFailed) end end diff --git a/spec/unit/resource/ruby_block_spec.rb b/spec/unit/resource/ruby_block_spec.rb index fb5a8815c7..ff01ddb802 100644 --- a/spec/unit/resource/ruby_block_spec.rb +++ b/spec/unit/resource/ruby_block_spec.rb @@ -41,9 +41,9 @@ describe Chef::Resource::RubyBlock do end it "accepts a ruby block/proc/.. for the 'block' parameter" do - expect(resource.block do + expect(resource.block { "foo" - end.call).to eql("foo") + }.call).to eql("foo") end describe "when it has been initialized with block code" do diff --git a/spec/unit/resource/scm_spec.rb b/spec/unit/resource/scm_spec.rb index 5478309a86..ad6f7cdcb2 100644 --- a/spec/unit/resource/scm_spec.rb +++ b/spec/unit/resource/scm_spec.rb @@ -133,7 +133,7 @@ describe Chef::Resource::Scm do describe "when it has a timeout property" do let(:ten_seconds) { 10 } - before { resource.timeout(ten_seconds) } + before do resource.timeout(ten_seconds) end it "stores this timeout" do expect(resource.timeout).to eq(ten_seconds) end @@ -165,7 +165,7 @@ describe Chef::Resource::Scm do describe "when it has a environment property" do let(:test_environment) { { "CHEF_ENV" => "/tmp" } } - before { resource.environment(test_environment) } + before do resource.environment(test_environment) end it "stores this environment" do expect(resource.environment).to eq(test_environment) end diff --git a/spec/unit/resource/service_spec.rb b/spec/unit/resource/service_spec.rb index be88d82f3b..cfebb70898 100644 --- a/spec/unit/resource/service_spec.rb +++ b/spec/unit/resource/service_spec.rb @@ -61,9 +61,9 @@ describe Chef::Resource::Service do end it "does not accept a regexp for the service pattern" do - expect do + expect { resource.pattern /.*/ - end.to raise_error(ArgumentError) + }.to raise_error(ArgumentError) end it "accepts a String for the user property" do @@ -88,9 +88,9 @@ describe Chef::Resource::Service do end it "does not accept a regexp for the init_command property" do - expect do + expect { resource.init_command /.*/ - end.to raise_error(ArgumentError) + }.to raise_error(ArgumentError) end it "accepts an array for options property" do @@ -109,9 +109,9 @@ describe Chef::Resource::Service do end it "does not accept a boolean for options property" do - expect do + expect { resource.options true - end.to raise_error(ArgumentError) + }.to raise_error(ArgumentError) end %w{restart_command start_command stop_command status_command reload_command}.each do |prop| diff --git a/spec/unit/resource/template_spec.rb b/spec/unit/resource/template_spec.rb index 2f8e234c85..dfabe38efb 100644 --- a/spec/unit/resource/template_spec.rb +++ b/spec/unit/resource/template_spec.rb @@ -129,19 +129,19 @@ describe Chef::Resource::Template do end it "collects helper method bodies as blocks" do - resource.helper(:example_1) { "example_1" } - resource.helper(:example_2) { "example_2" } + resource.helper(:example_1) do "example_1" end + resource.helper(:example_2) do "example_2" end expect(resource.inline_helper_blocks[:example_1].call).to eq("example_1") expect(resource.inline_helper_blocks[:example_2].call).to eq("example_2") end it "compiles helper methods into a module" do - resource.helper(:example_1) { "example_1" } - resource.helper(:example_2) { "example_2" } + resource.helper(:example_1) do "example_1" end + resource.helper(:example_2) do "example_2" end modules = resource.helper_modules expect(modules.size).to eq(1) o = Object.new - modules.each { |m| o.extend(m) } + modules.each do |m| o.extend(m) end expect(o.example_1).to eq("example_1") expect(o.example_2).to eq("example_2") end @@ -150,7 +150,7 @@ describe Chef::Resource::Template do resource.helper(:shout, &:upcase) modules = resource.helper_modules o = Object.new - modules.each { |m| o.extend(m) } + modules.each do |m| o.extend(m) end expect(o.shout("shout")).to eq("SHOUT") end @@ -181,7 +181,7 @@ describe Chef::Resource::Template do modules = resource.helper_modules expect(modules.size).to eq(1) o = Object.new - modules.each { |m| o.extend(m) } + modules.each do |m| o.extend(m) end expect(o.example_1).to eq("example_1") end @@ -209,11 +209,11 @@ describe Chef::Resource::Template do "inline_module" end end - resource.helper(:inline_method) { "inline_method" } + resource.helper(:inline_method) do "inline_method" end expect(resource.helper_modules.size).to eq(3) o = Object.new - resource.helper_modules.each { |m| o.extend(m) } + resource.helper_modules.each do |m| o.extend(m) end expect(o.static_example).to eq("static_example") expect(o.inline_module).to eq("inline_module") expect(o.inline_method).to eq("inline_method") diff --git a/spec/unit/resource/windows_task_spec.rb b/spec/unit/resource/windows_task_spec.rb index d08849d4be..4817a8aa4b 100644 --- a/spec/unit/resource/windows_task_spec.rb +++ b/spec/unit/resource/windows_task_spec.rb @@ -79,7 +79,7 @@ describe Chef::Resource::WindowsTask, :windows_only do end context "for an interactive task" do - before { resource.interactive_enabled true } + before do resource.interactive_enabled true end it "does not require a password" do expect { resource.after_created }.to_not raise_error end @@ -94,7 +94,7 @@ describe Chef::Resource::WindowsTask, :windows_only do end context "for a non-interactive task" do - before { resource.interactive_enabled false } + before do resource.interactive_enabled false end it "does not require a password" do expect { resource.after_created }.to_not raise_error end @@ -115,7 +115,7 @@ describe Chef::Resource::WindowsTask, :windows_only do resource.user "bob" end context "for an interactive task" do - before { resource.interactive_enabled true } + before do resource.interactive_enabled true end it "does not require a password" do expect { resource.after_created }.to_not raise_error end @@ -126,7 +126,7 @@ describe Chef::Resource::WindowsTask, :windows_only do end context "for a non-interactive task" do - before { resource.interactive_enabled false } + before do resource.interactive_enabled false end it "require a password" do expect { resource.after_created }.to raise_error(ArgumentError, %q{Please provide a password or check if this task needs to be interactive! Valid passwordless users are: 'SYSTEM', 'NT AUTHORITY\SYSTEM', 'LOCAL SERVICE', 'NT AUTHORITY\LOCAL SERVICE', 'NETWORK SERVICE', 'NT AUTHORITY\NETWORK SERVICE', 'ADMINISTRATORS', 'BUILTIN\ADMINISTRATORS', 'USERS', 'BUILTIN\USERS', 'GUESTS', 'BUILTIN\GUESTS'}) end diff --git a/spec/unit/resource_collection_spec.rb b/spec/unit/resource_collection_spec.rb index 60f17b6934..44dad6599b 100644 --- a/spec/unit/resource_collection_spec.rb +++ b/spec/unit/resource_collection_spec.rb @@ -98,11 +98,11 @@ describe Chef::ResourceCollection do it "should allow you to iterate over every resource in the collection" do load_up_resources results = [] - expect do + expect { rc.each do |r| results << r.name end - end.not_to raise_error + }.not_to raise_error results.each_index do |i| case i when 0 @@ -120,11 +120,11 @@ describe Chef::ResourceCollection do it "should allow you to iterate over every resource by index" do load_up_resources results = [] - expect do + expect { rc.each_index do |i| results << rc[i].name end - end.not_to raise_error + }.not_to raise_error results.each_index do |i| case i when 0 @@ -270,15 +270,15 @@ describe Chef::ResourceCollection do end it "rejects a malformed query string" do - expect do + expect { rc.validate_lookup_spec!("resource_type[missing-end-bracket") - end.to raise_error(Chef::Exceptions::InvalidResourceSpecification) + }.to raise_error(Chef::Exceptions::InvalidResourceSpecification) end it "rejects an argument that is not a String, Hash, or Chef::Resource" do - expect do + expect { rc.validate_lookup_spec!(Object.new) - end.to raise_error(Chef::Exceptions::InvalidResourceSpecification) + }.to raise_error(Chef::Exceptions::InvalidResourceSpecification) end end diff --git a/spec/unit/resource_definition_spec.rb b/spec/unit/resource_definition_spec.rb index a1c59eaaca..2a45dd6725 100644 --- a/spec/unit/resource_definition_spec.rb +++ b/spec/unit/resource_definition_spec.rb @@ -53,26 +53,26 @@ describe Chef::ResourceDefinition do end it "should accept a new definition with a symbol for a name" do - expect do + expect { defn.define :smoke do end - end.not_to raise_error - expect do + }.not_to raise_error + expect { defn.define "george washington" do end - end.to raise_error(ArgumentError) + }.to raise_error(ArgumentError) expect(defn.name).to eql(:smoke) end it "should accept a new definition with a hash" do - expect do + expect { defn.define :smoke, cigar: "cuban", cigarette: "marlboro" do end - end.not_to raise_error + }.not_to raise_error end it "should expose the prototype hash params in the params hash" do - defn.define(:smoke, cigar: "cuban", cigarette: "marlboro") {} + defn.define(:smoke, cigar: "cuban", cigarette: "marlboro") do end expect(defn.params[:cigar]).to eql("cuban") expect(defn.params[:cigarette]).to eql("marlboro") end @@ -91,16 +91,16 @@ describe Chef::ResourceDefinition do end it "should raise an exception if prototype_params is not a hash" do - expect do + expect { defn.define :monkey, [] do end - end.to raise_error(ArgumentError) + }.to raise_error(ArgumentError) end it "should raise an exception if define is called without a block" do - expect do + expect { defn.define :monkey - end.to raise_error(ArgumentError) + }.to raise_error(ArgumentError) end it "should load a description from a file" do diff --git a/spec/unit/resource_reporter_spec.rb b/spec/unit/resource_reporter_spec.rb index 1d7fd7fc79..2876c9ec29 100644 --- a/spec/unit/resource_reporter_spec.rb +++ b/spec/unit/resource_reporter_spec.rb @@ -716,9 +716,9 @@ describe Chef::ResourceReporter do it "fails the run and prints an message about the error" do expect(Chef::Log).to receive(:error).with(/500/) - expect do + expect { resource_reporter.run_started(run_status) - end.to raise_error(Net::HTTPClientException) + }.to raise_error(Net::HTTPClientException) end end @@ -801,9 +801,9 @@ describe Chef::ResourceReporter do it "should raise if an unkwown error happens" do allow(rest_client).to receive(:raw_request).and_raise(Exception.new) - expect do + expect { resource_reporter.post_reporting_data - end.to raise_error(Exception) + }.to raise_error(Exception) end end end diff --git a/spec/unit/resource_spec.rb b/spec/unit/resource_spec.rb index 6745dd448d..6a618079f3 100644 --- a/spec/unit/resource_spec.rb +++ b/spec/unit/resource_spec.rb @@ -242,9 +242,9 @@ describe Chef::Resource do it "should raise an exception if told to act in other than :delay or :immediate(ly)" do run_context.resource_collection << Chef::Resource::ZenMaster.new("coffee") - expect do + expect { resource.notifies :reload, run_context.resource_collection.find(zen_master: "coffee"), :someday - end.to raise_error(ArgumentError) + }.to raise_error(ArgumentError) end it "should allow multiple notified resources appear in the actions hash" do @@ -673,7 +673,7 @@ describe Chef::Resource do it "runs runs an only_if when one is given" do snitch_variable = nil - resource.only_if { snitch_variable = true } + resource.only_if do snitch_variable = true end expect(resource.only_if.first.positivity).to eq(:only_if) # Chef::Mixin::Command.should_receive(:only_if).with(true, {}).and_return(false) resource.run_action(:purr) @@ -682,8 +682,8 @@ describe Chef::Resource do it "runs multiple only_if conditionals" do snitch_var1, snitch_var2 = nil, nil - resource.only_if { snitch_var1 = 1 } - resource.only_if { snitch_var2 = 2 } + resource.only_if do snitch_var1 = 1 end + resource.only_if do snitch_var2 = 2 end resource.run_action(:purr) expect(snitch_var1).to eq(1) expect(snitch_var2).to eq(2) @@ -704,7 +704,7 @@ describe Chef::Resource do it "runs not_if as a block when it is a ruby block" do expect_any_instance_of(Chef::Resource::Conditional).to receive(:evaluate_block).at_least(1).times - resource.not_if { puts "foo" } + resource.not_if do puts "foo" end resource.run_action(:purr) end @@ -721,8 +721,8 @@ describe Chef::Resource do it "accepts multiple not_if conditionals" do snitch_var1, snitch_var2 = true, true - resource.not_if { snitch_var1 = nil } - resource.not_if { snitch_var2 = false } + resource.not_if do snitch_var1 = nil end + resource.not_if do snitch_var2 = false end resource.run_action(:purr) expect(snitch_var1).to be_nil expect(snitch_var2).to be_falsey @@ -766,62 +766,62 @@ describe Chef::Resource do end it "should return false when only_if is met" do - resource.only_if { true } + resource.only_if do true end expect(resource.should_skip?(:purr)).to be_falsey end it "should return true when only_if is not met" do - resource.only_if { false } + resource.only_if do false end expect(resource.should_skip?(:purr)).to be_truthy end it "should return true when not_if is met" do - resource.not_if { true } + resource.not_if do true end expect(resource.should_skip?(:purr)).to be_truthy end it "should return false when not_if is not met" do - resource.not_if { false } + resource.not_if do false end expect(resource.should_skip?(:purr)).to be_falsey end it "should return true when only_if is met but also not_if is met" do - resource.only_if { true } - resource.not_if { true } + resource.only_if do true end + resource.not_if do true end expect(resource.should_skip?(:purr)).to be_truthy end it "should return false when only_if is met and also not_if is not met" do - resource.only_if { true } - resource.not_if { false } + resource.only_if do true end + resource.not_if do false end expect(resource.should_skip?(:purr)).to be_falsey end it "should return true when one of multiple only_if's is not met" do - resource.only_if { true } - resource.only_if { false } - resource.only_if { true } + resource.only_if do true end + resource.only_if do false end + resource.only_if do true end expect(resource.should_skip?(:purr)).to be_truthy end it "should return true when one of multiple not_if's is met" do - resource.not_if { false } - resource.not_if { true } - resource.not_if { false } + resource.not_if do false end + resource.not_if do true end + resource.not_if do false end expect(resource.should_skip?(:purr)).to be_truthy end it "should return false when all of multiple only_if's are met" do - resource.only_if { true } - resource.only_if { true } - resource.only_if { true } + resource.only_if do true end + resource.only_if do true end + resource.only_if do true end expect(resource.should_skip?(:purr)).to be_falsey end it "should return false when all of multiple not_if's are not met" do - resource.not_if { false } - resource.not_if { false } - resource.not_if { false } + resource.not_if do false end + resource.not_if do false end + resource.not_if do false end expect(resource.should_skip?(:purr)).to be_falsey end @@ -830,8 +830,8 @@ describe Chef::Resource do end it "should return true when action is :nothing ignoring only_if/not_if conditionals" do - resource.only_if { true } - resource.not_if { false } + resource.only_if do true end + resource.not_if do false end expect(resource.should_skip?(:nothing)).to be_truthy end @@ -857,8 +857,8 @@ describe Chef::Resource do it "should not run only_if/not_if conditionals (CHEF-972)" do snitch_var1 = 0 - resource1.only_if { snitch_var1 = 1 } - resource1.not_if { snitch_var1 = 2 } + resource1.only_if do snitch_var1 = 1 end + resource1.not_if do snitch_var1 = 2 end resource1.run_action(:nothing) expect(snitch_var1).to eq(0) end @@ -869,8 +869,8 @@ describe Chef::Resource do Chef::Provider::SnakeOil.provides :cat - resource1.only_if { snitch_var1 = 1 } - resource1.not_if { snitch_var2 = 2 } + resource1.only_if do snitch_var1 = 1 end + resource1.not_if do snitch_var2 = 2 end resource2 = Chef::Resource::Cat.new("coffee", run_context) resource2.notifies :purr, resource1 resource2.action = :purr @@ -1021,9 +1021,9 @@ describe Chef::Resource do describe "with a syntax error in the resource spec" do it "raises an exception immmediately" do - expect do + expect { resource.notifies(:run, "typo[missing-closing-bracket") - end.to raise_error(Chef::Exceptions::InvalidResourceSpecification) + }.to raise_error(Chef::Exceptions::InvalidResourceSpecification) end end end @@ -1108,27 +1108,27 @@ describe Chef::Resource do end context "with a symbol action" do - before { resource.action(:one) } + before do resource.action(:one) end it { is_expected.to eq [:one] } end context "with a string action" do - before { resource.action("two") } + before do resource.action("two") end it { is_expected.to eq [:two] } end context "with an array action" do - before { resource.action(%i{two one}) } + before do resource.action(%i{two one}) end it { is_expected.to eq %i{two one} } end context "with an assignment" do - before { resource.action = :one } + before do resource.action = :one end it { is_expected.to eq [:one] } end context "with an array assignment" do - before { resource.action = %i{two one} } + before do resource.action = %i{two one} end it { is_expected.to eq %i{two one} } end diff --git a/spec/unit/run_context_spec.rb b/spec/unit/run_context_spec.rb index 0d66b1f66d..49fc92b6d0 100644 --- a/spec/unit/run_context_spec.rb +++ b/spec/unit/run_context_spec.rb @@ -136,16 +136,16 @@ describe Chef::RunContext do it "raises an error when attempting to include_recipe from a cookbook not reachable by run list or dependencies" do expect(node).to receive(:loaded_recipe).with(:ancient, "aliens") - expect do + expect { run_context.include_recipe("ancient::aliens") # In CHEF-5120, this becomes a Chef::Exceptions::MissingCookbookDependency error: - end.to raise_error(Chef::Exceptions::CookbookNotFound) + }.to raise_error(Chef::Exceptions::CookbookNotFound) end it "raises an error on a recipe with a leading :: with no current_cookbook" do - expect do + expect { run_context.include_recipe("::aliens") - end.to raise_error(RuntimeError) + }.to raise_error(RuntimeError) end end @@ -165,9 +165,9 @@ describe Chef::RunContext do end it "errors when querying for a template in a not-available cookbook" do - expect do + expect { run_context.has_template_in_cookbook?("no-such-cookbook", "foo.erb") - end.to raise_error(Chef::Exceptions::CookbookNotFound) + }.to raise_error(Chef::Exceptions::CookbookNotFound) end it "queries whether a given cookbook has a specific cookbook_file" do @@ -176,9 +176,9 @@ describe Chef::RunContext do end it "errors when querying for a cookbook_file in a not-available cookbook" do - expect do + expect { run_context.has_cookbook_file_in_cookbook?("no-such-cookbook", "foo.txt") - end.to raise_error(Chef::Exceptions::CookbookNotFound) + }.to raise_error(Chef::Exceptions::CookbookNotFound) end end diff --git a/spec/unit/run_list/versioned_recipe_list_spec.rb b/spec/unit/run_list/versioned_recipe_list_spec.rb index e116ffc130..de0109e83c 100644 --- a/spec/unit/run_list/versioned_recipe_list_spec.rb +++ b/spec/unit/run_list/versioned_recipe_list_spec.rb @@ -33,7 +33,7 @@ describe Chef::RunList::VersionedRecipeList do let(:recipes) { [] } before do - recipes.each { |r| list << r } + recipes.each do |r| list << r end versioned_recipes.each { |r| list.add_recipe r[:name], r[:version] } end diff --git a/spec/unit/run_list_spec.rb b/spec/unit/run_list_spec.rb index 5dc877ad9a..9d42a3dabf 100644 --- a/spec/unit/run_list_spec.rb +++ b/spec/unit/run_list_spec.rb @@ -134,7 +134,7 @@ describe Chef::RunList do @run_list << "foo" @run_list << "bar" seen = [] - @run_list.each { |r| seen << r } + @run_list.each do |r| seen << r end expect(seen).to be_include("recipe[foo]") expect(seen).to be_include("recipe[bar]") end @@ -143,7 +143,7 @@ describe Chef::RunList do describe "each_index" do it "should yield each members index to your block" do to_add = [ "recipe[foo]", "recipe[bar]", "recipe[baz]" ] - to_add.each { |i| @run_list << i } + to_add.each do |i| @run_list << i end @run_list.each_index { |i| expect(@run_list[i]).to eq(to_add[i]) } end end @@ -160,7 +160,7 @@ describe Chef::RunList do @run_list << "chromeo" list = %w{camp chairs snakes clowns} @run_list.reset!(list) - list.each { |i| expect(@run_list).to be_include(i) } + list.each do |i| expect(@run_list).to be_include(i) end expect(@run_list.include?("chromeo")).to eq(false) end end diff --git a/spec/unit/runner_spec.rb b/spec/unit/runner_spec.rb index ffb0cd523f..cd2f656cf7 100644 --- a/spec/unit/runner_spec.rb +++ b/spec/unit/runner_spec.rb @@ -359,10 +359,10 @@ describe Chef::Runner do first_resource.action = :buy only_if_called_times = 0 - first_resource.only_if { only_if_called_times += 1; true } + first_resource.only_if do only_if_called_times += 1; true end not_if_called_times = 0 - first_resource.not_if { not_if_called_times += 1; false } + first_resource.not_if do not_if_called_times += 1; false end second_resource = Chef::Resource::Cat.new("carmel", run_context) run_context.resource_collection << second_resource @@ -387,7 +387,7 @@ describe Chef::Runner do end second_resource = Chef::Resource::RubyBlock.new("myblock", run_context) run_context.resource_collection << second_resource - second_resource.block { lazy_resources.call } + second_resource.block do lazy_resources.call end runner.converge diff --git a/spec/unit/search/query_spec.rb b/spec/unit/search/query_spec.rb index 83f988911c..d9693573b1 100644 --- a/spec/unit/search/query_spec.rb +++ b/spec/unit/search/query_spec.rb @@ -207,13 +207,13 @@ describe Chef::Search::Query do it "calls a block for each object in the response" do @call_me = double("blocky") - response["rows"].each { |r| expect(@call_me).to receive(:do).with(Chef::Node.from_hash(r)) } + response["rows"].each do |r| expect(@call_me).to receive(:do).with(Chef::Node.from_hash(r)) end query.search(:node) { |r| @call_me.do(r) } end it "pages through the responses" do @call_me = double("blocky") - response["rows"].each { |r| expect(@call_me).to receive(:do).with(Chef::Node.from_hash(r)) } + response["rows"].each do |r| expect(@call_me).to receive(:do).with(Chef::Node.from_hash(r)) end query.search(:node, "*:*", start: 0, rows: 4) { |r| @call_me.do(r) } end diff --git a/spec/unit/util/dsc/configuration_generator_spec.rb b/spec/unit/util/dsc/configuration_generator_spec.rb index faf554326d..a128808ac4 100644 --- a/spec/unit/util/dsc/configuration_generator_spec.rb +++ b/spec/unit/util/dsc/configuration_generator_spec.rb @@ -40,9 +40,9 @@ describe Chef::Util::DSC::ConfigurationGenerator do %w{! @ # $ % ^ & * & * ( ) - = + \{ \} . ? < > \\ /}.each do |sym| it "raises an Argument error if it configuration name contains #{sym}" do - expect do + expect { conf_man.send(:validate_configuration_name!, "Hello#{sym}") - end.to raise_error(ArgumentError) + }.to raise_error(ArgumentError) end end end @@ -57,15 +57,15 @@ describe Chef::Util::DSC::ConfigurationGenerator do end it "should raise an ArgumentError if you try to override outputpath" do - expect do + expect { conf_man.send(:get_merged_configuration_flags!, { "outputpath" => "a" }, "hello") - end.to raise_error(ArgumentError) + }.to raise_error(ArgumentError) end it "should be case insensitive for switches that are not allowed" do - expect do + expect { conf_man.send(:get_merged_configuration_flags!, { "OutputPath" => "a" }, "hello") - end.to raise_error(ArgumentError) + }.to raise_error(ArgumentError) end it "should be case insensitive to switches that are allowed" do @@ -83,15 +83,15 @@ describe Chef::Util::DSC::ConfigurationGenerator do end it "should raise an ArgumentError if you try to override outputpath" do - expect do + expect { conf_man.send(:get_merged_configuration_flags!, { outputpath: "a" }, "hello") - end.to raise_error(ArgumentError) + }.to raise_error(ArgumentError) end it "should be case insensitive for switches that are not allowed" do - expect do + expect { conf_man.send(:get_merged_configuration_flags!, { OutputPath: "a" }, "hello") - end.to raise_error(ArgumentError) + }.to raise_error(ArgumentError) end it "should be case insensitive to switches that are allowed" do diff --git a/spec/unit/util/powershell/cmdlet_spec.rb b/spec/unit/util/powershell/cmdlet_spec.rb index 144e363979..6969eb3df5 100644 --- a/spec/unit/util/powershell/cmdlet_spec.rb +++ b/spec/unit/util/powershell/cmdlet_spec.rb @@ -40,9 +40,9 @@ describe Chef::Util::Powershell::Cmdlet do %w{! @ # $ % ^ & * & * ( ) - = + \{ \} . ? < > \\ /}.each do |sym| it "raises an Argument error if it configuration name contains #{sym}" do - expect do + expect { @cmdlet.send(:validate_switch_name!, "Hello#{sym}") - end.to raise_error(ArgumentError) + }.to raise_error(ArgumentError) end end end @@ -68,15 +68,15 @@ describe Chef::Util::Powershell::Cmdlet do describe "#command_switches_string" do it "raises an ArgumentError if the key is not a symbol" do - expect do + expect { @cmdlet.send(:command_switches_string, { "foo" => "bar" }) - end.to raise_error(ArgumentError) + }.to raise_error(ArgumentError) end it "does not allow invalid switch names" do - expect do + expect { @cmdlet.send(:command_switches_string, { foo!: "bar" }) - end.to raise_error(ArgumentError) + }.to raise_error(ArgumentError) end it "ignores switches with a false value" do diff --git a/spec/unit/util/threaded_job_queue_spec.rb b/spec/unit/util/threaded_job_queue_spec.rb index 48a34bce31..4134843f44 100644 --- a/spec/unit/util/threaded_job_queue_spec.rb +++ b/spec/unit/util/threaded_job_queue_spec.rb @@ -26,7 +26,7 @@ describe Chef::Util::ThreadedJobQueue do expect(job).to receive(:arity).at_least(:once).and_return(1) expect(job).to receive(:call).exactly(5).times.with(an_instance_of(Mutex)) - 5.times { queue << job } + 5.times do queue << job end queue.process end @@ -35,7 +35,7 @@ describe Chef::Util::ThreadedJobQueue do expect(job).to receive(:arity).at_least(:once).and_return(0) expect(job).to receive(:call).exactly(5).times.with(no_args) - 5.times { queue << job } + 5.times do queue << job end queue.process end diff --git a/spec/unit/version_class_spec.rb b/spec/unit/version_class_spec.rb index c6848491ee..81925478de 100644 --- a/spec/unit/version_class_spec.rb +++ b/spec/unit/version_class_spec.rb @@ -102,17 +102,17 @@ describe Chef::Version do end it "should sort an array of versions" do - a = %w{0.0.0 0.0.1 0.1.0 0.1.1 1.0.0 1.1.0 1.1.1}.map do |s| + a = %w{0.0.0 0.0.1 0.1.0 0.1.1 1.0.0 1.1.0 1.1.1}.map { |s| Chef::Version.new(s) - end + } got = a.sort.map(&:to_s) expect(got).to eq(%w{0.0.0 0.0.1 0.1.0 0.1.1 1.0.0 1.1.0 1.1.1}) end it "should sort an array of versions, part 2" do - a = %w{9.8.7 1.0.0 1.2.3 4.4.6 4.5.6 0.8.6 4.5.5 5.9.8 3.5.7}.map do |s| + a = %w{9.8.7 1.0.0 1.2.3 4.4.6 4.5.6 0.8.6 4.5.5 5.9.8 3.5.7}.map { |s| Chef::Version.new(s) - end + } got = a.sort.map(&:to_s) expect(got).to eq(%w{0.8.6 1.0.0 1.2.3 3.5.7 4.4.6 4.5.5 4.5.6 5.9.8 9.8.7}) end |
