diff options
Diffstat (limited to 'spec/functional/resource')
18 files changed, 55 insertions, 56 deletions
diff --git a/spec/functional/resource/aix_service_spec.rb b/spec/functional/resource/aix_service_spec.rb index 5fff3e00d7..9ffe05266d 100755 --- a/spec/functional/resource/aix_service_spec.rb +++ b/spec/functional/resource/aix_service_spec.rb @@ -77,7 +77,7 @@ describe Chef::Resource::Service, :requires_root, :aix_only do include Chef::Mixin::ShellOut def get_user_id - shell_out("id -u #{ENV['USER']}").stdout.chomp + shell_out("id -u #{ENV["USER"]}").stdout.chomp end describe "When service is a subsystem" do diff --git a/spec/functional/resource/aixinit_service_spec.rb b/spec/functional/resource/aixinit_service_spec.rb index 68ea5ab8b2..fc8a80eb08 100755 --- a/spec/functional/resource/aixinit_service_spec.rb +++ b/spec/functional/resource/aixinit_service_spec.rb @@ -40,7 +40,7 @@ describe Chef::Resource::Service, :requires_root, :aix_only do directory = [] if priority.is_a? Hash priority.each do |level, o| - directory << "/etc/rc.d/rc#{level}.d/#{(o[0] == :start ? 'S' : 'K')}#{o[1]}#{new_resource.service_name}" + directory << "/etc/rc.d/rc#{level}.d/#{(o[0] == :start ? "S" : "K")}#{o[1]}#{new_resource.service_name}" end directory else diff --git a/spec/functional/resource/chocolatey_package_spec.rb b/spec/functional/resource/chocolatey_package_spec.rb index 3c4b08a1f4..c5590b2d88 100644 --- a/spec/functional/resource/chocolatey_package_spec.rb +++ b/spec/functional/resource/chocolatey_package_spec.rb @@ -22,7 +22,7 @@ describe Chef::Resource::ChocolateyPackage, :windows_only, :choco_installed do include Chef::Mixin::PowershellOut let(:package_name) { "test-A" } - let(:package_list) { proc { powershell_out!("choco list -lo -r #{Array(package_name).join(' ')}").stdout.chomp } } + let(:package_list) { proc { powershell_out!("choco list -lo -r #{Array(package_name).join(" ")}").stdout.chomp } } let(:package_source) { File.join(CHEF_SPEC_ASSETS, "chocolatey_feed") } subject do diff --git a/spec/functional/resource/cookbook_file_spec.rb b/spec/functional/resource/cookbook_file_spec.rb index d127413c73..6e964a6499 100644 --- a/spec/functional/resource/cookbook_file_spec.rb +++ b/spec/functional/resource/cookbook_file_spec.rb @@ -25,9 +25,7 @@ describe Chef::Resource::CookbookFile do let(:source) { "java.response" } let(:cookbook_name) { "java" } let(:expected_content) do - content = File.open(File.join(CHEF_SPEC_DATA, "cookbooks", "java", "files", "default", "java.response"), "rb") do |f| - f.read - end + content = File.open(File.join(CHEF_SPEC_DATA, "cookbooks", "java", "files", "default", "java.response"), "rb", &:read) content.force_encoding(Encoding::BINARY) if content.respond_to?(:force_encoding) content end diff --git a/spec/functional/resource/cron_spec.rb b/spec/functional/resource/cron_spec.rb index f616b84ce9..16b0d2645c 100644 --- a/spec/functional/resource/cron_spec.rb +++ b/spec/functional/resource/cron_spec.rb @@ -118,6 +118,7 @@ describe Chef::Resource::Cron, :requires_root, :unix_only do def cron_attribute_should_exists(cron_name, attribute, value) 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/dsc_resource_spec.rb b/spec/functional/resource/dsc_resource_spec.rb index 3491bb6bbe..8f5ba5fd9e 100644 --- a/spec/functional/resource/dsc_resource_spec.rb +++ b/spec/functional/resource/dsc_resource_spec.rb @@ -46,7 +46,8 @@ describe Chef::Resource::DscResource, :windows_powershell_dsc_only do it "raises an exception if the resource is not found" do new_resource.resource "thisdoesnotexist" expect { new_resource.run_action(:run) }.to raise_error( - Chef::Exceptions::ResourceNotFound) + Chef::Exceptions::ResourceNotFound + ) end end diff --git a/spec/functional/resource/dsc_script_spec.rb b/spec/functional/resource/dsc_script_spec.rb index 0808927000..224141c0f8 100644 --- a/spec/functional/resource/dsc_script_spec.rb +++ b/spec/functional/resource/dsc_script_spec.rb @@ -184,8 +184,8 @@ describe Chef::Resource::DscScript, :windows_powershell_dsc_only do end let(:dsc_environment_env_var_name) { "dsc_test_cwd" } - let(:dsc_environment_no_fail_not_etc_directory) { "#{ENV['systemroot']}\\system32" } - let(:dsc_environment_fail_etc_directory) { "#{ENV['systemroot']}\\system32\\drivers\\etc" } + let(:dsc_environment_no_fail_not_etc_directory) { "#{ENV["systemroot"]}\\system32" } + let(:dsc_environment_fail_etc_directory) { "#{ENV["systemroot"]}\\system32\\drivers\\etc" } let(:exception_message_signature) { "LL927-LL928" } let(:dsc_environment_config) do <<~EOH @@ -349,9 +349,7 @@ describe Chef::Resource::DscScript, :windows_powershell_dsc_only do let(:config_param_section) { config_params } let(:config_flags) { { "#{dsc_user_prefix_param_name}": (dsc_user_prefix).to_s, "#{dsc_user_suffix_param_name}": (dsc_user_suffix).to_s } } it "does not directly contain the user name" do - configuration_script_content = ::File.open(dsc_test_resource.command) do |file| - file.read - end + configuration_script_content = ::File.open(dsc_test_resource.command, &:read) expect(configuration_script_content.include?(dsc_user)).to be(false) end it_behaves_like "a dsc_script with configuration data" @@ -361,9 +359,7 @@ describe Chef::Resource::DscScript, :windows_powershell_dsc_only do let(:dsc_user_code) { dsc_user_env_code } it "does not directly contain the user name" do - configuration_script_content = ::File.open(dsc_test_resource.command) do |file| - file.read - end + configuration_script_content = ::File.open(dsc_test_resource.command, &:read) expect(configuration_script_content.include?(dsc_user)).to be(false) end it_behaves_like "a dsc_script with configuration data" @@ -464,7 +460,7 @@ describe Chef::Resource::DscScript, :windows_powershell_dsc_only do User dsctestusercreate { UserName = '#{dsc_user}' - Password = #{r.ps_credential('jf9a8m49jrajf4#')} + Password = #{r.ps_credential("jf9a8m49jrajf4#")} Ensure = "Present" } EOF diff --git a/spec/functional/resource/group_spec.rb b/spec/functional/resource/group_spec.rb index efa089ca2e..5b34ad92d0 100644 --- a/spec/functional/resource/group_spec.rb +++ b/spec/functional/resource/group_spec.rb @@ -1,7 +1,7 @@ # # Author:: Chirag Jog (<chirag@clogeny.com>) # Author:: Siddheshwar More (<siddheshwar.more@clogeny.com>) -# Copyright:: Copyright 2013-2018, Chef Software Inc. +# Copyright:: Copyright 2013-2019, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -96,7 +96,7 @@ describe Chef::Resource::Group, :requires_root_or_running_windows do end def create_user(username, uid = nil) - if ! windows_domain_user?(username) + unless windows_domain_user?(username) user_to_create = user(username) user_to_create.uid(uid) if uid user_to_create.run_action(:create) @@ -105,7 +105,7 @@ describe Chef::Resource::Group, :requires_root_or_running_windows do end def remove_user(username) - if ! windows_domain_user?(username) + unless windows_domain_user?(username) u = user(username) u.manage_home false # jekins hosts throw mail spool file not owned by user if we use manage_home true u.run_action(:remove) @@ -152,7 +152,7 @@ describe Chef::Resource::Group, :requires_root_or_running_windows do let(:excluded_members) { [] } it "should raise an error" do - expect { group_resource.run_action(tested_action) }.to raise_error() + expect { group_resource.run_action(tested_action) }.to raise_error end end @@ -162,7 +162,7 @@ describe Chef::Resource::Group, :requires_root_or_running_windows do end it "should raise an error" do - expect { group_resource.run_action(tested_action) }.to raise_error() + expect { group_resource.run_action(tested_action) }.to raise_error end end end @@ -333,10 +333,11 @@ describe Chef::Resource::Group, :requires_root_or_running_windows do describe "when group name is length 256", :windows_only do let!(:group_name) do - "theoldmanwalkingdownthestreetalwayshadagood\ -smileonhisfacetheoldmanwalkingdownthestreetalwayshadagoodsmileonhisface\ -theoldmanwalkingdownthestreetalwayshadagoodsmileonhisfacetheoldmanwalking\ -downthestreetalwayshadagoodsmileonhisfacetheoldmanwalkingdownthestree" end + "theoldmanwalkingdownthestreetalwayshadagood"\ + "smileonhisfacetheoldmanwalkingdownthestreetalwayshadagoodsmileonhisface"\ + "theoldmanwalkingdownthestreetalwayshadagoodsmileonhisfacetheoldmanwalking"\ + "downthestreetalwayshadagoodsmileonhisfacetheoldmanwalkingdownthestree" + end it "should create a group" do group_resource.run_action(:create) @@ -359,10 +360,11 @@ downthestreetalwayshadagoodsmileonhisfacetheoldmanwalkingdownthestree" end # for group name > 256, Windows 2016 returns "The parameter is incorrect" context "group create action: when group name length is more than 256", :windows_only do let!(:group_name) do - "theoldmanwalkingdownthestreetalwayshadagood\ -smileonhisfacetheoldmanwalkingdownthestreetalwayshadagoodsmileonhisface\ -theoldmanwalkingdownthestreetalwayshadagoodsmileonhisfacetheoldmanwalking\ -downthestreetalwayshadagoodsmileonhisfacetheoldmanwalkingdownthestreeQQQQQQ" end + "theoldmanwalkingdownthestreetalwayshadagood"\ + "smileonhisfacetheoldmanwalkingdownthestreetalwayshadagoodsmileonhisface"\ + "theoldmanwalkingdownthestreetalwayshadagoodsmileonhisfacetheoldmanwalking"\ + "downthestreetalwayshadagoodsmileonhisfacetheoldmanwalkingdownthestreeQQQQQQ" + end it "should not create a group" do expect { group_resource.run_action(:create) }.to raise_error(ArgumentError) diff --git a/spec/functional/resource/link_spec.rb b/spec/functional/resource/link_spec.rb index d86a904098..4593dc1971 100644 --- a/spec/functional/resource/link_spec.rb +++ b/spec/functional/resource/link_spec.rb @@ -133,9 +133,9 @@ describe Chef::Resource::Link do end def get_sid(value) - if value.kind_of?(String) + if value.is_a?(String) Chef::ReservedNames::Win32::Security::SID.from_account(value) - elsif value.kind_of?(Chef::ReservedNames::Win32::Security::SID) + elsif value.is_a?(Chef::ReservedNames::Win32::Security::SID) value else raise "Must specify username or SID: #{value}" diff --git a/spec/functional/resource/locale_spec.rb b/spec/functional/resource/locale_spec.rb index 83dfc2d007..0103df305b 100644 --- a/spec/functional/resource/locale_spec.rb +++ b/spec/functional/resource/locale_spec.rb @@ -61,18 +61,18 @@ describe Chef::Resource::Locale, :requires_root do context "Unsets system variable" do it "when LC var is not given" do - resource.lc_env() + resource.lc_env resource.run_action(:update) unsets_system_locale("LC_MESSAGES=en_US") end it "when lang is not given" do - resource.lang() + resource.lang resource.run_action(:update) unsets_system_locale("LANG=en_US") end it "when both lang & LC vars are not given" do - resource.lang() - resource.lc_env() + resource.lang + resource.lc_env resource.run_action(:update) unsets_system_locale("LANG=en_US", "LC_TIME=en_IN") sets_system_locale("") diff --git a/spec/functional/resource/mount_spec.rb b/spec/functional/resource/mount_spec.rb index f6c7f91bcd..6dd9f54412 100644 --- a/spec/functional/resource/mount_spec.rb +++ b/spec/functional/resource/mount_spec.rb @@ -73,7 +73,7 @@ describe Chef::Resource::Mount, :requires_root, :skip_travis, external: include_ def mount_should_exist(mount_point, device, fstype = nil, options = nil) validation_cmd = "mount | grep #{mount_point} | grep #{device} " validation_cmd << " | grep #{fstype} " unless fstype.nil? - validation_cmd << " | grep #{options.join(',')} " unless options.nil? || options.empty? + validation_cmd << " | grep #{options.join(",")} " unless options.nil? || options.empty? expect(shell_out(validation_cmd).exitstatus).to eq(0) end diff --git a/spec/functional/resource/powershell_script_spec.rb b/spec/functional/resource/powershell_script_spec.rb index 850c273a6c..74ece0d33c 100644 --- a/spec/functional/resource/powershell_script_spec.rb +++ b/spec/functional/resource/powershell_script_spec.rb @@ -28,13 +28,13 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do it_behaves_like "a Windows script running on Windows" - let(:successful_executable_script_content) { "#{ENV['SystemRoot']}\\system32\\attrib.exe $env:systemroot" } - let(:failed_executable_script_content) { "#{ENV['SystemRoot']}\\system32\\attrib.exe /badargument" } + let(:successful_executable_script_content) { "#{ENV["SystemRoot"]}\\system32\\attrib.exe $env:systemroot" } + let(:failed_executable_script_content) { "#{ENV["SystemRoot"]}\\system32\\attrib.exe /badargument" } let(:processor_architecture_script_content) { "echo $env:PROCESSOR_ARCHITECTURE" } let(:native_architecture_script_content) { "echo $env:PROCESSOR_ARCHITECTUREW6432" } let(:cmdlet_exit_code_not_found_content) { "get-item '.\\thisdoesnotexist'" } let(:cmdlet_exit_code_success_content) { "get-item ." } - let(:windows_process_exit_code_success_content) { "#{ENV['SystemRoot']}\\system32\\attrib.exe $env:systemroot" } + let(:windows_process_exit_code_success_content) { "#{ENV["SystemRoot"]}\\system32\\attrib.exe $env:systemroot" } let(:windows_process_exit_code_not_found_content) { "findstr /notavalidswitch" } let(:arbitrary_nonzero_process_exit_code) { 4193 } let(:arbitrary_nonzero_process_exit_code_content) { "exit #{arbitrary_nonzero_process_exit_code}" } @@ -479,26 +479,26 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do end it "evaluates a not_if block using the cwd guard parameter" do - custom_cwd = "#{ENV['SystemRoot']}\\system32\\drivers\\etc" + custom_cwd = "#{ENV["SystemRoot"]}\\system32\\drivers\\etc" resource.not_if "exit ! [int32]($pwd.path -eq '#{custom_cwd}')", cwd: custom_cwd expect(resource.should_skip?(:run)).to be_truthy end it "evaluates an only_if block using the cwd guard parameter" do - custom_cwd = "#{ENV['SystemRoot']}\\system32\\drivers\\etc" + custom_cwd = "#{ENV["SystemRoot"]}\\system32\\drivers\\etc" resource.only_if "exit ! [int32]($pwd.path -eq '#{custom_cwd}')", cwd: custom_cwd expect(resource.should_skip?(:run)).to be_falsey end it "inherits cwd from the parent resource for only_if" do - custom_cwd = "#{ENV['SystemRoot']}\\system32\\drivers\\etc" + custom_cwd = "#{ENV["SystemRoot"]}\\system32\\drivers\\etc" resource.cwd custom_cwd resource.only_if "exit ! [int32]($pwd.path -eq '#{custom_cwd}')" expect(resource.should_skip?(:run)).to be_falsey end it "inherits cwd from the parent resource for not_if" do - custom_cwd = "#{ENV['SystemRoot']}\\system32\\drivers\\etc" + custom_cwd = "#{ENV["SystemRoot"]}\\system32\\drivers\\etc" resource.cwd custom_cwd resource.not_if "exit ! [int32]($pwd.path -eq '#{custom_cwd}')" expect(resource.should_skip?(:run)).to be_truthy @@ -590,7 +590,8 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do resource.only_if "$true", architecture: :i386 expect { resource.run_action(:run) }.to raise_error( Chef::Exceptions::Win32ArchitectureIncorrect, - /cannot execute script with requested architecture 'i386' on Windows Nano Server/) + /cannot execute script with requested architecture 'i386' on Windows Nano Server/ + ) end end end diff --git a/spec/functional/resource/reboot_spec.rb b/spec/functional/resource/reboot_spec.rb index 3b8e3efe8a..5489dc1c72 100644 --- a/spec/functional/resource/reboot_spec.rb +++ b/spec/functional/resource/reboot_spec.rb @@ -45,7 +45,7 @@ describe Chef::Resource::Reboot do shared_context "testing run context modification" do def test_reboot_action(resource) reboot_info = resource.run_context.reboot_info - expect(reboot_info.keys.sort).to eq([:delay_mins, :reason, :requested_by, :timestamp]) + expect(reboot_info.keys.sort).to eq(%i{delay_mins reason requested_by timestamp}) expect(reboot_info[:delay_mins]).to eq(expected[:delay_mins]) expect(reboot_info[:reason]).to eq(expected[:reason]) expect(reboot_info[:requested_by]).to eq(expected[:requested_by]) diff --git a/spec/functional/resource/remote_file_spec.rb b/spec/functional/resource/remote_file_spec.rb index 44a7a46d68..ffa0364d1d 100644 --- a/spec/functional/resource/remote_file_spec.rb +++ b/spec/functional/resource/remote_file_spec.rb @@ -134,7 +134,7 @@ describe Chef::Resource::RemoteFile do let(:smb_file_local_file_name) { "smb_file.txt" } let(:smb_file_local_path) { File.join( smb_share_root_directory, smb_file_local_file_name ) } let(:smb_share_name) { "chef_smb_test" } - let(:smb_remote_path) { File.join("//#{ENV['COMPUTERNAME']}", smb_share_name, smb_file_local_file_name).gsub(/\//, "\\") } + let(:smb_remote_path) { File.join("//#{ENV["COMPUTERNAME"]}", smb_share_name, smb_file_local_file_name).gsub(%r{/}, "\\") } let(:smb_file_content) { "hellofun" } let(:local_destination_path) { File.join(Dir.tmpdir, make_tmpname("chef_remote_file")) } let(:windows_current_user) { ENV["USERNAME"] } @@ -155,7 +155,7 @@ describe Chef::Resource::RemoteFile do before do shell_out("net.exe share #{smb_share_name} /delete") File.write(smb_file_local_path, smb_file_content ) - shell_out!("net.exe share #{smb_share_name}=\"#{smb_share_root_directory.gsub(/\//, '\\')}\" /grant:\"authenticated users\",read") + shell_out!("net.exe share #{smb_share_name}=\"#{smb_share_root_directory.gsub(%r{/}, '\\')}\" /grant:\"authenticated users\",read") end after do diff --git a/spec/functional/resource/template_spec.rb b/spec/functional/resource/template_spec.rb index 679ffe661a..feef97dd27 100644 --- a/spec/functional/resource/template_spec.rb +++ b/spec/functional/resource/template_spec.rb @@ -21,7 +21,7 @@ require "spec_helper" describe Chef::Resource::Template do def binread(file) - File.open(file, "rb") { |f| f.read } + File.open(file, "rb", &:read) end include_context Chef::Resource::File diff --git a/spec/functional/resource/user/windows_spec.rb b/spec/functional/resource/user/windows_spec.rb index 3a5535f194..6bab270f56 100644 --- a/spec/functional/resource/user/windows_spec.rb +++ b/spec/functional/resource/user/windows_spec.rb @@ -47,13 +47,13 @@ describe Chef::Provider::User::Windows, :windows_only do end def backup_secedit_policy - backup_command = "secedit /export /cfg #{ENV['TEMP']}\\secedit_restore.inf /areas SECURITYPOLICY" + backup_command = "secedit /export /cfg #{ENV["TEMP"]}\\secedit_restore.inf /areas SECURITYPOLICY" shell_out(backup_command) end def restore_secedit_policy security_database = "C:\\windows\\security\\database\\seceditnew.sdb" - restore_command = "secedit /configure /db #{security_database} /cfg #{ENV['TEMP']}\\secedit_restore.inf /areas SECURITYPOLICY" + restore_command = "secedit /configure /db #{security_database} /cfg #{ENV["TEMP"]}\\secedit_restore.inf /areas SECURITYPOLICY" shell_out(restore_command) end diff --git a/spec/functional/resource/windows_certificate_spec.rb b/spec/functional/resource/windows_certificate_spec.rb index 79b3cd890b..9b79de6a77 100644 --- a/spec/functional/resource/windows_certificate_spec.rb +++ b/spec/functional/resource/windows_certificate_spec.rb @@ -81,9 +81,9 @@ describe Chef::Resource::WindowsCertificate, :windows_only, :appveyor_only do # Byepassing the validation so that we may create a custom store allow_any_instance_of(Chef::Mixin::ParamsValidate) - .to receive(:_pv_equal_to) - .with(opts, key, to_be) - .and_return(true) + .to receive(:_pv_equal_to) + .with(opts, key, to_be) + .and_return(true) # Creating a custom store for the testing create_store(store) diff --git a/spec/functional/resource/windows_service_spec.rb b/spec/functional/resource/windows_service_spec.rb index f422ac21d6..999b235df1 100644 --- a/spec/functional/resource/windows_service_spec.rb +++ b/spec/functional/resource/windows_service_spec.rb @@ -24,7 +24,7 @@ describe Chef::Resource::WindowsService, :windows_only, :system_windows_service_ include_context "using Win32::Service" let(:username) { "service_spec_user" } - let(:qualified_username) { "#{ENV['COMPUTERNAME']}\\#{username}" } + let(:qualified_username) { "#{ENV["COMPUTERNAME"]}\\#{username}" } let(:password) { "1a2b3c4X!&narf" } let(:user_resource) do @@ -36,7 +36,7 @@ describe Chef::Resource::WindowsService, :windows_only, :system_windows_service_ end let(:global_service_file_path) do - "#{ENV['WINDIR']}\\temp\\#{File.basename(test_service[:service_file_path])}" + "#{ENV["WINDIR"]}\\temp\\#{File.basename(test_service[:service_file_path])}" end let(:service_params) do @@ -59,7 +59,7 @@ describe Chef::Resource::WindowsService, :windows_only, :system_windows_service_ let(:service_resource) do r = Chef::Resource::WindowsService.new(service_params[:service_name], run_context) - [:run_as_user, :run_as_password].each { |prop| r.send(prop, service_params[prop]) } + %i{run_as_user run_as_password}.each { |prop| r.send(prop, service_params[prop]) } r end |