diff options
Diffstat (limited to 'spec')
109 files changed, 391 insertions, 391 deletions
diff --git a/spec/functional/event_loggers/windows_eventlog_spec.rb b/spec/functional/event_loggers/windows_eventlog_spec.rb index 031405f718..69874ef677 100644 --- a/spec/functional/event_loggers/windows_eventlog_spec.rb +++ b/spec/functional/event_loggers/windows_eventlog_spec.rb @@ -19,7 +19,7 @@ require "spec_helper" require "securerandom" require "chef/event_loggers/windows_eventlog" -if Chef::Platform.windows? and not Chef::Platform::windows_server_2003? +if Chef::Platform.windows? and not Chef::Platform.windows_server_2003? require "win32/eventlog" include Win32 end diff --git a/spec/functional/resource/cookbook_file_spec.rb b/spec/functional/resource/cookbook_file_spec.rb index cd678e5e13..d127413c73 100644 --- a/spec/functional/resource/cookbook_file_spec.rb +++ b/spec/functional/resource/cookbook_file_spec.rb @@ -70,7 +70,7 @@ describe Chef::Resource::CookbookFile do let(:path) { File.join(windows_non_temp_dir, make_tmpname(file_base)) } before do - FileUtils::mkdir_p(windows_non_temp_dir) if Chef::Platform.windows? + FileUtils.mkdir_p(windows_non_temp_dir) if Chef::Platform.windows? end after do diff --git a/spec/functional/resource/cron_spec.rb b/spec/functional/resource/cron_spec.rb index 2906715f7a..b3464ab22a 100644 --- a/spec/functional/resource/cron_spec.rb +++ b/spec/functional/resource/cron_spec.rb @@ -104,7 +104,7 @@ describe Chef::Resource::Cron, :requires_root, :unix_only do end end - exclude_solaris = ["solaris", "opensolaris", "solaris2", "omnios"].include?(ohai[:platform]) + exclude_solaris = %w(solaris opensolaris solaris2 omnios).include?(ohai[:platform]) describe "create action with various attributes", :external => exclude_solaris do def create_and_validate_with_attribute(resource, attribute, value) if ohai[:platform] == "aix" @@ -117,7 +117,7 @@ describe Chef::Resource::Cron, :requires_root, :unix_only do end def cron_attribute_should_exists(cron_name, attribute, value) - return if ["aix", "solaris"].include?(ohai[:platform]) + return if %w(aix solaris).include?(ohai[:platform]) # Test if the attribute exists on newly created cron cron_should_exists(cron_name, "") expect(shell_out("crontab -l -u #{new_resource.user} | grep \"#{attribute.upcase}=#{value}\"").exitstatus).to eq(0) diff --git a/spec/functional/resource/deploy_revision_spec.rb b/spec/functional/resource/deploy_revision_spec.rb index 4772067949..2231712dcb 100644 --- a/spec/functional/resource/deploy_revision_spec.rb +++ b/spec/functional/resource/deploy_revision_spec.rb @@ -45,7 +45,7 @@ describe Chef::Resource::DeployRevision, :unix_only => true do before(:all) do @ohai = Ohai::System.new - @ohai.all_plugins(["platform", "os"]) + @ohai.all_plugins(%w(platform os)) end let(:node) do diff --git a/spec/functional/resource/dsc_script_spec.rb b/spec/functional/resource/dsc_script_spec.rb index 5f264fdca1..921638bcf8 100644 --- a/spec/functional/resource/dsc_script_spec.rb +++ b/spec/functional/resource/dsc_script_spec.rb @@ -280,7 +280,7 @@ EOH end let(:test_registry_data) { test_registry_data1 } - let(:dsc_parameterized_env_param_value) { "val" + Random::rand.to_s } + let(:dsc_parameterized_env_param_value) { "val" + Random.rand.to_s } it "should have a default value of nil for the configuration_data attribute" do expect(dsc_test_resource.configuration_data).to eql(nil) diff --git a/spec/functional/resource/execute_spec.rb b/spec/functional/resource/execute_spec.rb index 1ceeb70590..dd0f68bebb 100644 --- a/spec/functional/resource/execute_spec.rb +++ b/spec/functional/resource/execute_spec.rb @@ -145,7 +145,7 @@ describe Chef::Resource::Execute do # Timeout::timeout should be longer than resource.timeout, but less than the resource.command ruby sleep timer, # so we fail if we finish on resource.command instead of resource.timeout, but raise CommandTimeout anyway (#2175). it "times out when a timeout is set on the resource" do - Timeout::timeout(30) do + Timeout.timeout(30) do resource.command %{ruby -e 'sleep 300'} resource.timeout 0.1 expect { resource.run_action(:run) }.to raise_error(Mixlib::ShellOut::CommandTimeout) diff --git a/spec/functional/resource/git_spec.rb b/spec/functional/resource/git_spec.rb index 7174a99451..cace34b714 100644 --- a/spec/functional/resource/git_spec.rb +++ b/spec/functional/resource/git_spec.rb @@ -92,7 +92,7 @@ E before(:all) do @ohai = Ohai::System.new - @ohai.all_plugins(["platform", "os"]) + @ohai.all_plugins(%w(platform os)) end context "working with pathes with special characters" do diff --git a/spec/functional/resource/group_spec.rb b/spec/functional/resource/group_spec.rb index 063b5d9004..25f0989783 100644 --- a/spec/functional/resource/group_spec.rb +++ b/spec/functional/resource/group_spec.rb @@ -31,8 +31,8 @@ describe Chef::Resource::Group, :requires_root_or_running_windows, :not_supporte def group_should_exist(group) case ohai[:platform_family] when "debian", "fedora", "rhel", "suse", "gentoo", "slackware", "arch" - expect { Etc::getgrnam(group) }.not_to raise_error - expect(group).to eq(Etc::getgrnam(group).name) + expect { Etc.getgrnam(group) }.not_to raise_error + expect(group).to eq(Etc.getgrnam(group).name) when "windows" expect { Chef::Util::Windows::NetGroup.new(group).local_get_members }.not_to raise_error end @@ -49,21 +49,21 @@ describe Chef::Resource::Group, :requires_root_or_running_windows, :not_supporte members.shift # Get rid of GroupMembership: string members.include?(user) else - Etc::getgrnam(group_name).mem.include?(user) + Etc.getgrnam(group_name).mem.include?(user) end end def group_should_not_exist(group) case ohai[:platform_family] when "debian", "fedora", "rhel", "suse", "gentoo", "slackware", "arch" - expect { Etc::getgrnam(group) }.to raise_error(ArgumentError, "can't find group for #{group}") + expect { Etc.getgrnam(group) }.to raise_error(ArgumentError, "can't find group for #{group}") when "windows" expect { Chef::Util::Windows::NetGroup.new(group).local_get_members }.to raise_error(ArgumentError, /The group name could not be found./) end end def compare_gid(resource, gid) - return resource.gid == Etc::getgrnam(resource.name).gid if unix? + return resource.gid == Etc.getgrnam(resource.name).gid if unix? end def sid_string_from_user(user) @@ -361,7 +361,7 @@ downthestreetalwayshadagoodsmileonhisfacetheoldmanwalkingdownthestreeQQQQQQ" } end describe "group modify action", :not_supported_on_solaris do - let(:spec_members) { ["mnou5sdz", "htulrvwq", "x4c3g1lu"] } + let(:spec_members) { %w(mnou5sdz htulrvwq x4c3g1lu) } let(:included_members) { [spec_members[0], spec_members[1]] } let(:excluded_members) { [spec_members[2]] } let(:tested_action) { :modify } @@ -389,7 +389,7 @@ downthestreetalwayshadagoodsmileonhisfacetheoldmanwalkingdownthestreeQQQQQQ" } end describe "group manage action", :not_supported_on_solaris do - let(:spec_members) { ["mnou5sdz", "htulrvwq", "x4c3g1lu"] } + let(:spec_members) { %w(mnou5sdz htulrvwq x4c3g1lu) } let(:included_members) { [spec_members[0], spec_members[1]] } let(:excluded_members) { [spec_members[2]] } let(:tested_action) { :manage } @@ -443,7 +443,7 @@ downthestreetalwayshadagoodsmileonhisfacetheoldmanwalkingdownthestreeQQQQQQ" } end describe "when append is not set" do - let(:included_members) { ["gordon", "eric"] } + let(:included_members) { %w(gordon eric) } before(:each) do group_resource.append(false) diff --git a/spec/functional/resource/ifconfig_spec.rb b/spec/functional/resource/ifconfig_spec.rb index cac6d96981..b8229fd3a6 100644 --- a/spec/functional/resource/ifconfig_spec.rb +++ b/spec/functional/resource/ifconfig_spec.rb @@ -20,7 +20,7 @@ require "functional/resource/base" require "chef/mixin/shell_out" # run this test only for following platforms. -include_flag = !(["ubuntu", "centos", "aix"].include?(ohai[:platform])) +include_flag = !(%w(ubuntu centos aix).include?(ohai[:platform])) describe Chef::Resource::Ifconfig, :requires_root, :skip_travis, :external => include_flag do # This test does not work in travis because there is no eth0 diff --git a/spec/functional/resource/link_spec.rb b/spec/functional/resource/link_spec.rb index 9b9d696979..f55b9fca1e 100644 --- a/spec/functional/resource/link_spec.rb +++ b/spec/functional/resource/link_spec.rb @@ -38,11 +38,11 @@ describe Chef::Resource::Link do end before do - FileUtils::mkdir_p(test_file_dir) + FileUtils.mkdir_p(test_file_dir) end after do - FileUtils::rm_rf(test_file_dir) + FileUtils.rm_rf(test_file_dir) end let(:to) do @@ -559,7 +559,7 @@ describe Chef::Resource::Link do end context "and the link does not yet exist" do it "links to the target file" do - skip("OS X/FreeBSD/AIX symlink? and readlink working on hard links to symlinks") if (os_x? or freebsd? or aix?) + skip("OS X/FreeBSD/AIX symlink? and readlink working on hard links to symlinks") if os_x? or freebsd? or aix? resource.run_action(:create) expect(File.exists?(target_file)).to be_truthy # OS X gets angry about this sort of link. Bug in OS X, IMO. @@ -578,7 +578,7 @@ describe Chef::Resource::Link do end context "and the link does not yet exist" do it "links to the target file" do - skip("OS X/FreeBSD/AIX fails to create hardlinks to broken symlinks") if (os_x? or freebsd? or aix?) + skip("OS X/FreeBSD/AIX fails to create hardlinks to broken symlinks") if os_x? or freebsd? or aix? resource.run_action(:create) # Windows and Unix have different definitions of exists? here, and that's OK. if windows? diff --git a/spec/functional/resource/mount_spec.rb b/spec/functional/resource/mount_spec.rb index 7f088891e3..a00b937fcf 100644 --- a/spec/functional/resource/mount_spec.rb +++ b/spec/functional/resource/mount_spec.rb @@ -22,7 +22,7 @@ require "chef/mixin/shell_out" require "tmpdir" # run this test only for following platforms. -include_flag = !(["ubuntu", "centos", "aix", "solaris2"].include?(ohai[:platform])) +include_flag = !(%w(ubuntu centos aix solaris2).include?(ohai[:platform])) describe Chef::Resource::Mount, :requires_root, :skip_travis, :external => include_flag do # Disabled in travis because it refuses to let us mount a ramdisk. /dev/ramX does not diff --git a/spec/functional/resource/package_spec.rb b/spec/functional/resource/package_spec.rb index 36b106bf1c..1ab247a154 100644 --- a/spec/functional/resource/package_spec.rb +++ b/spec/functional/resource/package_spec.rb @@ -66,7 +66,7 @@ module AptServer @apt_server_thread = Thread.new do run_apt_server end - until tcp_test_port("localhost", 9000) do + until tcp_test_port("localhost", 9000) if @apt_server_thread.alive? sleep 1 else diff --git a/spec/functional/resource/registry_spec.rb b/spec/functional/resource/registry_spec.rb index 6cf8524883..8be2a70dfb 100644 --- a/spec/functional/resource/registry_spec.rb +++ b/spec/functional/resource/registry_spec.rb @@ -78,7 +78,7 @@ describe Chef::Resource::RegistryKey, :windows_only, :broken => true do hive_class.create(key_parent + '\Opscode', Win32::Registry::KEY_WRITE | flag) hive_class.open(key_parent + '\Opscode', Win32::Registry::KEY_ALL_ACCESS | flag) do |reg| reg["Color", Win32::Registry::REG_SZ] = "Orange" - reg.write("Opscode", Win32::Registry::REG_MULTI_SZ, ["Seattle", "Washington"]) + reg.write("Opscode", Win32::Registry::REG_MULTI_SZ, %w(Seattle Washington)) reg["AKA", Win32::Registry::REG_SZ] = "OC" end hive_class.create(key_parent + '\ReportKey', Win32::Registry::KEY_WRITE | flag) @@ -179,12 +179,12 @@ describe Chef::Resource::RegistryKey, :windows_only, :broken => true do it "creates subkey if parent exists" do @new_resource.key(reg_child + '\OpscodeTest') - @new_resource.values([{ :name => "Chef", :type => :multi_string, :data => ["OpscodeOrange", "Rules"] }]) + @new_resource.values([{ :name => "Chef", :type => :multi_string, :data => %w(OpscodeOrange Rules) }]) @new_resource.recursive(false) @new_resource.run_action(:create) expect(@registry.key_exists?(reg_child + '\OpscodeTest')).to eq(true) - expect(@registry.value_exists?(reg_child + '\OpscodeTest', { :name => "Chef", :type => :multi_string, :data => ["OpscodeOrange", "Rules"] })).to eq(true) + expect(@registry.value_exists?(reg_child + '\OpscodeTest', { :name => "Chef", :type => :multi_string, :data => %w(OpscodeOrange Rules) })).to eq(true) end it "gives error if action create and parent does not exist and recursive is set to false" do @@ -312,12 +312,12 @@ describe Chef::Resource::RegistryKey, :windows_only, :broken => true do it "creates subkey if parent exists" do @new_resource.key(reg_child + '\Pyrovile') - @new_resource.values([{ :name => "Chef", :type => :multi_string, :data => ["OpscodeOrange", "Rules"] }]) + @new_resource.values([{ :name => "Chef", :type => :multi_string, :data => %w(OpscodeOrange Rules) }]) @new_resource.recursive(false) @new_resource.run_action(:create_if_missing) expect(@registry.key_exists?(reg_child + '\Pyrovile')).to eq(true) - expect(@registry.value_exists?(reg_child + '\Pyrovile', { :name => "Chef", :type => :multi_string, :data => ["OpscodeOrange", "Rules"] })).to eq(true) + expect(@registry.value_exists?(reg_child + '\Pyrovile', { :name => "Chef", :type => :multi_string, :data => %w(OpscodeOrange Rules) })).to eq(true) end it "gives error if action create and parent does not exist and recursive is set to false" do @@ -409,7 +409,7 @@ describe Chef::Resource::RegistryKey, :windows_only, :broken => true do expect(@registry.data_exists?(reg_parent + '\Opscode', { :name => "Color", :type => :string, :data => "Orange" })).to eq(true) @new_resource.key(reg_parent + '\Opscode') - @new_resource.values([{ :name => "LooksLike", :type => :multi_string, :data => ["SeattleGrey", "OCOrange"] }]) + @new_resource.values([{ :name => "LooksLike", :type => :multi_string, :data => %w(SeattleGrey OCOrange) }]) @new_resource.recursive(false) @new_resource.run_action(:delete) @@ -418,18 +418,18 @@ describe Chef::Resource::RegistryKey, :windows_only, :broken => true do it "deletes only specified values under a key path" do @new_resource.key(reg_parent + '\Opscode') - @new_resource.values([{ :name => "Opscode", :type => :multi_string, :data => ["Seattle", "Washington"] }, { :name => "AKA", :type => :string, :data => "OC" }]) + @new_resource.values([{ :name => "Opscode", :type => :multi_string, :data => %w(Seattle Washington) }, { :name => "AKA", :type => :string, :data => "OC" }]) @new_resource.recursive(false) @new_resource.run_action(:delete) expect(@registry.data_exists?(reg_parent + '\Opscode', { :name => "Color", :type => :string, :data => "Orange" })).to eq(true) expect(@registry.value_exists?(reg_parent + '\Opscode', { :name => "AKA", :type => :string, :data => "OC" })).to eq(false) - expect(@registry.value_exists?(reg_parent + '\Opscode', { :name => "Opscode", :type => :multi_string, :data => ["Seattle", "Washington"] })).to eq(false) + expect(@registry.value_exists?(reg_parent + '\Opscode', { :name => "Opscode", :type => :multi_string, :data => %w(Seattle Washington) })).to eq(false) end it "it deletes the values with the same name irrespective of it type and data" do @new_resource.key(reg_parent + '\Opscode') - @new_resource.values([{ :name => "Color", :type => :multi_string, :data => ["Black", "Orange"] }]) + @new_resource.values([{ :name => "Color", :type => :multi_string, :data => %w(Black Orange) }]) @new_resource.recursive(false) @new_resource.run_action(:delete) diff --git a/spec/functional/resource/rpm_spec.rb b/spec/functional/resource/rpm_spec.rb index 6da74ead5f..a3c5ecd466 100644 --- a/spec/functional/resource/rpm_spec.rb +++ b/spec/functional/resource/rpm_spec.rb @@ -21,7 +21,7 @@ require "functional/resource/base" require "chef/mixin/shell_out" # run this test only for following platforms. -exclude_test = !["aix", "centos", "redhat", "suse"].include?(ohai[:platform]) +exclude_test = !%w(aix centos redhat suse).include?(ohai[:platform]) describe Chef::Resource::RpmPackage, :requires_root, :external => exclude_test do include Chef::Mixin::ShellOut diff --git a/spec/functional/resource/template_spec.rb b/spec/functional/resource/template_spec.rb index da8cbfc68a..d1082596fa 100644 --- a/spec/functional/resource/template_spec.rb +++ b/spec/functional/resource/template_spec.rb @@ -191,7 +191,7 @@ describe Chef::Resource::Template do describe "when template source contains windows style line endings" do include_context "diff disabled" - ["all", "some", "no"].each do |test_case| + %w(all some no).each do |test_case| context "for #{test_case} lines" do let(:resource) do r = create_resource diff --git a/spec/functional/resource/user/dscl_spec.rb b/spec/functional/resource/user/dscl_spec.rb index 37f6047dfc..d6e85d193c 100644 --- a/spec/functional/resource/user/dscl_spec.rb +++ b/spec/functional/resource/user/dscl_spec.rb @@ -168,7 +168,7 @@ c5adbbac718b7eb99463a7b679571e0f\ end describe "when a user is member of some groups" do - let(:groups) { ["staff", "operator"] } + let(:groups) { %w(staff operator) } before do existing_resource = user_resource.dup diff --git a/spec/functional/resource/windows_service_spec.rb b/spec/functional/resource/windows_service_spec.rb index 80faaece34..9353e92c24 100644 --- a/spec/functional/resource/windows_service_spec.rb +++ b/spec/functional/resource/windows_service_spec.rb @@ -68,7 +68,7 @@ describe Chef::Resource::WindowsService, :windows_only, :system_windows_service_ # the service executable has to be outside the current user's home # directory in order for the logon user to execute it. - FileUtils::copy_file(test_service[:service_file_path], global_service_file_path) + FileUtils.copy_file(test_service[:service_file_path], global_service_file_path) # if you don't make the file executable by the service user, you'll get # the not-very-helpful "service did not respond fast enough" error. diff --git a/spec/functional/run_lock_spec.rb b/spec/functional/run_lock_spec.rb index 288341bcb6..129324f02a 100644 --- a/spec/functional/run_lock_spec.rb +++ b/spec/functional/run_lock_spec.rb @@ -47,7 +47,7 @@ describe Chef::RunLock do WAIT_ON_LOCK_TIME = 1.0 def wait_on_lock - Timeout::timeout(WAIT_ON_LOCK_TIME) do + Timeout.timeout(WAIT_ON_LOCK_TIME) do until File.exist?(lockfile) sleep 0.1 end @@ -346,7 +346,7 @@ describe Chef::RunLock do background_block.call if background_block # Wait until it gets there - Timeout::timeout(CLIENT_PROCESS_TIMEOUT) do + Timeout.timeout(CLIENT_PROCESS_TIMEOUT) do until @last_event == "after #{to_event}" got_event, time = read_from_process.gets.split("@") example.log_event("#{name}.last_event got #{got_event}") @@ -373,7 +373,7 @@ describe Chef::RunLock do def wait_for_exit example.log_event("#{name}.wait_for_exit (pid #{pid})") - Timeout::timeout(CLIENT_PROCESS_TIMEOUT) do + Timeout.timeout(CLIENT_PROCESS_TIMEOUT) do Process.wait(pid) if pid end example.log_event("#{name}.wait_for_exit finished (pid #{pid})") @@ -384,9 +384,9 @@ describe Chef::RunLock do example.log_event("#{name}.stop (pid #{pid})") begin # Send it the kill signal over and over until it dies - Timeout::timeout(CLIENT_PROCESS_TIMEOUT) do + Timeout.timeout(CLIENT_PROCESS_TIMEOUT) do Process.kill(:KILL, pid) - while !Process.waitpid2(pid, Process::WNOHANG) + until Process.waitpid2(pid, Process::WNOHANG) sleep(0.05) end end @@ -431,7 +431,7 @@ describe Chef::RunLock do example.log_event("#{name}.start") @pid = fork do begin - Timeout::timeout(CLIENT_PROCESS_TIMEOUT) do + Timeout.timeout(CLIENT_PROCESS_TIMEOUT) do run_lock = TestRunLock.new(example.lockfile) run_lock.client_process = self fire_event("started") diff --git a/spec/functional/win32/registry_spec.rb b/spec/functional/win32/registry_spec.rb index f0258ab3b9..62af773b61 100644 --- a/spec/functional/win32/registry_spec.rb +++ b/spec/functional/win32/registry_spec.rb @@ -35,7 +35,7 @@ describe "Chef::Win32::Registry", :windows_only do reg["Strong", Win32::Registry::REG_SZ] = "bird nest" end ::Win32::Registry::HKEY_CURRENT_USER.open('Software\\Root\\Branch\\Flower', Win32::Registry::KEY_ALL_ACCESS) do |reg| - reg["Petals", Win32::Registry::REG_MULTI_SZ] = ["Pink", "Delicate"] + reg["Petals", Win32::Registry::REG_MULTI_SZ] = %w(Pink Delicate) end #Create the node with ohai data @@ -137,49 +137,49 @@ describe "Chef::Win32::Registry", :windows_only do describe "data_exists?" do it "throws an exception if the hive does not exist" do - expect { @registry.data_exists?("JKLM\\Software\\Branch\\Flower", { :name => "Petals", :type => :multi_string, :data => ["Pink", "Delicate"] }) }.to raise_error(Chef::Exceptions::Win32RegHiveMissing) + expect { @registry.data_exists?("JKLM\\Software\\Branch\\Flower", { :name => "Petals", :type => :multi_string, :data => %w(Pink Delicate) }) }.to raise_error(Chef::Exceptions::Win32RegHiveMissing) end it "throws an exception if the key does not exist" do - expect { @registry.data_exists?("HKCU\\Software\\Branch\\Flower", { :name => "Petals", :type => :multi_string, :data => ["Pink", "Delicate"] }) }.to raise_error(Chef::Exceptions::Win32RegKeyMissing) + expect { @registry.data_exists?("HKCU\\Software\\Branch\\Flower", { :name => "Petals", :type => :multi_string, :data => %w(Pink Delicate) }) }.to raise_error(Chef::Exceptions::Win32RegKeyMissing) end it "returns true if all the data matches" do - expect(@registry.data_exists?("HKCU\\Software\\Root\\Branch\\Flower", { :name => "Petals", :type => :multi_string, :data => ["Pink", "Delicate"] })).to eq(true) + expect(@registry.data_exists?("HKCU\\Software\\Root\\Branch\\Flower", { :name => "Petals", :type => :multi_string, :data => %w(Pink Delicate) })).to eq(true) end it "returns true if all the data matches with a case mismatch on the data name" do - expect(@registry.data_exists?("HKCU\\Software\\Root\\Branch\\Flower", { :name => "petals", :type => :multi_string, :data => ["Pink", "Delicate"] })).to eq(true) + expect(@registry.data_exists?("HKCU\\Software\\Root\\Branch\\Flower", { :name => "petals", :type => :multi_string, :data => %w(Pink Delicate) })).to eq(true) end it "returns false if the name does not exist" do - expect(@registry.data_exists?("HKCU\\Software\\Root\\Branch\\Flower", { :name => "slateP", :type => :multi_string, :data => ["Pink", "Delicate"] })).to eq(false) + expect(@registry.data_exists?("HKCU\\Software\\Root\\Branch\\Flower", { :name => "slateP", :type => :multi_string, :data => %w(Pink Delicate) })).to eq(false) end it "returns false if the types do not match" do expect(@registry.data_exists?("HKCU\\Software\\Root\\Branch\\Flower", { :name => "Petals", :type => :string, :data => "Pink" })).to eq(false) end it "returns false if the data does not match" do - expect(@registry.data_exists?("HKCU\\Software\\Root\\Branch\\Flower", { :name => "Petals", :type => :multi_string, :data => ["Mauve", "Delicate"] })).to eq(false) + expect(@registry.data_exists?("HKCU\\Software\\Root\\Branch\\Flower", { :name => "Petals", :type => :multi_string, :data => %w(Mauve Delicate) })).to eq(false) end end describe "data_exists!" do it "throws an exception if the hive does not exist" do - expect { @registry.data_exists!("JKLM\\Software\\Branch\\Flower", { :name => "Petals", :type => :multi_string, :data => ["Pink", "Delicate"] }) }.to raise_error(Chef::Exceptions::Win32RegHiveMissing) + expect { @registry.data_exists!("JKLM\\Software\\Branch\\Flower", { :name => "Petals", :type => :multi_string, :data => %w(Pink Delicate) }) }.to raise_error(Chef::Exceptions::Win32RegHiveMissing) end it "throws an exception if the key does not exist" do - expect { @registry.data_exists!("HKCU\\Software\\Branch\\Flower", { :name => "Petals", :type => :multi_string, :data => ["Pink", "Delicate"] }) }.to raise_error(Chef::Exceptions::Win32RegKeyMissing) + expect { @registry.data_exists!("HKCU\\Software\\Branch\\Flower", { :name => "Petals", :type => :multi_string, :data => %w(Pink Delicate) }) }.to raise_error(Chef::Exceptions::Win32RegKeyMissing) end it "returns true if all the data matches" do - expect(@registry.data_exists!("HKCU\\Software\\Root\\Branch\\Flower", { :name => "Petals", :type => :multi_string, :data => ["Pink", "Delicate"] })).to eq(true) + expect(@registry.data_exists!("HKCU\\Software\\Root\\Branch\\Flower", { :name => "Petals", :type => :multi_string, :data => %w(Pink Delicate) })).to eq(true) end it "returns true if all the data matches with a case mismatch on the data name" do - expect(@registry.data_exists!("HKCU\\Software\\Root\\Branch\\Flower", { :name => "petals", :type => :multi_string, :data => ["Pink", "Delicate"] })).to eq(true) + expect(@registry.data_exists!("HKCU\\Software\\Root\\Branch\\Flower", { :name => "petals", :type => :multi_string, :data => %w(Pink Delicate) })).to eq(true) end it "throws an exception if the name does not exist" do - expect { @registry.data_exists!("HKCU\\Software\\Root\\Branch\\Flower", { :name => "slateP", :type => :multi_string, :data => ["Pink", "Delicate"] }) }.to raise_error(Chef::Exceptions::Win32RegDataMissing) + expect { @registry.data_exists!("HKCU\\Software\\Root\\Branch\\Flower", { :name => "slateP", :type => :multi_string, :data => %w(Pink Delicate) }) }.to raise_error(Chef::Exceptions::Win32RegDataMissing) end it "throws an exception if the types do not match" do expect { @registry.data_exists!("HKCU\\Software\\Root\\Branch\\Flower", { :name => "Petals", :type => :string, :data => "Pink" }) }.to raise_error(Chef::Exceptions::Win32RegDataMissing) end it "throws an exception if the data does not match" do - expect { @registry.data_exists!("HKCU\\Software\\Root\\Branch\\Flower", { :name => "Petals", :type => :multi_string, :data => ["Mauve", "Delicate"] }) }.to raise_error(Chef::Exceptions::Win32RegDataMissing) + expect { @registry.data_exists!("HKCU\\Software\\Root\\Branch\\Flower", { :name => "Petals", :type => :multi_string, :data => %w(Mauve Delicate) }) }.to raise_error(Chef::Exceptions::Win32RegDataMissing) end end @@ -243,13 +243,13 @@ describe "Chef::Win32::Registry", :windows_only do end it "throws an exception when trying to cast an array to an int for a dword" do - expect { @registry.set_value("HKCU\\Software\\Root\\Branch\\Flower", { :name => "ShouldThrow", :type => :dword, :data => ["one", "two"] }) }.to raise_error + expect { @registry.set_value("HKCU\\Software\\Root\\Branch\\Flower", { :name => "ShouldThrow", :type => :dword, :data => %w(one two) }) }.to raise_error end # we are validating that the data gets .to_s called on it when type is a :string it "stores the string representation of an array into a string if you pass it an array" do - expect(@registry.set_value("HKCU\\Software\\Root\\Branch\\Flower", { :name => "ShouldBePainful", :type => :string, :data => ["one", "two"] })).to eq(true) + expect(@registry.set_value("HKCU\\Software\\Root\\Branch\\Flower", { :name => "ShouldBePainful", :type => :string, :data => %w(one two) })).to eq(true) expect(@registry.data_exists?("HKCU\\Software\\Root\\Branch\\Flower", { :name => "ShouldBePainful", :type => :string, :data => '["one", "two"]' })).to eq(true) end @@ -330,7 +330,7 @@ describe "Chef::Win32::Registry", :windows_only do before (:all) do ::Win32::Registry::HKEY_CURRENT_USER.create "Software\\Root\\Branch\\Fruit" ::Win32::Registry::HKEY_CURRENT_USER.open('Software\\Root\\Branch\\Fruit', Win32::Registry::KEY_ALL_ACCESS) do |reg| - reg["Apple", Win32::Registry::REG_MULTI_SZ] = ["Red", "Juicy"] + reg["Apple", Win32::Registry::REG_MULTI_SZ] = %w(Red Juicy) end ::Win32::Registry::HKEY_CURRENT_USER.create "Software\\Root\\Trunk\\Peck\\Woodpecker" ::Win32::Registry::HKEY_CURRENT_USER.open('Software\\Root\\Trunk\\Peck\\Woodpecker', Win32::Registry::KEY_ALL_ACCESS) do |reg| diff --git a/spec/functional/win32/service_manager_spec.rb b/spec/functional/win32/service_manager_spec.rb index 7f8e943367..33c6397af7 100644 --- a/spec/functional/win32/service_manager_spec.rb +++ b/spec/functional/win32/service_manager_spec.rb @@ -81,7 +81,7 @@ describe "Chef::Application::WindowsServiceManager", :windows_only, :system_wind end it "other actions => should say service doesn't exist" do - ["delete", "start", "stop", "pause", "resume", "uninstall"].each do |action| + %w(delete start stop pause resume uninstall).each do |action| service_manager.run(["-a", action]) expect(@service_manager_output.grep(/doesn't exist on the system/).length).to be > 0 @service_manager_output = [ ] @@ -106,7 +106,7 @@ describe "Chef::Application::WindowsServiceManager", :windows_only, :system_wind end context "and service is stopped" do - ["delete", "uninstall"].each do |action| + %w(delete uninstall).each do |action| it "#{action} => should remove the service", :volatile do service_manager.run(["-a", action]) expect(test_service_exists?).to be_falsey @@ -133,7 +133,7 @@ describe "Chef::Application::WindowsServiceManager", :windows_only, :system_wind expect(test_service_state).to eq("stopped") end - ["pause", "resume"].each do |action| + %w(pause resume).each do |action| it "#{action} => should raise error" do expect { service_manager.run(["-a", action]) }.to raise_error(SystemCallError) end @@ -144,7 +144,7 @@ describe "Chef::Application::WindowsServiceManager", :windows_only, :system_wind service_manager.run(["-a", "start"]) end - ["delete", "uninstall"].each do |action| + %w(delete uninstall).each do |action| it "#{action} => should remove the service", :volatile do service_manager.run(["-a", action]) expect(test_service_exists?).to be_falsey @@ -182,7 +182,7 @@ describe "Chef::Application::WindowsServiceManager", :windows_only, :system_wind service_manager.run(["-a", "pause"]) end - actions = ["delete", "uninstall"] + actions = %w(delete uninstall) actions.each do |action| it "#{action} => should remove the service" do service_manager.run(["-a", action]) diff --git a/spec/functional/win32/versions_spec.rb b/spec/functional/win32/versions_spec.rb index aee5bbbcd4..53fce39491 100644 --- a/spec/functional/win32/versions_spec.rb +++ b/spec/functional/win32/versions_spec.rb @@ -36,7 +36,7 @@ describe "Chef::ReservedNames::Win32::Version", :windows_only, :not_supported_on # from WMI contain extended characters such as registered # trademark on Win2k8 and Win2k3 that we're not using in our # library, so we have to set the expectation statically. - if Chef::Platform::windows_server_2003? + if Chef::Platform.windows_server_2003? @current_os_version = "Windows Server 2003 R2" elsif is_windows_server_2008?(host) @current_os_version = "Windows Server 2008" diff --git a/spec/integration/knife/upload_spec.rb b/spec/integration/knife/upload_spec.rb index 6f8dce5ae7..44a4a872bd 100644 --- a/spec/integration/knife/upload_spec.rb +++ b/spec/integration/knife/upload_spec.rb @@ -280,7 +280,7 @@ Created /data_bags/x/y.json EOM knife("diff --name-status /data_bags").should_succeed <<EOM EOM - expect(Chef::JSONCompat.parse(knife("raw /data/x/y").stdout, :create_additions => false).keys.sort).to eq([ "foo", "id" ]) + expect(Chef::JSONCompat.parse(knife("raw /data/x/y").stdout, :create_additions => false).keys.sort).to eq(%w(foo id)) end it "knife upload /data_bags/x /data_bags/x/y.json uploads x once" do @@ -304,7 +304,7 @@ Created /data_bags/x/y.json EOM knife("diff --name-status /data_bags").should_succeed "" result = Chef::JSONCompat.parse(knife("raw /data/x/y").stdout, :create_additions => false) - expect(result.keys.sort).to eq([ "chef_type", "data_bag", "id" ]) + expect(result.keys.sort).to eq(%w(chef_type data_bag id)) expect(result["chef_type"]).to eq("aaa") expect(result["data_bag"]).to eq("bbb") end @@ -1457,25 +1457,25 @@ EOM when_the_repository "wants to invite foo, bar and foobar" do before do - file "invitations.json", [ "foo", "bar", "foobar" ] + file "invitations.json", %w(foo bar foobar) end it "knife upload / emits a warning for bar and invites foobar" do knife("upload /").should_succeed "Updated /invitations.json\n", :stderr => "WARN: Could not invite bar to organization foo: User bar is already in organization foo\n" - expect(api.get("association_requests").map { |a| a["username"] }).to eq([ "foo", "foobar" ]) + expect(api.get("association_requests").map { |a| a["username"] }).to eq(%w(foo foobar)) expect(api.get("users").map { |a| a["user"]["username"] }).to eq([ "bar" ]) end end when_the_repository "wants to make foo, bar and foobar members" do before do - file "members.json", [ "foo", "bar", "foobar" ] + file "members.json", %w(foo bar foobar) end it "knife upload / emits a warning for bar and adds foo and foobar" do knife("upload /").should_succeed "Updated /members.json\n" expect(api.get("association_requests").map { |a| a["username"] }).to eq([ ]) - expect(api.get("users").map { |a| a["user"]["username"] }).to eq([ "bar", "foo", "foobar" ]) + expect(api.get("users").map { |a| a["user"]["username"] }).to eq(%w(bar foo foobar)) end end @@ -1498,12 +1498,12 @@ EOM when_the_repository "wants to invite foo and bar (different order)" do before do - file "invitations.json", [ "foo", "bar" ] + file "invitations.json", %w(foo bar) end it "knife upload / does nothing" do knife("upload /").should_succeed "" - expect(api.get("association_requests").map { |a| a["username"] }).to eq([ "bar", "foo" ]) + expect(api.get("association_requests").map { |a| a["username"] }).to eq(%w(bar foo)) expect(api.get("users").map { |a| a["user"]["username"] }).to eq([ ]) end end @@ -1514,13 +1514,13 @@ EOM when_the_repository "wants to add foo and bar (different order)" do before do - file "members.json", [ "foo", "bar" ] + file "members.json", %w(foo bar) end it "knife upload / does nothing" do knife("upload /").should_succeed "" expect(api.get("association_requests").map { |a| a["username"] }).to eq([ ]) - expect(api.get("users").map { |a| a["user"]["username"] }).to eq([ "bar", "foo" ]) + expect(api.get("users").map { |a| a["user"]["username"] }).to eq(%w(bar foo)) end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 47432f5a77..8ba4c8eb70 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -160,7 +160,7 @@ RSpec.configure do |config| config.filter_run_excluding :chef_gte_13_only => true unless chef_gte_13? config.filter_run_excluding :chef_lt_13_only => true unless chef_lt_13? config.filter_run_excluding :requires_root => true unless root? - config.filter_run_excluding :requires_root_or_running_windows => true unless (root? || windows?) + config.filter_run_excluding :requires_root_or_running_windows => true unless root? || windows? config.filter_run_excluding :requires_unprivileged_user => true if root? config.filter_run_excluding :uses_diff => true unless has_diff? config.filter_run_excluding :openssl_gte_101 => true unless openssl_gte_101? diff --git a/spec/stress/win32/security_spec.rb b/spec/stress/win32/security_spec.rb index e9da56620e..4fbd1dac9c 100644 --- a/spec/stress/win32/security_spec.rb +++ b/spec/stress/win32/security_spec.rb @@ -31,7 +31,7 @@ describe "Chef::ReservedNames::Win32::Security", :windows_only do end before :all do - @test_tempdir = File.join(Dir::tmpdir, "cheftests", "chef_win32_security") + @test_tempdir = File.join(Dir.tmpdir, "cheftests", "chef_win32_security") FileUtils.mkdir_p(@test_tempdir) @monkeyfoo = File.join(@test_tempdir, "monkeyfoo.txt") end diff --git a/spec/support/platforms/win32/spec_service.rb b/spec/support/platforms/win32/spec_service.rb index c196e13b6a..5548a79afc 100644 --- a/spec/support/platforms/win32/spec_service.rb +++ b/spec/support/platforms/win32/spec_service.rb @@ -24,7 +24,7 @@ class SpecService < ::Win32::Daemon end def service_main(*startup_parameters) - while running? do + while running? if !File.exists?(@test_service_file) File.open(@test_service_file, "wb") do |f| f.write("This file is created by SpecService") diff --git a/spec/support/shared/functional/directory_resource.rb b/spec/support/shared/functional/directory_resource.rb index 084cd43009..5e5e2bb360 100644 --- a/spec/support/shared/functional/directory_resource.rb +++ b/spec/support/shared/functional/directory_resource.rb @@ -163,11 +163,11 @@ shared_context Chef::Resource::Directory do end before do - FileUtils::mkdir_p(test_file_dir) + FileUtils.mkdir_p(test_file_dir) end after do - FileUtils::rm_rf(test_file_dir) + FileUtils.rm_rf(test_file_dir) end after(:each) do diff --git a/spec/support/shared/functional/file_resource.rb b/spec/support/shared/functional/file_resource.rb index 5f34f1efe6..bb8db772be 100644 --- a/spec/support/shared/functional/file_resource.rb +++ b/spec/support/shared/functional/file_resource.rb @@ -781,11 +781,11 @@ shared_examples_for "a configured file resource" do let(:test_socket_dir) { File.join(Dir.tmpdir, "sockets") } before do - FileUtils::mkdir_p(test_socket_dir) + FileUtils.mkdir_p(test_socket_dir) end after do - FileUtils::rm_rf(test_socket_dir) + FileUtils.rm_rf(test_socket_dir) end let(:path) do @@ -1035,7 +1035,7 @@ shared_context Chef::Resource::File do end before do - FileUtils::mkdir_p(test_file_dir) + FileUtils.mkdir_p(test_file_dir) end after(:each) do @@ -1044,6 +1044,6 @@ shared_context Chef::Resource::File do end after do - FileUtils::rm_rf(test_file_dir) + FileUtils.rm_rf(test_file_dir) end end diff --git a/spec/support/shared/functional/windows_script.rb b/spec/support/shared/functional/windows_script.rb index 67a53306ba..eb456b191f 100644 --- a/spec/support/shared/functional/windows_script.rb +++ b/spec/support/shared/functional/windows_script.rb @@ -24,7 +24,7 @@ require "chef/platform/query_helpers" shared_context Chef::Resource::WindowsScript do before(:all) do @ohai_reader = Ohai::System.new - @ohai_reader.all_plugins(["platform", "kernel"]) + @ohai_reader.all_plugins(%w(platform kernel)) new_node = Chef::Node.new new_node.consume_external_attrs(@ohai_reader.data, {}) diff --git a/spec/support/shared/integration/app_server_support.rb b/spec/support/shared/integration/app_server_support.rb index c504c7ca99..8327caf1c9 100644 --- a/spec/support/shared/integration/app_server_support.rb +++ b/spec/support/shared/integration/app_server_support.rb @@ -27,12 +27,12 @@ module AppServerSupport Rack::Handler::WEBrick.run(app, :Port => 9018, :AccessLog => [], - :Logger => WEBrick::Log::new(StringIO.new, 7), + :Logger => WEBrick::Log.new(StringIO.new, 7), ) do |found_server| server = found_server end end - Timeout::timeout(30) do + Timeout.timeout(30) do until server && server.status == :Running sleep(0.01) end diff --git a/spec/support/shared/unit/platform_introspector.rb b/spec/support/shared/unit/platform_introspector.rb index 2e6f74fb14..e458e1b941 100644 --- a/spec/support/shared/unit/platform_introspector.rb +++ b/spec/support/shared/unit/platform_introspector.rb @@ -26,7 +26,7 @@ shared_examples_for "a platform introspector" do "1.2.3" => "#{x}-1.2.3", } end - @platform_hash["debian"] = { ["5", "6"] => "debian-5/6", "default" => "debian" } + @platform_hash["debian"] = { %w(5 6) => "debian-5/6", "default" => "debian" } @platform_hash["default"] = "default" # The following @platform_hash keys are used for testing version constraints @platform_hash["exact_match"] = { "1.2.3" => "exact", ">= 1.0" => "not exact" } @@ -130,7 +130,7 @@ shared_examples_for "a platform introspector" do it "returns true if the node is a provided platform and platforms are provided as strings" do node.automatic_attrs[:platform] = "ubuntu" - expect(platform_introspector.platform?(["redhat", "ubuntu"])).to eq(true) + expect(platform_introspector.platform?(%w(redhat ubuntu))).to eq(true) end it "returns false if the node is not of the provided platforms" do @@ -148,7 +148,7 @@ shared_examples_for "a platform introspector" do it "returns true if the node is a provided platform and platforms are provided as strings" do node.automatic_attrs[:platform_family] = "rhel" - expect(platform_introspector.platform_family?(["rhel", "debian"])).to eq(true) + expect(platform_introspector.platform_family?(%w(rhel debian))).to eq(true) end it "returns false if the node is not of the provided platforms" do diff --git a/spec/support/shared/unit/provider/file.rb b/spec/support/shared/unit/provider/file.rb index 5e5fc058e7..7ddd51db80 100644 --- a/spec/support/shared/unit/provider/file.rb +++ b/spec/support/shared/unit/provider/file.rb @@ -142,7 +142,7 @@ shared_examples_for Chef::Provider::File do end after do - tempfile.close if (tempfile && !tempfile.closed?) + tempfile.close if tempfile && !tempfile.closed? File.unlink(tempfile.path) rescue nil end diff --git a/spec/support/shared/unit/provider/useradd_based_user_provider.rb b/spec/support/shared/unit/provider/useradd_based_user_provider.rb index 6694aa346c..0b024b5b60 100644 --- a/spec/support/shared/unit/provider/useradd_based_user_provider.rb +++ b/spec/support/shared/unit/provider/useradd_based_user_provider.rb @@ -315,7 +315,7 @@ shared_examples_for "a useradd-based user provider" do |supported_useradd_option expect { provider.check_lock }.to raise_error(Chef::Exceptions::User) end - ["redhat", "centos"].each do |os| + %w(redhat centos).each do |os| it "should not raise a Chef::Exceptions::User if passwd -S exits with 1 on #{os} and the passwd package is version 0.73-1" do @node.automatic_attrs[:platform] = os expect(passwd_s_status).to receive(:exitstatus).and_return(1) diff --git a/spec/unit/audit/control_group_data_spec.rb b/spec/unit/audit/control_group_data_spec.rb index f6935a4c75..2e21a13b17 100644 --- a/spec/unit/audit/control_group_data_spec.rb +++ b/spec/unit/audit/control_group_data_spec.rb @@ -360,19 +360,19 @@ describe Chef::Audit::ControlGroupData do context "and it's the first audit" do include_examples "mixed audit results" do - let(:audit_results) { ["failure", "success", "success"] } + let(:audit_results) { %w(failure success success) } end end context "and it's an audit in the middle" do include_examples "mixed audit results" do - let(:audit_results) { ["success", "failure", "success"] } + let(:audit_results) { %w(success failure success) } end end context "and it's the last audit" do include_examples "mixed audit results" do - let(:audit_results) { ["success", "success", "failure"] } + let(:audit_results) { %w(success success failure) } end end end diff --git a/spec/unit/chef_class_spec.rb b/spec/unit/chef_class_spec.rb index 3c1200e04c..6a52e17dd5 100644 --- a/spec/unit/chef_class_spec.rb +++ b/spec/unit/chef_class_spec.rb @@ -61,14 +61,14 @@ describe "Chef class" do end context "#set_provider_priority_array" do it "should delegate to the provider_priority_map" do - expect(provider_priority_map).to receive(:set_priority_array).with(:http_request, ["a", "b"], platform: "debian").and_return("stuff") - expect(Chef.set_provider_priority_array(:http_request, ["a", "b"], platform: "debian")).to eql("stuff") + expect(provider_priority_map).to receive(:set_priority_array).with(:http_request, %w(a b), platform: "debian").and_return("stuff") + expect(Chef.set_provider_priority_array(:http_request, %w(a b), platform: "debian")).to eql("stuff") end end context "#set_priority_map_for_resource" do it "should delegate to the resource_priority_map" do - expect(resource_priority_map).to receive(:set_priority_array).with(:http_request, ["a", "b"], platform: "debian").and_return("stuff") - expect(Chef.set_resource_priority_array(:http_request, ["a", "b"], platform: "debian")).to eql("stuff") + expect(resource_priority_map).to receive(:set_priority_array).with(:http_request, %w(a b), platform: "debian").and_return("stuff") + expect(Chef.set_resource_priority_array(:http_request, %w(a b), platform: "debian")).to eql("stuff") end end end diff --git a/spec/unit/chef_fs/parallelizer.rb b/spec/unit/chef_fs/parallelizer.rb index da18117bbd..20edbcdcde 100644 --- a/spec/unit/chef_fs/parallelizer.rb +++ b/spec/unit/chef_fs/parallelizer.rb @@ -211,7 +211,7 @@ describe Chef::ChefFS::Parallelizer do occupying_job_finished[0] = true end.wait end - while !started + until started sleep(0.01) end end diff --git a/spec/unit/cookbook/metadata_spec.rb b/spec/unit/cookbook/metadata_spec.rb index ff18333e70..d914ac6692 100644 --- a/spec/unit/cookbook/metadata_spec.rb +++ b/spec/unit/cookbook/metadata_spec.rb @@ -460,7 +460,7 @@ describe Chef::Cookbook::Metadata do attrs = { "display_name" => "MySQL Databases", "description" => "Description of MySQL", - "choice" => ["dedicated", "shared"], + "choice" => %w(dedicated shared), "calculated" => false, "type" => "string", "required" => "recommended", @@ -523,7 +523,7 @@ describe Chef::Cookbook::Metadata do it "should not accept anything but an array of strings for choice" do expect { - metadata.attribute("db/mysql/databases", :choice => ["dedicated", "shared"]) + metadata.attribute("db/mysql/databases", :choice => %w(dedicated shared)) }.not_to raise_error expect { metadata.attribute("db/mysql/databases", :choice => [10, "shared"]) @@ -651,7 +651,7 @@ describe Chef::Cookbook::Metadata do it "should limit the types allowed in the choice array" do options = { :type => "string", - :choice => [ "test1", "test2" ], + :choice => %w(test1 test2), :default => "test1", } expect { @@ -706,15 +706,15 @@ describe Chef::Cookbook::Metadata do it "should allow a default that is a choice" do expect { attrs = { - :choice => [ "a", "b", "c"], + :choice => %w(a b c), :default => "b", } metadata.attribute("db/mysql/databases", attrs) }.not_to raise_error expect { attrs = { - :choice => [ "a", "b", "c", "d", "e"], - :default => ["b", "d"], + :choice => %w(a b c d e), + :default => %w(b d), } metadata.attribute("db/mysql/databases", attrs) }.not_to raise_error @@ -723,15 +723,15 @@ describe Chef::Cookbook::Metadata do it "should error if default is not a choice" do expect { attrs = { - :choice => [ "a", "b", "c"], + :choice => %w(a b c), :default => "d", } metadata.attribute("db/mysql/databases", attrs) }.to raise_error(ArgumentError) expect { attrs = { - :choice => [ "a", "b", "c", "d", "e"], - :default => ["b", "z"], + :choice => %w(a b c d e), + :default => %w(b z), } metadata.attribute("db/mysql/databases", attrs) }.to raise_error(ArgumentError) diff --git a/spec/unit/cookbook_spec.rb b/spec/unit/cookbook_spec.rb index f931b43eaa..6ec0bcd2a2 100644 --- a/spec/unit/cookbook_spec.rb +++ b/spec/unit/cookbook_spec.rb @@ -39,7 +39,7 @@ describe Chef::CookbookVersion do it "should allow you to set the list of attribute files and create the mapping from short names to paths" do @cookbook.attribute_filenames = [ "attributes/one.rb", "attributes/two.rb" ] expect(@cookbook.attribute_filenames).to eq([ "attributes/one.rb", "attributes/two.rb" ]) - expect(@cookbook.attribute_filenames_by_short_filename.keys.sort).to eql(["one", "two"]) + expect(@cookbook.attribute_filenames_by_short_filename.keys.sort).to eql(%w(one two)) expect(@cookbook.attribute_filenames_by_short_filename["one"]).to eq("attributes/one.rb") expect(@cookbook.attribute_filenames_by_short_filename["two"]).to eq("attributes/two.rb") end @@ -47,7 +47,7 @@ describe Chef::CookbookVersion do it "should allow you to set the list of recipe files and create the mapping of recipe short name to filename" do @cookbook.recipe_filenames = [ "recipes/one.rb", "recipes/two.rb" ] expect(@cookbook.recipe_filenames).to eq([ "recipes/one.rb", "recipes/two.rb" ]) - expect(@cookbook.recipe_filenames_by_name.keys.sort).to eql(["one", "two"]) + expect(@cookbook.recipe_filenames_by_name.keys.sort).to eql(%w(one two)) expect(@cookbook.recipe_filenames_by_name["one"]).to eq("recipes/one.rb") expect(@cookbook.recipe_filenames_by_name["two"]).to eq("recipes/two.rb") end diff --git a/spec/unit/dsl/reboot_pending_spec.rb b/spec/unit/dsl/reboot_pending_spec.rb index 66f8b76d7f..5cd7c7794f 100644 --- a/spec/unit/dsl/reboot_pending_spec.rb +++ b/spec/unit/dsl/reboot_pending_spec.rb @@ -92,7 +92,7 @@ describe Chef::DSL::RebootPending do describe "in a resource" do it "responds to reboot_pending?" do - resource = Chef::Resource::new("Crackerjack::Timing", nil) + resource = Chef::Resource.new("Crackerjack::Timing", nil) expect(resource).to respond_to(:reboot_pending?) end end # describe in a resource diff --git a/spec/unit/dsl/regsitry_helper_spec.rb b/spec/unit/dsl/regsitry_helper_spec.rb index d6c2257003..45c7e73979 100644 --- a/spec/unit/dsl/regsitry_helper_spec.rb +++ b/spec/unit/dsl/regsitry_helper_spec.rb @@ -26,7 +26,7 @@ describe Chef::Resource::RegistryKey do node = Chef::Node.new node.consume_external_attrs(OHAI_SYSTEM.data, {}) run_context = Chef::RunContext.new(node, {}, events) - @resource = Chef::Resource::new("foo", run_context) + @resource = Chef::Resource.new("foo", run_context) end context "tests registry dsl" do diff --git a/spec/unit/encrypted_data_bag_item_spec.rb b/spec/unit/encrypted_data_bag_item_spec.rb index 14713682e7..e3b77852b7 100644 --- a/spec/unit/encrypted_data_bag_item_spec.rb +++ b/spec/unit/encrypted_data_bag_item_spec.rb @@ -112,7 +112,7 @@ describe Chef::EncryptedDataBagItem::Encryptor do it "includes the auth_tag in the envelope" do final_data = encryptor.for_encrypted_item - expect(final_data["auth_tag"]).to eq(Base64::encode64(encryptor.auth_tag)) + expect(final_data["auth_tag"]).to eq(Base64.encode64(encryptor.auth_tag)) end it "throws an error if auth tag is read before encrypting the data" do diff --git a/spec/unit/http/validate_content_length_spec.rb b/spec/unit/http/validate_content_length_spec.rb index c054529e48..3e129dc646 100644 --- a/spec/unit/http/validate_content_length_spec.rb +++ b/spec/unit/http/validate_content_length_spec.rb @@ -107,7 +107,7 @@ describe Chef::HTTP::ValidateContentLength do describe "without Content-Length header" do let(:response_headers) { {} } - [ "direct", "streaming" ].each do |req_type| + %w(direct streaming).each do |req_type| describe "when running #{req_type} request" do let(:request_type) { req_type.to_sym } @@ -120,7 +120,7 @@ describe Chef::HTTP::ValidateContentLength do end describe "with correct Content-Length header" do - [ "direct", "streaming" ].each do |req_type| + %w(direct streaming).each do |req_type| describe "when running #{req_type} request" do let(:request_type) { req_type.to_sym } @@ -134,7 +134,7 @@ describe Chef::HTTP::ValidateContentLength do describe "with wrong Content-Length header" do let(:content_length_value) { 25 } - [ "direct", "streaming" ].each do |req_type| + %w(direct streaming).each do |req_type| describe "when running #{req_type} request" do let(:request_type) { req_type.to_sym } @@ -161,7 +161,7 @@ describe Chef::HTTP::ValidateContentLength do } } - [ "direct", "streaming" ].each do |req_type| + %w(direct streaming).each do |req_type| describe "when running #{req_type} request" do let(:request_type) { req_type.to_sym } diff --git a/spec/unit/knife/bootstrap/chef_vault_handler_spec.rb b/spec/unit/knife/bootstrap/chef_vault_handler_spec.rb index ffc851e2b5..61aa9d0ae1 100644 --- a/spec/unit/knife/bootstrap/chef_vault_handler_spec.rb +++ b/spec/unit/knife/bootstrap/chef_vault_handler_spec.rb @@ -69,14 +69,14 @@ describe Chef::Knife::Bootstrap::ChefVaultHandler do end it "sets two items as an array" do - knife_config[:bootstrap_vault_item] = { "vault" => [ "item1", "item2" ] } + knife_config[:bootstrap_vault_item] = { "vault" => %w(item1 item2) } expect(chef_vault_handler).to receive(:load_chef_bootstrap_vault_item).with("vault", "item1").and_return(bootstrap_vault_item) expect(chef_vault_handler).to receive(:load_chef_bootstrap_vault_item).with("vault", "item2").and_return(bootstrap_vault_item) chef_vault_handler.run(client) end it "sets two vaults from different hash keys" do - knife_config[:bootstrap_vault_item] = { "vault" => [ "item1", "item2" ], "vault2" => [ "item3" ] } + knife_config[:bootstrap_vault_item] = { "vault" => %w(item1 item2), "vault2" => [ "item3" ] } expect(chef_vault_handler).to receive(:load_chef_bootstrap_vault_item).with("vault", "item1").and_return(bootstrap_vault_item) expect(chef_vault_handler).to receive(:load_chef_bootstrap_vault_item).with("vault", "item2").and_return(bootstrap_vault_item) expect(chef_vault_handler).to receive(:load_chef_bootstrap_vault_item).with("vault2", "item3").and_return(bootstrap_vault_item) diff --git a/spec/unit/knife/bootstrap_spec.rb b/spec/unit/knife/bootstrap_spec.rb index e8e75e43b5..357fee3867 100644 --- a/spec/unit/knife/bootstrap_spec.rb +++ b/spec/unit/knife/bootstrap_spec.rb @@ -51,7 +51,7 @@ describe Chef::Knife::Bootstrap do context "with --bootstrap-vault-item" do let(:bootstrap_cli_options) { [ "--bootstrap-vault-item", "vault1:item1", "--bootstrap-vault-item", "vault1:item2", "--bootstrap-vault-item", "vault2:item1" ] } it "sets the knife config cli option correctly" do - expect(knife.config[:bootstrap_vault_item]).to eq({ "vault1" => ["item1", "item2"], "vault2" => ["item1"] }) + expect(knife.config[:bootstrap_vault_item]).to eq({ "vault1" => %w(item1 item2), "vault2" => ["item1"] }) end end diff --git a/spec/unit/knife/cookbook_download_spec.rb b/spec/unit/knife/cookbook_download_spec.rb index a8248a80b9..44a47d8c37 100644 --- a/spec/unit/knife/cookbook_download_spec.rb +++ b/spec/unit/knife/cookbook_download_spec.rb @@ -119,7 +119,7 @@ describe Chef::Knife::CookbookDownload do it "should download the cookbook when the cookbook download directory doesn't exist" do expect(File).to receive(:exists?).with("/var/tmp/chef/foobar-1.0.0").and_return(false) @knife.run - ["attributes", "recipes", "templates"].each do |segment| + %w(attributes recipes templates).each do |segment| expect(@stderr.string).to match /downloading #{segment}/im end expect(@stderr.string).to match /downloading foobar cookbook version 1\.0\.0/im diff --git a/spec/unit/knife/cookbook_list_spec.rb b/spec/unit/knife/cookbook_list_spec.rb index 668f9afa4b..ba834e08e2 100644 --- a/spec/unit/knife/cookbook_list_spec.rb +++ b/spec/unit/knife/cookbook_list_spec.rb @@ -23,7 +23,7 @@ describe Chef::Knife::CookbookList do @knife = Chef::Knife::CookbookList.new @rest_mock = double("rest") allow(@knife).to receive(:rest).and_return(@rest_mock) - @cookbook_names = ["apache2", "mysql"] + @cookbook_names = %w(apache2 mysql) @base_url = "https://server.example.com/cookbooks" @cookbook_data = {} @cookbook_names.each do |item| diff --git a/spec/unit/knife/cookbook_site_install_spec.rb b/spec/unit/knife/cookbook_site_install_spec.rb index b0b1e8aec2..990e9ae098 100644 --- a/spec/unit/knife/cookbook_site_install_spec.rb +++ b/spec/unit/knife/cookbook_site_install_spec.rb @@ -71,7 +71,7 @@ describe Chef::Knife::CookbookSiteInstall do end it "raises an error if more than two arguments are given" do - knife.name_args = ["foo", "bar", "baz"] + knife.name_args = %w(foo bar baz) expect(knife.ui).to receive(:error).with("Installing multiple cookbooks at once is not supported.") expect { knife.run }.to raise_error(SystemExit) end diff --git a/spec/unit/knife/cookbook_site_share_spec.rb b/spec/unit/knife/cookbook_site_share_spec.rb index 662b53dd29..4b0f82d417 100644 --- a/spec/unit/knife/cookbook_site_share_spec.rb +++ b/spec/unit/knife/cookbook_site_share_spec.rb @@ -27,7 +27,7 @@ describe Chef::Knife::CookbookSiteShare do @knife = Chef::Knife::CookbookSiteShare.new # Merge default settings in. @knife.merge_configs - @knife.name_args = ["cookbook_name", "AwesomeSausage"] + @knife.name_args = %w(cookbook_name AwesomeSausage) @cookbook = Chef::CookbookVersion.new("cookbook_name") diff --git a/spec/unit/knife/cookbook_test_spec.rb b/spec/unit/knife/cookbook_test_spec.rb index abb88fe739..7f009f99d2 100644 --- a/spec/unit/knife/cookbook_test_spec.rb +++ b/spec/unit/knife/cookbook_test_spec.rb @@ -45,7 +45,7 @@ describe Chef::Knife::CookbookTest do it "should test multiple cookbooks when provided" do allow(@knife).to receive(:test_cookbook).and_return(true) - @knife.name_args = ["tats", "jimmy_johns"] + @knife.name_args = %w(tats jimmy_johns) expect(@knife).to receive(:test_cookbook).with("tats") expect(@knife).to receive(:test_cookbook).with("jimmy_johns") expect(@knife).not_to receive(:test_cookbook).with("central_market") @@ -56,7 +56,7 @@ describe Chef::Knife::CookbookTest do it "should test both ruby and templates" do @knife.name_args = ["example"] expect(@knife.config[:cookbook_path]).not_to be_empty - Array(@knife.config[:cookbook_path]).reverse.each do |path| + Array(@knife.config[:cookbook_path]).reverse_each do |path| expect(@knife).to receive(:test_ruby).with(an_instance_of(Chef::Cookbook::SyntaxCheck)) expect(@knife).to receive(:test_templates).with(an_instance_of(Chef::Cookbook::SyntaxCheck)) end diff --git a/spec/unit/knife/cookbook_upload_spec.rb b/spec/unit/knife/cookbook_upload_spec.rb index dc55a709b7..eb2b1f9856 100644 --- a/spec/unit/knife/cookbook_upload_spec.rb +++ b/spec/unit/knife/cookbook_upload_spec.rb @@ -96,7 +96,7 @@ describe Chef::Knife::CookbookUpload do describe "when specifying the same cookbook name twice" do it "should upload the cookbook only once" do - knife.name_args = ["test_cookbook", "test_cookbook"] + knife.name_args = %w(test_cookbook test_cookbook) expect(knife).to receive(:upload).once knife.run end @@ -181,10 +181,10 @@ E it "should upload all dependencies once" do knife.config[:depends] = true - allow(knife).to receive(:cookbook_names).and_return(["test_cookbook1", "test_cookbook2", "test_cookbook3"]) + 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 - Timeout::timeout(5) do + Timeout.timeout(5) do knife.run end end.not_to raise_error @@ -200,7 +200,7 @@ E { "test_cookbook" => cookbook, "dependency" => cookbook_dependency }[ckbk] end - allow(knife).to receive(:cookbook_names).and_return(["cookbook_dependency", "test_cookbook"]) + allow(knife).to receive(:cookbook_names).and_return(%w(cookbook_dependency test_cookbook)) @stdout, @stderr, @stdin = StringIO.new, StringIO.new, StringIO.new knife.ui = Chef::Knife::UI.new(@stdout, @stderr, @stdin, {}) end @@ -227,7 +227,7 @@ E "dependency" => cookbook_dependency, "dependency2" => cookbook_dependency2 }[ckbk] end - allow(knife).to receive(:cookbook_names).and_return(["dependency", "dependency2", "test_cookbook"]) + allow(knife).to receive(:cookbook_names).and_return(%w(dependency dependency2 test_cookbook)) expect { knife.run }.to raise_error(SystemExit) expect(@stderr.string).to include("Cookbook test_cookbook depends on cookbooks which are not currently") expect(@stderr.string).to include("being uploaded and cannot be found on the server.") @@ -253,7 +253,7 @@ E @test_cookbook1 = Chef::CookbookVersion.new("test_cookbook1", "/tmp/blah") @test_cookbook2 = Chef::CookbookVersion.new("test_cookbook2", "/tmp/blah") allow(cookbook_loader).to receive(:each).and_yield("test_cookbook1", @test_cookbook1).and_yield("test_cookbook2", @test_cookbook2) - allow(cookbook_loader).to receive(:cookbook_names).and_return(["test_cookbook1", "test_cookbook2"]) + allow(cookbook_loader).to receive(:cookbook_names).and_return(%w(test_cookbook1 test_cookbook2)) end it "should upload all cookbooks" do diff --git a/spec/unit/knife/core/hashed_command_loader_spec.rb b/spec/unit/knife/core/hashed_command_loader_spec.rb index d9f5e5761c..5c4a33b7e0 100644 --- a/spec/unit/knife/core/hashed_command_loader_spec.rb +++ b/spec/unit/knife/core/hashed_command_loader_spec.rb @@ -83,7 +83,7 @@ describe Chef::Knife::SubcommandLoader::HashedCommandLoader do end it "finds the right subcommand even when _'s are elided" do - expect(loader.subcommand_for_args(["cooler", "b"])).to eq("cooler_b") + expect(loader.subcommand_for_args(%w(cooler b))).to eq("cooler_b") end it "returns nil if the the subcommand isn't in our manifest" do diff --git a/spec/unit/knife/core/ui_spec.rb b/spec/unit/knife/core/ui_spec.rb index d2381f60cb..b5e4aefab6 100644 --- a/spec/unit/knife/core/ui_spec.rb +++ b/spec/unit/knife/core/ui_spec.rb @@ -205,7 +205,7 @@ EOM end it "formats arrays appropriately" do - @ui.output([ "a", "b" ]) + @ui.output(%w(a b)) expect(@out.string).to eq <<EOM a b @@ -228,7 +228,7 @@ EOM end it "formats nested arrays appropriately" do - @ui.output([ [ "a", "b" ], [ "c", "d" ]]) + @ui.output([ %w(a b), %w(c d)]) expect(@out.string).to eq <<EOM a b @@ -239,7 +239,7 @@ EOM end it "formats nested arrays with single- and empty subarrays appropriately" do - @ui.output([ [ "a", "b" ], [ "c" ], [], [ "d", "e" ]]) + @ui.output([ %w(a b), [ "c" ], [], %w(d e)]) expect(@out.string).to eq <<EOM a b @@ -282,7 +282,7 @@ EOM end it "formats hashes with array members appropriately" do - @ui.output({ "a" => [ "foo", "bar" ], "b" => "c" }) + @ui.output({ "a" => %w(foo bar), "b" => "c" }) expect(@out.string).to eq <<EOM a: foo @@ -301,7 +301,7 @@ EOM end it "formats hashes with nested array values appropriately" do - @ui.output({ "a" => [ [ "foo", "bar" ], [ "baz", "bjork" ] ], "b" => "c" }) + @ui.output({ "a" => [ %w(foo bar), %w(baz bjork) ], "b" => "c" }) # XXX: using a HEREDOC at this point results in a line with required spaces which auto-whitespace removal settings # on editors will remove and will break this test. expect(@out.string).to eq("a:\n foo\n bar\n \n baz\n bjork\nb: c\n") @@ -353,7 +353,7 @@ EOM it "should return multiple attributes" do input = { "gi" => "go", "hi" => "ho", "id" => "sample-data-bag-item" } - @ui.config[:attribute] = ["gi", "hi"] + @ui.config[:attribute] = %w(gi hi) expect(@ui.format_for_display(input)).to eq({ "sample-data-bag-item" => { "gi" => "go", "hi" => "ho" } }) end @@ -545,7 +545,7 @@ EOM end end - ["Y", "y"].each do |answer| + %w(Y y).each do |answer| describe "with answer #{answer}" do let(:answer) { answer } @@ -553,7 +553,7 @@ EOM end end - ["N", "n"].each do |answer| + %w(N n).each do |answer| describe "with answer #{answer}" do let(:answer) { answer } diff --git a/spec/unit/knife/environment_compare_spec.rb b/spec/unit/knife/environment_compare_spec.rb index 7a341192be..9d9a61a32f 100644 --- a/spec/unit/knife/environment_compare_spec.rb +++ b/spec/unit/knife/environment_compare_spec.rb @@ -42,7 +42,7 @@ describe Chef::Knife::EnvironmentCompare do @rest_double = double("rest") allow(@knife).to receive(:rest).and_return(@rest_double) - @cookbook_names = ["apache2", "mysql", "foo", "bar", "dummy", "chef_handler"] + @cookbook_names = %w(apache2 mysql foo bar dummy chef_handler) @base_url = "https://server.example.com/cookbooks" @cookbook_data = {} @cookbook_names.each do |item| diff --git a/spec/unit/knife/node_environment_set_spec.rb b/spec/unit/knife/node_environment_set_spec.rb index 13dd3762a2..ea4112fe87 100644 --- a/spec/unit/knife/node_environment_set_spec.rb +++ b/spec/unit/knife/node_environment_set_spec.rb @@ -22,7 +22,7 @@ describe Chef::Knife::NodeEnvironmentSet do before(:each) do Chef::Config[:node_name] = "webmonkey.example.com" @knife = Chef::Knife::NodeEnvironmentSet.new - @knife.name_args = [ "adam", "bar" ] + @knife.name_args = %w(adam bar) allow(@knife).to receive(:output).and_return(true) @node = Chef::Node.new() @node.name("knifetest-node") diff --git a/spec/unit/knife/node_list_spec.rb b/spec/unit/knife/node_list_spec.rb index ab17a45795..fbbe6bee06 100644 --- a/spec/unit/knife/node_list_spec.rb +++ b/spec/unit/knife/node_list_spec.rb @@ -40,7 +40,7 @@ describe Chef::Knife::NodeList do it "should pretty print the list" do expect(Chef::Node).to receive(:list).and_return(@list) - expect(@knife).to receive(:output).with([ "bar", "foo" ]) + expect(@knife).to receive(:output).with(%w(bar foo)) @knife.run end diff --git a/spec/unit/knife/node_run_list_remove_spec.rb b/spec/unit/knife/node_run_list_remove_spec.rb index e741f513eb..c5c7696091 100644 --- a/spec/unit/knife/node_run_list_remove_spec.rb +++ b/spec/unit/knife/node_run_list_remove_spec.rb @@ -96,7 +96,7 @@ describe Chef::Knife::NodeRunListRemove do it "should warn even more when the thing to remove is not in the runlist and unqualified" do @node.run_list << "role[blah]" @node.run_list << "recipe[duck::type]" - @knife.name_args = [ "adam", "blork" ] + @knife.name_args = %w(adam blork) expect(@knife.ui).to receive(:warn).with("blork is not in the run list") expect(@knife.ui).to receive(:warn).with(/did you forget recipe\[\] or role\[\]/) @knife.run diff --git a/spec/unit/knife/role_env_run_list_clear_spec.rb b/spec/unit/knife/role_env_run_list_clear_spec.rb index 1fb2f1f1c7..b843394c29 100644 --- a/spec/unit/knife/role_env_run_list_clear_spec.rb +++ b/spec/unit/knife/role_env_run_list_clear_spec.rb @@ -30,7 +30,7 @@ describe Chef::Knife::RoleEnvRunListClear do @knife.config = { :print_after => nil } - @knife.name_args = [ "will", "QA" ] + @knife.name_args = %w(will QA) allow(@knife).to receive(:output).and_return(true) @role = Chef::Role.new() @@ -79,7 +79,7 @@ describe Chef::Knife::RoleEnvRunListClear do @setup.run @setup.name_args = [ "will", "PRD", "recipe[orange::chicken]", "role[monkey]", "recipe[duck::type]", "role[person]", "role[bird]", "role[town]" ] @setup.run - @knife.name_args = [ "will", "QA" ] + @knife.name_args = %w(will QA) @knife.run expect(@role.run_list_for("QA")[0]).to be_nil expect(@role.run_list_for("PRD")[0]).to eq("recipe[orange::chicken]") diff --git a/spec/unit/knife/role_list_spec.rb b/spec/unit/knife/role_list_spec.rb index bfbba30288..b244039520 100644 --- a/spec/unit/knife/role_list_spec.rb +++ b/spec/unit/knife/role_list_spec.rb @@ -38,7 +38,7 @@ describe Chef::Knife::RoleList do it "should pretty print the list" do expect(Chef::Role).to receive(:list).and_return(@list) - expect(@knife).to receive(:output).with([ "bar", "foo" ]) + expect(@knife).to receive(:output).with(%w(bar foo)) @knife.run end diff --git a/spec/unit/knife/tag_delete_spec.rb b/spec/unit/knife/tag_delete_spec.rb index 3095eda191..43f06de23f 100644 --- a/spec/unit/knife/tag_delete_spec.rb +++ b/spec/unit/knife/tag_delete_spec.rb @@ -16,7 +16,7 @@ describe Chef::Knife::TagDelete do describe "run" do it "can delete tags on a node" do - expect(@node.tags).to eq(["sadtag", "happytag"]) + expect(@node.tags).to eq(%w(sadtag happytag)) @knife.run expect(@node.tags).to eq(["happytag"]) expect(@stderr.string).to match /deleted.+sadtag/i diff --git a/spec/unit/knife/user_create_spec.rb b/spec/unit/knife/user_create_spec.rb index 5ab77d2df6..1a5a394912 100644 --- a/spec/unit/knife/user_create_spec.rb +++ b/spec/unit/knife/user_create_spec.rb @@ -79,7 +79,7 @@ describe Chef::Knife::UserCreate do context "when FIRST_NAME isn't specified" do # from spec/support/shared/unit/knife_shared.rb it_should_behave_like "mandatory field missing" do - let(:name_args) { ["some_user", "some_display_name"] } + let(:name_args) { %w(some_user some_display_name) } let(:fieldname) { "first name" } end end @@ -87,7 +87,7 @@ describe Chef::Knife::UserCreate do context "when LAST_NAME isn't specified" do # from spec/support/shared/unit/knife_shared.rb it_should_behave_like "mandatory field missing" do - let(:name_args) { ["some_user", "some_display_name", "some_first_name"] } + let(:name_args) { %w(some_user some_display_name some_first_name) } let(:fieldname) { "last name" } end end @@ -95,7 +95,7 @@ describe Chef::Knife::UserCreate do context "when EMAIL isn't specified" do # from spec/support/shared/unit/knife_shared.rb it_should_behave_like "mandatory field missing" do - let(:name_args) { ["some_user", "some_display_name", "some_first_name", "some_last_name"] } + let(:name_args) { %w(some_user some_display_name some_first_name some_last_name) } let(:fieldname) { "email" } end end @@ -103,14 +103,14 @@ describe Chef::Knife::UserCreate do context "when PASSWORD isn't specified" do # from spec/support/shared/unit/knife_shared.rb it_should_behave_like "mandatory field missing" do - let(:name_args) { ["some_user", "some_display_name", "some_first_name", "some_last_name", "some_email"] } + let(:name_args) { %w(some_user some_display_name some_first_name some_last_name some_email) } let(:fieldname) { "password" } end end context "when all mandatory fields are validly specified" do before do - knife.name_args = ["some_user", "some_display_name", "some_first_name", "some_last_name", "some_email", "some_password"] + knife.name_args = %w(some_user some_display_name some_first_name some_last_name some_email some_password) allow(knife).to receive(:edit_data).and_return(knife.user.to_hash) allow(knife).to receive(:create_user_from_hash).and_return(knife.user) end diff --git a/spec/unit/mixin/deep_merge_spec.rb b/spec/unit/mixin/deep_merge_spec.rb index 2850193eb6..6a9ea55d2e 100644 --- a/spec/unit/mixin/deep_merge_spec.rb +++ b/spec/unit/mixin/deep_merge_spec.rb @@ -41,7 +41,7 @@ describe Chef::Mixin::DeepMerge, "deep_merge!" do end it "tests merging an hash w/array into blank hash" do - hash_src = { "region" => { "id" => ["227", "2"] } } + hash_src = { "region" => { "id" => %w(227 2) } } hash_dst = {} @dm.deep_merge!(hash_src, hash_dst) expect(hash_dst).to eq(hash_src) @@ -49,16 +49,16 @@ describe Chef::Mixin::DeepMerge, "deep_merge!" do it "tests merge from empty hash" do hash_src = {} - hash_dst = { "property" => ["2", "4"] } + hash_dst = { "property" => %w(2 4) } @dm.deep_merge!(hash_src, hash_dst) - expect(hash_dst).to eq({ "property" => ["2", "4"] }) + expect(hash_dst).to eq({ "property" => %w(2 4) }) end it "tests merge to empty hash" do - hash_src = { "property" => ["2", "4"] } + hash_src = { "property" => %w(2 4) } hash_dst = {} @dm.deep_merge!(hash_src, hash_dst) - expect(hash_dst).to eq({ "property" => ["2", "4"] }) + expect(hash_dst).to eq({ "property" => %w(2 4) }) end it "tests simple string overwrite" do @@ -76,36 +76,36 @@ describe Chef::Mixin::DeepMerge, "deep_merge!" do end it "tests hashes holding array" do - hash_src = { "property" => ["1", "3"] } - hash_dst = { "property" => ["2", "4"] } + hash_src = { "property" => %w(1 3) } + hash_dst = { "property" => %w(2 4) } @dm.deep_merge!(hash_src, hash_dst) - expect(hash_dst).to eq({ "property" => ["2", "4", "1", "3"] }) + expect(hash_dst).to eq({ "property" => %w(2 4 1 3) }) end it "tests hashes holding hashes holding arrays (array with duplicate elements is merged with dest then src" do - hash_src = { "property" => { "bedroom_count" => ["1", "2"], "bathroom_count" => ["1", "4+"] } } - hash_dst = { "property" => { "bedroom_count" => ["3", "2"], "bathroom_count" => ["2"] } } + hash_src = { "property" => { "bedroom_count" => %w(1 2), "bathroom_count" => ["1", "4+"] } } + hash_dst = { "property" => { "bedroom_count" => %w(3 2), "bathroom_count" => ["2"] } } @dm.deep_merge!(hash_src, hash_dst) - expect(hash_dst).to eq({ "property" => { "bedroom_count" => ["3", "2", "1"], "bathroom_count" => ["2", "1", "4+"] } }) + expect(hash_dst).to eq({ "property" => { "bedroom_count" => %w(3 2 1), "bathroom_count" => ["2", "1", "4+"] } }) end it "tests hash holding hash holding array v string (string is overwritten by array)" do - hash_src = { "property" => { "bedroom_count" => ["1", "2"], "bathroom_count" => ["1", "4+"] } } + hash_src = { "property" => { "bedroom_count" => %w(1 2), "bathroom_count" => ["1", "4+"] } } hash_dst = { "property" => { "bedroom_count" => "3", "bathroom_count" => ["2"] } } @dm.deep_merge!(hash_src, hash_dst) - expect(hash_dst).to eq({ "property" => { "bedroom_count" => ["1", "2"], "bathroom_count" => ["2", "1", "4+"] } }) + expect(hash_dst).to eq({ "property" => { "bedroom_count" => %w(1 2), "bathroom_count" => ["2", "1", "4+"] } }) end it "tests hash holding hash holding string v array (array is overwritten by string)" do hash_src = { "property" => { "bedroom_count" => "3", "bathroom_count" => ["1", "4+"] } } - hash_dst = { "property" => { "bedroom_count" => ["1", "2"], "bathroom_count" => ["2"] } } + hash_dst = { "property" => { "bedroom_count" => %w(1 2), "bathroom_count" => ["2"] } } @dm.deep_merge!(hash_src, hash_dst) expect(hash_dst).to eq({ "property" => { "bedroom_count" => "3", "bathroom_count" => ["2", "1", "4+"] } }) end it "tests hash holding hash holding hash v array (array is overwritten by hash)" do hash_src = { "property" => { "bedroom_count" => { "king_bed" => 3, "queen_bed" => 1 }, "bathroom_count" => ["1", "4+"] } } - hash_dst = { "property" => { "bedroom_count" => ["1", "2"], "bathroom_count" => ["2"] } } + hash_dst = { "property" => { "bedroom_count" => %w(1 2), "bathroom_count" => ["2"] } } @dm.deep_merge!(hash_src, hash_dst) expect(hash_dst).to eq({ "property" => { "bedroom_count" => { "king_bed" => 3, "queen_bed" => 1 }, "bathroom_count" => ["2", "1", "4+"] } }) end @@ -142,21 +142,21 @@ describe Chef::Mixin::DeepMerge, "deep_merge!" do hash_src = { "property" => { "bedroom_count" => { "king_bed" => 3, "queen_bed" => [1] }, "bathroom_count" => ["1"] } } hash_dst = { "property" => { "bedroom_count" => { "king_bed" => [2], "queen_bed" => [4] }, "bathroom_count" => ["2"] } } @dm.deep_merge!(hash_src, hash_dst) - expect(hash_dst).to eq({ "property" => { "bedroom_count" => { "king_bed" => 3, "queen_bed" => [4, 1] }, "bathroom_count" => ["2", "1"] } }) + expect(hash_dst).to eq({ "property" => { "bedroom_count" => { "king_bed" => 3, "queen_bed" => [4, 1] }, "bathroom_count" => %w(2 1) } }) end it "tests 3 hash layers holding arrays of int, but source is incomplete." do hash_src = { "property" => { "bedroom_count" => { "king_bed" => [3] }, "bathroom_count" => ["1"] } } hash_dst = { "property" => { "bedroom_count" => { "king_bed" => [2], "queen_bed" => [4] }, "bathroom_count" => ["2"] } } @dm.deep_merge!(hash_src, hash_dst) - expect(hash_dst).to eq({ "property" => { "bedroom_count" => { "king_bed" => [2, 3], "queen_bed" => [4] }, "bathroom_count" => ["2", "1"] } }) + expect(hash_dst).to eq({ "property" => { "bedroom_count" => { "king_bed" => [2, 3], "queen_bed" => [4] }, "bathroom_count" => %w(2 1) } }) end it "tests 3 hash layers holding arrays of int, but source is shorter and has new 2nd level ints." do hash_src = { "property" => { "bedroom_count" => { 2 => 3, "king_bed" => [3] }, "bathroom_count" => ["1"] } } hash_dst = { "property" => { "bedroom_count" => { "king_bed" => [2], "queen_bed" => [4] }, "bathroom_count" => ["2"] } } @dm.deep_merge!(hash_src, hash_dst) - expect(hash_dst).to eq({ "property" => { "bedroom_count" => { 2 => 3, "king_bed" => [2, 3], "queen_bed" => [4] }, "bathroom_count" => ["2", "1"] } }) + expect(hash_dst).to eq({ "property" => { "bedroom_count" => { 2 => 3, "king_bed" => [2, 3], "queen_bed" => [4] }, "bathroom_count" => %w(2 1) } }) end it "tests 3 hash layers holding arrays of int, but source is empty" do @@ -174,10 +174,10 @@ describe Chef::Mixin::DeepMerge, "deep_merge!" do end it "tests hash holding arrays of arrays" do - hash_src = { ["1", "2", "3"] => ["1", "2"] } - hash_dst = { ["4", "5"] => ["3"] } + hash_src = { %w(1 2 3) => %w(1 2) } + hash_dst = { %w(4 5) => ["3"] } @dm.deep_merge!(hash_src, hash_dst) - expect(hash_dst).to eq({ ["1", "2", "3"] => ["1", "2"], ["4", "5"] => ["3"] }) + expect(hash_dst).to eq({ %w(1 2 3) => %w(1 2), %w(4 5) => ["3"] }) end it "tests merging of hash with blank hash, and make sure that source array split does not function when turned off" do @@ -253,7 +253,7 @@ describe Chef::Mixin::DeepMerge do it "should merge a nested hash into an empty hash" do hash_dst = {} - hash_src = { "region" => { "id" => ["227", "2"] } } + hash_src = { "region" => { "id" => %w(227 2) } } expect(@dm.merge(hash_dst, hash_src)).to eq(hash_src) end @@ -264,9 +264,9 @@ describe Chef::Mixin::DeepMerge do end it "should merge arrays within hashes" do - hash_dst = { "property" => ["2", "4"] } - hash_src = { "property" => ["1", "3"] } - expect(@dm.merge(hash_dst, hash_src)).to eq({ "property" => ["2", "4", "1", "3"] }) + hash_dst = { "property" => %w(2 4) } + hash_src = { "property" => %w(1 3) } + expect(@dm.merge(hash_dst, hash_src)).to eq({ "property" => %w(2 4 1 3) }) end it "should merge deeply nested hashes" do @@ -276,12 +276,12 @@ describe Chef::Mixin::DeepMerge do end it "should not modify the source or destination during the merge" do - hash_dst = { "property" => ["1", "2", "3"] } - hash_src = { "property" => ["4", "5", "6"] } + hash_dst = { "property" => %w(1 2 3) } + hash_src = { "property" => %w(4 5 6) } ret = @dm.merge(hash_dst, hash_src) - expect(hash_dst).to eq({ "property" => ["1", "2", "3"] }) - expect(hash_src).to eq({ "property" => ["4", "5", "6"] }) - expect(ret).to eq({ "property" => ["1", "2", "3", "4", "5", "6"] }) + expect(hash_dst).to eq({ "property" => %w(1 2 3) }) + expect(hash_src).to eq({ "property" => %w(4 5 6) }) + expect(ret).to eq({ "property" => %w(1 2 3 4 5 6) }) end it "should not error merging un-dupable objects" do diff --git a/spec/unit/mixin/params_validate_spec.rb b/spec/unit/mixin/params_validate_spec.rb index 259b89032e..ae0cdcc803 100644 --- a/spec/unit/mixin/params_validate_spec.rb +++ b/spec/unit/mixin/params_validate_spec.rb @@ -144,7 +144,7 @@ describe Chef::Mixin::ParamsValidate do { :one => @vo }, { :one => { - :respond_to => ["validate", "music"] + :respond_to => %w(validate music) } }, ) @@ -155,7 +155,7 @@ describe Chef::Mixin::ParamsValidate do { :one => @vo }, { :one => { - :respond_to => ["monkey", "validate"] + :respond_to => %w(monkey validate) } }, ) diff --git a/spec/unit/mixin/properties_spec.rb b/spec/unit/mixin/properties_spec.rb index 00e339a221..95babb2fe7 100644 --- a/spec/unit/mixin/properties_spec.rb +++ b/spec/unit/mixin/properties_spec.rb @@ -9,8 +9,8 @@ module ChefMixinPropertiesSpec class A include Chef::Mixin::Properties property :a, "a", default: "a" - property :ab, ["a", "b"], default: "a" - property :ac, ["a", "c"], default: "a" + property :ab, %w(a b), default: "a" + property :ac, %w(a c), default: "a" end context "and a module B with properties b, ab and bc" do @@ -18,7 +18,7 @@ module ChefMixinPropertiesSpec include Chef::Mixin::Properties property :b, "b", default: "b" property :ab, default: "b" - property :bc, ["b", "c"], default: "c" + property :bc, %w(b c), default: "c" end context "and a derived class C < A with properties c, ac and bc" do @@ -32,22 +32,22 @@ module ChefMixinPropertiesSpec it "A.properties has a, ab, and ac with types 'a', ['a', 'b'], and ['b', 'c']" do expect(A.properties.keys).to eq [ :a, :ab, :ac ] expect(A.properties[:a].validation_options[:is]).to eq "a" - expect(A.properties[:ab].validation_options[:is]).to eq [ "a", "b" ] - expect(A.properties[:ac].validation_options[:is]).to eq [ "a", "c" ] + expect(A.properties[:ab].validation_options[:is]).to eq %w(a b) + expect(A.properties[:ac].validation_options[:is]).to eq %w(a c) end it "B.properties has b, ab, and bc with types 'b', nil and ['b', 'c']" do expect(B.properties.keys).to eq [ :b, :ab, :bc ] expect(B.properties[:b].validation_options[:is]).to eq "b" expect(B.properties[:ab].validation_options[:is]).to be_nil - expect(B.properties[:bc].validation_options[:is]).to eq [ "b", "c" ] + expect(B.properties[:bc].validation_options[:is]).to eq %w(b c) end it "C.properties has a, b, c, ac and bc with merged types" do expect(C.properties.keys).to eq [ :a, :ab, :ac, :b, :bc, :c ] expect(C.properties[:a].validation_options[:is]).to eq "a" expect(C.properties[:b].validation_options[:is]).to eq "b" expect(C.properties[:c].validation_options[:is]).to eq "c" - expect(C.properties[:ac].validation_options[:is]).to eq [ "a", "c" ] - expect(C.properties[:bc].validation_options[:is]).to eq [ "b", "c" ] + expect(C.properties[:ac].validation_options[:is]).to eq %w(a c) + expect(C.properties[:bc].validation_options[:is]).to eq %w(b c) end it "C.properties has ab with a non-merged type (from B)" do expect(C.properties[:ab].validation_options[:is]).to be_nil diff --git a/spec/unit/mixin/template_spec.rb b/spec/unit/mixin/template_spec.rb index 48150f7198..1021cbc5f3 100644 --- a/spec/unit/mixin/template_spec.rb +++ b/spec/unit/mixin/template_spec.rb @@ -209,7 +209,7 @@ describe Chef::Mixin::Template, "render_template" do def render_template_from_string end end - ["node", "render", "render_template", "render_template_from_string"].each do |method_name| + %w(node render render_template render_template_from_string).each do |method_name| expect(Chef::Log).to receive(:warn).with(/^Core template method `#{method_name}' overridden by extension module/) end @template_context._extend_modules([mod]) diff --git a/spec/unit/mixin/windows_architecture_helper_spec.rb b/spec/unit/mixin/windows_architecture_helper_spec.rb index aaf9fa4b2b..59b03b4726 100644 --- a/spec/unit/mixin/windows_architecture_helper_spec.rb +++ b/spec/unit/mixin/windows_architecture_helper_spec.rb @@ -59,14 +59,14 @@ describe Chef::Mixin::WindowsArchitectureHelper do it "returns true only for supported desired architecture passed to node_supports_windows_architecture" do with_node_architecture_combinations do |node, desired_arch| - expect(node_supports_windows_architecture?(node, desired_arch)).to be true if (node_windows_architecture(node) == :x86_64 || desired_arch == :i386 ) - expect(node_supports_windows_architecture?(node, desired_arch)).to be false if (node_windows_architecture(node) == :i386 && desired_arch == :x86_64 ) + expect(node_supports_windows_architecture?(node, desired_arch)).to be true if node_windows_architecture(node) == :x86_64 || desired_arch == :i386 + expect(node_supports_windows_architecture?(node, desired_arch)).to be false if node_windows_architecture(node) == :i386 && desired_arch == :x86_64 end end it "returns true only when forced_32bit_override_required? has 64-bit node architecture and 32-bit desired architecture" do with_node_architecture_combinations do |node, desired_arch| - expect(forced_32bit_override_required?(node, desired_arch)).to be true if ((node_windows_architecture(node) == :x86_64) && (desired_arch == :i386) && !is_i386_process_on_x86_64_windows?) + expect(forced_32bit_override_required?(node, desired_arch)).to be true if (node_windows_architecture(node) == :x86_64) && (desired_arch == :i386) && !is_i386_process_on_x86_64_windows? expect(forced_32bit_override_required?(node, desired_arch)).to be false if ! ((node_windows_architecture(node) == :x86_64) && (desired_arch == :i386)) end end diff --git a/spec/unit/node/attribute_spec.rb b/spec/unit/node/attribute_spec.rb index c69748ac49..4bef0f1c71 100644 --- a/spec/unit/node/attribute_spec.rb +++ b/spec/unit/node/attribute_spec.rb @@ -29,7 +29,7 @@ describe Chef::Node::Attribute do "platform" => "mac_os_x", "ipaddress" => "192.168.0.117", "network" => { "default_interface" => "en1", - "interfaces" => { "vmnet1" => { "flags" => ["UP", "BROADCAST", "SMART", "RUNNING", "SIMPLEX", "MULTICAST"], + "interfaces" => { "vmnet1" => { "flags" => %w(UP BROADCAST SMART RUNNING SIMPLEX MULTICAST), "number" => "1", "addresses" => { "00:50:56:c0:00:01" => { "family" => "lladdr" }, "192.168.110.1" => { "broadcast" => "192.168.110.255", @@ -45,7 +45,7 @@ describe Chef::Node::Attribute do "mtu" => "1280", "type" => "stf", "encapsulation" => "6to4" }, - "lo0" => { "flags" => ["UP", "LOOPBACK", "RUNNING", "MULTICAST"], + "lo0" => { "flags" => %w(UP LOOPBACK RUNNING MULTICAST), "number" => "0", "addresses" => { "::1" => { "scope" => "Node", "prefixlen" => "128", "family" => "inet6" }, "127.0.0.1" => { "netmask" => "255.0.0.0", "family" => "inet" }, @@ -53,13 +53,13 @@ describe Chef::Node::Attribute do "mtu" => "16384", "type" => "lo", "encapsulation" => "Loopback" }, - "gif0" => { "flags" => ["POINTOPOINT", "MULTICAST"], + "gif0" => { "flags" => %w(POINTOPOINT MULTICAST), "number" => "0", "addresses" => {}, "mtu" => "1280", "type" => "gif", "encapsulation" => "IPIP" }, - "vmnet8" => { "flags" => ["UP", "BROADCAST", "SMART", "RUNNING", "SIMPLEX", "MULTICAST"], + "vmnet8" => { "flags" => %w(UP BROADCAST SMART RUNNING SIMPLEX MULTICAST), "number" => "8", "addresses" => { "192.168.4.1" => { "broadcast" => "192.168.4.255", "netmask" => "255.255.255.0", @@ -70,7 +70,7 @@ describe Chef::Node::Attribute do "arp" => { "192.168.4.255" => "ff:ff:ff:ff:ff:ff" }, "encapsulation" => "Ethernet" }, "en0" => { "status" => "inactive", - "flags" => ["UP", "BROADCAST", "SMART", "RUNNING", "SIMPLEX", "MULTICAST"], + "flags" => %w(UP BROADCAST SMART RUNNING SIMPLEX MULTICAST), "number" => "0", "addresses" => { "00:23:32:b0:32:f2" => { "family" => "lladdr" } }, "mtu" => "1500", @@ -83,7 +83,7 @@ describe Chef::Node::Attribute do "type" => "en", "encapsulation" => "Ethernet" }, "en1" => { "status" => "active", - "flags" => ["UP", "BROADCAST", "SMART", "RUNNING", "SIMPLEX", "MULTICAST"], + "flags" => %w(UP BROADCAST SMART RUNNING SIMPLEX MULTICAST), "number" => "1", "addresses" => { "fe80::223:6cff:fe7f:676c" => { "scope" => "Link", "prefixlen" => "64", "family" => "inet6" }, "00:23:6c:7f:67:6c" => { "family" => "lladdr" }, @@ -102,7 +102,7 @@ describe Chef::Node::Attribute do "192.168.0.152" => "0:26:8:7d:2:4c" }, "encapsulation" => "Ethernet" }, "en2" => { "status" => "active", - "flags" => ["UP", "BROADCAST", "SMART", "RUNNING", "SIMPLEX", "MULTICAST"], + "flags" => %w(UP BROADCAST SMART RUNNING SIMPLEX MULTICAST), "number" => "2", "addresses" => { "169.254.206.152" => { "broadcast" => "169.254.255.255", "netmask" => "255.255.0.0", @@ -115,7 +115,7 @@ describe Chef::Node::Attribute do "type" => "en", "encapsulation" => "Ethernet" }, "fw0" => { "status" => "inactive", - "flags" => ["BROADCAST", "SIMPLEX", "MULTICAST"], + "flags" => %w(BROADCAST SIMPLEX MULTICAST), "number" => "0", "addresses" => { "00:23:32:ff:fe:b0:32:f2" => { "family" => "lladdr" } }, "mtu" => "4078", @@ -124,7 +124,7 @@ describe Chef::Node::Attribute do "type" => "fw", "encapsulation" => "1394" }, "en3" => { "status" => "active", - "flags" => ["UP", "BROADCAST", "SMART", "RUNNING", "SIMPLEX", "MULTICAST"], + "flags" => %w(UP BROADCAST SMART RUNNING SIMPLEX MULTICAST), "number" => "3", "addresses" => { "169.254.206.152" => { "broadcast" => "169.254.255.255", "netmask" => "255.255.0.0", @@ -219,16 +219,16 @@ describe Chef::Node::Attribute do it "gives the value at each level of precedence for a path spec" do expected = [["set_unless_enabled?", false], - ["default", "default"], - ["env_default", "env_default"], - ["role_default", "role_default"], - ["force_default", "force_default"], - ["normal", "normal"], - ["override", "override"], - ["role_override", "role_override"], - ["env_override", "env_override"], - ["force_override", "force_override"], - ["automatic", "automatic"], + %w(default default), + %w(env_default env_default), + %w(role_default role_default), + %w(force_default force_default), + %w(normal normal), + %w(override override), + %w(role_override role_override), + %w(env_override env_override), + %w(force_override force_override), + %w(automatic automatic), ] expect(@attributes.debug_value(:foo, :bar)).to eq(expected) end @@ -457,7 +457,7 @@ describe Chef::Node::Attribute do hash = @attributes["foo"].to_hash expect(hash).to eql({ "bar" => [ "fizz" ] }) hash["bar"].push("buzz") - expect(hash).to eql({ "bar" => [ "fizz", "buzz" ] }) + expect(hash).to eql({ "bar" => %w(fizz buzz) }) expect(@attributes.default["foo"]).to eql({ "bar" => [ "fizz" ] }) end @@ -537,8 +537,8 @@ describe Chef::Node::Attribute do end it "should allow the last method to set a value if it has an = sign on the end" do - @attributes.normal.music.mastodon = [ "dream", "still", "shining" ] - expect(@attributes.normal.music.mastodon).to eq([ "dream", "still", "shining" ]) + @attributes.normal.music.mastodon = %w(dream still shining) + expect(@attributes.normal.music.mastodon).to eq(%w(dream still shining)) end end @@ -999,9 +999,9 @@ describe Chef::Node::Attribute do it "should return a new array of k,v pairs for which the block returns true" do expect(@attributes.select { true }.sort).to eq( [ - ["hut", "three"], - ["one", "six"], - ["snack", "cookies"], + %w(hut three), + %w(one six), + %w(snack cookies), ["snakes", "on a plane"], ] ) diff --git a/spec/unit/node_spec.rb b/spec/unit/node_spec.rb index d3c58c6f6a..fae0e7eb5c 100644 --- a/spec/unit/node_spec.rb +++ b/spec/unit/node_spec.rb @@ -291,9 +291,9 @@ describe Chef::Node do end it "should let you use tag as a convience method for the tags attribute" do - node.normal["tags"] = ["one", "two"] + node.normal["tags"] = %w(one two) node.tag("three", "four") - expect(node["tags"]).to eq(["one", "two", "three", "four"]) + expect(node["tags"]).to eq(%w(one two three four)) end end @@ -766,15 +766,15 @@ describe Chef::Node do end it "should overwrites the run list with the run list it consumes" do - node.consume_run_list "recipes" => [ "one", "two" ] + node.consume_run_list "recipes" => %w(one two) node.consume_run_list "recipes" => [ "three" ] expect(node.run_list).to eq([ "three" ]) end it "should not add duplicate recipes from the json attributes" do node.run_list << "one" - node.consume_run_list "recipes" => [ "one", "two", "three" ] - expect(node.run_list).to eq([ "one", "two", "three" ]) + node.consume_run_list "recipes" => %w(one two three) + expect(node.run_list).to eq(%w(one two three)) end it "doesn't change the run list if no run_list is specified in the json" do @@ -887,7 +887,7 @@ describe Chef::Node do it "sets the 'roles' automatic attribute to the expanded role list" do @expansion.instance_variable_set(:@applied_roles, { "arf" => nil, "countersnark" => nil }) node.expand! - expect(node.automatic_attrs[:roles].sort).to eq(["arf", "countersnark"]) + expect(node.automatic_attrs[:roles].sort).to eq(%w(arf countersnark)) end it "applies default attributes from the environment as environment defaults" do diff --git a/spec/unit/policy_builder/policyfile_spec.rb b/spec/unit/policy_builder/policyfile_spec.rb index 6b71b4d43e..1e19747589 100644 --- a/spec/unit/policy_builder/policyfile_spec.rb +++ b/spec/unit/policy_builder/policyfile_spec.rb @@ -660,7 +660,7 @@ describe Chef::PolicyBuilder::Policyfile do expect_any_instance_of(Chef::CookbookCollection).to receive(:validate!) run_context = policy_builder.setup_run_context expect(run_context.node).to eq(node) - expect(run_context.cookbook_collection.keys).to match_array(["example1", "example2"]) + expect(run_context.cookbook_collection.keys).to match_array(%w(example1 example2)) end it "makes the run context available via static method on Chef" do diff --git a/spec/unit/property/validation_spec.rb b/spec/unit/property/validation_spec.rb index 0b2a8e0bc9..ffa6a06796 100644 --- a/spec/unit/property/validation_spec.rb +++ b/spec/unit/property/validation_spec.rb @@ -292,7 +292,7 @@ describe "Chef::Resource.property validation" do # Regex validation_test "is: /abc/", - [ "abc", "wowabcwow" ], + %w(abc wowabcwow), [ "", "abac" ] # Property @@ -427,17 +427,17 @@ describe "Chef::Resource.property validation" do :nil_is_valid validation_test "regex: [ /abc/, /z/ ]", - [ "xabcy", "aza" ], + %w(xabcy aza), [ "gbh", 123 ], :nil_is_valid validation_test "regex: [ /z/, /abc/ ]", - [ "xabcy", "aza" ], + %w(xabcy aza), [ "gbh", 123 ], :nil_is_valid validation_test "regex: [ [ /z/, /abc/ ], [ /n/ ] ]", - [ "xabcy", "aza", "ana" ], + %w(xabcy aza ana), [ "gbh", 123 ], :nil_is_valid diff --git a/spec/unit/property_spec.rb b/spec/unit/property_spec.rb index ecea666072..af014c5244 100644 --- a/spec/unit/property_spec.rb +++ b/spec/unit/property_spec.rb @@ -985,7 +985,7 @@ describe "Chef::Resource.property" do end end - [ "name_attribute", "name_property" ].each do |name| + %w(name_attribute name_property).each do |name| context "Chef::Resource::Property##{name}" do with_property ":x, #{name}: true" do it "defaults x to resource.name" do diff --git a/spec/unit/provider/file/content_spec.rb b/spec/unit/provider/file/content_spec.rb index ebef4faa09..9ebcf10dcc 100644 --- a/spec/unit/provider/file/content_spec.rb +++ b/spec/unit/provider/file/content_spec.rb @@ -66,13 +66,13 @@ describe Chef::Provider::File::Content do it "returns a tempfile in the tempdir when :file_staging_uses_destdir is not set" do Chef::Config[:file_staging_uses_destdir] = false - expect(content.tempfile.path.start_with?(Dir::tmpdir)).to be_truthy + expect(content.tempfile.path.start_with?(Dir.tmpdir)).to be_truthy expect(canonicalize_path(content.tempfile.path).start_with?(enclosing_directory)).to be_falsey end it "returns a tempfile in the destdir when :file_deployment_uses_destdir is set" do Chef::Config[:file_staging_uses_destdir] = true - expect(content.tempfile.path.start_with?(Dir::tmpdir)).to be_falsey + expect(content.tempfile.path.start_with?(Dir.tmpdir)).to be_falsey expect(canonicalize_path(content.tempfile.path).start_with?(enclosing_directory)).to be_truthy end @@ -83,7 +83,7 @@ describe Chef::Provider::File::Content do it "returns a tempfile in the tempdir when :file_deployment_uses_destdir is set to :auto" do Chef::Config[:file_staging_uses_destdir] = :auto - expect(content.tempfile.path.start_with?(Dir::tmpdir)).to be_truthy + expect(content.tempfile.path.start_with?(Dir.tmpdir)).to be_truthy expect(canonicalize_path(content.tempfile.path).start_with?(enclosing_directory)).to be_falsey end @@ -93,7 +93,7 @@ describe Chef::Provider::File::Content do end it "returns a tempfile in the tempdir when :file_desployment_uses_destdir is not set" do - expect(content.tempfile.path.start_with?(Dir::tmpdir)).to be_truthy + expect(content.tempfile.path.start_with?(Dir.tmpdir)).to be_truthy expect(canonicalize_path(content.tempfile.path).start_with?(enclosing_directory)).to be_falsey end end diff --git a/spec/unit/provider/group/dscl_spec.rb b/spec/unit/provider/group/dscl_spec.rb index 52aff87dc5..e060e4af10 100644 --- a/spec/unit/provider/group/dscl_spec.rb +++ b/spec/unit/provider/group/dscl_spec.rb @@ -184,7 +184,7 @@ describe Chef::Provider::Group::Dscl do before do allow(@new_resource).to receive(:members).and_return([]) allow(@new_resource).to receive(:append).and_return(false) - allow(@current_resource).to receive(:members).and_return(["all", "your", "base"]) + allow(@current_resource).to receive(:members).and_return(%w(all your base)) end it "should log an appropriate message" do @@ -201,7 +201,7 @@ describe Chef::Provider::Group::Dscl do describe "with supplied members in the new resource" do before do - @new_resource.members(["all", "your", "base"]) + @new_resource.members(%w(all your base)) @current_resource.members([]) end @@ -326,6 +326,6 @@ EOF end it "should parse members properly" do allow(File).to receive(:exists?).and_return(true) - expect(@current_resource.members).to eq(["waka", "bar"]) + expect(@current_resource.members).to eq(%w(waka bar)) end end diff --git a/spec/unit/provider/group/groupadd_spec.rb b/spec/unit/provider/group/groupadd_spec.rb index b4295c9dff..e8b47621c4 100644 --- a/spec/unit/provider/group/groupadd_spec.rb +++ b/spec/unit/provider/group/groupadd_spec.rb @@ -25,12 +25,12 @@ describe Chef::Provider::Group::Groupadd, "set_options" do @run_context = Chef::RunContext.new(@node, {}, @events) @new_resource = Chef::Resource::Group.new("aj") @new_resource.gid(50) - @new_resource.members(["root", "aj"]) + @new_resource.members(%w(root aj)) @new_resource.system false @new_resource.non_unique false @current_resource = Chef::Resource::Group.new("aj") @current_resource.gid(50) - @current_resource.members(["root", "aj"]) + @current_resource.members(%w(root aj)) @current_resource.system false @current_resource.non_unique false @provider = Chef::Provider::Group::Groupadd.new(@new_resource, @run_context) diff --git a/spec/unit/provider/group/pw_spec.rb b/spec/unit/provider/group/pw_spec.rb index 2c563750f3..250946fd1a 100644 --- a/spec/unit/provider/group/pw_spec.rb +++ b/spec/unit/provider/group/pw_spec.rb @@ -26,11 +26,11 @@ describe Chef::Provider::Group::Pw do @new_resource = Chef::Resource::Group.new("wheel") @new_resource.gid 50 - @new_resource.members [ "root", "aj"] + @new_resource.members %w(root aj) @current_resource = Chef::Resource::Group.new("aj") @current_resource.gid 50 - @current_resource.members [ "root", "aj"] + @current_resource.members %w(root aj) @provider = Chef::Provider::Group::Pw.new(@new_resource, @run_context) @provider.current_resource = @current_resource end @@ -89,7 +89,7 @@ describe Chef::Provider::Group::Pw do describe "with an empty members array in the new resource and existing members in the current resource" do before do allow(@new_resource).to receive(:members).and_return([]) - allow(@current_resource).to receive(:members).and_return(["all", "your", "base"]) + allow(@current_resource).to receive(:members).and_return(%w(all your base)) end it "should log an appropriate message" do @@ -104,7 +104,7 @@ describe Chef::Provider::Group::Pw do describe "with supplied members array in the new resource and an empty members array in the current resource" do before do - allow(@new_resource).to receive(:members).and_return(["all", "your", "base"]) + allow(@new_resource).to receive(:members).and_return(%w(all your base)) allow(@current_resource).to receive(:members).and_return([]) end diff --git a/spec/unit/provider/group/usermod_spec.rb b/spec/unit/provider/group/usermod_spec.rb index 1a718b1d40..5ab5d2bce0 100644 --- a/spec/unit/provider/group/usermod_spec.rb +++ b/spec/unit/provider/group/usermod_spec.rb @@ -24,7 +24,7 @@ describe Chef::Provider::Group::Usermod do @events = Chef::EventDispatch::Dispatcher.new @run_context = Chef::RunContext.new(@node, {}, @events) @new_resource = Chef::Resource::Group.new("wheel") - @new_resource.members [ "all", "your", "base" ] + @new_resource.members %w(all your base) @new_resource.excluded_members [ ] @provider = Chef::Provider::Group::Usermod.new(@new_resource, @run_context) allow(@provider).to receive(:run_command) @@ -56,7 +56,7 @@ describe Chef::Provider::Group::Usermod do } before do - allow(@new_resource).to receive(:members).and_return(["all", "your", "base"]) + allow(@new_resource).to receive(:members).and_return(%w(all your base)) allow(File).to receive(:exists?).and_return(true) end diff --git a/spec/unit/provider/group/windows_spec.rb b/spec/unit/provider/group/windows_spec.rb index c331e2b021..7ff58848fa 100644 --- a/spec/unit/provider/group/windows_spec.rb +++ b/spec/unit/provider/group/windows_spec.rb @@ -50,7 +50,7 @@ describe Chef::Provider::Group::Windows do before do @new_resource.members([ "us" ]) @current_resource = Chef::Resource::Group.new("staff") - @current_resource.members [ "all", "your", "base" ] + @current_resource.members %w(all your base) allow(Chef::Util::Windows::NetGroup).to receive(:new).and_return(@net_group) allow(@net_group).to receive(:local_add_members) diff --git a/spec/unit/provider/group_spec.rb b/spec/unit/provider/group_spec.rb index d41b0689ee..ed0537adfe 100644 --- a/spec/unit/provider/group_spec.rb +++ b/spec/unit/provider/group_spec.rb @@ -39,7 +39,7 @@ describe Chef::Provider::User do @pw_group = double("Struct::Group", :name => "wheel", :gid => 20, - :mem => [ "root", "aj" ], + :mem => %w(root aj), ) allow(Etc).to receive(:getgrnam).with("wheel").and_return(@pw_group) end diff --git a/spec/unit/provider/mount/mount_spec.rb b/spec/unit/provider/mount/mount_spec.rb index 50ed356049..4e636fba5f 100644 --- a/spec/unit/provider/mount/mount_spec.rb +++ b/spec/unit/provider/mount/mount_spec.rb @@ -107,7 +107,7 @@ describe Chef::Provider::Mount::Mount do expect { @provider.load_current_resource();@provider.mountable? }.to raise_error(Chef::Exceptions::Mount) end - [ "tmpfs", "fuse", "cgroup" ].each do |fstype| + %w(tmpfs fuse cgroup).each do |fstype| it "does not expect the device to exist for #{fstype}" do @new_resource.fstype(fstype) @new_resource.device("whatever") diff --git a/spec/unit/provider/mount/solaris_spec.rb b/spec/unit/provider/mount/solaris_spec.rb index a6d0620df6..3d5ce53619 100644 --- a/spec/unit/provider/mount/solaris_spec.rb +++ b/spec/unit/provider/mount/solaris_spec.rb @@ -316,7 +316,7 @@ describe Chef::Provider::Mount::Solaris, :unix_only do end it "should set the options field on the current_resource" do - expect(provider.current_resource.options).to eql(["rw", "soft"]) + expect(provider.current_resource.options).to eql(%w(rw soft)) end it "should set the pass field on the current_resource" do diff --git a/spec/unit/provider/package/chocolatey_spec.rb b/spec/unit/provider/package/chocolatey_spec.rb index aeb420fa7a..34cfec2c05 100644 --- a/spec/unit/provider/package/chocolatey_spec.rb +++ b/spec/unit/provider/package/chocolatey_spec.rb @@ -95,26 +95,26 @@ munin-node|1.6.1.20130823 end it "should set the candidate_version correctly when there are two packages to install" do - allow_remote_list(["ConEmu", "chocolatey"]) - new_resource.package_name(["ConEmu", "chocolatey"]) + allow_remote_list(%w(ConEmu chocolatey)) + new_resource.package_name(%w(ConEmu chocolatey)) expect(provider.candidate_version).to eql(["15.10.25.1", "0.9.9.11"]) end it "should set the candidate_version correctly when only the first is installable" do - allow_remote_list(["ConEmu", "vim"]) - new_resource.package_name(["ConEmu", "vim"]) + allow_remote_list(%w(ConEmu vim)) + new_resource.package_name(%w(ConEmu vim)) expect(provider.candidate_version).to eql(["15.10.25.1", nil]) end it "should set the candidate_version correctly when only the last is installable" do - allow_remote_list(["vim", "chocolatey"]) - new_resource.package_name(["vim", "chocolatey"]) + allow_remote_list(%w(vim chocolatey)) + new_resource.package_name(%w(vim chocolatey)) expect(provider.candidate_version).to eql([nil, "0.9.9.11"]) end it "should set the candidate_version correctly when neither are is installable" do - allow_remote_list(["vim", "ruby"]) - new_resource.package_name(["vim", "ruby"]) + allow_remote_list(%w(vim ruby)) + new_resource.package_name(%w(vim ruby)) expect(provider.candidate_version).to eql([nil, nil]) end end @@ -156,25 +156,25 @@ munin-node|1.6.1.20130823 end it "should set the current_resource.version when there are two packages that are installed" do - new_resource.package_name(["ConEmu", "chocolatey"]) + new_resource.package_name(%w(ConEmu chocolatey)) provider.load_current_resource expect(provider.current_resource.version).to eql(["15.10.25.0", "0.9.9.11"]) end it "should set the current_resource.version correctly when only the first is installed" do - new_resource.package_name(["ConEmu", "git"]) + new_resource.package_name(%w(ConEmu git)) provider.load_current_resource expect(provider.current_resource.version).to eql(["15.10.25.0", nil]) end it "should set the current_resource.version correctly when only the last is installed" do - new_resource.package_name(["git", "chocolatey"]) + new_resource.package_name(%w(git chocolatey)) provider.load_current_resource expect(provider.current_resource.version).to eql([nil, "0.9.9.11"]) end it "should set the current_resource.version correctly when none are installed" do - new_resource.package_name(["git", "vim"]) + new_resource.package_name(%w(git vim)) provider.load_current_resource expect(provider.current_resource.version).to eql([nil, nil]) end @@ -233,8 +233,8 @@ munin-node|1.6.1.20130823 # chocolatey will be pruned by the superclass out of the args to install_package and we # implicitly test that we correctly pick up new_resource.version[1] instead of # new_version.resource[0] - allow_remote_list(["chocolatey", "ConEmu"]) - new_resource.package_name(["chocolatey", "ConEmu"]) + allow_remote_list(%w(chocolatey ConEmu)) + new_resource.package_name(%w(chocolatey ConEmu)) new_resource.version([nil, "15.10.25.1"]) provider.load_current_resource expect(provider).to receive(:shell_out!).with("#{choco_exe} install -y -version 15.10.25.1 conemu", { :timeout => timeout }).and_return(double) @@ -253,8 +253,8 @@ munin-node|1.6.1.20130823 end it "should split up commands when given two packages, one with a version pin" do - allow_remote_list(["ConEmu", "git"]) - new_resource.package_name(["ConEmu", "git"]) + allow_remote_list(%w(ConEmu git)) + new_resource.package_name(%w(ConEmu git)) new_resource.version(["15.10.25.1", nil]) provider.load_current_resource expect(provider).to receive(:shell_out!).with("#{choco_exe} install -y -version 15.10.25.1 conemu", { :timeout => timeout }).and_return(double) @@ -371,8 +371,8 @@ munin-node|1.6.1.20130823 end it "upgrading multiple packages uses a single command" do - allow_remote_list(["conemu", "git"]) - new_resource.package_name(["conemu", "git"]) + allow_remote_list(%w(conemu git)) + new_resource.package_name(%w(conemu git)) expect(provider).to receive(:shell_out!).with("#{choco_exe} upgrade -y conemu git", { :timeout => timeout }).and_return(double) provider.run_action(:upgrade) expect(new_resource).to be_updated_by_last_action @@ -441,8 +441,8 @@ munin-node|1.6.1.20130823 it "removes a single package when its the only one installed" do pending "this is a bug in the superclass" - allow_remote_list(["git", "conemu"]) - new_resource.package_name(["git", "conemu"]) + allow_remote_list(%w(git conemu)) + new_resource.package_name(%w(git conemu)) provider.load_current_resource expect(provider).to receive(:shell_out!).with("#{choco_exe} uninstall -y conemu", { :timeout => timeout }).and_return(double) provider.run_action(:remove) diff --git a/spec/unit/provider/package/yum_spec.rb b/spec/unit/provider/package/yum_spec.rb index 98fe9551a6..2d4bcc6bef 100644 --- a/spec/unit/provider/package/yum_spec.rb +++ b/spec/unit/provider/package/yum_spec.rb @@ -987,7 +987,7 @@ describe Chef::Provider::Package::Yum::RPMUtils do end it "tests isalnum good input" do - [ "a", "z", "A", "Z", "0", "9" ].each do |t| + %w(a z A Z 0 9).each do |t| expect(@rpmutils.isalnum(t)).to eq(true) end end @@ -999,7 +999,7 @@ describe Chef::Provider::Package::Yum::RPMUtils do end it "tests isalpha good input" do - [ "a", "z", "A", "Z" ].each do |t| + %w(a z A Z).each do |t| expect(@rpmutils.isalpha(t)).to eq(true) end end @@ -1011,7 +1011,7 @@ describe Chef::Provider::Package::Yum::RPMUtils do end it "tests isdigit good input" do - [ "0", "9" ].each do |t| + %w(0 9).each do |t| expect(@rpmutils.isdigit(t)).to eq(true) end end @@ -1119,8 +1119,8 @@ describe Chef::Provider::Package::Yum::RPMVersion do "3.3-15.el5" ], [ "alpha9.8", "beta9.8" ], - [ "14jpp", - "15jpp" ], + %w(14jpp +15jpp), [ "0.9.0-0.6", "0.9.0-0.7" ], [ "0:1.9", @@ -1297,8 +1297,8 @@ describe Chef::Provider::Package::Yum::RPMPackage do "B-test" ], [ "Aa-test", "aA-test" ], - [ "1test", - "2test" ], + %w(1test +2test), ].each do |smaller, larger| sm = Chef::Provider::Package::Yum::RPMPackage.new(smaller, "0:0.0.1-1", "x86_64", []) lg = Chef::Provider::Package::Yum::RPMPackage.new(larger, "0:0.0.1-1", "x86_64", []) @@ -1310,12 +1310,12 @@ describe Chef::Provider::Package::Yum::RPMPackage do it "should sort alphabetically based on package arch" do [ - [ "i386", - "x86_64" ], - [ "i386", - "noarch" ], - [ "noarch", - "x86_64" ], + %w(i386 +x86_64), + %w(i386 +noarch), + %w(noarch +x86_64), ].each do |smaller, larger| sm = Chef::Provider::Package::Yum::RPMPackage.new("test-package", "0:0.0.1-1", smaller, []) lg = Chef::Provider::Package::Yum::RPMPackage.new("test-package", "0:0.0.1-1", larger, []) @@ -2113,7 +2113,7 @@ describe "Chef::Provider::Package::Yum - Multi" do @node = Chef::Node.new @events = Chef::EventDispatch::Dispatcher.new @run_context = Chef::RunContext.new(@node, {}, @events) - @new_resource = Chef::Resource::Package.new(["cups", "vim"]) + @new_resource = Chef::Resource::Package.new(%w(cups vim)) @status = double("Status", :exitstatus => 0) @yum_cache = double( "Chef::Provider::Yum::YumCache", @@ -2142,7 +2142,7 @@ describe "Chef::Provider::Package::Yum - Multi" do it "should set the current resources package name to the new resources package name" do @provider.load_current_resource - expect(@provider.current_resource.package_name).to eq(["cups", "vim"]) + expect(@provider.current_resource.package_name).to eq(%w(cups vim)) end it "should set the installed version to nil on the current resource if no installed package" do @@ -2196,9 +2196,9 @@ describe "Chef::Provider::Package::Yum - Multi" do expect(Chef::Log).to receive(:debug).exactly(1).times.with(%r{candidate version: \["1.2.4-11.18.el5_2.3", "24.4"\]}) expect(Chef::Log).to receive(:debug).at_least(2).times.with(%r{checking yum info}) @provider.load_current_resource - expect(@provider.new_resource.package_name).to eq(["cups", "emacs"]) + expect(@provider.new_resource.package_name).to eq(%w(cups emacs)) expect(@provider.new_resource.version).to eq(["1.2.4-11.18.el5_2.3", "24.4"]) - expect(@provider.send(:package_name_array)).to eq(["cups", "emacs"]) + expect(@provider.send(:package_name_array)).to eq(%w(cups emacs)) expect(@provider.send(:new_version_array)).to eq(["1.2.4-11.18.el5_2.3", "24.4"]) end end @@ -2213,7 +2213,7 @@ describe "Chef::Provider::Package::Yum - Multi" do expect(@provider).to receive(:yum_command).with( "-d0 -e0 -y install cups-1.2.4-11.19.el5 vim-1.0" ) - @provider.install_package(["cups", "vim"], ["1.2.4-11.19.el5", "1.0"]) + @provider.install_package(%w(cups vim), ["1.2.4-11.19.el5", "1.0"]) end it "should run yum install with the package name, version and arch" do @@ -2223,7 +2223,7 @@ describe "Chef::Provider::Package::Yum - Multi" do expect(@provider).to receive(:yum_command).with( "-d0 -e0 -y install cups-1.2.4-11.19.el5.i386 vim-1.0.i386" ) - @provider.install_package(["cups", "vim"], ["1.2.4-11.19.el5", "1.0"]) + @provider.install_package(%w(cups vim), ["1.2.4-11.19.el5", "1.0"]) end it "installs the package with the options given in the resource" do @@ -2235,7 +2235,7 @@ describe "Chef::Provider::Package::Yum - Multi" do "-d0 -e0 -y --disablerepo epmd install cups-1.2.4-11.19.el5 vim-1.0" ) allow(@new_resource).to receive(:options).and_return("--disablerepo epmd") - @provider.install_package(["cups", "vim"], ["1.2.4-11.19.el5", "1.0"]) + @provider.install_package(%w(cups vim), ["1.2.4-11.19.el5", "1.0"]) end it "should run yum install with the package name and version when name has arch" do @@ -2260,7 +2260,7 @@ describe "Chef::Provider::Package::Yum - Multi" do expect(@provider).to receive(:yum_command).with( "-d0 -e0 -y install cups-1.2.4-11.19.el5.x86_64 vim-1.0" ) - @provider.install_package(["cups", "vim"], ["1.2.4-11.19.el5", "1.0"]) + @provider.install_package(%w(cups vim), ["1.2.4-11.19.el5", "1.0"]) end end diff --git a/spec/unit/provider/package/zypper_spec.rb b/spec/unit/provider/package/zypper_spec.rb index c998c93d6e..b64ef5ea93 100644 --- a/spec/unit/provider/package/zypper_spec.rb +++ b/spec/unit/provider/package/zypper_spec.rb @@ -254,7 +254,7 @@ describe Chef::Provider::Package::Zypper do shell_out_expectation!( "zypper --non-interactive --no-gpg-checks install " + "--auto-agree-with-licenses emacs=1.0 vim=2.0" ) - provider.install_package(["emacs", "vim"], ["1.0", "2.0"]) + provider.install_package(%w(emacs vim), ["1.0", "2.0"]) end it "should remove an array of package names and versions" do @@ -262,7 +262,7 @@ describe Chef::Provider::Package::Zypper do shell_out_expectation!( "zypper --non-interactive --no-gpg-checks remove emacs=1.0 vim=2.0" ) - provider.remove_package(["emacs", "vim"], ["1.0", "2.0"]) + provider.remove_package(%w(emacs vim), ["1.0", "2.0"]) end end end diff --git a/spec/unit/provider/package_spec.rb b/spec/unit/provider/package_spec.rb index 50016c623d..b2287ed8ce 100644 --- a/spec/unit/provider/package_spec.rb +++ b/spec/unit/provider/package_spec.rb @@ -44,7 +44,7 @@ describe Chef::Provider::Package do end it "raises a Chef::Exceptions::InvalidResourceSpecification if both multipackage and source are provided" do - new_resource.package_name(["a", "b"]) + new_resource.package_name(%w(a b)) new_resource.source("foo") expect { provider.run_action(:install) }.to raise_error(Chef::Exceptions::InvalidResourceSpecification) end @@ -563,8 +563,8 @@ describe "Chef::Provider::Package - Multi" do let(:node) { Chef::Node.new } let(:events) { Chef::EventDispatch::Dispatcher.new } let(:run_context) { Chef::RunContext.new(node, {}, events) } - let(:new_resource) { Chef::Resource::Package.new(["emacs", "vi"]) } - let(:current_resource) { Chef::Resource::Package.new(["emacs", "vi"]) } + let(:new_resource) { Chef::Resource::Package.new(%w(emacs vi)) } + let(:current_resource) { Chef::Resource::Package.new(%w(emacs vi)) } let(:candidate_version) { [ "1.0", "6.2" ] } let(:provider) do provider = Chef::Provider::Package.new(new_resource, run_context) @@ -581,7 +581,7 @@ describe "Chef::Provider::Package - Multi" do it "installs the candidate versions when none are installed" do expect(provider).to receive(:install_package).with( - ["emacs", "vi"], + %w(emacs vi), ["1.0", "6.2"], ).and_return(true) provider.run_action(:install) @@ -731,7 +731,7 @@ describe "Chef::Provider::Package - Multi" do it "should remove the packages if all are installed" do expect(provider).to be_removing_package - expect(provider).to receive(:remove_package).with(["emacs", "vi"], nil) + expect(provider).to receive(:remove_package).with(%w(emacs vi), nil) provider.run_action(:remove) expect(new_resource).to be_updated expect(new_resource).to be_updated_by_last_action @@ -740,7 +740,7 @@ describe "Chef::Provider::Package - Multi" do it "should remove the packages if some are installed" do current_resource.version ["1.0", nil] expect(provider).to be_removing_package - expect(provider).to receive(:remove_package).with(["emacs", "vi"], nil) + expect(provider).to receive(:remove_package).with(%w(emacs vi), nil) provider.run_action(:remove) expect(new_resource).to be_updated expect(new_resource).to be_updated_by_last_action @@ -749,7 +749,7 @@ describe "Chef::Provider::Package - Multi" do it "should remove the packages at a specific version if they are installed at that version" do new_resource.version ["1.0", "6.2"] expect(provider).to be_removing_package - expect(provider).to receive(:remove_package).with(["emacs", "vi"], ["1.0", "6.2"]) + expect(provider).to receive(:remove_package).with(%w(emacs vi), ["1.0", "6.2"]) provider.run_action(:remove) expect(new_resource).to be_updated_by_last_action end @@ -757,7 +757,7 @@ describe "Chef::Provider::Package - Multi" do it "should remove the packages at a specific version any are is installed at that version" do new_resource.version ["0.5", "6.2"] expect(provider).to be_removing_package - expect(provider).to receive(:remove_package).with(["emacs", "vi"], ["0.5", "6.2"]) + expect(provider).to receive(:remove_package).with(%w(emacs vi), ["0.5", "6.2"]) provider.run_action(:remove) expect(new_resource).to be_updated_by_last_action end @@ -787,7 +787,7 @@ describe "Chef::Provider::Package - Multi" do it "should purge the packages if all are installed" do expect(provider).to be_removing_package - expect(provider).to receive(:purge_package).with(["emacs", "vi"], nil) + expect(provider).to receive(:purge_package).with(%w(emacs vi), nil) provider.run_action(:purge) expect(new_resource).to be_updated expect(new_resource).to be_updated_by_last_action @@ -796,7 +796,7 @@ describe "Chef::Provider::Package - Multi" do it "should purge the packages if some are installed" do current_resource.version ["1.0", nil] expect(provider).to be_removing_package - expect(provider).to receive(:purge_package).with(["emacs", "vi"], nil) + expect(provider).to receive(:purge_package).with(%w(emacs vi), nil) provider.run_action(:purge) expect(new_resource).to be_updated expect(new_resource).to be_updated_by_last_action @@ -805,7 +805,7 @@ describe "Chef::Provider::Package - Multi" do it "should purge the packages at a specific version if they are installed at that version" do new_resource.version ["1.0", "6.2"] expect(provider).to be_removing_package - expect(provider).to receive(:purge_package).with(["emacs", "vi"], ["1.0", "6.2"]) + expect(provider).to receive(:purge_package).with(%w(emacs vi), ["1.0", "6.2"]) provider.run_action(:purge) expect(new_resource).to be_updated_by_last_action end @@ -813,7 +813,7 @@ describe "Chef::Provider::Package - Multi" do it "should purge the packages at a specific version any are is installed at that version" do new_resource.version ["0.5", "6.2"] expect(provider).to be_removing_package - expect(provider).to receive(:purge_package).with(["emacs", "vi"], ["0.5", "6.2"]) + expect(provider).to receive(:purge_package).with(%w(emacs vi), ["0.5", "6.2"]) provider.run_action(:purge) expect(new_resource).to be_updated_by_last_action end diff --git a/spec/unit/provider/service/arch_service_spec.rb b/spec/unit/provider/service/arch_service_spec.rb index 47f874cc0e..d95b020357 100644 --- a/spec/unit/provider/service/arch_service_spec.rb +++ b/spec/unit/provider/service/arch_service_spec.rb @@ -180,7 +180,7 @@ RUNNING_PS it "should add chef to DAEMONS array" do allow(::File).to receive(:read).with("/etc/rc.conf").and_return("DAEMONS=(network)") - expect(@provider).to receive(:update_daemons).with(["network", "chef"]) + expect(@provider).to receive(:update_daemons).with(%w(network chef)) @provider.enable_service() end end diff --git a/spec/unit/provider/service/freebsd_service_spec.rb b/spec/unit/provider/service/freebsd_service_spec.rb index e64aa517e2..224ce3b026 100644 --- a/spec/unit/provider/service/freebsd_service_spec.rb +++ b/spec/unit/provider/service/freebsd_service_spec.rb @@ -495,7 +495,7 @@ EOF allow(provider).to receive(:service_enable_variable_name).and_return("#{new_resource.service_name}_enable") end - [ "start", "reload", "restart", "enable" ].each do |action| + %w(start reload restart enable).each do |action| it "should raise an exception when the action is #{action}" do provider.define_resource_requirements provider.action = action @@ -503,7 +503,7 @@ EOF end end - [ "stop", "disable" ].each do |action| + %w(stop disable).each do |action| it "should not raise an error when the action is #{action}" do provider.define_resource_requirements provider.action = action @@ -518,7 +518,7 @@ EOF allow(provider).to receive(:service_enable_variable_name).and_return(nil) end - [ "start", "reload", "restart", "enable" ].each do |action| + %w(start reload restart enable).each do |action| it "should raise an exception when the action is #{action}" do provider.action = action provider.define_resource_requirements @@ -526,7 +526,7 @@ EOF end end - [ "stop", "disable" ].each do |action| + %w(stop disable).each do |action| it "should not raise an error when the action is #{action}" do provider.action = action provider.define_resource_requirements @@ -558,7 +558,7 @@ EOF it "should enable the service if it is not enabled and not already specified in the rc.conf file" do allow(current_resource).to receive(:enabled).and_return(false) - expect(provider).to receive(:read_rc_conf).and_return([ "foo", "bar" ]) + expect(provider).to receive(:read_rc_conf).and_return(%w(foo bar)) expect(provider).to receive(:write_rc_conf).with(["foo", "bar", "#{new_resource.service_name}_enable=\"YES\""]) provider.enable_service() end diff --git a/spec/unit/provider/service/macosx_spec.rb b/spec/unit/provider/service/macosx_spec.rb index 29ebf2da11..0828425523 100644 --- a/spec/unit/provider/service/macosx_spec.rb +++ b/spec/unit/provider/service/macosx_spec.rb @@ -58,7 +58,7 @@ describe Chef::Provider::Service::Macosx do </plist> XML - ["Daemon", "Agent"].each do |service_type| + %w(Daemon Agent).each do |service_type| ["redis-server", "io.redis.redis-server"].each do |service_name| ["10.9", "10.10", "10.11"].each do |platform_version| let(:plist) { "/Library/LaunchDaemons/io.redis.redis-server.plist" } diff --git a/spec/unit/provider/service/openbsd_service_spec.rb b/spec/unit/provider/service/openbsd_service_spec.rb index 7b64214e65..5f5dc80b85 100644 --- a/spec/unit/provider/service/openbsd_service_spec.rb +++ b/spec/unit/provider/service/openbsd_service_spec.rb @@ -338,7 +338,7 @@ describe Chef::Provider::Service::Openbsd do allow(provider).to receive(:builtin_service_enable_variable_name).and_return("#{new_resource.service_name}_enable") end - [ "start", "reload", "restart", "enable" ].each do |action| + %w(start reload restart enable).each do |action| it "should raise an exception when the action is #{action}" do provider.define_resource_requirements provider.action = action @@ -346,7 +346,7 @@ describe Chef::Provider::Service::Openbsd do end end - [ "stop", "disable" ].each do |action| + %w(stop disable).each do |action| it "should not raise an error when the action is #{action}" do provider.define_resource_requirements provider.action = action @@ -360,7 +360,7 @@ describe Chef::Provider::Service::Openbsd do allow(provider).to receive(:builtin_service_enable_variable_name).and_return(nil) end - [ "start", "reload", "restart", "enable" ].each do |action| + %w(start reload restart enable).each do |action| it "should raise an exception when the action is #{action}" do provider.action = action provider.define_resource_requirements @@ -368,7 +368,7 @@ describe Chef::Provider::Service::Openbsd do end end - [ "stop", "disable" ].each do |action| + %w(stop disable).each do |action| it "should not raise an error when the action is #{action}" do provider.action = action provider.define_resource_requirements diff --git a/spec/unit/provider/service/redhat_spec.rb b/spec/unit/provider/service/redhat_spec.rb index 5d03c688fc..7023e6848a 100644 --- a/spec/unit/provider/service/redhat_spec.rb +++ b/spec/unit/provider/service/redhat_spec.rb @@ -150,14 +150,14 @@ describe "Chef::Provider::Service::Redhat" do @provider.define_resource_requirements end - [ "start", "reload", "restart", "enable" ].each do |action| + %w(start reload restart enable).each do |action| it "should raise an error when the action is #{action}" do @provider.action = action expect { @provider.process_resource_requirements }.to raise_error(Chef::Exceptions::Service) end end - [ "stop", "disable" ].each do |action| + %w(stop disable).each do |action| it "should not raise an error when the action is #{action}" do @provider.action = action expect { @provider.process_resource_requirements }.not_to raise_error diff --git a/spec/unit/provider/template/content_spec.rb b/spec/unit/provider/template/content_spec.rb index 4f7b4c256c..0f936c8f11 100644 --- a/spec/unit/provider/template/content_spec.rb +++ b/spec/unit/provider/template/content_spec.rb @@ -91,7 +91,7 @@ describe Chef::Provider::Template::Content do it "returns a tempfile in the tempdir when :file_staging_uses_destdir is not set" do Chef::Config[:file_staging_uses_destdir] = false - expect(content.tempfile.path.start_with?(Dir::tmpdir)).to be true + expect(content.tempfile.path.start_with?(Dir.tmpdir)).to be true expect(canonicalize_path(content.tempfile.path).start_with?(enclosing_directory)).to be false end @@ -107,7 +107,7 @@ describe Chef::Provider::Template::Content do it "returns a tempfile in the tempdir when :file_deployment_uses_destdir is set to :auto" do Chef::Config[:file_staging_uses_destdir] = :auto - expect(content.tempfile.path.start_with?(Dir::tmpdir)).to be true + expect(content.tempfile.path.start_with?(Dir.tmpdir)).to be true expect(canonicalize_path(content.tempfile.path).start_with?(enclosing_directory)).to be false end @@ -117,7 +117,7 @@ describe Chef::Provider::Template::Content do end it "returns a tempfile in the tempdir when :file_desployment_uses_destdir is not set" do - expect(content.tempfile.path.start_with?(Dir::tmpdir)).to be true + expect(content.tempfile.path.start_with?(Dir.tmpdir)).to be true expect(canonicalize_path(content.tempfile.path).start_with?(enclosing_directory)).to be false end end diff --git a/spec/unit/provider/user_spec.rb b/spec/unit/provider/user_spec.rb index 0794ce0328..6e5a469112 100644 --- a/spec/unit/provider/user_spec.rb +++ b/spec/unit/provider/user_spec.rb @@ -192,13 +192,13 @@ describe Chef::Provider::User do describe "compare_user" do let(:mapping) { { - "username" => ["adam", "Adam"], + "username" => %w(adam Adam), "comment" => ["Adam Jacob", "adam jacob"], "uid" => [1000, 1001], "gid" => [1000, 1001], "home" => ["/home/adam", "/Users/adam"], "shell" => ["/usr/bin/zsh", "/bin/bash"], - "password" => ["abcd", "12345"], + "password" => %w(abcd 12345), } } diff --git a/spec/unit/recipe_spec.rb b/spec/unit/recipe_spec.rb index 8f43d0cbca..5a0ceda084 100644 --- a/spec/unit/recipe_spec.rb +++ b/spec/unit/recipe_spec.rb @@ -100,7 +100,7 @@ describe Chef::Recipe do end end - expect(run_context.resource_collection.map { |r| r.name }).to eql(["monkey", "dog", "cat"]) + expect(run_context.resource_collection.map { |r| r.name }).to eql(%w(monkey dog cat)) end it "should return the new resource after creating it" do diff --git a/spec/unit/resource/chocolatey_package_spec.rb b/spec/unit/resource/chocolatey_package_spec.rb index dfd6a3e679..34874ac6b1 100644 --- a/spec/unit/resource/chocolatey_package_spec.rb +++ b/spec/unit/resource/chocolatey_package_spec.rb @@ -42,13 +42,13 @@ describe Chef::Resource::ChocolateyPackage do end it "the package_name setter should accept arrays" do - resource.package_name(["git", "unzip"]) - expect(resource.package_name).to eql(["git", "unzip"]) + resource.package_name(%w(git unzip)) + expect(resource.package_name).to eql(%w(git unzip)) end it "the name should accept arrays" do - resource = Chef::Resource::ChocolateyPackage.new(["git", "unzip"]) - expect(resource.package_name).to eql(["git", "unzip"]) + resource = Chef::Resource::ChocolateyPackage.new(%w(git unzip)) + expect(resource.package_name).to eql(%w(git unzip)) end it "the default version should be nil" do diff --git a/spec/unit/resource/cron_spec.rb b/spec/unit/resource/cron_spec.rb index 037bbaf733..1e3f629864 100644 --- a/spec/unit/resource/cron_spec.rb +++ b/spec/unit/resource/cron_spec.rb @@ -106,19 +106,19 @@ describe Chef::Resource::Cron do end it "should allow * for all time and date values" do - [ "minute", "hour", "day", "month", "weekday" ].each do |x| + %w(minute hour day month weekday).each do |x| expect(@resource.send(x, "*")).to eql("*") end end it "should allow ranges for all time and date values" do - [ "minute", "hour", "day", "month", "weekday" ].each do |x| + %w(minute hour day month weekday).each do |x| expect(@resource.send(x, "1-2,5")).to eql("1-2,5") end end it "should have a default value of * for all time and date values" do - [ "minute", "hour", "day", "month", "weekday" ].each do |x| + %w(minute hour day month weekday).each do |x| expect(@resource.send(x)).to eql("*") end end @@ -153,7 +153,7 @@ describe Chef::Resource::Cron do end it "should convert integer schedule values to a string" do - [ "minute", "hour", "day", "month", "weekday" ].each do |x| + %w(minute hour day month weekday).each do |x| expect(@resource.send(x, 5)).to eql("5") end end diff --git a/spec/unit/resource/dsc_script_spec.rb b/spec/unit/resource/dsc_script_spec.rb index 55473e3146..d5954119d2 100644 --- a/spec/unit/resource/dsc_script_spec.rb +++ b/spec/unit/resource/dsc_script_spec.rb @@ -77,7 +77,7 @@ describe Chef::Resource::DscScript do context "when calling imports" do let(:module_name) { "FooModule" } let(:module_name_b) { "BarModule" } - let(:dsc_resources) { ["ResourceA", "ResourceB"] } + let(:dsc_resources) { %w(ResourceA ResourceB) } it "allows an arbitrary number of resources to be set for a module to be set" do dsc_test_resource.imports module_name, *dsc_resources diff --git a/spec/unit/resource/group_spec.rb b/spec/unit/resource/group_spec.rb index 7cfec23365..40a184c08b 100644 --- a/spec/unit/resource/group_spec.rb +++ b/spec/unit/resource/group_spec.rb @@ -111,8 +111,8 @@ describe Chef::Resource::Group, "members" do end it "(#{method}) should allow an array" do - @resource.send(method, [ "aj", "adam" ]) - expect(@resource.send(method)).to eql( ["aj", "adam"] ) + @resource.send(method, %w(aj adam)) + expect(@resource.send(method)).to eql( %w(aj adam) ) end it "(#{method}) should not allow a hash" do @@ -142,12 +142,12 @@ describe Chef::Resource::Group, "append" do describe "when it has members" do before do @resource.group_name("pokemon") - @resource.members(["blastoise", "pikachu"]) + @resource.members(%w(blastoise pikachu)) end it "describes its state" do state = @resource.state - expect(state[:members]).to eql(["blastoise", "pikachu"]) + expect(state[:members]).to eql(%w(blastoise pikachu)) end it "returns the group name as its identity" do diff --git a/spec/unit/resource/mdadm_spec.rb b/spec/unit/resource/mdadm_spec.rb index 6a446a2815..b6f9c191b7 100644 --- a/spec/unit/resource/mdadm_spec.rb +++ b/spec/unit/resource/mdadm_spec.rb @@ -82,14 +82,14 @@ describe Chef::Resource::Mdadm do describe "when it has devices, level, and chunk" do before do @resource.raid_device("raider") - @resource.devices(["device1", "device2"]) + @resource.devices(%w(device1 device2)) @resource.level(1) @resource.chunk(42) end it "describes its state" do state = @resource.state - expect(state[:devices]).to eql(["device1", "device2"]) + expect(state[:devices]).to eql(%w(device1 device2)) expect(state[:level]).to eq(1) expect(state[:chunk]).to eq(42) end diff --git a/spec/unit/resource/mount_spec.rb b/spec/unit/resource/mount_spec.rb index ea20511990..8741ac3e75 100644 --- a/spec/unit/resource/mount_spec.rb +++ b/spec/unit/resource/mount_spec.rb @@ -87,19 +87,19 @@ describe Chef::Resource::Mount do end it "should allow options attribute as an array" do - @resource.options ["ro", "nosuid"] + @resource.options %w(ro nosuid) expect(@resource.options).to be_a_kind_of(Array) end it "should allow options to be sent as a delayed evaluator" do - @resource.options Chef::DelayedEvaluator.new { ["rw", "noexec"] } - expect(@resource.options).to eql(["rw", "noexec"]) + @resource.options Chef::DelayedEvaluator.new { %w(rw noexec) } + expect(@resource.options).to eql(%w(rw noexec)) end it "should allow options to be sent as a delayed evaluator, and convert to array" do @resource.options Chef::DelayedEvaluator.new { "rw,noexec" } expect(@resource.options).to be_a_kind_of(Array) - expect(@resource.options).to eql(["rw", "noexec"]) + expect(@resource.options).to eql(%w(rw noexec)) end it "should accept true for mounted" do diff --git a/spec/unit/resource/resource_notification_spec.rb b/spec/unit/resource/resource_notification_spec.rb index 5bb3ba95ea..c720156cec 100644 --- a/spec/unit/resource/resource_notification_spec.rb +++ b/spec/unit/resource/resource_notification_spec.rb @@ -100,7 +100,7 @@ describe Chef::Resource::Notification do end it "raises a RuntimeError if you try to reference multiple resources" do - notification.resource = { :cat => ["keyboard_cat", "cheez_cat"] } + notification.resource = { :cat => %w(keyboard_cat cheez_cat) } @keyboard_cat = Chef::Resource::Cat.new("keyboard_cat") @cheez_cat = Chef::Resource::Cat.new("cheez_cat") @resource_collection = Chef::ResourceCollection.new @@ -112,7 +112,7 @@ describe Chef::Resource::Notification do end it "raises a RuntimeError if you try to reference multiple notifying resources" do - notification.notifying_resource = { :cat => ["long_cat", "cheez_cat"] } + notification.notifying_resource = { :cat => %w(long_cat cheez_cat) } @long_cat = Chef::Resource::Cat.new("long_cat") @cheez_cat = Chef::Resource::Cat.new("cheez_cat") @resource_collection = Chef::ResourceCollection.new diff --git a/spec/unit/resource_collection/resource_set_spec.rb b/spec/unit/resource_collection/resource_set_spec.rb index 2f8ba0e1aa..e7b24369d7 100644 --- a/spec/unit/resource_collection/resource_set_spec.rb +++ b/spec/unit/resource_collection/resource_set_spec.rb @@ -84,7 +84,7 @@ describe Chef::ResourceCollection::ResourceSet do it "should find a resource by type symbol and array of names with custom names" do collection.insert_as(zen_master, :zzz, "name1") collection.insert_as(zen_master2, :zzz, "name2") - check_by_names(collection.find( :zzz => ["name1", "name2"]), zen_master_name, zen_master2_name) + check_by_names(collection.find( :zzz => %w(name1 name2)), zen_master_name, zen_master2_name) end it "should find resources of multiple kinds (:zen_master => a, :zen_follower => b)" do @@ -98,7 +98,7 @@ describe Chef::ResourceCollection::ResourceSet do collection.insert_as(zen_master, :zzz, "name1") collection.insert_as(zen_master2, :zzz, "name2") collection.insert_as(zen_follower, :yyy, "name3") - check_by_names(collection.find(:zzz => ["name1", "name2"], :yyy => ["name3"]), + check_by_names(collection.find(:zzz => %w(name1 name2), :yyy => ["name3"]), zen_master_name, zen_follower_name, zen_master2_name) end diff --git a/spec/unit/resource_collection_spec.rb b/spec/unit/resource_collection_spec.rb index 178d58b303..c267d85a34 100644 --- a/spec/unit/resource_collection_spec.rb +++ b/spec/unit/resource_collection_spec.rb @@ -171,7 +171,7 @@ describe Chef::ResourceCollection do it "should find a resource by symbol and array of names (:zen_master => [a,b])" do load_up_resources - results = rc.resources(:zen_master => [ "monkey", "dog" ]) + results = rc.resources(:zen_master => %w(monkey dog)) expect(results.length).to eql(2) check_by_names(results, "monkey", "dog") end diff --git a/spec/unit/resource_spec.rb b/spec/unit/resource_spec.rb index 1297ed6f04..64f0b72b8f 100644 --- a/spec/unit/resource_spec.rb +++ b/spec/unit/resource_spec.rb @@ -205,7 +205,7 @@ describe Chef::Resource do end it "coerces arrays to names" do - expect(resource.name ["a", "b"]).to eql("a, b") + expect(resource.name %w(a b)).to eql("a, b") end it "should coerce objects to a string" do @@ -270,7 +270,7 @@ describe Chef::Resource do end it "notifies a resource with an array for its name via its prettified string name" do - run_context.resource_collection << Chef::Resource::ZenMaster.new(["coffee", "tea"]) + run_context.resource_collection << Chef::Resource::ZenMaster.new(%w(coffee tea)) resource.notifies :reload, run_context.resource_collection.find(:zen_master => "coffee, tea") expect(resource.delayed_notifications.detect { |e| e.resource.name == "coffee, tea" && e.action == :reload }).not_to be_nil end @@ -859,9 +859,9 @@ describe Chef::Resource do it "adds mappings for multiple platforms" do expect(Chef.resource_handler_map).to receive(:set).with( - :energy, Chef::Resource::Klz, { platform: ["autobots", "decepticons"] } + :energy, Chef::Resource::Klz, { platform: %w(autobots decepticons) } ) - klz.provides :energy, platform: ["autobots", "decepticons"] + klz.provides :energy, platform: %w(autobots decepticons) end it "adds mappings for all platforms" do diff --git a/spec/unit/role_spec.rb b/spec/unit/role_spec.rb index 1ff76d7207..a7b329c3d6 100644 --- a/spec/unit/role_spec.rb +++ b/spec/unit/role_spec.rb @@ -85,12 +85,12 @@ describe Chef::Role do describe "using the old #recipes API" do it "should let you set the recipe array" do - expect(@role.recipes([ "one", "two" ])).to eq([ "one", "two" ]) + expect(@role.recipes(%w(one two))).to eq(%w(one two)) end it "should let you return the recipe array" do - @role.recipes([ "one", "two" ]) - expect(@role.recipes).to eq([ "one", "two" ]) + @role.recipes(%w(one two)) + expect(@role.recipes).to eq(%w(one two)) end it "should not list roles in the recipe array" do diff --git a/spec/unit/run_list/run_list_expansion_spec.rb b/spec/unit/run_list/run_list_expansion_spec.rb index b0cb978bb1..d902ff6707 100644 --- a/spec/unit/run_list/run_list_expansion_spec.rb +++ b/spec/unit/run_list/run_list_expansion_spec.rb @@ -119,7 +119,7 @@ describe Chef::RunList::RunListExpansion do it "has the list of all roles applied" do # this is the correct order, but 1.8 hash order is not stable - expect(@expansion.roles).to match_array(["rage", "mollusk"]) + expect(@expansion.roles).to match_array(%w(rage mollusk)) 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 2b1c6edebc..c5bdf4d24a 100644 --- a/spec/unit/run_list/versioned_recipe_list_spec.rb +++ b/spec/unit/run_list/versioned_recipe_list_spec.rb @@ -43,23 +43,23 @@ describe Chef::RunList::VersionedRecipeList do it "should append the recipe to the end of the list" do list.add_recipe "rails" - expect(list).to eq(["apt", "god", "apache2", "rails"]) + expect(list).to eq(%w(apt god apache2 rails)) end it "should not duplicate entries" do list.add_recipe "apt" - expect(list).to eq(["apt", "god", "apache2"]) + expect(list).to eq(%w(apt god apache2)) end it "should allow you to specify a version" do list.add_recipe "rails", "1.0.0" - expect(list).to eq(["apt", "god", "apache2", "rails"]) + expect(list).to eq(%w(apt god apache2 rails)) expect(list.with_versions).to include({ :name => "rails", :version => "1.0.0" }) end it "should allow you to specify a version for a recipe that already exists" do list.add_recipe "apt", "1.2.3" - expect(list).to eq(["apt", "god", "apache2"]) + expect(list).to eq(%w(apt god apache2)) expect(list.with_versions).to include({ :name => "apt", :version => "1.2.3" }) end diff --git a/spec/unit/run_list_spec.rb b/spec/unit/run_list_spec.rb index 6d17e654cd..cf32d0a6be 100644 --- a/spec/unit/run_list_spec.rb +++ b/spec/unit/run_list_spec.rb @@ -95,7 +95,7 @@ describe Chef::RunList do it "should believe a RunList is equal to an array named after it's members" do @run_list << "foo" @run_list << "baz" - expect(@run_list).to eq([ "foo", "baz" ]) + expect(@run_list).to eq(%w(foo baz)) end end @@ -199,7 +199,7 @@ describe Chef::RunList do it "should load the role from the chef server" do #@rest.should_receive(:get).with("roles/stubby") expansion = @run_list.expand("_default", "server") - expect(expansion.recipes).to eq(["one", "two", "kitty"]) + expect(expansion.recipes).to eq(%w(one two kitty)) end it "should default to expanding from the server" do diff --git a/spec/unit/search/query_spec.rb b/spec/unit/search/query_spec.rb index 9652d69783..d5cd698af2 100644 --- a/spec/unit/search/query_spec.rb +++ b/spec/unit/search/query_spec.rb @@ -30,7 +30,7 @@ describe Chef::Search::Query do let(:filter_hash) { { "env" => [ "chef_environment" ], - "ruby_plat" => [ "languages", "ruby", "platform" ], + "ruby_plat" => %w(languages ruby platform), } } let(:response) { diff --git a/spec/unit/util/backup_spec.rb b/spec/unit/util/backup_spec.rb index 3454e07692..2d20021b23 100644 --- a/spec/unit/util/backup_spec.rb +++ b/spec/unit/util/backup_spec.rb @@ -76,7 +76,7 @@ describe Chef::Util::Backup do end it "should keep only 1 backup copy" do - expect(@backup).to receive(:sorted_backup_files).and_return(["a", "b", "c"]) + expect(@backup).to receive(:sorted_backup_files).and_return(%w(a b c)) expect(@backup).to receive(:delete_backup).with("b") expect(@backup).to receive(:delete_backup).with("c") @backup.backup! @@ -89,13 +89,13 @@ describe Chef::Util::Backup do end it "should not delete anything if we only have one other backup" do - expect(@backup).to receive(:sorted_backup_files).and_return(["a", "b"]) + expect(@backup).to receive(:sorted_backup_files).and_return(%w(a b)) expect(@backup).not_to receive(:delete_backup) @backup.backup! end it "should keep only 2 backup copies" do - expect(@backup).to receive(:sorted_backup_files).and_return(["a", "b", "c", "d"]) + expect(@backup).to receive(:sorted_backup_files).and_return(%w(a b c d)) expect(@backup).to receive(:delete_backup).with("c") expect(@backup).to receive(:delete_backup).with("d") @backup.backup! diff --git a/spec/unit/util/dsc/configuration_generator_spec.rb b/spec/unit/util/dsc/configuration_generator_spec.rb index d59423e1e5..5b739c33c0 100644 --- a/spec/unit/util/dsc/configuration_generator_spec.rb +++ b/spec/unit/util/dsc/configuration_generator_spec.rb @@ -151,7 +151,7 @@ describe Chef::Util::DSC::ConfigurationGenerator do allow(File).to receive(:join) do |a, b| [a, b].join("++") end - allow(Dir).to receive(:entries).with("tmp++hello") { ["f1", "f2", "f3"] } + allow(Dir).to receive(:entries).with("tmp++hello") { %w(f1 f2 f3) } expect(conf_man.send(:find_configuration_document, "hello")).to be_nil end end @@ -179,12 +179,12 @@ describe Chef::Util::DSC::ConfigurationGenerator do end it "should import specific resources when a module has list without * that is not empty" do - dsc = conf_man.send(:configuration_code, "archive{}", "hello", { "FooModule" => ["FooResource", "BarResource"] }) + dsc = conf_man.send(:configuration_code, "archive{}", "hello", { "FooModule" => %w(FooResource BarResource) }) expect(dsc).to match(/Import-DscResource -ModuleName FooModule -Name FooResource,BarResource/) end it "should import multiple modules with multiple import statements" do - dsc = conf_man.send(:configuration_code, "archive{}", "hello", { "FooModule" => ["FooResource", "BarResource"], "BazModule" => [] }) + dsc = conf_man.send(:configuration_code, "archive{}", "hello", { "FooModule" => %w(FooResource BarResource), "BazModule" => [] }) expect(dsc).to match(/Import-DscResource -ModuleName FooModule -Name FooResource,BarResource/) expect(dsc).to match(/Import-DscResource -ModuleName BazModule\s*\n/) end diff --git a/spec/unit/util/dsc/lcm_output_parser_spec.rb b/spec/unit/util/dsc/lcm_output_parser_spec.rb index 69eb8724ea..d59497de6f 100644 --- a/spec/unit/util/dsc/lcm_output_parser_spec.rb +++ b/spec/unit/util/dsc/lcm_output_parser_spec.rb @@ -24,11 +24,11 @@ describe Chef::Util::DSC::LocalConfigurationManager::Parser do str = <<-EOF EOF - expect { Chef::Util::DSC::LocalConfigurationManager::Parser::parse(str) }.to raise_error(Chef::Exceptions::LCMParser) + expect { Chef::Util::DSC::LocalConfigurationManager::Parser.parse(str) }.to raise_error(Chef::Exceptions::LCMParser) end it "raises an exception for a nil input" do - expect { Chef::Util::DSC::LocalConfigurationManager::Parser::parse(nil) }.to raise_error(Chef::Exceptions::LCMParser) + expect { Chef::Util::DSC::LocalConfigurationManager::Parser.parse(nil) }.to raise_error(Chef::Exceptions::LCMParser) end end @@ -40,7 +40,7 @@ logtype: [machinename]: LCM: [ Start Resource ] [name] logtype: [machinename]: LCM: [ End Resource ] [name] logtype: [machinename]: LCM: [ End Set ] EOF - resources = Chef::Util::DSC::LocalConfigurationManager::Parser::parse(str) + resources = Chef::Util::DSC::LocalConfigurationManager::Parser.parse(str) expect(resources.length).to eq(1) expect(resources[0].name).to eq("[name]") end @@ -54,7 +54,7 @@ logtype: [machinename]: LCM: [ End Set ] [name] logtype: [machinename]: LCM: [ End Resource ] [name] logtype: [machinename]: LCM: [ End Set ] EOF - resources = Chef::Util::DSC::LocalConfigurationManager::Parser::parse(str) + resources = Chef::Util::DSC::LocalConfigurationManager::Parser.parse(str) expect(resources[0].changes_state?).to be_truthy end @@ -68,7 +68,7 @@ logtype: [machinename]: LCM: [ End Set ] [name] logtype: [machinename]: LCM: [ End Resource ] [name] logtype: [machinename]: LCM: [ End Set ] EOF - resources = Chef::Util::DSC::LocalConfigurationManager::Parser::parse(str) + resources = Chef::Util::DSC::LocalConfigurationManager::Parser.parse(str) expect(resources[0].change_log).to match_array(["[name]", "[message]", "[name]"]) end @@ -80,7 +80,7 @@ logtype: [machinename]: LCM: [ Skip Set ] [name] logtype: [machinename]: LCM: [ End Resource ] [name] logtype: [machinename]: LCM: [ End Set ] EOF - resources = Chef::Util::DSC::LocalConfigurationManager::Parser::parse(str) + resources = Chef::Util::DSC::LocalConfigurationManager::Parser.parse(str) expect(resources[0].changes_state?).to be_falsey end @@ -92,7 +92,7 @@ logtype: [machinename]: LCM: [ Skip Set ] [name] logtype: [machinename]: LCM: [ End Resource ] [name] logtype: [machinename]: LCM: [ End Set ] EOF - resources = Chef::Util::DSC::LocalConfigurationManager::Parser::parse(str) + resources = Chef::Util::DSC::LocalConfigurationManager::Parser.parse(str) expect(resources[0].change_log).to be_empty end end @@ -114,7 +114,7 @@ logtype: [machinename]: LCM: [ End Set ] logtype: [machinename]: LCM: [ End Set ] EOF - resources = Chef::Util::DSC::LocalConfigurationManager::Parser::parse(str) + resources = Chef::Util::DSC::LocalConfigurationManager::Parser.parse(str) expect(resources[0].changes_state?).to be_falsey expect(resources[1].changes_state?).to be_truthy end @@ -135,7 +135,7 @@ logtype: [machinename]: LCM: [ End Resource ] logtype: [machinename]: LCM: [ End Set ] EOF - resources = Chef::Util::DSC::LocalConfigurationManager::Parser::parse(str) + resources = Chef::Util::DSC::LocalConfigurationManager::Parser.parse(str) expect(resources[0].changes_state?).to be_falsey expect(resources[1].changes_state?).to be_truthy end @@ -154,7 +154,7 @@ logtype: [machinename]: LCM: [ End Set ] logtype: [machinename]: LCM: [ End Resource ] logtype: [machinename]: LCM: [ End Set ] EOF - resources = Chef::Util::DSC::LocalConfigurationManager::Parser::parse(str) + resources = Chef::Util::DSC::LocalConfigurationManager::Parser.parse(str) expect(resources[0].changes_state?).to be_truthy expect(resources[0].name).to eql("[name]") expect(resources[1].changes_state?).to be_truthy diff --git a/spec/unit/util/editor_spec.rb b/spec/unit/util/editor_spec.rb index 9db7e85931..cdba502101 100644 --- a/spec/unit/util/editor_spec.rb +++ b/spec/unit/util/editor_spec.rb @@ -16,7 +16,7 @@ describe Chef::Util::Editor do end subject(:editor) { described_class.new(input_lines) } - let(:input_lines) { ["one", "two", "two", "three"] } + let(:input_lines) { %w(one two two three) } describe '#append_line_after' do context "when there is no match" do @@ -34,7 +34,7 @@ describe Chef::Util::Editor do it("returns the number of added lines") { is_expected.to eq(2) } it "adds a line after each match" do execute - expect(editor.lines).to be == ["one", "two", "new", "two", "new", "three"] + expect(editor.lines).to be == %w(one two new two new three) end end @@ -51,7 +51,7 @@ describe Chef::Util::Editor do it("returns the number of added lines") { is_expected.to eq(1) } it "adds a line to the end" do execute - expect(editor.lines).to be == ["one", "two", "two", "three", "new"] + expect(editor.lines).to be == %w(one two two three new) end end @@ -86,7 +86,7 @@ describe Chef::Util::Editor do it("returns the number of removed lines") { is_expected.to eq(2) } it "removes the matching lines" do execute - expect(editor.lines).to be == ["one", "three"] + expect(editor.lines).to be == %w(one three) end end @@ -112,14 +112,14 @@ describe Chef::Util::Editor do it("returns the number of changed lines") { is_expected.to eq(2) } it "replaces the matching portions" do execute - expect(editor.lines).to be == ["one", "new", "new", "three"] + expect(editor.lines).to be == %w(one new new three) end end it "matches a Regexp" do expect(editor.replace(/^ee/, "new")).to be == 0 expect(editor.replace(/ee$/, "new")).to be == 1 - expect(editor.lines).to be == ["one", "two", "two", "thrnew"] + expect(editor.lines).to be == %w(one two two thrnew) end end @@ -139,14 +139,14 @@ describe Chef::Util::Editor do it("returns the number of replaced lines") { is_expected.to eq(2) } it "replaces the matching line" do execute - expect(editor.lines).to be == ["one", "new", "new", "three"] + expect(editor.lines).to be == %w(one new new three) end end it "matches a Regexp" do expect(editor.replace_lines(/^ee/, "new")).to be == 0 expect(editor.replace_lines(/ee$/, "new")).to be == 1 - expect(editor.lines).to be == ["one", "two", "two", "new"] + expect(editor.lines).to be == %w(one two two new) end end end |