diff options
Diffstat (limited to 'spec/unit')
181 files changed, 987 insertions, 911 deletions
diff --git a/spec/unit/api_client/registration_spec.rb b/spec/unit/api_client/registration_spec.rb index 6fd1d4d0e1..3e786c3c02 100644 --- a/spec/unit/api_client/registration_spec.rb +++ b/spec/unit/api_client/registration_spec.rb @@ -98,7 +98,7 @@ describe Chef::ApiClient::Registration do it "has an HTTP client configured with validator credentials" do expect(registration.http_api).to be_a_kind_of(Chef::ServerAPI) expect(registration.http_api.options[:client_name]).to eq("test-validator") - auth = registration.http_api.middlewares.find { |klass| klass.kind_of? Chef::HTTP::Authenticator } + auth = registration.http_api.middlewares.find { |klass| klass.is_a? Chef::HTTP::Authenticator } expect(auth.client_name).to eq("test-validator") end diff --git a/spec/unit/api_client_spec.rb b/spec/unit/api_client_spec.rb index e6b2eec820..f36cbc721d 100644 --- a/spec/unit/api_client_spec.rb +++ b/spec/unit/api_client_spec.rb @@ -41,7 +41,7 @@ describe Chef::ApiClient do end it "only allows string values for the name" do - expect { @client.name Hash.new }.to raise_error(ArgumentError) + expect { @client.name({}) }.to raise_error(ArgumentError) end it "has an admin flag attribute" do @@ -55,7 +55,7 @@ describe Chef::ApiClient do it "allows only boolean values for the admin flag" do expect { @client.admin(false) }.not_to raise_error - expect { @client.admin(Hash.new) }.to raise_error(ArgumentError) + expect { @client.admin({}) }.to raise_error(ArgumentError) end it "has a 'validator' flag attribute" do @@ -69,7 +69,7 @@ describe Chef::ApiClient do it "allows only boolean values for the 'validator' flag" do expect { @client.validator(false) }.not_to raise_error - expect { @client.validator(Hash.new) }.to raise_error(ArgumentError) + expect { @client.validator({}) }.to raise_error(ArgumentError) end it "has a public key attribute" do @@ -79,7 +79,7 @@ describe Chef::ApiClient do it "accepts only String values for the public key" do expect { @client.public_key "" }.not_to raise_error - expect { @client.public_key Hash.new }.to raise_error(ArgumentError) + expect { @client.public_key({}) }.to raise_error(ArgumentError) end it "has a private key attribute" do @@ -89,7 +89,7 @@ describe Chef::ApiClient do it "accepts only String values for the private key" do expect { @client.private_key "" }.not_to raise_error - expect { @client.private_key Hash.new }.to raise_error(ArgumentError) + expect { @client.private_key({}) }.to raise_error(ArgumentError) end describe "when serializing to JSON" do diff --git a/spec/unit/api_client_v1_spec.rb b/spec/unit/api_client_v1_spec.rb index 6c4e7fe188..3bad466a13 100644 --- a/spec/unit/api_client_v1_spec.rb +++ b/spec/unit/api_client_v1_spec.rb @@ -36,7 +36,7 @@ describe Chef::ApiClientV1 do end it "only allows string values for the name" do - expect { @client.name Hash.new }.to raise_error(ArgumentError) + expect { @client.name({}) }.to raise_error(ArgumentError) end it "has an admin flag attribute" do @@ -50,7 +50,7 @@ describe Chef::ApiClientV1 do it "allows only boolean values for the admin flag" do expect { @client.admin(false) }.not_to raise_error - expect { @client.admin(Hash.new) }.to raise_error(ArgumentError) + expect { @client.admin({}) }.to raise_error(ArgumentError) end it "has an create_key flag attribute" do @@ -64,7 +64,7 @@ describe Chef::ApiClientV1 do it "allows only boolean values for the create_key flag" do expect { @client.create_key(false) }.not_to raise_error - expect { @client.create_key(Hash.new) }.to raise_error(ArgumentError) + expect { @client.create_key({}) }.to raise_error(ArgumentError) end it "has a 'validator' flag attribute" do @@ -78,7 +78,7 @@ describe Chef::ApiClientV1 do it "allows only boolean values for the 'validator' flag" do expect { @client.validator(false) }.not_to raise_error - expect { @client.validator(Hash.new) }.to raise_error(ArgumentError) + expect { @client.validator({}) }.to raise_error(ArgumentError) end it "has a public key attribute" do @@ -88,7 +88,7 @@ describe Chef::ApiClientV1 do it "accepts only String values for the public key" do expect { @client.public_key "" }.not_to raise_error - expect { @client.public_key Hash.new }.to raise_error(ArgumentError) + expect { @client.public_key({}) }.to raise_error(ArgumentError) end it "has a private key attribute" do @@ -98,7 +98,7 @@ describe Chef::ApiClientV1 do it "accepts only String values for the private key" do expect { @client.private_key "" }.not_to raise_error - expect { @client.private_key Hash.new }.to raise_error(ArgumentError) + expect { @client.private_key({}) }.to raise_error(ArgumentError) end describe "when serializing to JSON" do diff --git a/spec/unit/application/exit_code_spec.rb b/spec/unit/application/exit_code_spec.rb index 6800ad0de5..7a02672796 100644 --- a/spec/unit/application/exit_code_spec.rb +++ b/spec/unit/application/exit_code_spec.rb @@ -70,7 +70,8 @@ describe Chef::Application::ExitCode do it "does write a warning on non-standard exit codes" do expect(Chef::Log).to receive(:warn).with( - /attempted to exit with a non-standard exit code of 151/) + /attempted to exit with a non-standard exit code of 151/ + ) expect(exit_codes.normalize_exit_code(151)).to eq(1) end @@ -79,7 +80,7 @@ describe Chef::Application::ExitCode do end it "returns GENERIC_FAILURE when no exit code is specified" do - expect(exit_codes.normalize_exit_code()).to eq(1) + expect(exit_codes.normalize_exit_code).to eq(1) end it "returns SIGINT_RECEIVED when a SIGINT is received" do diff --git a/spec/unit/application/knife_spec.rb b/spec/unit/application/knife_spec.rb index f8f5560597..ea5083ac15 100644 --- a/spec/unit/application/knife_spec.rb +++ b/spec/unit/application/knife_spec.rb @@ -28,8 +28,7 @@ describe Chef::Application::Knife do long: "-optwithdefault VALUE", default: "default-value" - def run - end + def run; end end end diff --git a/spec/unit/chef_fs/config_spec.rb b/spec/unit/chef_fs/config_spec.rb index 0adcbbfbfb..bdb9bc2c72 100644 --- a/spec/unit/chef_fs/config_spec.rb +++ b/spec/unit/chef_fs/config_spec.rb @@ -23,7 +23,7 @@ require "lib/chef/chef_fs/config.rb" describe Chef::ChefFS::Config do describe "initialize" do it "warns when hosted setups use 'everything'" do - base_config = Hash.new() + base_config = {} base_config[:repo_mode] = "everything" base_config[:chef_server_url] = "http://foo.com/organizations/fake_org/" @@ -34,7 +34,7 @@ describe Chef::ChefFS::Config do end it "doesn't warn when hosted setups use 'hosted_everything'" do - base_config = Hash.new() + base_config = {} base_config[:repo_mode] = "hosted_everything" base_config[:chef_server_url] = "http://foo.com/organizations/fake_org/" @@ -45,7 +45,7 @@ describe Chef::ChefFS::Config do end it "doesn't warn when non-hosted setups use 'everything'" do - base_config = Hash.new() + base_config = {} base_config[:repo_mode] = "everything" base_config[:chef_server_url] = "http://foo.com/" diff --git a/spec/unit/chef_fs/file_system/repository/directory_spec.rb b/spec/unit/chef_fs/file_system/repository/directory_spec.rb index 5b2a0a47b8..ec147ba6a8 100644 --- a/spec/unit/chef_fs/file_system/repository/directory_spec.rb +++ b/spec/unit/chef_fs/file_system/repository/directory_spec.rb @@ -106,7 +106,7 @@ describe Chef::ChefFS::FileSystem::Repository::Directory do end it "filters invalid names" do - expect(test_directory.children.map { |c| c.name }).to eql %w{ test1.json test2.json test3.json } + expect(test_directory.children.map(&:name)).to eql %w{ test1.json test2.json test3.json } end end diff --git a/spec/unit/chef_fs/parallelizer.rb b/spec/unit/chef_fs/parallelizer.rb index 32e56c4231..d43e48b7bc 100644 --- a/spec/unit/chef_fs/parallelizer.rb +++ b/spec/unit/chef_fs/parallelizer.rb @@ -443,7 +443,7 @@ describe Chef::ChefFS::Parallelizer do threads = 0.upto(99).map do |i| Thread.new { outputs[i] = parallelizers[i].to_a } end - threads.each { |thread| thread.join } + threads.each(&:join) outputs.each { |output| expect(output.sort).to eq(2.upto(501).to_a) } end end diff --git a/spec/unit/client_spec.rb b/spec/unit/client_spec.rb index 476647a651..5182717af8 100644 --- a/spec/unit/client_spec.rb +++ b/spec/unit/client_spec.rb @@ -647,7 +647,7 @@ describe Chef::Client do EOM end it "should not raise an error" do - expect { client.load_required_recipe(rest, run_context) }.not_to raise_error() + expect { client.load_required_recipe(rest, run_context) }.not_to raise_error end end end diff --git a/spec/unit/config_fetcher_spec.rb b/spec/unit/config_fetcher_spec.rb index abaea6b2dc..8dadd9e681 100644 --- a/spec/unit/config_fetcher_spec.rb +++ b/spec/unit/config_fetcher_spec.rb @@ -7,7 +7,7 @@ describe Chef::ConfigFetcher do let(:http) { double("Chef::HTTP::Simple") } let(:config_location_regex) { Regexp.escape(config_location) } - let(:invalid_json_error_regex) { %r{Could not parse the provided JSON file \(#{config_location_regex}\)} } + let(:invalid_json_error_regex) { /Could not parse the provided JSON file \(#{config_location_regex}\)/ } let(:fetcher) { Chef::ConfigFetcher.new(config_location) } diff --git a/spec/unit/cookbook/metadata_spec.rb b/spec/unit/cookbook/metadata_spec.rb index 8d65efbd6a..7f66fe0c32 100644 --- a/spec/unit/cookbook/metadata_spec.rb +++ b/spec/unit/cookbook/metadata_spec.rb @@ -26,10 +26,10 @@ describe Chef::Cookbook::Metadata do describe "when comparing for equality" do before do - @fields = [ :name, :description, :long_description, :maintainer, - :maintainer_email, :license, :platforms, :dependencies, - :providing, :recipes, :version, :source_url, :issues_url, - :privacy, :ohai_versions, :chef_versions, :gems ] + @fields = %i{name description long_description maintainer + maintainer_email license platforms dependencies + providing recipes version source_url issues_url + privacy ohai_versions chef_versions gems} end it "does not depend on object identity for equality" do diff --git a/spec/unit/cookbook_loader_spec.rb b/spec/unit/cookbook_loader_spec.rb index 9180f13f33..c747f14dd0 100644 --- a/spec/unit/cookbook_loader_spec.rb +++ b/spec/unit/cookbook_loader_spec.rb @@ -88,7 +88,7 @@ describe Chef::CookbookLoader do describe "each" do it "should allow you to iterate over cookbooks with each" do - seen = Hash.new + seen = {} cookbook_loader.each_key do |cookbook_name| seen[cookbook_name] = true end @@ -97,7 +97,7 @@ describe Chef::CookbookLoader do end it "should iterate in alphabetical order" do - seen = Array.new + seen = [] cookbook_loader.each_key do |cookbook_name| seen << cookbook_name end @@ -113,19 +113,19 @@ describe Chef::CookbookLoader do it "should load different attribute files from deeper paths" do expect(full_paths_for_part(:openldap, "attributes").detect do |f| - f =~ /cookbooks\/openldap\/attributes\/smokey.rb/ + f =~ %r{cookbooks/openldap/attributes/smokey.rb} end).not_to eql(nil) end it "should load definition files from deeper paths" do expect(full_paths_for_part(:openldap, "definitions").detect do |f| - f =~ /cookbooks\/openldap\/definitions\/server.rb/ + f =~ %r{cookbooks/openldap/definitions/server.rb} end).not_to eql(nil) end it "should load recipe files from deeper paths" do expect(full_paths_for_part(:openldap, "recipes").detect do |f| - f =~ /cookbooks\/openldap\/recipes\/one.rb/ + f =~ %r{cookbooks/openldap/recipes/one.rb} end).not_to eql(nil) end @@ -134,8 +134,8 @@ describe Chef::CookbookLoader do f =~ /\.dotfile$/ end).to match(/\.dotfile$/) expect(full_paths_for_part(:openldap, "files").detect do |f| - f =~ /\.ssh\/id_rsa$/ - end).to match(/\.ssh\/id_rsa$/) + f =~ %r{\.ssh/id_rsa$} + end).to match(%r{\.ssh/id_rsa$}) end it "should load the metadata for the cookbook" do @@ -173,7 +173,7 @@ describe Chef::CookbookLoader do end it "should have loaded the correct cookbook" do - seen = Hash.new + seen = {} cookbook_loader.each_key do |cookbook_name| seen[cookbook_name] = true end @@ -203,7 +203,7 @@ describe Chef::CookbookLoader do end it "should not load the other cookbooks" do - seen = Hash.new + seen = {} cookbook_loader.each_key do |cookbook_name| seen[cookbook_name] = true end @@ -239,7 +239,7 @@ describe Chef::CookbookLoader do end it "should load all cookbooks" do - seen = Hash.new + seen = {} cookbook_loader.each_key do |cookbook_name| seen[cookbook_name] = true end diff --git a/spec/unit/cookbook_site_streaming_uploader_spec.rb b/spec/unit/cookbook_site_streaming_uploader_spec.rb index 87ff7abdd7..af714094d0 100644 --- a/spec/unit/cookbook_site_streaming_uploader_spec.rb +++ b/spec/unit/cookbook_site_streaming_uploader_spec.rb @@ -25,8 +25,7 @@ class FakeTempfile @basename = basename end - def close - end + def close; end def path "#{@basename}.ZZZ" diff --git a/spec/unit/data_bag_item_spec.rb b/spec/unit/data_bag_item_spec.rb index 70fcd7041e..78953c6b6f 100644 --- a/spec/unit/data_bag_item_spec.rb +++ b/spec/unit/data_bag_item_spec.rb @@ -1,6 +1,6 @@ # # Author:: Adam Jacob (<adam@chef.io>) -# Copyright:: Copyright 2008-2018, Chef Software Inc. +# Copyright:: Copyright 2008-2019, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -43,7 +43,7 @@ describe Chef::DataBagItem do end it "should throw an ArgumentError if you feed it anything but a string" do - expect { data_bag_item.data_bag Hash.new }.to raise_error(ArgumentError) + expect { data_bag_item.data_bag({}) }.to raise_error(ArgumentError) end end @@ -148,12 +148,12 @@ describe Chef::DataBagItem do end it "implements all the methods of Hash" do - methods = [:rehash, :to_hash, :[], :fetch, :[]=, :store, :default, - :default=, :default_proc, :index, :size, :length, - :empty?, :each_value, :each_key, :each_pair, :each, :keys, :values, - :values_at, :delete, :delete_if, :reject!, :clear, - :invert, :update, :replace, :merge!, :merge, :has_key?, :has_value?, - :key?, :value?] + methods = %i{rehash to_hash [] fetch []= store default + default= default_proc index size length + empty? each_value each_key each_pair each keys values + values_at delete delete_if reject! clear + invert update replace merge! merge has_key? has_value? + key? value?} methods.each do |m| expect(data_bag_item).to respond_to(m) end diff --git a/spec/unit/data_bag_spec.rb b/spec/unit/data_bag_spec.rb index 388c35232f..4b0ba42172 100644 --- a/spec/unit/data_bag_spec.rb +++ b/spec/unit/data_bag_spec.rb @@ -46,7 +46,7 @@ describe Chef::DataBag do end it "should throw an ArgumentError if you feed it anything but a string" do - expect { @data_bag.name Hash.new }.to raise_error(ArgumentError) + expect { @data_bag.name({}) }.to raise_error(ArgumentError) end [ ".", "-", "_", "1"].each do |char| diff --git a/spec/unit/decorator_spec.rb b/spec/unit/decorator_spec.rb index 6d73db2cc4..80bbd73bdf 100644 --- a/spec/unit/decorator_spec.rb +++ b/spec/unit/decorator_spec.rb @@ -28,11 +28,11 @@ def impersonates_a(klass) end it "#kind_of?(#{klass}) is true" do - expect(decorator.kind_of?(klass)).to be true + expect(decorator.is_a?(klass)).to be true end it "#kind_of?(Chef::Decorator) is true" do - expect(decorator.kind_of?(Chef::Decorator)).to be true + expect(decorator.is_a?(Chef::Decorator)).to be true end it "#instance_of?(#{klass}) is false" do diff --git a/spec/unit/deprecated_spec.rb b/spec/unit/deprecated_spec.rb index 9c60080cef..7564c042c4 100644 --- a/spec/unit/deprecated_spec.rb +++ b/spec/unit/deprecated_spec.rb @@ -44,7 +44,7 @@ describe Chef::Deprecated do let(:location) { "the location" } it "displays the full URL" do - expect(TestDeprecation.new().url).to eql("https://docs.chef.io/deprecations_test.html") + expect(TestDeprecation.new.url).to eql("https://docs.chef.io/deprecations_test.html") end it "formats a complete deprecation message" do @@ -59,7 +59,7 @@ describe Chef::Deprecated do end collisions = id_map.select { |k, v| v.size != 1 } unless collisions.empty? - raise "Found deprecation ID collisions:\n#{collisions.map { |k, v| "* #{k} #{v.map(&:name).join(', ')}" }.join("\n")}" + raise "Found deprecation ID collisions:\n#{collisions.map { |k, v| "* #{k} #{v.map(&:name).join(", ")}" }.join("\n")}" end end end diff --git a/spec/unit/dsl/data_query_spec.rb b/spec/unit/dsl/data_query_spec.rb index f93f07bc52..afc2eacbd7 100644 --- a/spec/unit/dsl/data_query_spec.rb +++ b/spec/unit/dsl/data_query_spec.rb @@ -24,7 +24,7 @@ class DataQueryDSLTester end describe Chef::DSL::DataQuery do - let(:node) { Hash.new } + let(:node) { {} } let(:language) do language = DataQueryDSLTester.new @@ -68,7 +68,8 @@ describe Chef::DSL::DataQuery do "a1" => [1, 2, 3], "a2" => { "b1" => true }, }, - } end + } + end let(:item) do item = Chef::DataBagItem.new diff --git a/spec/unit/dsl/declare_resource_spec.rb b/spec/unit/dsl/declare_resource_spec.rb index 255e85e22e..ead0be2967 100644 --- a/spec/unit/dsl/declare_resource_spec.rb +++ b/spec/unit/dsl/declare_resource_spec.rb @@ -34,7 +34,7 @@ describe Chef::ResourceCollection do describe "mixed in correctly" do it "the resources() method winds up in the right classes" do - methods = [ :resources, :find_resource, :find_resource!, :edit_resource, :edit_resource!, :delete_resource, :delete_resource!, :declare_resource, :build_resource ] + methods = %i{resources find_resource find_resource! edit_resource edit_resource! delete_resource delete_resource! declare_resource build_resource} expect(Chef::Resource.instance_methods).to include(*methods) expect(Chef::Recipe.instance_methods).to include(*methods) expect(Chef::Provider.instance_methods).to include(*methods) diff --git a/spec/unit/dsl/platform_introspection_spec.rb b/spec/unit/dsl/platform_introspection_spec.rb index 51123ba930..7af233a769 100644 --- a/spec/unit/dsl/platform_introspection_spec.rb +++ b/spec/unit/dsl/platform_introspection_spec.rb @@ -40,7 +40,7 @@ describe Chef::DSL::PlatformIntrospection::PlatformDependentValue do before do platform_hash = { :openbsd => { default: "free, functional, secure" }, - [:redhat, :centos, :fedora, :scientific] => { default: '"stable"' }, + %i{redhat centos fedora scientific} => { default: '"stable"' }, :ubuntu => { "10.04" => "using upstart more", :default => "using init more" }, :default => "bork da bork", } @@ -84,7 +84,7 @@ describe Chef::DSL::PlatformIntrospection::PlatformDependentValue do end describe Chef::DSL::PlatformIntrospection::PlatformFamilyDependentValue do before do - @array_values = [:stop, :start, :reload] + @array_values = %i{stop start reload} @platform_family_hash = { "debian" => "debian value", diff --git a/spec/unit/encrypted_data_bag_item/check_encrypted_spec.rb b/spec/unit/encrypted_data_bag_item/check_encrypted_spec.rb index 7e885f8818..f8fcb654d9 100644 --- a/spec/unit/encrypted_data_bag_item/check_encrypted_spec.rb +++ b/spec/unit/encrypted_data_bag_item/check_encrypted_spec.rb @@ -47,7 +47,8 @@ describe Chef::EncryptedDataBagItem::CheckEncrypted do "a1" => [1, 2, 3], "a2" => { "b1" => true }, }, - } end + } + end let(:version) { 1 } let(:encoded_data) do diff --git a/spec/unit/encrypted_data_bag_item_spec.rb b/spec/unit/encrypted_data_bag_item_spec.rb index 14b5d9eb28..f406aa2ad0 100644 --- a/spec/unit/encrypted_data_bag_item_spec.rb +++ b/spec/unit/encrypted_data_bag_item_spec.rb @@ -325,7 +325,8 @@ describe Chef::EncryptedDataBagItem do "id" => "item_name", "greeting" => "hello", "nested" => { "a1" => [1, 2, 3], "a2" => { "b1" => true } }, - } end + } + end let(:secret) { "abc123SECRET" } let(:encoded_data) { subject.encrypt_data_bag_item(plaintext_data, secret) } diff --git a/spec/unit/environment_spec.rb b/spec/unit/environment_spec.rb index 4da3a9fa0e..42906ef772 100644 --- a/spec/unit/environment_spec.rb +++ b/spec/unit/environment_spec.rb @@ -48,8 +48,8 @@ describe Chef::Environment do end it "should not accept anything but strings" do - expect { @environment.name(Array.new) }.to raise_error(ArgumentError) - expect { @environment.name(Hash.new) }.to raise_error(ArgumentError) + expect { @environment.name([]) }.to raise_error(ArgumentError) + expect { @environment.name({}) }.to raise_error(ArgumentError) expect { @environment.name(2) }.to raise_error(ArgumentError) end end @@ -65,8 +65,8 @@ describe Chef::Environment do end it "should not accept anything but strings" do - expect { @environment.description(Array.new) }.to raise_error(ArgumentError) - expect { @environment.description(Hash.new) }.to raise_error(ArgumentError) + expect { @environment.description([]) }.to raise_error(ArgumentError) + expect { @environment.description({}) }.to raise_error(ArgumentError) expect { @environment.description(42) }.to raise_error(ArgumentError) end end @@ -82,7 +82,7 @@ describe Chef::Environment do end it "should throw an ArgumentError if we aren't a kind of hash" do - expect { @environment.default_attributes(Array.new) }.to raise_error(ArgumentError) + expect { @environment.default_attributes([]) }.to raise_error(ArgumentError) end end @@ -97,7 +97,7 @@ describe Chef::Environment do end it "should throw an ArgumentError if we aren't a kind of hash" do - expect { @environment.override_attributes(Array.new) }.to raise_error(ArgumentError) + expect { @environment.override_attributes([]) }.to raise_error(ArgumentError) end end @@ -121,7 +121,7 @@ describe Chef::Environment do it "should not accept anything but a hash" do expect { @environment.cookbook_versions("I am a string!") }.to raise_error(ArgumentError) - expect { @environment.cookbook_versions(Array.new) }.to raise_error(ArgumentError) + expect { @environment.cookbook_versions([]) }.to raise_error(ArgumentError) expect { @environment.cookbook_versions(42) }.to raise_error(ArgumentError) end @@ -257,7 +257,7 @@ describe Chef::Environment do end it "should return false if anything other than a hash is passed as the argument" do - expect(Chef::Environment.validate_cookbook_versions(Array.new)).to eq(false) + expect(Chef::Environment.validate_cookbook_versions([])).to eq(false) expect(Chef::Environment.validate_cookbook_versions(42)).to eq(false) expect(Chef::Environment.validate_cookbook_versions(Chef::CookbookVersion.new("meta"))).to eq(false) expect(Chef::Environment.validate_cookbook_versions("cookbook => 1.2.3")).to eq(false) diff --git a/spec/unit/event_dispatch/dsl_spec.rb b/spec/unit/event_dispatch/dsl_spec.rb index 979b067fb6..009242f4fb 100644 --- a/spec/unit/event_dispatch/dsl_spec.rb +++ b/spec/unit/event_dispatch/dsl_spec.rb @@ -63,7 +63,7 @@ describe Chef::EventDispatch::DSL do resource = Chef::Resource::RubyBlock.new("foo", run_context) resource.block {} resource.run_action(:run) - expect(calls).to eq([:started, :updated]) + expect(calls).to eq(%i{started updated}) end it "preserve instance variables across handler callbacks" do diff --git a/spec/unit/formatters/error_inspectors/resource_failure_inspector_spec.rb b/spec/unit/formatters/error_inspectors/resource_failure_inspector_spec.rb index 0cdb06c3b3..7add65150a 100644 --- a/spec/unit/formatters/error_inspectors/resource_failure_inspector_spec.rb +++ b/spec/unit/formatters/error_inspectors/resource_failure_inspector_spec.rb @@ -60,7 +60,7 @@ describe Chef::Formatters::ErrorInspectors::ResourceFailureInspector do @trace = [ "/var/chef/cache/cookbooks/syntax-err/recipes/default.rb:14:in `from_file'", "/var/chef/cache/cookbooks/syntax-err/recipes/default.rb:11:in `from_file'", - "/usr/local/lib/ruby/gems/chef/lib/chef/client.rb:123:in `run'" # should not display + "/usr/local/lib/ruby/gems/chef/lib/chef/client.rb:123:in `run'", # should not display ] @exception = Chef::Exceptions::Package.new("No such package 'non-existing-package'") @exception.set_backtrace(@trace) @@ -122,7 +122,7 @@ describe Chef::Formatters::ErrorInspectors::ResourceFailureInspector do source_line = "C:/Users/btm/chef/chef/spec/unit/fake_file.rb:2: undefined local variable or method `non_existent' for main:Object (NameError)" @resource.source_line = source_line @inspector = Chef::Formatters::ErrorInspectors::ResourceFailureInspector.new(@resource, :create, @exception) - expect(@inspector.recipe_snippet).to match(/^# In C:\/Users\/btm/) + expect(@inspector.recipe_snippet).to match(%r{^# In C:/Users/btm}) end it "parses a Windows path" do @@ -136,7 +136,7 @@ describe Chef::Formatters::ErrorInspectors::ResourceFailureInspector do source_line = "/home/btm/src/chef/chef/spec/unit/fake_file.rb:2: undefined local variable or method `non_existent' for main:Object (NameError)" @resource.source_line = source_line @inspector = Chef::Formatters::ErrorInspectors::ResourceFailureInspector.new(@resource, :create, @exception) - expect(@inspector.recipe_snippet).to match(/^# In \/home\/btm/) + expect(@inspector.recipe_snippet).to match(%r{^# In /home/btm}) end context "when the recipe file does not exist" do diff --git a/spec/unit/guard_interpreter/resource_guard_interpreter_spec.rb b/spec/unit/guard_interpreter/resource_guard_interpreter_spec.rb index b2ca8704b0..6d7f31c6f1 100644 --- a/spec/unit/guard_interpreter/resource_guard_interpreter_spec.rb +++ b/spec/unit/guard_interpreter/resource_guard_interpreter_spec.rb @@ -22,7 +22,7 @@ describe Chef::GuardInterpreter::ResourceGuardInterpreter do let(:node) do node = Chef::Node.new - node.default["kernel"] = Hash.new + node.default["kernel"] = {} node.default["kernel"][:machine] = :x86_64.to_s node.automatic[:os] = "windows" node diff --git a/spec/unit/http/authenticator_spec.rb b/spec/unit/http/authenticator_spec.rb index a2d4cb4815..0713aacc24 100644 --- a/spec/unit/http/authenticator_spec.rb +++ b/spec/unit/http/authenticator_spec.rb @@ -23,7 +23,7 @@ describe Chef::HTTP::Authenticator do let(:class_instance) { Chef::HTTP::Authenticator.new(client_name: "test") } let(:method) { "GET" } let(:url) { URI("https://chef.example.com/organizations/test") } - let(:headers) { Hash.new } + let(:headers) { {} } let(:data) { "" } context "when handle_request is called" do @@ -92,7 +92,8 @@ describe Chef::HTTP::Authenticator do it "calls authentication_headers with the proper input" do expect(class_instance).to receive(:authentication_headers).with( method, url, data, - { "X-Ops-Server-API-Version" => Chef::HTTP::Authenticator::DEFAULT_SERVER_API_VERSION }).and_return({}) + { "X-Ops-Server-API-Version" => Chef::HTTP::Authenticator::DEFAULT_SERVER_API_VERSION } + ).and_return({}) class_instance.handle_request(method, url, headers, data) end end diff --git a/spec/unit/http/json_input_spec.rb b/spec/unit/http/json_input_spec.rb index a76c8d1dc7..cddad20f55 100644 --- a/spec/unit/http/json_input_spec.rb +++ b/spec/unit/http/json_input_spec.rb @@ -21,7 +21,7 @@ require "chef/http/json_input" describe Chef::HTTP::JSONInput do - let(:json_encoder) { described_class.new() } + let(:json_encoder) { described_class.new } let(:url) { URI.parse("http://example.com") } let(:headers) { {} } diff --git a/spec/unit/key_spec.rb b/spec/unit/key_spec.rb index e3d9f8e7ad..efae549490 100644 --- a/spec/unit/key_spec.rb +++ b/spec/unit/key_spec.rb @@ -66,7 +66,7 @@ describe Chef::Key do context "when you feed it anything but a string" do it "should raise an ArgumentError" do - expect { key.send(field, Hash.new) }.to raise_error(ArgumentError) + expect { key.send(field, {}) }.to raise_error(ArgumentError) end end end diff --git a/spec/unit/knife/bootstrap_spec.rb b/spec/unit/knife/bootstrap_spec.rb index ee376e2bb4..5f4be8dfa2 100644 --- a/spec/unit/knife/bootstrap_spec.rb +++ b/spec/unit/knife/bootstrap_spec.rb @@ -35,7 +35,8 @@ describe Chef::Knife::Bootstrap do double("TrainConnector", windows?: windows_test, linux?: linux_test, - unix?: unix_test) end + unix?: unix_test) + end let(:knife) do Chef::Log.logger = Logger.new(StringIO.new) @@ -107,7 +108,7 @@ describe Chef::Knife::Bootstrap do expect(knife).to receive(:read_secret).and_return("secrets") expect(rendered_template).to match("cat > /etc/chef/encrypted_data_bag_secret <<'EOP'") expect(rendered_template).to match('{"run_list":\[\]}') - expect(rendered_template).to match(%r{secrets}) + expect(rendered_template).to match(/secrets/) end end end @@ -127,7 +128,7 @@ describe Chef::Knife::Bootstrap do knife.render_template end it "configures the preinstall command in the bootstrap template correctly" do - expect(rendered_template).to match(%r{command}) + expect(rendered_template).to match(/command/) end end @@ -138,7 +139,7 @@ describe Chef::Knife::Bootstrap do knife.render_template end it "configures the https_proxy environment variable in the bootstrap template correctly" do - expect(rendered_template).to match(%r{https_proxy="1.1.1.1" export https_proxy}) + expect(rendered_template).to match(/https_proxy="1.1.1.1" export https_proxy/) end end @@ -149,7 +150,7 @@ describe Chef::Knife::Bootstrap do knife.render_template end it "configures the https_proxy environment variable in the bootstrap template correctly" do - expect(rendered_template).to match(%r{no_proxy="localserver" export no_proxy}) + expect(rendered_template).to match(/no_proxy="localserver" export no_proxy/) end end @@ -360,7 +361,7 @@ describe Chef::Knife::Bootstrap do it "should create a hint file when told to" do knife.parse_options(["--hint", "openstack"]) knife.merge_configs - expect(knife.render_template).to match(/\/etc\/chef\/ohai\/hints\/openstack.json/) + expect(knife.render_template).to match(%r{/etc/chef/ohai/hints/openstack.json}) end it "should populate a hint file with JSON when given a file to read" do @@ -393,7 +394,7 @@ describe Chef::Knife::Bootstrap do let(:setting) { "api.opscode.com" } it "renders the client.rb with a single FQDN no_proxy entry" do - expect(rendered_template).to match(%r{.*no_proxy\s*"api.opscode.com".*}) + expect(rendered_template).to match(/.*no_proxy\s*"api.opscode.com".*/) end end @@ -401,7 +402,7 @@ describe Chef::Knife::Bootstrap do let(:setting) { "api.opscode.com,172.16.10.*" } it "renders the client.rb with comma-separated FQDN and wildcard IP address no_proxy entries" do - expect(rendered_template).to match(%r{.*no_proxy\s*"api.opscode.com,172.16.10.\*".*}) + expect(rendered_template).to match(/.*no_proxy\s*"api.opscode.com,172.16.10.\*".*/) end end @@ -459,7 +460,7 @@ describe Chef::Knife::Bootstrap do it "creates a secret file" do expect(knife).to receive(:encryption_secret_provided_ignore_encrypt_flag?).and_return(true) expect(knife).to receive(:read_secret).and_return(secret) - expect(rendered_template).to match(%r{#{secret}}) + expect(rendered_template).to match(/#{secret}/) end it "renders the client.rb with an encrypted_data_bag_secret entry" do @@ -569,7 +570,9 @@ describe Chef::Knife::Bootstrap do context "when client_d_dir is set" do let(:client_d_dir) do Chef::Util::PathHelper.cleanpath( - File.join(File.dirname(__FILE__), "../../data/client.d_00")) end + File.join(File.dirname(__FILE__), "../../data/client.d_00") + ) + end it "creates /etc/chef/client.d" do expect(rendered_template).to match("mkdir -p /etc/chef/client\.d") @@ -594,7 +597,9 @@ describe Chef::Knife::Bootstrap do context "a nested directory structure" do let(:client_d_dir) do Chef::Util::PathHelper.cleanpath( - File.join(File.dirname(__FILE__), "../../data/client.d_01")) end + File.join(File.dirname(__FILE__), "../../data/client.d_01") + ) + end it "creates a file foo/bar.rb" do expect(rendered_template).to match("cat > /etc/chef/client.d/foo/bar.rb <<'EOP'") expect(rendered_template).to match("1 / 0") @@ -1554,7 +1559,8 @@ describe Chef::Knife::Bootstrap do ssl: false, ssl_peer_fingerprint: nil, operation_timeout: 60, - } end + } + end it "generates a correct configuration hash with expected defaults" do expect(knife.winrm_opts).to eq expected @@ -1730,7 +1736,7 @@ describe Chef::Knife::Bootstrap do before do Chef::Config[:validation_key] = "/blah" allow(vault_handler_mock).to receive(:doing_chef_vault?).and_return false - allow(File).to receive(:exist?).with(/\/blah/).and_return false + allow(File).to receive(:exist?).with(%r{/blah}).and_return false end it_behaves_like "creating the client locally" end @@ -1738,7 +1744,7 @@ describe Chef::Knife::Bootstrap do context "when a valid validation key is given and we're doing old-style client creation" do before do Chef::Config[:validation_key] = "/blah" - allow(File).to receive(:exist?).with(/\/blah/).and_return true + allow(File).to receive(:exist?).with(%r{/blah}).and_return true allow(vault_handler_mock).to receive(:doing_chef_vault?).and_return false end diff --git a/spec/unit/knife/client_bulk_delete_spec.rb b/spec/unit/knife/client_bulk_delete_spec.rb index feebab4986..770ba8762f 100644 --- a/spec/unit/knife/client_bulk_delete_spec.rb +++ b/spec/unit/knife/client_bulk_delete_spec.rb @@ -42,10 +42,10 @@ describe Chef::Knife::ClientBulkDelete do let(:nonvalidator_client_names) { %w{tim dan stephen} } let(:nonvalidator_clients) do - clients = Hash.new + clients = {} nonvalidator_client_names.each do |client_name| - client = Chef::ApiClientV1.new() + client = Chef::ApiClientV1.new client.name(client_name) allow(client).to receive(:destroy).and_return(true) clients[client_name] = client @@ -56,10 +56,10 @@ describe Chef::Knife::ClientBulkDelete do let(:validator_client_names) { %w{myorg-validator} } let(:validator_clients) do - clients = Hash.new + clients = {} validator_client_names.each do |validator_client_name| - validator_client = Chef::ApiClientV1.new() + validator_client = Chef::ApiClientV1.new validator_client.name(validator_client_name) allow(validator_client).to receive(:validator).and_return(true) allow(validator_client).to receive(:destroy).and_return(true) diff --git a/spec/unit/knife/configure_client_spec.rb b/spec/unit/knife/configure_client_spec.rb index c83ceed6cb..be76250e7c 100644 --- a/spec/unit/knife/configure_client_spec.rb +++ b/spec/unit/knife/configure_client_spec.rb @@ -58,7 +58,7 @@ describe Chef::Knife::ConfigureClient do it "should write out the config file" do allow(FileUtils).to receive(:mkdir_p) @knife.run - expect(@client_file.string).to match /chef_server_url\s+'https\:\/\/chef\.example\.com'/ + expect(@client_file.string).to match %r{chef_server_url\s+'https\://chef\.example\.com'} expect(@client_file.string).to match /validation_client_name\s+'chef-validator'/ end diff --git a/spec/unit/knife/configure_spec.rb b/spec/unit/knife/configure_spec.rb index 1cdad0cd0e..6b41e54778 100644 --- a/spec/unit/knife/configure_spec.rb +++ b/spec/unit/knife/configure_spec.rb @@ -159,7 +159,7 @@ describe Chef::Knife::Configure do @knife.run expect(config_file.string).to match(/^client_name[\s]+=[\s]+'#{Etc.getlogin}'$/) expect(config_file.string).to match(%r{^client_key[\s]+=[\s]+'/home/you/.chef/#{Etc.getlogin}.pem'$}) - expect(config_file.string).to match(%r{^chef_server_url\s+=[\s]+'#{default_server_url}'$}) + expect(config_file.string).to match(/^chef_server_url\s+=[\s]+'#{default_server_url}'$/) end it "creates a new client when given the --initial option" do diff --git a/spec/unit/knife/cookbook_bulk_delete_spec.rb b/spec/unit/knife/cookbook_bulk_delete_spec.rb index c8c1873081..d01213227b 100644 --- a/spec/unit/knife/cookbook_bulk_delete_spec.rb +++ b/spec/unit/knife/cookbook_bulk_delete_spec.rb @@ -31,7 +31,7 @@ describe Chef::Knife::CookbookBulkDelete do allow(@knife.ui).to receive(:stdout).and_return(@stdout) allow(@knife.ui).to receive(:stderr).and_return(@stderr) allow(@knife.ui).to receive(:confirm).and_return(true) - @cookbooks = Hash.new + @cookbooks = {} %w{cheezburger pizza lasagna}.each do |cookbook_name| cookbook = Chef::CookbookVersion.new(cookbook_name) @cookbooks[cookbook_name] = cookbook diff --git a/spec/unit/knife/cookbook_delete_spec.rb b/spec/unit/knife/cookbook_delete_spec.rb index b2f17778cd..4de907e94d 100644 --- a/spec/unit/knife/cookbook_delete_spec.rb +++ b/spec/unit/knife/cookbook_delete_spec.rb @@ -77,7 +77,7 @@ describe Chef::Knife::CookbookDelete do @knife.version = "1.0.0" expect(@knife).to receive(:delete_object).with(Chef::CookbookVersion, "foobar version 1.0.0", - "cookbook").and_yield() + "cookbook").and_yield expect(@knife).to receive(:delete_request).with("cookbooks/foobar/1.0.0") @knife.delete_explicit_version end diff --git a/spec/unit/knife/cookbook_download_spec.rb b/spec/unit/knife/cookbook_download_spec.rb index 122c284b93..78dd20e2d2 100644 --- a/spec/unit/knife/cookbook_download_spec.rb +++ b/spec/unit/knife/cookbook_download_spec.rb @@ -112,7 +112,7 @@ describe Chef::Knife::CookbookDownload do it "should print an error and exit if the cookbook download directory already exists" do expect(File).to receive(:exists?).with("/var/tmp/chef/foobar-1.0.0").and_return(true) - expect(@knife.ui).to receive(:fatal).with(/\/var\/tmp\/chef\/foobar-1\.0\.0 exists/i) + expect(@knife.ui).to receive(:fatal).with(%r{/var/tmp/chef/foobar-1\.0\.0 exists}i) expect { @knife.run }.to raise_error(SystemExit) end @@ -141,7 +141,7 @@ describe Chef::Knife::CookbookDownload do expect(@stderr.string).to match /downloading #{segment}/im end expect(@stderr.string).to match /downloading foobar cookbook version 1\.0\.0/im - expect(@stderr.string).to match /cookbook downloaded to \/var\/tmp\/chef\/foobar-1\.0\.0/im + expect(@stderr.string).to match %r{cookbook downloaded to /var/tmp/chef/foobar-1\.0\.0}im end describe "with -f or --force" do diff --git a/spec/unit/knife/cookbook_metadata_spec.rb b/spec/unit/knife/cookbook_metadata_spec.rb index c19fc5ae2d..04d851be6a 100644 --- a/spec/unit/knife/cookbook_metadata_spec.rb +++ b/spec/unit/knife/cookbook_metadata_spec.rb @@ -98,8 +98,8 @@ describe Chef::Knife::CookbookMetadata do it "should generate the metadata for each cookbook" do expect(Chef::CookbookLoader).to receive(:new).with(cookbook_dir).and_call_original knife.run - expect(stderr.string).to match /generating metadata for foo from #{cookbook_dir}\/foo\/metadata\.rb/im - expect(stderr.string).to match /generating metadata for bar from #{cookbook_dir}\/bar\/metadata\.rb/im + expect(stderr.string).to match %r{generating metadata for foo from #{cookbook_dir}/foo/metadata\.rb}im + expect(stderr.string).to match %r{generating metadata for bar from #{cookbook_dir}/bar/metadata\.rb}im end it "with -o or --cookbook_path should look in the provided path and generate cookbook metadata" do @@ -107,8 +107,8 @@ describe Chef::Knife::CookbookMetadata do knife.config[:cookbook_path] = cookbook_dir expect(Chef::CookbookLoader).to receive(:new).with(cookbook_dir).and_call_original knife.run - expect(stderr.string).to match /generating metadata for foo from #{cookbook_dir}\/foo\/metadata\.rb/im - expect(stderr.string).to match /generating metadata for bar from #{cookbook_dir}\/bar\/metadata\.rb/im + expect(stderr.string).to match %r{generating metadata for foo from #{cookbook_dir}/foo/metadata\.rb}im + expect(stderr.string).to match %r{generating metadata for bar from #{cookbook_dir}/bar/metadata\.rb}im end end diff --git a/spec/unit/knife/cookbook_upload_spec.rb b/spec/unit/knife/cookbook_upload_spec.rb index 8bff31197c..9c371c4140 100644 --- a/spec/unit/knife/cookbook_upload_spec.rb +++ b/spec/unit/knife/cookbook_upload_spec.rb @@ -264,7 +264,8 @@ describe Chef::Knife::CookbookUpload do it "should warn users that no cookbooks exist" do knife.config[:cookbook_path] = ["/chef-repo/cookbooks", "/home/user/cookbooks"] expect(knife.ui).to receive(:warn).with( - /Could not find any cookbooks in your cookbook path: #{knife.config[:cookbook_path].join(', ')}\. Use --cookbook-path to specify the desired path\./) + /Could not find any cookbooks in your cookbook path: #{knife.config[:cookbook_path].join(', ')}\. Use --cookbook-path to specify the desired path\./ + ) knife.run end end @@ -273,7 +274,8 @@ describe Chef::Knife::CookbookUpload do it "should warn users that no cookbooks exist" do knife.config[:cookbook_path] = "/chef-repo/cookbooks" expect(knife.ui).to receive(:warn).with( - /Could not find any cookbooks in your cookbook path: #{knife.config[:cookbook_path]}\. Use --cookbook-path to specify the desired path\./) + /Could not find any cookbooks in your cookbook path: #{knife.config[:cookbook_path]}\. Use --cookbook-path to specify the desired path\./ + ) knife.run end end diff --git a/spec/unit/knife/core/gem_glob_loader_spec.rb b/spec/unit/knife/core/gem_glob_loader_spec.rb index 689426de1b..c8bd34d4a9 100644 --- a/spec/unit/knife/core/gem_glob_loader_spec.rb +++ b/spec/unit/knife/core/gem_glob_loader_spec.rb @@ -34,7 +34,7 @@ describe Chef::Knife::SubcommandLoader::GemGlobLoader do it "builds a list of the core subcommand file require paths" do expect(loader.subcommand_files).not_to be_empty loader.subcommand_files.each do |require_path| - expect(require_path).to match(/chef\/knife\/.*|plugins\/knife\/.*/) + expect(require_path).to match(%r{chef/knife/.*|plugins/knife/.*}) end end @@ -52,7 +52,7 @@ describe Chef::Knife::SubcommandLoader::GemGlobLoader do expect($LOAD_PATH).to receive(:map).and_return([]) if Gem::Specification.respond_to? :latest_specs expect(Gem::Specification).to receive(:latest_specs).with(true).and_return(gems) - expect(gems[0]).to receive(:matches_for_glob).with(/chef\/knife\/\*\.rb\{(.*),\.rb,(.*)\}/).and_return(gem_files) + expect(gems[0]).to receive(:matches_for_glob).with(%r{chef/knife/\*\.rb\{(.*),\.rb,(.*)\}}).and_return(gem_files) else expect(Gem.source_index).to receive(:latest_specs).with(true).and_return(gems) expect(gems[0]).to receive(:require_paths).twice.and_return(["lib"]) @@ -185,7 +185,7 @@ describe Chef::Knife::SubcommandLoader::GemGlobLoader do expect(Gem.source_index).to receive(:latest_specs).and_call_original end loader.subcommand_files.each do |require_path| - expect(require_path).to match(/chef\/knife\/.*|plugins\/knife\/.*/) + expect(require_path).to match(%r{chef/knife/.*|plugins/knife/.*}) end end @@ -201,7 +201,7 @@ describe Chef::Knife::SubcommandLoader::GemGlobLoader do expect(Gem.source_index).to receive(:latest_specs).and_call_original end loader.subcommand_files.each do |require_path| - expect(require_path).to match(/chef\/knife\/.*|plugins\/knife\/.*/) + expect(require_path).to match(%r{chef/knife/.*|plugins/knife/.*}) end end end diff --git a/spec/unit/knife/core/hashed_command_loader_spec.rb b/spec/unit/knife/core/hashed_command_loader_spec.rb index c59838478e..c463a36fb4 100644 --- a/spec/unit/knife/core/hashed_command_loader_spec.rb +++ b/spec/unit/knife/core/hashed_command_loader_spec.rb @@ -44,7 +44,9 @@ describe Chef::Knife::SubcommandLoader::HashedCommandLoader do let(:loader) do Chef::Knife::SubcommandLoader::HashedCommandLoader.new( File.join(CHEF_SPEC_DATA, "knife-site-subcommands"), - plugin_manifest) end + plugin_manifest + ) + end describe "#list_commands" do before do diff --git a/spec/unit/knife/core/node_editor_spec.rb b/spec/unit/knife/core/node_editor_spec.rb index ccf6776593..493de3c5b1 100644 --- a/spec/unit/knife/core/node_editor_spec.rb +++ b/spec/unit/knife/core/node_editor_spec.rb @@ -44,13 +44,13 @@ describe Chef::Knife::NodeEditor do describe "#view" do it "returns a Hash with only the name, chef_environment, normal, " + "policy_name, policy_group, and run_list properties" do - expected = node_data.select do |key,| - %w{ name chef_environment normal - policy_name policy_group run_list }.include?(key) - end + expected = node_data.select do |key,| + %w{ name chef_environment normal + policy_name policy_group run_list }.include?(key) + end - expect(subject.view).to eq(expected) - end + expect(subject.view).to eq(expected) + end context "when config[:all_attributes] == true" do let(:config) { base_config.merge(all_attributes: true) } @@ -190,8 +190,8 @@ describe Chef::Knife::NodeEditor do it "returns an array of property names that doesn't include " + "the non-editable properties" do - expect(subject.updated?).to eql %w{ chef_environment normal policy_name policy_group run_list } - end + expect(subject.updated?).to eql %w{ chef_environment normal policy_name policy_group run_list } + end end end diff --git a/spec/unit/knife/core/windows_bootstrap_context_spec.rb b/spec/unit/knife/core/windows_bootstrap_context_spec.rb index a662b1c203..e5a4e955e8 100644 --- a/spec/unit/knife/core/windows_bootstrap_context_spec.rb +++ b/spec/unit/knife/core/windows_bootstrap_context_spec.rb @@ -157,8 +157,7 @@ describe Chef::Knife::Core::WindowsBootstrapContext do validation_client_name: "chef-validator-testing", file_cache_path: "c:/chef/cache", file_backup_path: "c:/chef/backup", - cache_options: ({ path: "c:/chef/cache/checksums", skip_expires: true }) - )) + cache_options: ({ path: "c:/chef/cache/checksums", skip_expires: true }))) end it "generates the config file data" do diff --git a/spec/unit/knife/data_bag_from_file_spec.rb b/spec/unit/knife/data_bag_from_file_spec.rb index 3bea392ae2..bc0ca330e8 100644 --- a/spec/unit/knife/data_bag_from_file_spec.rb +++ b/spec/unit/knife/data_bag_from_file_spec.rb @@ -77,7 +77,8 @@ describe Chef::Knife::DataBagFromFile do "id" => "item_name", "greeting" => "hello", "nested" => { "a1" => [1, 2, 3], "a2" => { "b1" => true } }, - } end + } + end let(:enc_data) { Chef::EncryptedDataBagItem.encrypt_data_bag_item(plain_data, secret) } let(:rest) { double("Chef::ServerAPI") } diff --git a/spec/unit/knife/data_bag_show_spec.rb b/spec/unit/knife/data_bag_show_spec.rb index 8dd0669993..6ac6dd3c95 100644 --- a/spec/unit/knife/data_bag_show_spec.rb +++ b/spec/unit/knife/data_bag_show_spec.rb @@ -47,7 +47,8 @@ describe Chef::Knife::DataBagShow do let(:data_bag_contents) do { "id" => "id", "baz" => "http://localhost:4000/data/bag_o_data/baz", - "qux" => "http://localhost:4000/data/bag_o_data/qux" } end + "qux" => "http://localhost:4000/data/bag_o_data/qux" } + end let(:enc_hash) { Chef::EncryptedDataBagItem.encrypt_data_bag_item(data_bag_contents, secret) } let(:data_bag) { Chef::DataBagItem.from_hash(data_bag_contents) } let(:data_bag_with_encoded_hash) { Chef::DataBagItem.from_hash(enc_hash) } diff --git a/spec/unit/knife/key_create_spec.rb b/spec/unit/knife/key_create_spec.rb index fcbfd40381..6437ba2bcd 100644 --- a/spec/unit/knife/key_create_spec.rb +++ b/spec/unit/knife/key_create_spec.rb @@ -84,7 +84,7 @@ Tfuc9dUYsFjptWYrV6pfEQ+bgo1OGBXORBFcFL+2D7u9JYquKrMgosznHoEkQNLo 0wIDAQAB -----END PUBLIC KEY-----" end - let(:config) { Hash.new } + let(:config) { {} } let(:actor) { "charmander" } let(:ui) { instance_double("Chef::Knife::UI") } diff --git a/spec/unit/knife/key_edit_spec.rb b/spec/unit/knife/key_edit_spec.rb index 7c409f5ea0..1f8067c160 100644 --- a/spec/unit/knife/key_edit_spec.rb +++ b/spec/unit/knife/key_edit_spec.rb @@ -86,7 +86,7 @@ Tfuc9dUYsFjptWYrV6pfEQ+bgo1OGBXORBFcFL+2D7u9JYquKrMgosznHoEkQNLo 0wIDAQAB -----END PUBLIC KEY-----" end - let(:config) { Hash.new } + let(:config) { {} } let(:actor) { "charmander" } let(:keyname) { "charmander-key" } let(:ui) { instance_double("Chef::Knife::UI") } diff --git a/spec/unit/knife/key_list_spec.rb b/spec/unit/knife/key_list_spec.rb index e221a4da72..c65a11b08c 100644 --- a/spec/unit/knife/key_list_spec.rb +++ b/spec/unit/knife/key_list_spec.rb @@ -73,7 +73,7 @@ describe "key list commands that inherit knife" do end describe Chef::Knife::KeyList do - let(:config) { Hash.new } + let(:config) { {} } let(:actor) { "charmander" } let(:ui) { instance_double("Chef::Knife::UI") } diff --git a/spec/unit/knife/node_bulk_delete_spec.rb b/spec/unit/knife/node_bulk_delete_spec.rb index 2a3563e563..db9e2caab1 100644 --- a/spec/unit/knife/node_bulk_delete_spec.rb +++ b/spec/unit/knife/node_bulk_delete_spec.rb @@ -28,7 +28,7 @@ describe Chef::Knife::NodeBulkDelete do @stdout = StringIO.new allow(@knife.ui).to receive(:stdout).and_return(@stdout) allow(@knife.ui).to receive(:confirm).and_return(true) - @nodes = Hash.new + @nodes = {} %w{adam brent jacob}.each do |node_name| @nodes[node_name] = "http://localhost:4000/nodes/#{node_name}" end @@ -44,14 +44,14 @@ describe Chef::Knife::NodeBulkDelete do # I hate not having == defined for anything :( actual = @knife.all_nodes expect(actual.keys).to match_array(expected.keys) - expect(actual.values.map { |n| n.name }).to match_array(%w{adam brent jacob}) + expect(actual.values.map(&:name)).to match_array(%w{adam brent jacob}) end end describe "run" do before do @inflatedish_list = @nodes.keys.inject({}) do |nodes_by_name, name| - node = Chef::Node.new() + node = Chef::Node.new node.name(name) allow(node).to receive(:destroy).and_return(true) nodes_by_name[name] = node diff --git a/spec/unit/knife/node_delete_spec.rb b/spec/unit/knife/node_delete_spec.rb index cc2e0b23af..c5b8925fb5 100644 --- a/spec/unit/knife/node_delete_spec.rb +++ b/spec/unit/knife/node_delete_spec.rb @@ -29,8 +29,8 @@ describe Chef::Knife::NodeDelete do allow(@knife).to receive(:output).and_return(true) allow(@knife).to receive(:confirm).and_return(true) - @adam_node = Chef::Node.new() - @ben_node = Chef::Node.new() + @adam_node = Chef::Node.new + @ben_node = Chef::Node.new allow(@ben_node).to receive(:destroy).and_return(true) allow(@adam_node).to receive(:destroy).and_return(true) allow(Chef::Node).to receive(:load).with("adam").and_return(@adam_node) diff --git a/spec/unit/knife/node_edit_spec.rb b/spec/unit/knife/node_edit_spec.rb index dfc0986ebe..83d78b68f1 100644 --- a/spec/unit/knife/node_edit_spec.rb +++ b/spec/unit/knife/node_edit_spec.rb @@ -35,7 +35,7 @@ describe Chef::Knife::NodeEdit do print_after: nil, } @knife.name_args = [ "adam" ] - @node = Chef::Node.new() + @node = Chef::Node.new end it "should load the node" do diff --git a/spec/unit/knife/node_environment_set_spec.rb b/spec/unit/knife/node_environment_set_spec.rb index 7ceafdad78..5b704c4219 100644 --- a/spec/unit/knife/node_environment_set_spec.rb +++ b/spec/unit/knife/node_environment_set_spec.rb @@ -24,7 +24,7 @@ describe Chef::Knife::NodeEnvironmentSet do @knife = Chef::Knife::NodeEnvironmentSet.new @knife.name_args = %w{adam bar} allow(@knife).to receive(:output).and_return(true) - @node = Chef::Node.new() + @node = Chef::Node.new @node.name("knifetest-node") @node.chef_environment << "foo" allow(@node).to receive(:save).and_return(true) diff --git a/spec/unit/knife/node_from_file_spec.rb b/spec/unit/knife/node_from_file_spec.rb index cf128a80a0..524780c0b8 100644 --- a/spec/unit/knife/node_from_file_spec.rb +++ b/spec/unit/knife/node_from_file_spec.rb @@ -30,7 +30,7 @@ describe Chef::Knife::NodeFromFile do @knife.name_args = [ "adam.rb" ] allow(@knife).to receive(:output).and_return(true) allow(@knife).to receive(:confirm).and_return(true) - @node = Chef::Node.new() + @node = Chef::Node.new allow(@node).to receive(:save) allow(@knife.loader).to receive(:load_from).and_return(@node) @stdout = StringIO.new diff --git a/spec/unit/knife/node_policy_set_spec.rb b/spec/unit/knife/node_policy_set_spec.rb index 35306937d8..da84019fe1 100644 --- a/spec/unit/knife/node_policy_set_spec.rb +++ b/spec/unit/knife/node_policy_set_spec.rb @@ -20,7 +20,7 @@ require "spec_helper" describe Chef::Knife::NodePolicySet do let(:node) do - node = Chef::Node.new() + node = Chef::Node.new node.name("adam") node.run_list = ["role[base]"] node diff --git a/spec/unit/knife/node_run_list_add_spec.rb b/spec/unit/knife/node_run_list_add_spec.rb index 03c89ff9eb..b793333c99 100644 --- a/spec/unit/knife/node_run_list_add_spec.rb +++ b/spec/unit/knife/node_run_list_add_spec.rb @@ -27,7 +27,7 @@ describe Chef::Knife::NodeRunListAdd do } @knife.name_args = [ "adam", "role[monkey]" ] allow(@knife).to receive(:output).and_return(true) - @node = Chef::Node.new() + @node = Chef::Node.new allow(@node).to receive(:save).and_return(true) allow(Chef::Node).to receive(:load).and_return(@node) end diff --git a/spec/unit/knife/node_run_list_remove_spec.rb b/spec/unit/knife/node_run_list_remove_spec.rb index 4f753d7991..a62b6f4b71 100644 --- a/spec/unit/knife/node_run_list_remove_spec.rb +++ b/spec/unit/knife/node_run_list_remove_spec.rb @@ -24,7 +24,7 @@ describe Chef::Knife::NodeRunListRemove do @knife = Chef::Knife::NodeRunListRemove.new @knife.config[:print_after] = nil @knife.name_args = [ "adam", "role[monkey]" ] - @node = Chef::Node.new() + @node = Chef::Node.new @node.name("knifetest-node") @node.run_list << "role[monkey]" allow(@node).to receive(:save).and_return(true) diff --git a/spec/unit/knife/node_run_list_set_spec.rb b/spec/unit/knife/node_run_list_set_spec.rb index bd55edb997..6246dfce6a 100644 --- a/spec/unit/knife/node_run_list_set_spec.rb +++ b/spec/unit/knife/node_run_list_set_spec.rb @@ -25,7 +25,7 @@ describe Chef::Knife::NodeRunListSet do @knife.config = {} @knife.name_args = [ "adam", "role[monkey]" ] allow(@knife).to receive(:output).and_return(true) - @node = Chef::Node.new() + @node = Chef::Node.new allow(@node).to receive(:save).and_return(true) allow(Chef::Node).to receive(:load).and_return(@node) end diff --git a/spec/unit/knife/node_show_spec.rb b/spec/unit/knife/node_show_spec.rb index 2f684b27f4..f26bae4233 100644 --- a/spec/unit/knife/node_show_spec.rb +++ b/spec/unit/knife/node_show_spec.rb @@ -21,7 +21,7 @@ require "spec_helper" describe Chef::Knife::NodeShow do let(:node) do - node = Chef::Node.new() + node = Chef::Node.new node.name("adam") node.run_list = ["role[base]"] node diff --git a/spec/unit/knife/role_bulk_delete_spec.rb b/spec/unit/knife/role_bulk_delete_spec.rb index d49adb9354..07a9b484c4 100644 --- a/spec/unit/knife/role_bulk_delete_spec.rb +++ b/spec/unit/knife/role_bulk_delete_spec.rb @@ -29,9 +29,9 @@ describe Chef::Knife::RoleBulkDelete do @stdout = StringIO.new allow(@knife.ui).to receive(:stdout).and_return(@stdout) allow(@knife.ui).to receive(:confirm).and_return(true) - @roles = Hash.new + @roles = {} %w{dev staging production}.each do |role_name| - role = Chef::Role.new() + role = Chef::Role.new role.name(role_name) allow(role).to receive(:destroy).and_return(true) @roles[role_name] = role diff --git a/spec/unit/knife/role_create_spec.rb b/spec/unit/knife/role_create_spec.rb index 5e2b2caeb5..fa3ef1c9e8 100644 --- a/spec/unit/knife/role_create_spec.rb +++ b/spec/unit/knife/role_create_spec.rb @@ -27,7 +27,7 @@ describe Chef::Knife::RoleCreate do } @knife.name_args = [ "adam" ] allow(@knife).to receive(:output).and_return(true) - @role = Chef::Role.new() + @role = Chef::Role.new allow(@role).to receive(:save) allow(Chef::Role).to receive(:new).and_return(@role) allow(@knife).to receive(:edit_data).and_return(@role) diff --git a/spec/unit/knife/role_delete_spec.rb b/spec/unit/knife/role_delete_spec.rb index 98c0cde9b2..889287fd04 100644 --- a/spec/unit/knife/role_delete_spec.rb +++ b/spec/unit/knife/role_delete_spec.rb @@ -28,7 +28,7 @@ describe Chef::Knife::RoleDelete do @knife.name_args = [ "adam" ] allow(@knife).to receive(:output).and_return(true) allow(@knife).to receive(:confirm).and_return(true) - @role = Chef::Role.new() + @role = Chef::Role.new allow(@role).to receive(:destroy).and_return(true) allow(Chef::Role).to receive(:load).and_return(@role) @stdout = StringIO.new diff --git a/spec/unit/knife/role_edit_spec.rb b/spec/unit/knife/role_edit_spec.rb index 5e03b7aef3..3828bc51b9 100644 --- a/spec/unit/knife/role_edit_spec.rb +++ b/spec/unit/knife/role_edit_spec.rb @@ -25,7 +25,7 @@ describe Chef::Knife::RoleEdit do @knife.config[:print_after] = nil @knife.name_args = [ "adam" ] allow(@knife.ui).to receive(:output).and_return(true) - @role = Chef::Role.new() + @role = Chef::Role.new allow(@role).to receive(:save) allow(Chef::Role).to receive(:load).and_return(@role) allow(@knife.ui).to receive(:edit_data).and_return(@role) diff --git a/spec/unit/knife/role_env_run_list_add_spec.rb b/spec/unit/knife/role_env_run_list_add_spec.rb index 242beeb4a2..39c9740f50 100644 --- a/spec/unit/knife/role_env_run_list_add_spec.rb +++ b/spec/unit/knife/role_env_run_list_add_spec.rb @@ -29,7 +29,7 @@ describe Chef::Knife::RoleEnvRunListAdd do } @knife.name_args = [ "will", "QA", "role[monkey]" ] allow(@knife).to receive(:output).and_return(true) - @role = Chef::Role.new() + @role = Chef::Role.new allow(@role).to receive(:save).and_return(true) allow(Chef::Role).to receive(:load).and_return(@role) end 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 7a580ecd4a..14d818fa66 100644 --- a/spec/unit/knife/role_env_run_list_clear_spec.rb +++ b/spec/unit/knife/role_env_run_list_clear_spec.rb @@ -33,7 +33,7 @@ describe Chef::Knife::RoleEnvRunListClear do @knife.name_args = %w{will QA} allow(@knife).to receive(:output).and_return(true) - @role = Chef::Role.new() + @role = Chef::Role.new @role.name("will") allow(@role).to receive(:save).and_return(true) diff --git a/spec/unit/knife/role_env_run_list_remove_spec.rb b/spec/unit/knife/role_env_run_list_remove_spec.rb index afbabec528..a9eedf9aa1 100644 --- a/spec/unit/knife/role_env_run_list_remove_spec.rb +++ b/spec/unit/knife/role_env_run_list_remove_spec.rb @@ -33,7 +33,7 @@ describe Chef::Knife::RoleEnvRunListRemove do @knife.name_args = [ "will", "QA", "role[monkey]" ] allow(@knife).to receive(:output).and_return(true) - @role = Chef::Role.new() + @role = Chef::Role.new @role.name("will") allow(@role).to receive(:save).and_return(true) diff --git a/spec/unit/knife/role_env_run_list_replace_spec.rb b/spec/unit/knife/role_env_run_list_replace_spec.rb index c4d231d638..94ef75fa07 100644 --- a/spec/unit/knife/role_env_run_list_replace_spec.rb +++ b/spec/unit/knife/role_env_run_list_replace_spec.rb @@ -33,7 +33,7 @@ describe Chef::Knife::RoleEnvRunListReplace do @knife.name_args = [ "will", "QA", "role[dude]", "role[person]" ] allow(@knife).to receive(:output).and_return(true) - @role = Chef::Role.new() + @role = Chef::Role.new @role.name("will") allow(@role).to receive(:save).and_return(true) diff --git a/spec/unit/knife/role_env_run_list_set_spec.rb b/spec/unit/knife/role_env_run_list_set_spec.rb index 79bd3b152e..4fdef5729f 100644 --- a/spec/unit/knife/role_env_run_list_set_spec.rb +++ b/spec/unit/knife/role_env_run_list_set_spec.rb @@ -33,7 +33,7 @@ describe Chef::Knife::RoleEnvRunListSet do @knife.name_args = [ "will", "QA", "role[owen]", "role[mauntel]" ] allow(@knife).to receive(:output).and_return(true) - @role = Chef::Role.new() + @role = Chef::Role.new @role.name("will") allow(@role).to receive(:save).and_return(true) diff --git a/spec/unit/knife/role_from_file_spec.rb b/spec/unit/knife/role_from_file_spec.rb index 827b8ae04d..65a152c1f0 100644 --- a/spec/unit/knife/role_from_file_spec.rb +++ b/spec/unit/knife/role_from_file_spec.rb @@ -30,7 +30,7 @@ describe Chef::Knife::RoleFromFile do @knife.name_args = [ "adam.rb" ] allow(@knife).to receive(:output).and_return(true) allow(@knife).to receive(:confirm).and_return(true) - @role = Chef::Role.new() + @role = Chef::Role.new allow(@role).to receive(:save) allow(@knife.loader).to receive(:load_from).and_return(@role) @stdout = StringIO.new diff --git a/spec/unit/knife/role_run_list_add_spec.rb b/spec/unit/knife/role_run_list_add_spec.rb index a38b6de9da..38ead92d86 100644 --- a/spec/unit/knife/role_run_list_add_spec.rb +++ b/spec/unit/knife/role_run_list_add_spec.rb @@ -29,7 +29,7 @@ describe Chef::Knife::RoleRunListAdd do } @knife.name_args = [ "will", "role[monkey]" ] allow(@knife).to receive(:output).and_return(true) - @role = Chef::Role.new() + @role = Chef::Role.new allow(@role).to receive(:save).and_return(true) allow(Chef::Role).to receive(:load).and_return(@role) end diff --git a/spec/unit/knife/role_run_list_clear_spec.rb b/spec/unit/knife/role_run_list_clear_spec.rb index 8bbc816d6f..b62cc06571 100644 --- a/spec/unit/knife/role_run_list_clear_spec.rb +++ b/spec/unit/knife/role_run_list_clear_spec.rb @@ -32,7 +32,7 @@ describe Chef::Knife::RoleRunListClear do @knife.name_args = [ "will" ] allow(@knife).to receive(:output).and_return(true) - @role = Chef::Role.new() + @role = Chef::Role.new @role.name("will") allow(@role).to receive(:save).and_return(true) diff --git a/spec/unit/knife/role_run_list_remove_spec.rb b/spec/unit/knife/role_run_list_remove_spec.rb index c18416feca..c4f0e6d32e 100644 --- a/spec/unit/knife/role_run_list_remove_spec.rb +++ b/spec/unit/knife/role_run_list_remove_spec.rb @@ -32,7 +32,7 @@ describe Chef::Knife::RoleRunListRemove do @knife.name_args = [ "will", "role[monkey]" ] allow(@knife).to receive(:output).and_return(true) - @role = Chef::Role.new() + @role = Chef::Role.new @role.name("will") allow(@role).to receive(:save).and_return(true) diff --git a/spec/unit/knife/role_run_list_replace_spec.rb b/spec/unit/knife/role_run_list_replace_spec.rb index 9b212de0ae..aa76efe249 100644 --- a/spec/unit/knife/role_run_list_replace_spec.rb +++ b/spec/unit/knife/role_run_list_replace_spec.rb @@ -32,7 +32,7 @@ describe Chef::Knife::RoleRunListReplace do @knife.name_args = [ "will", "role[dude]", "role[person]" ] allow(@knife).to receive(:output).and_return(true) - @role = Chef::Role.new() + @role = Chef::Role.new @role.name("will") allow(@role).to receive(:save).and_return(true) diff --git a/spec/unit/knife/role_run_list_set_spec.rb b/spec/unit/knife/role_run_list_set_spec.rb index f8e440f524..69543dbda4 100644 --- a/spec/unit/knife/role_run_list_set_spec.rb +++ b/spec/unit/knife/role_run_list_set_spec.rb @@ -32,7 +32,7 @@ describe Chef::Knife::RoleRunListSet do @knife.name_args = [ "will", "role[owen]", "role[mauntel]" ] allow(@knife).to receive(:output).and_return(true) - @role = Chef::Role.new() + @role = Chef::Role.new @role.name("will") allow(@role).to receive(:save).and_return(true) diff --git a/spec/unit/knife/status_spec.rb b/spec/unit/knife/status_spec.rb index 929a0f742b..dc66007c32 100644 --- a/spec/unit/knife/status_spec.rb +++ b/spec/unit/knife/status_spec.rb @@ -40,7 +40,8 @@ describe Chef::Knife::Status do { filter_result: { name: ["name"], ipaddress: ["ipaddress"], ohai_time: ["ohai_time"], ec2: ["ec2"], run_list: ["run_list"], platform: ["platform"], - platform_version: ["platform_version"], chef_environment: ["chef_environment"] } } end + platform_version: ["platform_version"], chef_environment: ["chef_environment"] } } + end it "should default to searching for everything" do expect(@query).to receive(:search).with(:node, "*:*", opts) diff --git a/spec/unit/knife/supermarket_install_spec.rb b/spec/unit/knife/supermarket_install_spec.rb index d891de9268..9c969106fc 100644 --- a/spec/unit/knife/supermarket_install_spec.rb +++ b/spec/unit/knife/supermarket_install_spec.rb @@ -23,12 +23,13 @@ describe Chef::Knife::SupermarketInstall do let(:knife) { Chef::Knife::SupermarketInstall.new } let(:stdout) { StringIO.new } let(:stderr) { StringIO.new } - let(:downloader) { Hash.new } + let(:downloader) { {} } let(:archive) { double(Mixlib::Archive, extract: true) } let(:repo) do double(sanity_check: true, reset_to_default_state: true, prepare_to_import: true, finalize_updates_to: true, - merge_updates_from: true) end + merge_updates_from: true) + end let(:install_path) do if Chef::Platform.windows? "C:/tmp/chef" diff --git a/spec/unit/knife/supermarket_share_spec.rb b/spec/unit/knife/supermarket_share_spec.rb index 6601cdcd31..6fdcc6c92f 100644 --- a/spec/unit/knife/supermarket_share_spec.rb +++ b/spec/unit/knife/supermarket_share_spec.rb @@ -175,7 +175,7 @@ describe Chef::Knife::SupermarketShare do response_text = Chef::JSONCompat.to_json({ uri: "https://supermarket.chef.io/cookbooks/cookbook_name" }) allow(@upload_response).to receive(:body).and_return(response_text) allow(@upload_response).to receive(:code).and_return(201) - expect(Chef::CookbookSiteStreamingUploader).to receive(:post).with(/supermarket\.chef\.io/, anything(), anything(), anything()) + expect(Chef::CookbookSiteStreamingUploader).to receive(:post).with(/supermarket\.chef\.io/, anything, anything, anything) @knife.run end diff --git a/spec/unit/knife_spec.rb b/spec/unit/knife_spec.rb index 2c14e417b4..6ed7ddd70e 100644 --- a/spec/unit/knife_spec.rb +++ b/spec/unit/knife_spec.rb @@ -55,7 +55,7 @@ describe Chef::Knife do allow(knife.ui).to receive(:print) allow(Chef::Log).to receive(:init) allow(Chef::Log).to receive(:level) - [:debug, :info, :warn, :error, :crit].each do |level_sym| + %i{debug info warn error crit}.each do |level_sym| allow(Chef::Log).to receive(level_sym) end allow(Chef::Knife).to receive(:puts) @@ -166,7 +166,8 @@ describe Chef::Knife do "X-Chef-Version" => Chef::VERSION, "Host" => "api.opscode.piab", "X-REMOTE-REQUEST-ID" => request_id, - } end + } + end let(:request_id) { "1234" } @@ -205,7 +206,7 @@ describe Chef::Knife do KnifeSpecs.send :remove_const, :TestYourself end Kernel.load(File.join(CHEF_SPEC_DATA, "knife_subcommand", "test_yourself.rb")) - Chef::Knife.subcommands.each { |name, klass| Chef::Knife.subcommands.delete(name) unless klass.kind_of?(Class) } + Chef::Knife.subcommands.each { |name, klass| Chef::Knife.subcommands.delete(name) unless klass.is_a?(Class) } end it "confirms that the headers include X-Remote-Request-Id" do @@ -220,7 +221,7 @@ describe Chef::Knife do KnifeSpecs.send :remove_const, :TestYourself end Kernel.load(File.join(CHEF_SPEC_DATA, "knife_subcommand", "test_yourself.rb")) - Chef::Knife.subcommands.each { |name, klass| Chef::Knife.subcommands.delete(name) unless klass.kind_of?(Class) } + Chef::Knife.subcommands.each { |name, klass| Chef::Knife.subcommands.delete(name) unless klass.is_a?(Class) } end it "merges the global knife CLI options" do @@ -468,8 +469,8 @@ describe Chef::Knife do allow(knife).to receive(:run).and_raise(Net::HTTPClientException.new("403 Forbidden", response)) allow(knife).to receive(:username).and_return("sadpanda") knife.run_with_pretty_exceptions - expect(stderr.string).to match(%r{ERROR: You authenticated successfully to http.+ as sadpanda but you are not authorized for this action}) - expect(stderr.string).to match(%r{Response: y u no administrator}) + expect(stderr.string).to match(/ERROR: You authenticated successfully to http.+ as sadpanda but you are not authorized for this action/) + expect(stderr.string).to match(/Response: y u no administrator/) end context "when proxy servers are set" do @@ -488,9 +489,9 @@ describe Chef::Knife do allow(knife).to receive(:run).and_raise(Net::HTTPClientException.new("403 Forbidden", response)) allow(knife).to receive(:username).and_return("sadpanda") knife.run_with_pretty_exceptions - expect(stderr.string).to match(%r{ERROR: You authenticated successfully to http.+ as sadpanda but you are not authorized for this action}) - expect(stderr.string).to match(%r{ERROR: There are proxy servers configured, your server url may need to be added to NO_PROXY.}) - expect(stderr.string).to match(%r{Response: y u no administrator}) + expect(stderr.string).to match(/ERROR: You authenticated successfully to http.+ as sadpanda but you are not authorized for this action/) + expect(stderr.string).to match(/ERROR: There are proxy servers configured, your server url may need to be added to NO_PROXY./) + expect(stderr.string).to match(/Response: y u no administrator/) end end @@ -500,8 +501,8 @@ describe Chef::Knife do allow(response).to receive(:body).and_return(Chef::JSONCompat.to_json(error: "y u search wrong")) allow(knife).to receive(:run).and_raise(Net::HTTPClientException.new("400 Bad Request", response)) knife.run_with_pretty_exceptions - expect(stderr.string).to match(%r{ERROR: The data in your request was invalid}) - expect(stderr.string).to match(%r{Response: y u search wrong}) + expect(stderr.string).to match(/ERROR: The data in your request was invalid/) + expect(stderr.string).to match(/Response: y u search wrong/) end it "formats 404s nicely" do @@ -510,8 +511,8 @@ describe Chef::Knife do allow(response).to receive(:body).and_return(Chef::JSONCompat.to_json(error: "nothing to see here")) allow(knife).to receive(:run).and_raise(Net::HTTPClientException.new("404 Not Found", response)) knife.run_with_pretty_exceptions - expect(stderr.string).to match(%r{ERROR: The object you are looking for could not be found}) - expect(stderr.string).to match(%r{Response: nothing to see here}) + expect(stderr.string).to match(/ERROR: The object you are looking for could not be found/) + expect(stderr.string).to match(/Response: nothing to see here/) end it "formats 406s (non-supported API version error) nicely" do @@ -536,8 +537,8 @@ describe Chef::Knife do allow(response).to receive(:body).and_return(Chef::JSONCompat.to_json(error: "sad trombone")) allow(knife).to receive(:run).and_raise(Net::HTTPFatalError.new("500 Internal Server Error", response)) knife.run_with_pretty_exceptions - expect(stderr.string).to match(%r{ERROR: internal server error}) - expect(stderr.string).to match(%r{Response: sad trombone}) + expect(stderr.string).to match(/ERROR: internal server error/) + expect(stderr.string).to match(/Response: sad trombone/) end it "formats 502s nicely" do @@ -546,8 +547,8 @@ describe Chef::Knife do allow(response).to receive(:body).and_return(Chef::JSONCompat.to_json(error: "sadder trombone")) allow(knife).to receive(:run).and_raise(Net::HTTPFatalError.new("502 Bad Gateway", response)) knife.run_with_pretty_exceptions - expect(stderr.string).to match(%r{ERROR: bad gateway}) - expect(stderr.string).to match(%r{Response: sadder trombone}) + expect(stderr.string).to match(/ERROR: bad gateway/) + expect(stderr.string).to match(/Response: sadder trombone/) end it "formats 503s nicely" do @@ -556,8 +557,8 @@ describe Chef::Knife do allow(response).to receive(:body).and_return(Chef::JSONCompat.to_json(error: "saddest trombone")) allow(knife).to receive(:run).and_raise(Net::HTTPFatalError.new("503 Service Unavailable", response)) knife.run_with_pretty_exceptions - expect(stderr.string).to match(%r{ERROR: Service temporarily unavailable}) - expect(stderr.string).to match(%r{Response: saddest trombone}) + expect(stderr.string).to match(/ERROR: Service temporarily unavailable/) + expect(stderr.string).to match(/Response: saddest trombone/) end it "formats other HTTP errors nicely" do @@ -566,16 +567,16 @@ describe Chef::Knife do allow(response).to receive(:body).and_return(Chef::JSONCompat.to_json(error: "nobugfixtillyoubuy")) allow(knife).to receive(:run).and_raise(Net::HTTPClientException.new("402 Payment Required", response)) knife.run_with_pretty_exceptions - expect(stderr.string).to match(%r{ERROR: Payment Required}) - expect(stderr.string).to match(%r{Response: nobugfixtillyoubuy}) + expect(stderr.string).to match(/ERROR: Payment Required/) + expect(stderr.string).to match(/Response: nobugfixtillyoubuy/) end it "formats NameError and NoMethodError nicely" do allow(knife).to receive(:run).and_raise(NameError.new("Undefined constant FUUU")) knife.run_with_pretty_exceptions - expect(stderr.string).to match(%r{ERROR: .* encountered an unexpected error}) - expect(stderr.string).to match(%r{This may be a bug in the 'knife' .* command or plugin}) - expect(stderr.string).to match(%r{Exception: NameError: Undefined constant FUUU}) + expect(stderr.string).to match(/ERROR: .* encountered an unexpected error/) + expect(stderr.string).to match(/This may be a bug in the 'knife' .* command or plugin/) + expect(stderr.string).to match(/Exception: NameError: Undefined constant FUUU/) end it "formats missing private key errors nicely" do @@ -583,7 +584,7 @@ describe Chef::Knife do allow(knife).to receive(:api_key).and_return("/home/root/.chef/no-key-here.pem") knife.run_with_pretty_exceptions expect(stderr.string).to match(%r{ERROR: Your private key could not be loaded from /home/root/.chef/no-key-here.pem}) - expect(stderr.string).to match(%r{Check your configuration file and ensure that your private key is readable}) + expect(stderr.string).to match(/Check your configuration file and ensure that your private key is readable/) end it "formats connection refused errors nicely" do @@ -592,8 +593,8 @@ describe Chef::Knife do # Errno::ECONNREFUSED message differs by platform # *nix = Errno::ECONNREFUSED: Connection refused # win32: Errno::ECONNREFUSED: No connection could be made because the target machine actively refused it. - expect(stderr.string).to match(%r{ERROR: Network Error: .* - y u no shut up}) - expect(stderr.string).to match(%r{Check your .* configuration and network settings}) + expect(stderr.string).to match(/ERROR: Network Error: .* - y u no shut up/) + expect(stderr.string).to match(/Check your .* configuration and network settings/) end it "formats SSL errors nicely and suggests to use `knife ssl check` and `knife ssl fetch`" do diff --git a/spec/unit/lwrp_spec.rb b/spec/unit/lwrp_spec.rb index a7f95f8bfd..def981801e 100644 --- a/spec/unit/lwrp_spec.rb +++ b/spec/unit/lwrp_spec.rb @@ -199,7 +199,7 @@ describe "LWRP" do end it "should create a method for each attribute" do - expect(get_lwrp(:lwrp_foo).new("blah").methods.map { |m| m.to_sym }).to include(:monkey) + expect(get_lwrp(:lwrp_foo).new("blah").methods.map(&:to_sym)).to include(:monkey) end it "should build attribute methods that respect validation rules" do @@ -264,12 +264,12 @@ describe "LWRP" do let(:lwrp) do Class.new(Chef::Resource::LWRPBase) do actions :eat, :sleep - default_action [:eat, :sleep] + default_action %i{eat sleep} end end it "returns the array of default actions" do - expect(lwrp.default_action).to eq([:eat, :sleep]) + expect(lwrp.default_action).to eq(%i{eat sleep}) end end @@ -287,7 +287,7 @@ describe "LWRP" do end it "delegates #actions to the parent" do - expect(child.actions).to eq([:nothing, :eat, :sleep]) + expect(child.actions).to eq(%i{nothing eat sleep}) end it "delegates #default_action to the parent" do @@ -304,7 +304,7 @@ describe "LWRP" do end it "does not delegate #actions to the parent" do - expect(child.actions).to eq([:nothing, :dont_eat, :dont_sleep]) + expect(child.actions).to eq(%i{nothing dont_eat dont_sleep}) end it "does not delegate #default_action to the parent" do @@ -322,7 +322,7 @@ describe "LWRP" do end it "amends actions when they are already defined" do - expect(child.actions).to eq([:nothing, :eat, :sleep, :drink]) + expect(child.actions).to eq(%i{nothing eat sleep drink}) end end end @@ -330,40 +330,40 @@ describe "LWRP" do describe "when actions is set to an array" do let(:resource_class) do Class.new(Chef::Resource::LWRPBase) do - actions [ :eat, :sleep ] + actions %i{eat sleep} end end let(:resource) do resource_class.new("blah") end it "actions includes those actions" do - expect(resource_class.actions).to eq [ :nothing, :eat, :sleep ] + expect(resource_class.actions).to eq %i{nothing eat sleep} end it "allowed_actions includes those actions" do - expect(resource_class.allowed_actions).to eq [ :nothing, :eat, :sleep ] + expect(resource_class.allowed_actions).to eq %i{nothing eat sleep} end it "resource.allowed_actions includes those actions" do - expect(resource.allowed_actions).to eq [ :nothing, :eat, :sleep ] + expect(resource.allowed_actions).to eq %i{nothing eat sleep} end end describe "when allowed_actions is set to an array" do let(:resource_class) do Class.new(Chef::Resource::LWRPBase) do - allowed_actions [ :eat, :sleep ] + allowed_actions %i{eat sleep} end end let(:resource) do resource_class.new("blah") end it "actions includes those actions" do - expect(resource_class.actions).to eq [ :nothing, :eat, :sleep ] + expect(resource_class.actions).to eq %i{nothing eat sleep} end it "allowed_actions includes those actions" do - expect(resource_class.allowed_actions).to eq [ :nothing, :eat, :sleep ] + expect(resource_class.allowed_actions).to eq %i{nothing eat sleep} end it "resource.allowed_actions includes those actions" do - expect(resource.allowed_actions).to eq [ :nothing, :eat, :sleep ] + expect(resource.allowed_actions).to eq %i{nothing eat sleep} end end end @@ -590,7 +590,7 @@ describe "LWRP" do it "get_lwrp(:lwrp_once).new is an instance of the LWRP class" do lwrp = get_lwrp(:lwrp_once).new("hi") - expect(lwrp.kind_of?(test_lwrp_class)).to be_truthy + expect(lwrp.is_a?(test_lwrp_class)).to be_truthy expect(lwrp.is_a?(test_lwrp_class)).to be_truthy expect(get_lwrp(:lwrp_once) === lwrp).to be_truthy expect(test_lwrp_class === lwrp).to be_truthy @@ -603,28 +603,28 @@ describe "LWRP" do it "subclass.new is a subclass" do lwrp = subclass.new("hi") - expect(lwrp.kind_of?(subclass)).to be_truthy + expect(lwrp.is_a?(subclass)).to be_truthy expect(lwrp.is_a?(subclass)).to be_truthy expect(subclass === lwrp).to be_truthy expect(lwrp.class === subclass) end it "subclass.new is an instance of the LWRP class" do lwrp = subclass.new("hi") - expect(lwrp.kind_of?(test_lwrp_class)).to be_truthy + expect(lwrp.is_a?(test_lwrp_class)).to be_truthy expect(lwrp.is_a?(test_lwrp_class)).to be_truthy expect(test_lwrp_class === lwrp).to be_truthy expect(lwrp.class === test_lwrp_class) end it "subclass.new is a get_lwrp(:lwrp_once)" do lwrp = subclass.new("hi") - expect(lwrp.kind_of?(get_lwrp(:lwrp_once))).to be_truthy + expect(lwrp.is_a?(get_lwrp(:lwrp_once))).to be_truthy expect(lwrp.is_a?(get_lwrp(:lwrp_once))).to be_truthy expect(get_lwrp(:lwrp_once) === lwrp).to be_truthy expect(lwrp.class === get_lwrp(:lwrp_once)) end it "get_lwrp(:lwrp_once).new is *not* a subclass" do lwrp = get_lwrp(:lwrp_once).new("hi") - expect(lwrp.kind_of?(subclass)).to be_falsey + expect(lwrp.is_a?(subclass)).to be_falsey expect(lwrp.is_a?(subclass)).to be_falsey expect(subclass === lwrp.class).to be_falsey expect(subclass === get_lwrp(:lwrp_once)).to be_falsey diff --git a/spec/unit/mixin/homebrew_user_spec.rb b/spec/unit/mixin/homebrew_user_spec.rb index df89962cce..7d2da85e2d 100644 --- a/spec/unit/mixin/homebrew_user_spec.rb +++ b/spec/unit/mixin/homebrew_user_spec.rb @@ -48,7 +48,7 @@ describe Chef::Mixin::HomebrewUser do let(:brew_owner) { 2001 } let(:default_brew_path) { "/usr/local/bin/brew" } let(:stat_double) do - d = double() + d = double expect(d).to receive(:uid).and_return(brew_owner) d end diff --git a/spec/unit/mixin/params_validate_spec.rb b/spec/unit/mixin/params_validate_spec.rb index 1cc7fef58e..489742cb7d 100644 --- a/spec/unit/mixin/params_validate_spec.rb +++ b/spec/unit/mixin/params_validate_spec.rb @@ -30,7 +30,7 @@ end describe Chef::Mixin::ParamsValidate do before(:each) do - @vo = TinyClass.new() + @vo = TinyClass.new end it "should allow a hash and a hash as arguments to validate" do @@ -44,7 +44,7 @@ describe Chef::Mixin::ParamsValidate do it "should require validation map keys to be symbols or strings" do expect { @vo.validate({ one: "two" }, { one: true }) }.not_to raise_error expect { @vo.validate({ one: "two" }, { "one" => true }) }.not_to raise_error - expect { @vo.validate({ one: "two" }, { Hash.new => true }) }.to raise_error(ArgumentError) + expect { @vo.validate({ one: "two" }, { {} => true }) }.to raise_error(ArgumentError) end it "should allow options to be required with true" do @@ -163,7 +163,7 @@ describe Chef::Mixin::ParamsValidate do end it "should let you set a default value with default => value" do - arguments = Hash.new + arguments = {} @vo.validate(arguments, { one: { default: "is the loneliest number", @@ -236,7 +236,7 @@ describe Chef::Mixin::ParamsValidate do { one: { kind_of: String, - respond_to: [ :to_s, :upcase ], + respond_to: %i{to_s upcase}, regex: /^is good/, callbacks: { "should be your friend" => lambda do |a| @@ -260,7 +260,7 @@ describe Chef::Mixin::ParamsValidate do { one: { kind_of: String, - respond_to: [ :to_s, :upcase ], + respond_to: %i{to_s upcase}, regex: /^is good/, callbacks: { "should be your friend" => lambda do |a| @@ -321,7 +321,7 @@ describe Chef::Mixin::ParamsValidate do end.not_to raise_error expect do @vo.validate( - { one: Hash.new }, + { one: {} }, { one: { kind_of: [ String, Array ], @@ -334,22 +334,22 @@ describe Chef::Mixin::ParamsValidate do it "asserts that a value returns false from a predicate method" do expect do @vo.validate({ not_blank: "should pass" }, - { not_blank: { cannot_be: [ :nil, :empty ] } }) + { not_blank: { cannot_be: %i{nil empty} } }) end.not_to raise_error expect do @vo.validate({ not_blank: "" }, - { not_blank: { cannot_be: [ :nil, :empty ] } }) + { not_blank: { cannot_be: %i{nil empty} } }) end.to raise_error(Chef::Exceptions::ValidationFailed) end it "allows a custom validation message" do expect do @vo.validate({ not_blank: "should pass" }, - { not_blank: { cannot_be: [ :nil, :empty ], validation_message: "my validation message" } }) + { not_blank: { cannot_be: %i{nil empty}, validation_message: "my validation message" } }) end.not_to raise_error expect do @vo.validate({ not_blank: "" }, - { not_blank: { cannot_be: [ :nil, :empty ], validation_message: "my validation message" } }) + { not_blank: { cannot_be: %i{nil empty}, validation_message: "my validation message" } }) end.to raise_error(Chef::Exceptions::ValidationFailed, "my validation message") end diff --git a/spec/unit/mixin/properties_spec.rb b/spec/unit/mixin/properties_spec.rb index ee0c252381..25b94178e5 100644 --- a/spec/unit/mixin/properties_spec.rb +++ b/spec/unit/mixin/properties_spec.rb @@ -31,7 +31,7 @@ module ChefMixinPropertiesSpec end 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, :d ] + expect(A.properties.keys).to eq %i{a ab ac d} expect(A.properties[:a].validation_options[:is]).to eq "a" expect(A.properties[:ab].validation_options[:is]).to eq %w{a b} expect(A.properties[:ac].validation_options[:is]).to eq %w{a c} @@ -46,13 +46,13 @@ module ChefMixinPropertiesSpec 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.keys).to eq %i{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 %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, :d, :b, :bc, :c ] + expect(C.properties.keys).to eq %i{a ab ac d 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" @@ -99,7 +99,7 @@ module ChefMixinPropertiesSpec end it "Outerest.properties.validation_options[:is] inner, outer, outerest" do - expect(Outerest.properties.keys).to eq [:inner, :outer, :outerest] + expect(Outerest.properties.keys).to eq %i{inner outer outerest} end end end diff --git a/spec/unit/mixin/shell_out_spec.rb b/spec/unit/mixin/shell_out_spec.rb index 4f8e4dafac..1c4f59b50b 100644 --- a/spec/unit/mixin/shell_out_spec.rb +++ b/spec/unit/mixin/shell_out_spec.rb @@ -51,7 +51,7 @@ describe Chef::Mixin::ShellOut do let(:retobj) { instance_double(Mixlib::ShellOut, "error!" => false) } let(:cmd) { "echo '#{rand(1000)}'" } - [ :shell_out, :shell_out! ].each do |method| + %i{shell_out shell_out!}.each do |method| describe "##{method}" do describe "when the last argument is a Hash" do @@ -248,7 +248,7 @@ describe Chef::Mixin::ShellOut do let(:provider) { new_resource.provider_for_action(:install) } describe "on Chef-15", chef: ">= 15" do - [ :shell_out, :shell_out! ].each do |method| + %i{shell_out shell_out!}.each do |method| stubbed_method = (method == :shell_out) ? :shell_out_compacted : :shell_out_compacted! it "#{method} defaults to 900 seconds" do expect(provider).to receive(stubbed_method).with("foo", timeout: 900) @@ -284,7 +284,7 @@ describe Chef::Mixin::ShellOut do let(:new_resource) { Chef::Resource::Package.new("foo") } let(:provider) { new_resource.provider_for_action(:install) } - [ :shell_out, :shell_out! ].each do |method| + %i{shell_out shell_out!}.each do |method| stubbed_method = (method == :shell_out) ? :shell_out_compacted : :shell_out_compacted! it "#{method} defaults to 900 seconds" do expect(provider).to receive(stubbed_method).with("foo", timeout: 900) diff --git a/spec/unit/mixin/template_spec.rb b/spec/unit/mixin/template_spec.rb index 96b983a9dd..04071988ad 100644 --- a/spec/unit/mixin/template_spec.rb +++ b/spec/unit/mixin/template_spec.rb @@ -242,17 +242,13 @@ describe Chef::Mixin::Template, "render_template" do it "emits a warning when overriding 'core' methods" do mod = Module.new do - def render - end + def render; end - def node - end + def node; end - def render_template - end + def render_template; end - def render_template_from_string - end + def render_template_from_string; end end %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/) diff --git a/spec/unit/mixin/unformatter_spec.rb b/spec/unit/mixin/unformatter_spec.rb index b2b57c150c..3c8dba1962 100644 --- a/spec/unit/mixin/unformatter_spec.rb +++ b/spec/unit/mixin/unformatter_spec.rb @@ -22,8 +22,7 @@ require "chef/mixin/unformatter" class Chef::UnformatterTest include Chef::Mixin::Unformatter - def foo - end + def foo; end end diff --git a/spec/unit/mixin/user_context_spec.rb b/spec/unit/mixin/user_context_spec.rb index 896241f173..31e182d042 100644 --- a/spec/unit/mixin/user_context_spec.rb +++ b/spec/unit/mixin/user_context_spec.rb @@ -56,8 +56,7 @@ describe "a class that mixes in user_context" do let(:block_object) do class BlockClass - def block_method - end + def block_method; end end BlockClass.new end diff --git a/spec/unit/mixin/which.rb b/spec/unit/mixin/which.rb index 1764b3b89f..c47eaf37ab 100644 --- a/spec/unit/mixin/which.rb +++ b/spec/unit/mixin/which.rb @@ -88,11 +88,13 @@ describe Chef::Mixin::Which do test_which("passes in the filename as the arg", "foo1", finds: "/dir1/foo1") do |f| raise "bad arg to block" unless f == "/dir1/foo1" + true end test_which("arrays with blocks", "foo1", "foo2", finds: "/dir2/foo1", others: [ "/dir1/foo2" ]) do |f| raise "bad arg to block" unless f == "/dir2/foo1" || f == "/dir1/foo2" + true end end diff --git a/spec/unit/mixin/windows_architecture_helper_spec.rb b/spec/unit/mixin/windows_architecture_helper_spec.rb index 4559702e1c..ad7bee0ec9 100644 --- a/spec/unit/mixin/windows_architecture_helper_spec.rb +++ b/spec/unit/mixin/windows_architecture_helper_spec.rb @@ -23,7 +23,7 @@ describe Chef::Mixin::WindowsArchitectureHelper do include Chef::Mixin::WindowsArchitectureHelper before do - @valid_architectures = [ :i386, :x86_64 ] + @valid_architectures = %i{i386 x86_64} @invalid_architectures = [ "i386", "x86_64", :x64, :x86, :arm ] @node_i386 = Chef::Node.new @@ -67,14 +67,14 @@ describe Chef::Mixin::WindowsArchitectureHelper do 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 false if ! ((node_windows_architecture(node) == :x86_64) && (desired_arch == :i386)) + expect(forced_32bit_override_required?(node, desired_arch)).to be false unless (node_windows_architecture(node) == :x86_64) && (desired_arch == :i386) end end def with_node_architecture_combinations @valid_architectures.each do |node_architecture| new_node = Chef::Node.new - new_node.default["kernel"] = Hash.new + new_node.default["kernel"] = {} new_node.default["kernel"][:machine] = node_architecture.to_s @valid_architectures.each do |architecture| diff --git a/spec/unit/node/attribute_spec.rb b/spec/unit/node/attribute_spec.rb index 29e299566b..5055941d06 100644 --- a/spec/unit/node/attribute_spec.rb +++ b/spec/unit/node/attribute_spec.rb @@ -182,7 +182,7 @@ describe Chef::Node::Attribute do expect { Chef::Node::Attribute.new({}, {}, {}, {}) }.not_to raise_error end - [ :normal, :default, :override, :automatic ].each do |accessor| + %i{normal default override automatic}.each do |accessor| it "should set #{accessor}" do na = Chef::Node::Attribute.new({ normal: true }, { default: true }, { override: true }, { automatic: true }) expect(na.send(accessor)).to eq({ accessor.to_s => true }) @@ -546,7 +546,7 @@ describe Chef::Node::Attribute do expect(@attributes["music"]["this"]).not_to have_key("must") end - [:include?, :key?, :member?].each do |method| + %i{include? key? member?}.each do |method| it "should alias the method #{method} to itself" do expect(@attributes).to respond_to(method) end @@ -589,7 +589,7 @@ describe Chef::Node::Attribute do end it "should yield each top level key" do - collect = Array.new + collect = [] @attributes.each_key do |k| collect << k end @@ -602,7 +602,7 @@ describe Chef::Node::Attribute do end it "should yield lower if we go deeper" do - collect = Array.new + collect = [] @attributes["one"].each_key do |k| collect << k end @@ -637,7 +637,7 @@ describe Chef::Node::Attribute do end it "should yield each top level key and value, post merge rules" do - collect = Hash.new + collect = {} @attributes.each do |k, v| collect[k] = v end @@ -679,7 +679,7 @@ describe Chef::Node::Attribute do end it "should yield each top level key, post merge rules" do - collect = Array.new + collect = [] @attributes.each_key do |k| collect << k end @@ -715,7 +715,7 @@ describe Chef::Node::Attribute do end it "should yield each top level key and value pair, post merge rules" do - collect = Hash.new + collect = {} @attributes.each_pair do |k, v| collect[k] = v end @@ -751,7 +751,7 @@ describe Chef::Node::Attribute do end it "should yield each value, post merge rules" do - collect = Array.new + collect = [] @attributes.each_value do |v| collect << v end @@ -762,7 +762,7 @@ describe Chef::Node::Attribute do end it "should yield four elements" do - collect = Array.new + collect = [] @attributes.each_value do |v| collect << v end diff --git a/spec/unit/node/immutable_collections_spec.rb b/spec/unit/node/immutable_collections_spec.rb index 2208c45717..f23e40dc4c 100644 --- a/spec/unit/node/immutable_collections_spec.rb +++ b/spec/unit/node/immutable_collections_spec.rb @@ -1,6 +1,6 @@ # # Author:: Daniel DeLeo (<dan@chef.io>) -# Copyright:: Copyright 2012-2018, Chef Software Inc. +# Copyright:: Copyright 2012-2019, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -145,25 +145,25 @@ describe Chef::Node::ImmutableMash do end end - [ - :[]=, - :clear, - :default=, - :default_proc=, - :delete, - :delete_if, - :keep_if, - :merge!, - :update, - :reject!, - :replace, - :select!, - :shift, - :write, - :write!, - :unlink, - :unlink!, - ].each do |mutator| + %i{ + []= + clear + default= + default_proc= + delete + delete_if + keep_if + merge! + update + reject! + replace + select! + shift + write + write! + unlink + unlink! + }.each do |mutator| it "doesn't allow mutation via `#{mutator}'" do expect { @immutable_mash.send(mutator) }.to raise_error(Chef::Exceptions::ImmutableAttributeModification) end @@ -190,36 +190,36 @@ describe Chef::Node::ImmutableArray do # with ImmutableMash, above ### - [ - :<<, - :[]=, - :clear, - :collect!, - :compact!, - :default=, - :default_proc=, - :delete, - :delete_at, - :delete_if, - :fill, - :flatten!, - :insert, - :keep_if, - :map!, - :merge!, - :pop, - :push, - :reject!, - :reverse!, - :replace, - :select!, - :shift, - :slice!, - :sort!, - :sort_by!, - :uniq!, - :unshift, - ].each do |mutator| + %i{ + << + []= + clear + collect! + compact! + default= + default_proc= + delete + delete_at + delete_if + fill + flatten! + insert + keep_if + map! + merge! + pop + push + reject! + reverse! + replace + select! + shift + slice! + sort! + sort_by! + uniq! + unshift + }.each do |mutator| it "does not allow mutation via `#{mutator}" do expect { @immutable_array.send(mutator) }.to raise_error(Chef::Exceptions::ImmutableAttributeModification) end diff --git a/spec/unit/node_spec.rb b/spec/unit/node_spec.rb index 2d28a3e961..1c84278ad5 100644 --- a/spec/unit/node_spec.rb +++ b/spec/unit/node_spec.rb @@ -21,7 +21,7 @@ require "ostruct" describe Chef::Node do - let(:node) { Chef::Node.new() } + let(:node) { Chef::Node.new } let(:platform_introspector) { node } it_behaves_like "a platform introspector" @@ -103,7 +103,7 @@ describe Chef::Node do end it "should always have a string for name" do - expect { node.name(Hash.new) }.to raise_error(ArgumentError) + expect { node.name({}) }.to raise_error(ArgumentError) end it "cannot be blank" do @@ -126,7 +126,7 @@ describe Chef::Node do end it "should disallow non-strings" do - expect { node.chef_environment(Hash.new) }.to raise_error(ArgumentError) + expect { node.chef_environment({}) }.to raise_error(ArgumentError) expect { node.chef_environment(42) }.to raise_error(ArgumentError) end @@ -162,7 +162,7 @@ describe Chef::Node do end it "disallows non-strings" do - expect { node.policy_name(Hash.new) }.to raise_error(Chef::Exceptions::ValidationFailed) + expect { node.policy_name({}) }.to raise_error(Chef::Exceptions::ValidationFailed) expect { node.policy_name(42) }.to raise_error(Chef::Exceptions::ValidationFailed) end @@ -198,7 +198,7 @@ describe Chef::Node do end it "disallows non-strings" do - expect { node.policy_group(Hash.new) }.to raise_error(Chef::Exceptions::ValidationFailed) + expect { node.policy_group({}) }.to raise_error(Chef::Exceptions::ValidationFailed) expect { node.policy_group(42) }.to raise_error(Chef::Exceptions::ValidationFailed) end @@ -769,7 +769,7 @@ describe Chef::Node do it "caches both strings and symbols correctly" do node.force_default[:solr][:version] = "4.10.2" - node.force_default[:solr][:data_dir] = "/opt/solr-#{node['solr'][:version]}/example/solr" + node.force_default[:solr][:data_dir] = "/opt/solr-#{node["solr"][:version]}/example/solr" node.force_default[:solr][:xms] = "512M" expect(node[:solr][:xms]).to eql("512M") expect(node["solr"][:xms]).to eql("512M") @@ -778,8 +778,8 @@ describe Chef::Node do it "method interpolation syntax also works" do Chef::Config[:treat_deprecation_warnings_as_errors] = false node.default["passenger"]["version"] = "4.0.57" - node.default["passenger"]["root_path"] = "passenger-#{node['passenger']['version']}" - node.default["passenger"]["root_path_2"] = "passenger-#{node[:passenger]['version']}" + node.default["passenger"]["root_path"] = "passenger-#{node["passenger"]["version"]}" + node.default["passenger"]["root_path_2"] = "passenger-#{node[:passenger]["version"]}" expect(node["passenger"]["root_path_2"]).to eql("passenger-4.0.57") expect(node[:passenger]["root_path_2"]).to eql("passenger-4.0.57") end @@ -793,7 +793,7 @@ describe Chef::Node do it "should allow you to iterate over attributes with each_attribute" do node.default["sunshine"] = "is bright" node.default["canada"] = "is a nice place" - seen_attributes = Hash.new + seen_attributes = {} node.each_attribute do |a, v| seen_attributes[a] = v end @@ -1207,7 +1207,7 @@ describe Chef::Node do node.run_list << "role[leninist]" node.run_list << "recipe[stalinist]" - @example = Chef::Node.new() + @example = Chef::Node.new @example.name("newname") @example.chef_environment("prod") @example.default_attrs = { "alpha" => { "bravo" => "charlie", "delta" => "echo" } } @@ -1385,7 +1385,7 @@ describe Chef::Node do describe "inflated" do it "should return a hash of node names and objects" do n1 = double("Chef::Node", name: "one") - allow(n1).to receive(:kind_of?).with(Chef::Node) { true } + allow(n1).to receive(:is_a?).with(Chef::Node) { true } expect(@query).to receive(:search).with(:node).and_yield(n1) r = Chef::Node.list(true) expect(r["one"]).to eq(n1) diff --git a/spec/unit/org_spec.rb b/spec/unit/org_spec.rb index 79a29b1fff..b291b7cb86 100644 --- a/spec/unit/org_spec.rb +++ b/spec/unit/org_spec.rb @@ -52,7 +52,7 @@ describe Chef::Org do end it "raises an ArgumentError if you feed it anything but a string" do - expect { org.name Hash.new }.to raise_error(ArgumentError) + expect { org.name({}) }.to raise_error(ArgumentError) end end @@ -63,7 +63,7 @@ describe Chef::Org do end it "raises an ArgumentError if you feed it anything but a string" do - expect { org.name Hash.new }.to raise_error(ArgumentError) + expect { org.name({}) }.to raise_error(ArgumentError) end end @@ -74,7 +74,7 @@ describe Chef::Org do end it "raises an ArgumentError if you feed it something lame" do - expect { org.private_key Hash.new }.to raise_error(ArgumentError) + expect { org.private_key({}) }.to raise_error(ArgumentError) end end diff --git a/spec/unit/policy_builder/policyfile_spec.rb b/spec/unit/policy_builder/policyfile_spec.rb index f22e2a74b3..d08a9f5b33 100644 --- a/spec/unit/policy_builder/policyfile_spec.rb +++ b/spec/unit/policy_builder/policyfile_spec.rb @@ -403,9 +403,9 @@ describe Chef::PolicyBuilder::Policyfile do before do allow(policy_builder).to receive(:run_list) - .and_return(run_list) + .and_return(run_list) allow(policy_builder).to receive(:cookbook_lock_for) - .and_return(version_hash) + .and_return(version_hash) end it "sends the run_list_expanded event" do diff --git a/spec/unit/property/state_spec.rb b/spec/unit/property/state_spec.rb index 5c54ec71b2..a6428e8617 100644 --- a/spec/unit/property/state_spec.rb +++ b/spec/unit/property/state_spec.rb @@ -28,7 +28,8 @@ describe "Chef::Resource#identity and #state" do def self.english_join(values) return "<nothing>" if values.size == 0 return values[0].inspect if values.size == 1 - "#{values[0..-2].map { |v| v.inspect }.join(", ")} and #{values[-1].inspect}" + + "#{values[0..-2].map(&:inspect).join(", ")} and #{values[-1].inspect}" end def self.with_property(*properties, &block) @@ -256,29 +257,29 @@ describe "Chef::Resource#identity and #state" do with_property ":x, identity: true, default: 'xxx'", ":y, identity: true, default: 'yyy'", ":z, identity: true, default: 'zzz'" do - it "identity_property raises an error if multiple identity values are defined" do - expect { resource_class.identity_property }.to raise_error Chef::Exceptions::MultipleIdentityError - end - it "identity_attr raises an error if multiple identity values are defined" do - expect { resource_class.identity_attr }.to raise_error Chef::Exceptions::MultipleIdentityError - end - it "identity returns all identity values in a hash if multiple are defined" do - resource.x "foo" - resource.y "bar" - resource.z "baz" - expect(resource.identity).to eq(x: "foo", y: "bar", z: "baz") - end - it "identity returns all values whether any value is set or not" do - expect(resource.identity).to eq(x: "xxx", y: "yyy", z: "zzz") - end - it "identity_properties wipes out any other identity attributes if multiple are defined" do - resource_class.identity_properties :y - resource.x "foo" - resource.y "bar" - resource.z "baz" - expect(resource.identity).to eq "bar" + it "identity_property raises an error if multiple identity values are defined" do + expect { resource_class.identity_property }.to raise_error Chef::Exceptions::MultipleIdentityError + end + it "identity_attr raises an error if multiple identity values are defined" do + expect { resource_class.identity_attr }.to raise_error Chef::Exceptions::MultipleIdentityError + end + it "identity returns all identity values in a hash if multiple are defined" do + resource.x "foo" + resource.y "bar" + resource.z "baz" + expect(resource.identity).to eq(x: "foo", y: "bar", z: "baz") + end + it "identity returns all values whether any value is set or not" do + expect(resource.identity).to eq(x: "xxx", y: "yyy", z: "zzz") + end + it "identity_properties wipes out any other identity attributes if multiple are defined" do + resource_class.identity_properties :y + resource.x "foo" + resource.y "bar" + resource.z "baz" + expect(resource.identity).to eq "bar" + end end - end with_property ":x, identity: true, name_property: true" do it "identity when x is not defined returns the value of x" do diff --git a/spec/unit/property/validation_spec.rb b/spec/unit/property/validation_spec.rb index b05d8c4e17..dab2be8000 100644 --- a/spec/unit/property/validation_spec.rb +++ b/spec/unit/property/validation_spec.rb @@ -55,7 +55,8 @@ describe "Chef::Resource.property validation" do def self.english_join(values) return "<nothing>" if values.size == 0 return values[0].inspect if values.size == 1 - "#{values[0..-2].map { |v| v.inspect }.join(", ")} and #{values[-1].inspect}" + + "#{values[0..-2].map(&:inspect).join(", ")} and #{values[-1].inspect}" end def self.with_property(*properties, &block) @@ -231,19 +232,19 @@ describe "Chef::Resource.property validation" do [ :b ] validation_test ":a, is: :b", - [ :a, :b ], + %i{a b}, [ :c ] validation_test ":a, is: [ :b, :c ]", - [ :a, :b, :c ], + %i{a b c}, [ :d ] validation_test "[ :a, :b ], is: :c", - [ :a, :b, :c ], + %i{a b c}, [ :d ] validation_test "[ :a, :b ], is: [ :c, :d ]", - [ :a, :b, :c, :d ], + %i{a b c d}, [ :e ] validation_test "nil", @@ -279,12 +280,12 @@ describe "Chef::Resource.property validation" do [ :b ] validation_test "is: [ :a, :b ]", - [ :a, :b ], - [ [ :a, :b ] ] + %i{a b}, + [ %i{a b} ] validation_test "is: [ [ :a, :b ] ]", - [ [ :a, :b ] ], - [ :a, :b ] + [ %i{a b} ], + %i{a b} # Regex validation_test "is: /abc/", @@ -352,13 +353,13 @@ describe "Chef::Resource.property validation" do :nil_is_valid validation_test "equal_to: [ :a, :b ]", - [ :a, :b ], - [ [ :a, :b ] ], + %i{a b}, + [ %i{a b} ], :nil_is_valid validation_test "equal_to: [ [ :a, :b ] ]", - [ [ :a, :b ] ], - [ :a, :b ], + [ %i{a b} ], + %i{a b}, :nil_is_valid validation_test "equal_to: nil", diff --git a/spec/unit/property_spec.rb b/spec/unit/property_spec.rb index 56e44fd1d1..1fcbb77e8e 100644 --- a/spec/unit/property_spec.rb +++ b/spec/unit/property_spec.rb @@ -51,7 +51,8 @@ describe "Chef::Resource.property" do def self.english_join(values) return "<nothing>" if values.size == 0 return values[0].inspect if values.size == 1 - "#{values[0..-2].map { |v| v.inspect }.join(", ")} and #{values[-1].inspect}" + + "#{values[0..-2].map(&:inspect).join(", ")} and #{values[-1].inspect}" end def self.with_property(*properties, &block) @@ -1051,19 +1052,19 @@ describe "Chef::Resource.property" do context "default ordering deprecation warnings" do it "emits an error for property :x, default: 10, #{name}: true" do expect { resource_class.property :x, :default => 10, name.to_sym => true }.to raise_error ArgumentError, - /A property cannot be both a name_property\/name_attribute and have a default value. Use one or the other on property x of resource chef_resource_property_spec_(\d+)/ + %r{A property cannot be both a name_property/name_attribute and have a default value. Use one or the other on property x of resource chef_resource_property_spec_(\d+)} end it "emits an error for property :x, default: nil, #{name}: true" do expect { resource_class.property :x, :default => nil, name.to_sym => true }.to raise_error ArgumentError, - /A property cannot be both a name_property\/name_attribute and have a default value. Use one or the other on property x of resource chef_resource_property_spec_(\d+)/ + %r{A property cannot be both a name_property/name_attribute and have a default value. Use one or the other on property x of resource chef_resource_property_spec_(\d+)} end it "emits an error for property :x, #{name}: true, default: 10" do expect { resource_class.property :x, name.to_sym => true, :default => 10 }.to raise_error ArgumentError, - /A property cannot be both a name_property\/name_attribute and have a default value. Use one or the other on property x of resource chef_resource_property_spec_(\d+)/ + %r{A property cannot be both a name_property/name_attribute and have a default value. Use one or the other on property x of resource chef_resource_property_spec_(\d+)} end it "emits an error for property :x, #{name}: true, default: nil" do expect { resource_class.property :x, name.to_sym => true, :default => nil }.to raise_error ArgumentError, - /A property cannot be both a name_property\/name_attribute and have a default value. Use one or the other on property x of resource chef_resource_property_spec_(\d+)/ + %r{A property cannot be both a name_property/name_attribute and have a default value. Use one or the other on property x of resource chef_resource_property_spec_(\d+)} end end end @@ -1085,13 +1086,13 @@ describe "Chef::Resource.property" do expect do module ::PropertySpecPropertyTypes include Chef::Mixin::Properties - property_type(is: [:a, :b], default: :c) + property_type(is: %i{a b}, default: :c) end end.to raise_error(Chef::Exceptions::ValidationFailed) expect do module ::PropertySpecPropertyTypes include Chef::Mixin::Properties - property_type(is: [:a, :b], default: :b) + property_type(is: %i{a b}, default: :b) end end.not_to raise_error end @@ -1100,8 +1101,8 @@ describe "Chef::Resource.property" do before :all do module ::PropertySpecPropertyTypes include Chef::Mixin::Properties - ABType = property_type(is: [:a, :b]) - CDType = property_type(is: [:c, :d]) + ABType = property_type(is: %i{a b}) + CDType = property_type(is: %i{c d}) end end @@ -1304,7 +1305,7 @@ describe "Chef::Resource.property" do it "copies only foo when bar and name are excluded" do thing_one_resource.foo "foo" thing_one_resource.bar "bar" - thing_two_resource.copy_properties_from(thing_one_resource, exclude: [ :name, :bar ]) + thing_two_resource.copy_properties_from(thing_one_resource, exclude: %i{name bar}) expect(thing_two_resource.name).to eql("name_two") expect(thing_two_resource.foo).to eql("foo") expect(thing_two_resource.bar).to eql(nil) diff --git a/spec/unit/provider/apt_update_spec.rb b/spec/unit/provider/apt_update_spec.rb index 5cd327b66b..ed91131aff 100644 --- a/spec/unit/provider/apt_update_spec.rb +++ b/spec/unit/provider/apt_update_spec.rb @@ -47,7 +47,7 @@ describe Chef::Provider::AptUpdate do before do FileUtils.rmdir config_dir expect(File.exist?(config_dir)).to be false - allow_any_instance_of(Chef::Provider::Execute).to receive(:shell_out_compacted!).with(*apt_update_cmd, anything()) + allow_any_instance_of(Chef::Provider::Execute).to receive(:shell_out_compacted!).with(*apt_update_cmd, anything) end it "should create the directory" do @@ -66,7 +66,7 @@ describe Chef::Provider::AptUpdate do describe "#action_update" do it "should update the apt cache" do provider.load_current_resource - expect_any_instance_of(Chef::Provider::Execute).to receive(:shell_out_compacted!).with(*apt_update_cmd, anything()) + expect_any_instance_of(Chef::Provider::Execute).to receive(:shell_out_compacted!).with(*apt_update_cmd, anything) provider.run_action(:update) expect(new_resource).to be_updated_by_last_action end @@ -81,14 +81,14 @@ describe Chef::Provider::AptUpdate do it "should run if the time stamp is old" do expect(File).to receive(:mtime).with("#{stamp_dir}/update-success-stamp").and_return(Time.now - 86_500) - expect_any_instance_of(Chef::Provider::Execute).to receive(:shell_out_compacted!).with(*apt_update_cmd, anything()) + expect_any_instance_of(Chef::Provider::Execute).to receive(:shell_out_compacted!).with(*apt_update_cmd, anything) provider.run_action(:periodic) expect(new_resource).to be_updated_by_last_action end it "should not run if the time stamp is new" do expect(File).to receive(:mtime).with("#{stamp_dir}/update-success-stamp").and_return(Time.now) - expect_any_instance_of(Chef::Provider::Execute).not_to receive(:shell_out_compacted!).with(*apt_update_cmd, anything()) + expect_any_instance_of(Chef::Provider::Execute).not_to receive(:shell_out_compacted!).with(*apt_update_cmd, anything) provider.run_action(:periodic) expect(new_resource).to_not be_updated_by_last_action end @@ -100,14 +100,14 @@ describe Chef::Provider::AptUpdate do it "should run if the time stamp is old" do expect(File).to receive(:mtime).with("#{stamp_dir}/update-success-stamp").and_return(Time.now - 500) - expect_any_instance_of(Chef::Provider::Execute).to receive(:shell_out_compacted!).with(*apt_update_cmd, anything()) + expect_any_instance_of(Chef::Provider::Execute).to receive(:shell_out_compacted!).with(*apt_update_cmd, anything) provider.run_action(:periodic) expect(new_resource).to be_updated_by_last_action end it "should not run if the time stamp is new" do expect(File).to receive(:mtime).with("#{stamp_dir}/update-success-stamp").and_return(Time.now - 300) - expect_any_instance_of(Chef::Provider::Execute).not_to receive(:shell_out_compacted!).with(*apt_update_cmd, anything()) + expect_any_instance_of(Chef::Provider::Execute).not_to receive(:shell_out_compacted!).with(*apt_update_cmd, anything) provider.run_action(:periodic) expect(new_resource).to_not be_updated_by_last_action end diff --git a/spec/unit/provider/cron_spec.rb b/spec/unit/provider/cron_spec.rb index 6bfc18c359..4cd8a140af 100644 --- a/spec/unit/provider/cron_spec.rb +++ b/spec/unit/provider/cron_spec.rb @@ -401,7 +401,7 @@ describe Chef::Provider::Cron do @provider.current_resource = @current_resource end - [:minute, :hour, :day, :month, :weekday, :command, :mailto, :path, :shell, :home].each do |property| + %i{minute hour day month weekday command mailto path shell home}.each do |property| it "should return true if #{property} doesn't match" do @new_resource.send(property, "something_else") expect(@provider.cron_different?).to eql(true) diff --git a/spec/unit/provider/dsc_resource_spec.rb b/spec/unit/provider/dsc_resource_spec.rb index 6edf0963b8..cf6ab88eb4 100644 --- a/spec/unit/provider/dsc_resource_spec.rb +++ b/spec/unit/provider/dsc_resource_spec.rb @@ -36,7 +36,8 @@ describe Chef::Provider::DscResource do it "raises a ProviderNotFound exception" do expect(provider).not_to receive(:meta_configuration) expect { provider.run_action(:run) }.to raise_error( - Chef::Exceptions::ProviderNotFound, /5\.0\.10018\.0/) + Chef::Exceptions::ProviderNotFound, /5\.0\.10018\.0/ + ) end end @@ -52,7 +53,8 @@ describe Chef::Provider::DscResource do it "raises an exception" do expect(provider).to receive(:dsc_refresh_mode_disabled?).and_return(false) expect { provider.run_action(:run) }.to raise_error( - Chef::Exceptions::ProviderNotFound, /Disabled/) + Chef::Exceptions::ProviderNotFound, /Disabled/ + ) end end context "and the WMF is 5 RTM or newer" do @@ -157,7 +159,8 @@ describe Chef::Provider::DscResource do [ { "Module" => { "Name" => "ModuleName1", "Version" => "1.0.0.0" } }, { "Module" => { "Name" => "ModuleName1", "Version" => "2.0.0.0" } }, - ] end + ] + end it "raises MultipleDscResourcesFound" do expect { provider.run_action(:run) }.to raise_error(Chef::Exceptions::MultipleDscResourcesFound) diff --git a/spec/unit/provider/dsc_script_spec.rb b/spec/unit/provider/dsc_script_spec.rb index c880683a0f..a1115150e8 100644 --- a/spec/unit/provider/dsc_script_spec.rb +++ b/spec/unit/provider/dsc_script_spec.rb @@ -99,7 +99,7 @@ describe Chef::Provider::DscScript do it "should noop if neither code or command are provided" do allow(provider).to receive(:load_current_resource) generator = double("Chef::Util::DSC::ConfigurationGenerator") - expect(generator).to receive(:configuration_document_from_script_code).with("", anything(), anything(), anything()) + expect(generator).to receive(:configuration_document_from_script_code).with("", anything, anything, anything) allow(Chef::Util::DSC::ConfigurationGenerator).to receive(:new).and_return(generator) provider.send(:generate_configuration_document, "tmp", nil) end diff --git a/spec/unit/provider/group/dscl_spec.rb b/spec/unit/provider/group/dscl_spec.rb index 94322a89f9..910470b1b7 100644 --- a/spec/unit/provider/group/dscl_spec.rb +++ b/spec/unit/provider/group/dscl_spec.rb @@ -121,7 +121,7 @@ describe Chef::Provider::Group::Dscl do 500 ) EOS - ) + ) end it "should run safe_dscl with search /Groups gid" do diff --git a/spec/unit/provider/group/groupadd_spec.rb b/spec/unit/provider/group/groupadd_spec.rb index 84997a258d..79586eac71 100644 --- a/spec/unit/provider/group/groupadd_spec.rb +++ b/spec/unit/provider/group/groupadd_spec.rb @@ -155,7 +155,7 @@ describe Chef::Provider::Group::Groupadd do end end - [:add_member, :remove_member, :set_members].each do |m| + %i{add_member remove_member set_members}.each do |m| it "should raise an error when calling #{m}" do expect { provider.send(m, [ ]) }.to raise_error(Chef::Exceptions::Group, "you must override #{m} in #{provider}") end diff --git a/spec/unit/provider/group_spec.rb b/spec/unit/provider/group_spec.rb index bacb711d1b..d7fdfb299c 100644 --- a/spec/unit/provider/group_spec.rb +++ b/spec/unit/provider/group_spec.rb @@ -39,8 +39,7 @@ describe Chef::Provider::User do @pw_group = double("Struct::Group", name: "wheel", gid: 20, - mem: %w{root aj} - ) + mem: %w{root aj}) allow(Etc).to receive(:getgrnam).with("wheel").and_return(@pw_group) end @@ -85,7 +84,7 @@ describe Chef::Provider::User do end describe "when determining if the system is already in the target state" do - [ :gid, :members ].each do |property| + %i{gid members}.each do |property| it "should return true if #{property} doesn't match" do allow(@current_resource).to receive(property).and_return("looooooooooooooooooool") expect(@provider.compare_group).to be_truthy diff --git a/spec/unit/provider/launchd_spec.rb b/spec/unit/provider/launchd_spec.rb index 8b5edc68b5..53b56b4960 100644 --- a/spec/unit/provider/launchd_spec.rb +++ b/spec/unit/provider/launchd_spec.rb @@ -89,7 +89,8 @@ describe Chef::Provider::Launchd do "Weekday" => 7, }, "TimeOut" => 300, - } end + } + end before(:each) do provider.load_current_resource @@ -197,9 +198,11 @@ describe Chef::Provider::Launchd do describe "and the file has been updated" do before(:each) do allow(provider).to receive( - :manage_plist).with(:create).and_return(true) + :manage_plist + ).with(:create).and_return(true) allow(provider).to receive( - :manage_service).with(:restart).and_return(true) + :manage_service + ).with(:restart).and_return(true) end it "should call manage_service with a :restart action" do @@ -215,9 +218,11 @@ describe Chef::Provider::Launchd do describe "and the file has not been updated" do before(:each) do allow(provider).to receive( - :manage_plist).with(:create).and_return(nil) + :manage_plist + ).with(:create).and_return(nil) allow(provider).to receive( - :manage_service).with(:enable).and_return(true) + :manage_service + ).with(:enable).and_return(true) end it "should call manage_service with a :enable action" do @@ -236,9 +241,11 @@ describe Chef::Provider::Launchd do before(:each) do allow(File).to receive(:exists?).and_return(true) allow(provider).to receive( - :manage_service).with(:disable).and_return(true) + :manage_service + ).with(:disable).and_return(true) allow(provider).to receive( - :manage_plist).with(:delete).and_return(true) + :manage_plist + ).with(:delete).and_return(true) end it "should call manage_service with a :disable action" do @@ -255,7 +262,8 @@ describe Chef::Provider::Launchd do before(:each) do allow(File).to receive(:exists?).and_return(false) allow(provider).to receive( - :manage_plist).with(:delete).and_return(true) + :manage_plist + ).with(:delete).and_return(true) end it "works with action :delete" do diff --git a/spec/unit/provider/link_spec.rb b/spec/unit/provider/link_spec.rb index 027b318c7e..fff2c1ffa8 100644 --- a/spec/unit/provider/link_spec.rb +++ b/spec/unit/provider/link_spec.rb @@ -259,7 +259,8 @@ describe Chef::Resource::Link do allow(stat).to receive(:gid).and_return(501) allow(stat).to receive(:mode).and_return(0755) allow(provider.file_class).to receive(:stat).with( - "#{CHEF_SPEC_DATA}/fofile-link").and_return(stat) + "#{CHEF_SPEC_DATA}/fofile-link" + ).and_return(stat) provider.load_current_resource end @@ -267,7 +268,8 @@ describe Chef::Resource::Link do shared_context "delete link to directories on Windows" do before do allow(::File).to receive(:directory?).with( - "#{CHEF_SPEC_DATA}/fofile-link").and_return(true) + "#{CHEF_SPEC_DATA}/fofile-link" + ).and_return(true) end it "invokes Dir.delete method to delete the link" do @@ -280,7 +282,8 @@ describe Chef::Resource::Link do shared_context "delete link to directories on Linux" do before do allow(::File).to receive(:directory?).with( - "#{CHEF_SPEC_DATA}/fofile-link").and_return(true) + "#{CHEF_SPEC_DATA}/fofile-link" + ).and_return(true) end it "invokes File.delete method to delete the link" do @@ -293,7 +296,8 @@ describe Chef::Resource::Link do shared_context "delete link to files" do before do allow(::File).to receive(:directory?).with( - "#{CHEF_SPEC_DATA}/fofile-link").and_return(false) + "#{CHEF_SPEC_DATA}/fofile-link" + ).and_return(false) end it "invokes File.delete method to delete the link" do @@ -306,9 +310,11 @@ describe Chef::Resource::Link do shared_context "soft links prerequisites" do before(:each) do allow(provider.file_class).to receive(:symlink?).with( - "#{CHEF_SPEC_DATA}/fofile-link").and_return(true) + "#{CHEF_SPEC_DATA}/fofile-link" + ).and_return(true) allow(provider.file_class).to receive(:readlink).with( - "#{CHEF_SPEC_DATA}/fofile-link").and_return("#{CHEF_SPEC_DATA}/fofile") + "#{CHEF_SPEC_DATA}/fofile-link" + ).and_return("#{CHEF_SPEC_DATA}/fofile") end end @@ -327,15 +333,19 @@ describe Chef::Resource::Link do allow(stat).to receive(:mode).and_return(0644) allow(provider.file_class).to receive(:symlink?).with( - "#{CHEF_SPEC_DATA}/fofile-link").and_return(false) + "#{CHEF_SPEC_DATA}/fofile-link" + ).and_return(false) allow(File).to receive(:exists?).with( - "#{CHEF_SPEC_DATA}/fofile-link").and_return(true) + "#{CHEF_SPEC_DATA}/fofile-link" + ).and_return(true) allow(File).to receive(:exists?).with( - "#{CHEF_SPEC_DATA}/fofile").and_return(true) + "#{CHEF_SPEC_DATA}/fofile" + ).and_return(true) allow(provider.file_class).to receive(:stat).with( - "#{CHEF_SPEC_DATA}/fofile").and_return(stat) + "#{CHEF_SPEC_DATA}/fofile" + ).and_return(stat) end end @@ -346,7 +356,8 @@ describe Chef::Resource::Link do before(:each) do allow(Chef::Resource::Link).to receive(:new).with( - provider.new_resource.name).and_return(resource_link) + provider.new_resource.name + ).and_return(resource_link) allow(resource_link).to receive(:verify_links_supported!) allow(Chef::Platform).to receive(:windows?).and_return(true) end diff --git a/spec/unit/provider/mount/mount_spec.rb b/spec/unit/provider/mount/mount_spec.rb index 2353d992d0..5e1ffbf208 100644 --- a/spec/unit/provider/mount/mount_spec.rb +++ b/spec/unit/provider/mount/mount_spec.rb @@ -67,23 +67,23 @@ describe Chef::Provider::Mount::Mount do describe "when dealing with network mounts" do { "nfs" => "nfsserver:/vol/path", "cifs" => "//cifsserver/share" }.each do |type, fs_spec| - it "should detect network fs_spec (#{type})" do - @new_resource.device fs_spec - expect(@provider.network_device?).to be_truthy + it "should detect network fs_spec (#{type})" do + @new_resource.device fs_spec + expect(@provider.network_device?).to be_truthy + end + + it "should ignore trailing slash and set mounted to true for network mount (#{type})" do + @new_resource.device fs_spec + allow(@provider).to receive(:shell_out!).and_return(OpenStruct.new(stdout: "#{fs_spec}/ on /tmp/foo type #{type} (rw)\n")) + @provider.load_current_resource + expect(@provider.current_resource.mounted).to be_truthy + end end - - it "should ignore trailing slash and set mounted to true for network mount (#{type})" do - @new_resource.device fs_spec - allow(@provider).to receive(:shell_out!).and_return(OpenStruct.new(stdout: "#{fs_spec}/ on /tmp/foo type #{type} (rw)\n")) - @provider.load_current_resource - expect(@provider.current_resource.mounted).to be_truthy - end - end end it "should raise an error if the mount device does not exist" do allow(::File).to receive(:exists?).with("/dev/sdz1").and_return false - expect { @provider.load_current_resource(); @provider.mountable? }.to raise_error(Chef::Exceptions::Mount) + expect { @provider.load_current_resource; @provider.mountable? }.to raise_error(Chef::Exceptions::Mount) end it "should not call mountable? with load_current_resource - CHEF-1565" do @@ -100,36 +100,36 @@ describe Chef::Provider::Mount::Mount do @new_resource.device "d21afe51-a0fe-4dc6-9152-ac733763ae0a" expect(@provider).to receive(:shell_out_compacted).with("/sbin/findfs", "UUID=d21afe51-a0fe-4dc6-9152-ac733763ae0a").and_return(status) expect(::File).to receive(:exists?).with("").and_return(false) - expect { @provider.load_current_resource(); @provider.mountable? }.to raise_error(Chef::Exceptions::Mount) + expect { @provider.load_current_resource; @provider.mountable? }.to raise_error(Chef::Exceptions::Mount) end it "should raise an error if the mount point does not exist" do allow(::File).to receive(:exists?).with("/tmp/foo").and_return false - expect { @provider.load_current_resource(); @provider.mountable? }.to raise_error(Chef::Exceptions::Mount) + expect { @provider.load_current_resource; @provider.mountable? }.to raise_error(Chef::Exceptions::Mount) end %w{tmpfs fuse cgroup vboxsf zfs}.each do |fstype| it "does not expect the device to exist for #{fstype}" do @new_resource.fstype(fstype) @new_resource.device("whatever") - expect { @provider.load_current_resource(); @provider.mountable? }.not_to raise_error + expect { @provider.load_current_resource; @provider.mountable? }.not_to raise_error end end it "does not expect the device to exist if it's none" do @new_resource.device("none") - expect { @provider.load_current_resource(); @provider.mountable? }.not_to raise_error + expect { @provider.load_current_resource; @provider.mountable? }.not_to raise_error end it "should set mounted true if the mount point is found in the mounts list" do allow(@provider).to receive(:shell_out!).and_return(OpenStruct.new(stdout: "/dev/sdz1 on /tmp/foo type ext3 (rw)\n")) - @provider.load_current_resource() + @provider.load_current_resource expect(@provider.current_resource.mounted).to be_truthy end it "should set mounted false if another mount point beginning with the same path is found in the mounts list" do allow(@provider).to receive(:shell_out!).and_return(OpenStruct.new(stdout: "/dev/sdz1 on /tmp/foobar type ext3 (rw)\n")) - @provider.load_current_resource() + @provider.load_current_resource expect(@provider.current_resource.mounted).to be_falsey end @@ -141,7 +141,7 @@ describe Chef::Provider::Mount::Mount do allow(::File).to receive(:readlink).with((@new_resource.device).to_s).and_return(target) allow(@provider).to receive(:shell_out!).and_return(OpenStruct.new(stdout: "#{target} on /tmp/foo type ext3 (rw)\n")) - @provider.load_current_resource() + @provider.load_current_resource expect(@provider.current_resource.mounted).to be_truthy end @@ -155,7 +155,7 @@ describe Chef::Provider::Mount::Mount do allow(::File).to receive(:readlink).with((@new_resource.device).to_s).and_return(target) allow(@provider).to receive(:shell_out!).and_return(OpenStruct.new(stdout: "#{absolute_target} on /tmp/foo type ext3 (rw)\n")) - @provider.load_current_resource() + @provider.load_current_resource expect(@provider.current_resource.mounted).to be_truthy end @@ -164,7 +164,7 @@ describe Chef::Provider::Mount::Mount do mount << "#{@new_resource.device} on #{@new_resource.mount_point} type ext3 (rw)\n" allow(@provider).to receive(:shell_out!).and_return(OpenStruct.new(stdout: mount)) - @provider.load_current_resource() + @provider.load_current_resource expect(@provider.current_resource.mounted).to be_truthy end @@ -173,13 +173,13 @@ describe Chef::Provider::Mount::Mount do mount << "/dev/sdy1 on #{@new_resource.mount_point} type ext3 (rw)\n" allow(@provider).to receive(:shell_out!).and_return(OpenStruct.new(stdout: mount)) - @provider.load_current_resource() + @provider.load_current_resource expect(@provider.current_resource.mounted).to be_falsey end it "mounted should be false if the mount point is not found in the mounts list" do allow(@provider).to receive(:shell_out!).and_return(OpenStruct.new(stdout: "/dev/sdy1 on /tmp/foo type ext3 (rw)\n")) - @provider.load_current_resource() + @provider.load_current_resource expect(@provider.current_resource.mounted).to be_falsey end @@ -297,14 +297,14 @@ describe Chef::Provider::Mount::Mount do describe "mount_fs" do it "should mount the filesystem if it is not mounted" do expect(@provider).to receive(:shell_out_compacted!).with("mount", "-t", "ext3", "-o", "defaults", "/dev/sdz1", "/tmp/foo") - @provider.mount_fs() + @provider.mount_fs end it "should mount the filesystem with options if options were passed" do options = "rw,noexec,noauto" @new_resource.options(%w{rw noexec noauto}) expect(@provider).to receive(:shell_out_compacted!).with("mount", "-t", "ext3", "-o", "rw,noexec,noauto", "/dev/sdz1", "/tmp/foo") - @provider.mount_fs() + @provider.mount_fs end it "should mount the filesystem specified by uuid", :not_supported_on_solaris do @@ -315,13 +315,13 @@ describe Chef::Provider::Mount::Mount do @stdout_mock = double("stdout mock") allow(@stdout_mock).to receive(:each).and_yield("#{@new_resource.device} on #{@new_resource.mount_point}") expect(@provider).to receive(:shell_out_compacted!).with("mount", "-t", @new_resource.fstype, "-o", "defaults", "-U", @new_resource.device, @new_resource.mount_point).and_return(@stdout_mock) - @provider.mount_fs() + @provider.mount_fs end it "should not mount the filesystem if it is mounted" do allow(@current_resource).to receive(:mounted).and_return(true) expect(@provider).not_to receive(:shell_out!) - @provider.mount_fs() + @provider.mount_fs end end @@ -330,13 +330,13 @@ describe Chef::Provider::Mount::Mount do it "should umount the filesystem if it is mounted" do @current_resource.mounted(true) expect(@provider).to receive(:shell_out!).with("umount", "/tmp/foo") - @provider.umount_fs() + @provider.umount_fs end it "should not umount the filesystem if it is not mounted" do @current_resource.mounted(false) expect(@provider).not_to receive(:shell_out!) - @provider.umount_fs() + @provider.umount_fs end end @@ -363,7 +363,7 @@ describe Chef::Provider::Mount::Mount do expect(@provider).to receive(:umount_fs) expect(@provider).to receive(:sleep).with(1) expect(@provider).to receive(:mount_fs) - @provider.remount_fs() + @provider.remount_fs end it "should not try to remount at all if mounted is false" do @@ -371,7 +371,7 @@ describe Chef::Provider::Mount::Mount do expect(@provider).not_to receive(:shell_out!) expect(@provider).not_to receive(:umount_fs) expect(@provider).not_to receive(:mount_fs) - @provider.remount_fs() + @provider.remount_fs end end diff --git a/spec/unit/provider/mount/solaris_spec.rb b/spec/unit/provider/mount/solaris_spec.rb index 4e73bc77b5..006eb690cb 100644 --- a/spec/unit/provider/mount/solaris_spec.rb +++ b/spec/unit/provider/mount/solaris_spec.rb @@ -103,7 +103,7 @@ describe Chef::Provider::Mount::Solaris, :unix_only do describe "#define_resource_requirements" do before do # we're not testing the actual actions so stub them all out - [:mount_fs, :umount_fs, :remount_fs, :enable_fs, :disable_fs].each { |m| allow(provider).to receive(m) } + %i{mount_fs umount_fs remount_fs enable_fs disable_fs}.each { |m| allow(provider).to receive(m) } end it "run_action(:mount) should raise an error if the device does not exist" do @@ -350,7 +350,7 @@ describe Chef::Provider::Mount::Solaris, :unix_only do expect(File).to receive(:symlink?).with(device).at_least(:once).and_return(true) expect(File).to receive(:readlink).with(device).at_least(:once).and_return(target) - provider.load_current_resource() + provider.load_current_resource end it "should set mounted true if the symlink target of the device is found in the mounts list" do @@ -387,7 +387,7 @@ describe Chef::Provider::Mount::Solaris, :unix_only do expect(File).to receive(:symlink?).with(device).at_least(:once).and_return(true) expect(File).to receive(:readlink).with(device).at_least(:once).and_return(target) - provider.load_current_resource() + provider.load_current_resource end it "should set mounted true if the symlink target of the device is found in the mounts list" do @@ -411,7 +411,7 @@ describe Chef::Provider::Mount::Solaris, :unix_only do EOF end it "should set mounted true" do - provider.load_current_resource() + provider.load_current_resource expect(provider.current_resource.mounted).to be_truthy end end @@ -424,7 +424,7 @@ describe Chef::Provider::Mount::Solaris, :unix_only do EOF end it "should set mounted false" do - provider.load_current_resource() + provider.load_current_resource expect(provider.current_resource.mounted).to be_falsey end end @@ -436,7 +436,7 @@ describe Chef::Provider::Mount::Solaris, :unix_only do EOF end it "should set mounted false" do - provider.load_current_resource() + provider.load_current_resource expect(provider.current_resource.mounted).to be_falsey end end @@ -448,7 +448,7 @@ describe Chef::Provider::Mount::Solaris, :unix_only do EOF end it "should set mounted false" do - provider.load_current_resource() + provider.load_current_resource expect(provider.current_resource.mounted).to be_falsey end end @@ -539,28 +539,28 @@ describe Chef::Provider::Mount::Solaris, :unix_only do describe "mount_fs" do it "should mount the filesystem" do expect(provider).to receive(:shell_out_compacted!).with("mount", "-F", fstype, device, mountpoint) - provider.mount_fs() + provider.mount_fs end it "should mount the filesystem with options if options were passed" do options = "logging,noatime,largefiles,nosuid,rw,quota" new_resource.options(options.split(/,/)) expect(provider).to receive(:shell_out_compacted!).with("mount", "-F", fstype, "-o", options, device, mountpoint) - provider.mount_fs() + provider.mount_fs end it "should delete the 'noauto' magic option" do options = "rw,noauto" new_resource.options(%w{rw noauto}) expect(provider).to receive(:shell_out_compacted!).with("mount", "-F", fstype, "-o", "rw", device, mountpoint) - provider.mount_fs() + provider.mount_fs end end describe "umount_fs" do it "should umount the filesystem if it is mounted" do expect(provider).to receive(:shell_out_compacted!).with("umount", mountpoint) - provider.umount_fs() + provider.umount_fs end end diff --git a/spec/unit/provider/osx_profile_spec.rb b/spec/unit/provider/osx_profile_spec.rb index 8f99ad6817..017041bc60 100644 --- a/spec/unit/provider/osx_profile_spec.rb +++ b/spec/unit/provider/osx_profile_spec.rb @@ -132,7 +132,7 @@ describe Chef::Provider::OsxProfile do provider.load_current_resource expect( provider.instance_variable_get(:@new_profile_identifier) - ).to eql(test_profile["PayloadIdentifier"]) + ).to eql(test_profile["PayloadIdentifier"]) end it "should install when not installed" do @@ -167,7 +167,7 @@ describe Chef::Provider::OsxProfile do provider.load_current_resource allow(provider).to receive(:write_profile_to_disk).and_return(profile_path) expect(provider).to receive(:shell_out_compacted).with("/usr/bin/profiles", "-I", "-F", profile_path).and_return(shell_out_success) - provider.action_install() + provider.action_install end it "should fail if there is no identifier inside the profile" do @@ -228,16 +228,14 @@ describe Chef::Provider::OsxProfile do new_resource.profile_name "com.testprofile.screensaver" new_resource.action(:remove) provider.load_current_resource - expect(provider.instance_variable_get(:@new_profile_identifier) - ).to eql(new_resource.profile_name) + expect(provider.instance_variable_get(:@new_profile_identifier)).to eql(new_resource.profile_name) end it "should use specified identifier" do new_resource.identifier "com.testprofile.screensaver" new_resource.action(:remove) provider.load_current_resource - expect(provider.instance_variable_get(:@new_profile_identifier) - ).to eql(new_resource.identifier) + expect(provider.instance_variable_get(:@new_profile_identifier)).to eql(new_resource.identifier) end it "should work with spaces in the identifier" do @@ -251,7 +249,7 @@ describe Chef::Provider::OsxProfile do new_resource.action(:remove) provider.load_current_resource expect(provider).to receive(:shell_out_compacted).with("/usr/bin/profiles", "-R", "-p", new_resource.identifier).and_return(shell_out_success) - provider.action_remove() + provider.action_remove end end end diff --git a/spec/unit/provider/package/apt_spec.rb b/spec/unit/provider/package/apt_spec.rb index bfc78cbb7f..b2c051d2f1 100644 --- a/spec/unit/provider/package/apt_spec.rb +++ b/spec/unit/provider/package/apt_spec.rb @@ -511,8 +511,8 @@ describe Chef::Provider::Package::Apt do allow(@provider).to receive(:shell_out_compacted!).with( "apt-mark", "showhold", timeout: 900 ).and_return(instance_double( - Mixlib::ShellOut, stdout: "irssi") - ) + Mixlib::ShellOut, stdout: "irssi" + )) expect(logger).to receive(:trace).with("#{@provider.new_resource} is already locked") @provider.action_lock @@ -532,8 +532,8 @@ describe Chef::Provider::Package::Apt do allow(@provider).to receive(:shell_out_compacted!).with( "apt-mark", "showhold", timeout: 900 ).and_return(instance_double( - Mixlib::ShellOut, stdout: "") - ) + Mixlib::ShellOut, stdout: "" + )) expect(logger).to receive(:trace).with("#{@provider.new_resource} is already unlocked") @provider.action_unlock diff --git a/spec/unit/provider/package/bff_spec.rb b/spec/unit/provider/package/bff_spec.rb index 7606092762..b428ec0a72 100644 --- a/spec/unit/provider/package/bff_spec.rb +++ b/spec/unit/provider/package/bff_spec.rb @@ -81,7 +81,7 @@ describe Chef::Provider::Package::Bff do status = double("Status", stdout: info, exitstatus: 0) expect(@provider).to receive(:shell_out_compacted).with("installp", "-L", "-d", "/tmp/samba.base", timeout: 900).and_return(status) expect(@provider).to receive(:shell_out_compacted).with("lslpp", "-lcq", "samba.base", timeout: 900).and_return(@empty_status) - expect(logger).to receive(:warn).once.with(%r{bff package by product name}) + expect(logger).to receive(:warn).once.with(/bff package by product name/) @provider.load_current_resource expect(@provider.current_resource.package_name).to eq("samba.base") diff --git a/spec/unit/provider/package/cab_spec.rb b/spec/unit/provider/package/cab_spec.rb index 2ed40566f4..0ffbcd4a51 100644 --- a/spec/unit/provider/package/cab_spec.rb +++ b/spec/unit/provider/package/cab_spec.rb @@ -260,7 +260,7 @@ describe Chef::Provider::Package::Cab do end before do - new_resource.source = "#{ENV['TEMP']}/test6.1-kb2664825-v3-x64.cab" + new_resource.source = "#{ENV["TEMP"]}/test6.1-kb2664825-v3-x64.cab" installed_package_list_obj = double(stdout: installed_package_list_stdout) allow(provider).to receive(:dism_command).with("/Get-Packages").and_return(installed_package_list_obj) end diff --git a/spec/unit/provider/package/msu_spec.rb b/spec/unit/provider/package/msu_spec.rb index b2f0b22963..905d48649f 100644 --- a/spec/unit/provider/package/msu_spec.rb +++ b/spec/unit/provider/package/msu_spec.rb @@ -243,7 +243,7 @@ describe Chef::Provider::Package::Msu, :windows_only do describe "#extract_msu_contents" do it "extracts the msu contents by using mixlib shellout" do - expect(provider).to receive(:shell_out!).with("#{ENV['SYSTEMROOT']}\\system32\\expand.exe -f:* msu_file destination") + expect(provider).to receive(:shell_out!).with("#{ENV["SYSTEMROOT"]}\\system32\\expand.exe -f:* msu_file destination") provider.extract_msu_contents("msu_file", "destination") end end diff --git a/spec/unit/provider/package/openbsd_spec.rb b/spec/unit/provider/package/openbsd_spec.rb index 01d6571f65..c8de4b7471 100644 --- a/spec/unit/provider/package/openbsd_spec.rb +++ b/spec/unit/provider/package/openbsd_spec.rb @@ -45,15 +45,16 @@ describe Chef::Provider::Package::Openbsd do context "when not already installed" do before do - allow(provider).to receive(:shell_out_compacted!).with("pkg_info", "-e", "#{name}->0", anything()).and_return(instance_double("shellout", stdout: "")) + allow(provider).to receive(:shell_out_compacted!).with("pkg_info", "-e", "#{name}->0", anything).and_return(instance_double("shellout", stdout: "")) end context "when there is a single candidate" do context "when source is not provided" do it "should run the installation command" do - expect(provider).to receive(:shell_out_compacted!).with("pkg_info", "-I", name, anything()).and_return( - instance_double("shellout", stdout: "#{name}-#{version}\n")) + expect(provider).to receive(:shell_out_compacted!).with("pkg_info", "-I", name, anything).and_return( + instance_double("shellout", stdout: "#{name}-#{version}\n") + ) expect(provider).to receive(:shell_out_compacted!).with( "pkg_add", "-r", "#{name}-#{version}", { env: { "PKG_PATH" => "http://ftp.OpenBSD.org/pub/OpenBSD/5.5/packages/amd64/" }, timeout: 900 } @@ -69,8 +70,9 @@ describe Chef::Provider::Package::Openbsd do context "if no version is specified" do it "should raise an exception" do - expect(provider).to receive(:shell_out_compacted!).with("pkg_info", "-I", name, anything()).and_return( - instance_double("shellout", stdout: "#{name}-#{version}-#{flavor_a}\n#{name}-#{version}-#{flavor_b}\n")) + expect(provider).to receive(:shell_out_compacted!).with("pkg_info", "-I", name, anything).and_return( + instance_double("shellout", stdout: "#{name}-#{version}-#{flavor_a}\n#{name}-#{version}-#{flavor_b}\n") + ) expect { provider.run_action(:install) }.to raise_error(Chef::Exceptions::Package, /multiple matching candidates/) end end @@ -83,9 +85,10 @@ describe Chef::Provider::Package::Openbsd do context "if no version is specified" do it "should run the installation command" do - expect(provider).to receive(:shell_out_compacted!).with("pkg_info", "-e", "#{package_name}->0", anything()).and_return(instance_double("shellout", stdout: "")) - expect(provider).to receive(:shell_out_compacted!).with("pkg_info", "-I", name, anything()).and_return( - instance_double("shellout", stdout: "#{name}-#{version}-#{flavor}\n")) + expect(provider).to receive(:shell_out_compacted!).with("pkg_info", "-e", "#{package_name}->0", anything).and_return(instance_double("shellout", stdout: "")) + expect(provider).to receive(:shell_out_compacted!).with("pkg_info", "-I", name, anything).and_return( + instance_double("shellout", stdout: "#{name}-#{version}-#{flavor}\n") + ) expect(provider).to receive(:shell_out_compacted!).with( "pkg_add", "-r", "#{name}-#{version}-#{flavor}", { env: { "PKG_PATH" => "http://ftp.OpenBSD.org/pub/OpenBSD/5.5/packages/amd64/" }, timeout: 900 } @@ -98,8 +101,9 @@ describe Chef::Provider::Package::Openbsd do context "if a version is specified" do it "should use the flavor from the version" do - expect(provider).to receive(:shell_out_compacted!).with("pkg_info", "-I", "#{name}-#{version}-#{flavor_b}", anything()).and_return( - instance_double("shellout", stdout: "#{name}-#{version}-#{flavor_a}\n")) + expect(provider).to receive(:shell_out_compacted!).with("pkg_info", "-I", "#{name}-#{version}-#{flavor_b}", anything).and_return( + instance_double("shellout", stdout: "#{name}-#{version}-#{flavor_a}\n") + ) new_resource.version("#{version}-#{flavor_b}") expect(provider).to receive(:shell_out_compacted!).with( diff --git a/spec/unit/provider/package/smartos_spec.rb b/spec/unit/provider/package/smartos_spec.rb index cd85e1b3d9..726420fe23 100644 --- a/spec/unit/provider/package/smartos_spec.rb +++ b/spec/unit/provider/package/smartos_spec.rb @@ -75,7 +75,7 @@ describe Chef::Provider::Package::SmartOS, "load_current_resource" do end it "should lookup the candidate_version if the variable is not already set (pkgin separated by spaces)" do - search = double() + search = double expect(search).to receive(:each_line) .and_yield("something-varnish-1.1.1 something varnish like\n") .and_yield("varnish-2.3.4 actual varnish\n") @@ -85,7 +85,7 @@ describe Chef::Provider::Package::SmartOS, "load_current_resource" do end it "should lookup the candidate_version if the variable is not already set (pkgin separated by semicolons)" do - search = double() + search = double expect(search).to receive(:each_line) .and_yield("something-varnish-1.1.1;;something varnish like\n") .and_yield("varnish-2.3.4;;actual varnish\n") diff --git a/spec/unit/provider/package/windows/exe_spec.rb b/spec/unit/provider/package/windows/exe_spec.rb index 4f6a6121bd..6fa1747b03 100644 --- a/spec/unit/provider/package/windows/exe_spec.rb +++ b/spec/unit/provider/package/windows/exe_spec.rb @@ -117,7 +117,7 @@ describe Chef::Provider::Package::Windows::Exe do context "no version given and one package installed with unquoted uninstall string" do it "removes installed package and quotes uninstall string" do allow(::File).to receive(:exist?).with("uninst_dir/uninst_file").and_return(true) - expect(provider).to receive(:shell_out!).with(/start \"\" \/wait \"uninst_dir\/uninst_file\" \/S \/NCRC & exit %%%%ERRORLEVEL%%%%/, kind_of(Hash)) + expect(provider).to receive(:shell_out!).with(%r{start \"\" /wait \"uninst_dir/uninst_file\" /S /NCRC & exit %%%%ERRORLEVEL%%%%}, kind_of(Hash)) provider.remove_package end end @@ -126,7 +126,7 @@ describe Chef::Provider::Package::Windows::Exe do it "removes installed package and quotes uninstall string" do new_resource.timeout = 300 allow(::File).to receive(:exist?).with("uninst_dir/uninst_file").and_return(true) - expect(provider).to receive(:shell_out!).with(/start \"\" \/wait \"uninst_dir\/uninst_file\" \/S \/NCRC & exit %%%%ERRORLEVEL%%%%/, timeout: 300, returns: [0]) + expect(provider).to receive(:shell_out!).with(%r{start \"\" /wait \"uninst_dir/uninst_file\" /S /NCRC & exit %%%%ERRORLEVEL%%%%}, timeout: 300, returns: [0]) provider.remove_package end end @@ -148,15 +148,15 @@ describe Chef::Provider::Package::Windows::Exe do context "version given and installed" do it "removes given version" do new_resource.version("v2") - expect(provider).to receive(:shell_out!).with(/start \"\" \/wait \"uninst_dir2\/uninst_file2\" \/S \/NCRC & exit %%%%ERRORLEVEL%%%%/, kind_of(Hash)) + expect(provider).to receive(:shell_out!).with(%r{start \"\" /wait \"uninst_dir2/uninst_file2\" /S /NCRC & exit %%%%ERRORLEVEL%%%%}, kind_of(Hash)) provider.remove_package end end context "no version given" do it "removes both versions" do - expect(provider).to receive(:shell_out!).with(/start \"\" \/wait \"uninst_dir1\/uninst_file1\" \/S \/NCRC & exit %%%%ERRORLEVEL%%%%/, kind_of(Hash)) - expect(provider).to receive(:shell_out!).with(/start \"\" \/wait \"uninst_dir2\/uninst_file2\" \/S \/NCRC & exit %%%%ERRORLEVEL%%%%/, kind_of(Hash)) + expect(provider).to receive(:shell_out!).with(%r{start \"\" /wait \"uninst_dir1/uninst_file1\" /S /NCRC & exit %%%%ERRORLEVEL%%%%}, kind_of(Hash)) + expect(provider).to receive(:shell_out!).with(%r{start \"\" /wait \"uninst_dir2/uninst_file2\" /S /NCRC & exit %%%%ERRORLEVEL%%%%}, kind_of(Hash)) provider.remove_package end end @@ -167,7 +167,7 @@ describe Chef::Provider::Package::Windows::Exe do let(:provider) { Chef::Provider::Package::Windows::Exe.new(new_resource, :nsis, uninstall_entry) } it "calls installer with the correct flags" do - expect(provider).to receive(:shell_out!).with(/start \"\" \/wait \"#{Regexp.quote(new_resource.source)}\" \/S \/NCRC & exit %%%%ERRORLEVEL%%%%/, kind_of(Hash)) + expect(provider).to receive(:shell_out!).with(%r{start \"\" /wait \"#{Regexp.quote(new_resource.source)}\" /S /NCRC & exit %%%%ERRORLEVEL%%%%}, kind_of(Hash)) provider.install_package end end @@ -176,7 +176,7 @@ describe Chef::Provider::Package::Windows::Exe do let(:provider) { Chef::Provider::Package::Windows::Exe.new(new_resource, :installshield, uninstall_entry) } it "calls installer with the correct flags" do - expect(provider).to receive(:shell_out!).with(/start \"\" \/wait \"#{Regexp.quote(new_resource.source)}\" \/s \/sms & exit %%%%ERRORLEVEL%%%%/, kind_of(Hash)) + expect(provider).to receive(:shell_out!).with(%r{start \"\" /wait \"#{Regexp.quote(new_resource.source)}\" /s /sms & exit %%%%ERRORLEVEL%%%%}, kind_of(Hash)) provider.install_package end end @@ -185,7 +185,7 @@ describe Chef::Provider::Package::Windows::Exe do let(:provider) { Chef::Provider::Package::Windows::Exe.new(new_resource, :inno, uninstall_entry) } it "calls installer with the correct flags" do - expect(provider).to receive(:shell_out!).with(/start \"\" \/wait \"#{Regexp.quote(new_resource.source)}\" \/VERYSILENT \/SUPPRESSMSGBOXES \/NORESTART & exit %%%%ERRORLEVEL%%%%/, kind_of(Hash)) + expect(provider).to receive(:shell_out!).with(%r{start \"\" /wait \"#{Regexp.quote(new_resource.source)}\" /VERYSILENT /SUPPRESSMSGBOXES /NORESTART & exit %%%%ERRORLEVEL%%%%}, kind_of(Hash)) provider.install_package end end @@ -194,7 +194,7 @@ describe Chef::Provider::Package::Windows::Exe do let(:provider) { Chef::Provider::Package::Windows::Exe.new(new_resource, :wise, uninstall_entry) } it "calls installer with the correct flags" do - expect(provider).to receive(:shell_out!).with(/start \"\" \/wait \"#{Regexp.quote(new_resource.source)}\" \/s & exit %%%%ERRORLEVEL%%%%/, kind_of(Hash)) + expect(provider).to receive(:shell_out!).with(%r{start \"\" /wait \"#{Regexp.quote(new_resource.source)}\" /s & exit %%%%ERRORLEVEL%%%%}, kind_of(Hash)) provider.install_package end end diff --git a/spec/unit/provider/package/windows/msi_spec.rb b/spec/unit/provider/package/windows/msi_spec.rb index 0e939610db..d2902e1bb1 100644 --- a/spec/unit/provider/package/windows/msi_spec.rb +++ b/spec/unit/provider/package/windows/msi_spec.rb @@ -104,14 +104,14 @@ describe Chef::Provider::Package::Windows::MSI do describe "install_package" do it "calls msiexec /qn /i" do - expect(provider).to receive(:shell_out!).with(/msiexec \/qn \/i \"#{Regexp.quote(new_resource.source)}\"/, kind_of(Hash)) + expect(provider).to receive(:shell_out!).with(%r{msiexec /qn /i \"#{Regexp.quote(new_resource.source)}\"}, kind_of(Hash)) provider.install_package end end describe "remove_package" do it "calls msiexec /qn /x" do - expect(provider).to receive(:shell_out!).with(/msiexec \/qn \/x \"#{Regexp.quote(new_resource.source)}\"/, kind_of(Hash)) + expect(provider).to receive(:shell_out!).with(%r{msiexec /qn /x \"#{Regexp.quote(new_resource.source)}\"}, kind_of(Hash)) provider.remove_package end @@ -121,7 +121,7 @@ describe Chef::Provider::Package::Windows::MSI do end it "removes installed package" do - expect(provider).to receive(:shell_out!).with(/msiexec \/x {guid} \/q/, kind_of(Hash)) + expect(provider).to receive(:shell_out!).with(%r{msiexec /x {guid} /q}, kind_of(Hash)) provider.remove_package end @@ -140,8 +140,8 @@ describe Chef::Provider::Package::Windows::MSI do end it "removes both installed package" do - expect(provider).to receive(:shell_out!).with(/msiexec \/x {guid} \/q/, kind_of(Hash)) - expect(provider).to receive(:shell_out!).with(/msiexec \/x {guid2} \/q/, kind_of(Hash)) + expect(provider).to receive(:shell_out!).with(%r{msiexec /x {guid} /q}, kind_of(Hash)) + expect(provider).to receive(:shell_out!).with(%r{msiexec /x {guid2} /q}, kind_of(Hash)) provider.remove_package end end @@ -150,7 +150,7 @@ describe Chef::Provider::Package::Windows::MSI do before { new_resource.options("/Q") } it "does not duplicate quiet switch" do - expect(provider).to receive(:shell_out!).with(/msiexec \/x {guid} \/Q/, kind_of(Hash)) + expect(provider).to receive(:shell_out!).with(%r{msiexec /x {guid} /Q}, kind_of(Hash)) provider.remove_package end end @@ -159,7 +159,7 @@ describe Chef::Provider::Package::Windows::MSI do before { new_resource.options("/qn") } it "does not duplicate quiet switch" do - expect(provider).to receive(:shell_out!).with(/msiexec \/x {guid} \/qn/, kind_of(Hash)) + expect(provider).to receive(:shell_out!).with(%r{msiexec /x {guid} /qn}, kind_of(Hash)) provider.remove_package end end diff --git a/spec/unit/provider/package/windows_spec.rb b/spec/unit/provider/package/windows_spec.rb index 6b85013f3d..2fafb3bd0e 100644 --- a/spec/unit/provider/package/windows_spec.rb +++ b/spec/unit/provider/package/windows_spec.rb @@ -436,7 +436,8 @@ describe Chef::Provider::Package::Windows, :windows_only do it "raises the checksum mismatch exception" do expect { provider.send(:validate_content!) }.to raise_error( - Chef::Exceptions::ChecksumMismatch) + Chef::Exceptions::ChecksumMismatch + ) end end end diff --git a/spec/unit/provider/package/yum/yum_cache_spec.rb b/spec/unit/provider/package/yum/yum_cache_spec.rb index 6b2a617ac8..9867c31c37 100644 --- a/spec/unit/provider/package/yum/yum_cache_spec.rb +++ b/spec/unit/provider/package/yum/yum_cache_spec.rb @@ -60,7 +60,7 @@ describe Chef::Provider::Package::Yum::YumCache do expect( yum_cache.version_available?("foo", "1.2.3", "x86_64") ).to be true end - [ :refresh, :reload, :reload_installed, :reload_provides, :reset, :reset_installed ].each do |method| + %i{refresh reload reload_installed reload_provides reset reset_installed}.each do |method| it "restarts the python helper when #{method} is called" do expect( python_helper ).to receive(:restart) yum_cache.send(method) diff --git a/spec/unit/provider/powershell_script_spec.rb b/spec/unit/provider/powershell_script_spec.rb index 61c415f88d..cca0f34067 100644 --- a/spec/unit/provider/powershell_script_spec.rb +++ b/spec/unit/provider/powershell_script_spec.rb @@ -22,9 +22,9 @@ describe Chef::Provider::PowershellScript, "action_run" do let(:powershell_version) { nil } let(:node) do node = Chef::Node.new - node.default["kernel"] = Hash.new + node.default["kernel"] = {} node.default["kernel"][:machine] = :x86_64.to_s - if ! powershell_version.nil? + unless powershell_version.nil? node.default[:languages] = { powershell: { version: powershell_version } } end node @@ -107,19 +107,19 @@ describe Chef::Provider::PowershellScript, "action_run" do "3.6" => "Bypass", "4.0" => "Bypass", "5.0" => "Bypass" }.each do |version_policy| - let(:powershell_version) { version_policy[0].to_f } - context "when running PowerShell version #{version_policy[0]}" do let(:powershell_version) { version_policy[0].to_f } - - it "sets default -ExecutionPolicy flag to '#{version_policy[1]}'" do - expect(execution_policy_flag.downcase).to eq(version_policy[1].downcase) - end - it "sets user defined -ExecutionPolicy flag to 'RemoteSigned'" do - set_user_defined_flag - expect(execution_policy_flag.downcase).to eq("RemoteSigned".downcase) + context "when running PowerShell version #{version_policy[0]}" do + let(:powershell_version) { version_policy[0].to_f } + + it "sets default -ExecutionPolicy flag to '#{version_policy[1]}'" do + expect(execution_policy_flag.downcase).to eq(version_policy[1].downcase) + end + it "sets user defined -ExecutionPolicy flag to 'RemoteSigned'" do + set_user_defined_flag + expect(execution_policy_flag.downcase).to eq("RemoteSigned".downcase) + end end end - end end end end diff --git a/spec/unit/provider/registry_key_spec.rb b/spec/unit/provider/registry_key_spec.rb index 9a7dd9996e..2df2c917f9 100644 --- a/spec/unit/provider/registry_key_spec.rb +++ b/spec/unit/provider/registry_key_spec.rb @@ -322,7 +322,7 @@ describe Chef::Provider::RegistryKey do expect(@double_registry).to receive(:get_values).with(keyname).and_return( [ { name: "one", type: :string, data: "initial value" }, - { name: "two", type: :dword, data: 9001 } + { name: "two", type: :dword, data: 9001 }, ] ) end diff --git a/spec/unit/provider/route_spec.rb b/spec/unit/provider/route_spec.rb index 67311aa6f7..ad5223a04f 100644 --- a/spec/unit/provider/route_spec.rb +++ b/spec/unit/provider/route_spec.rb @@ -125,7 +125,7 @@ describe Chef::Provider::Route do @resource_add.action(:add) @provider.run_action(:add) expect(route_file.string.split("\n").size).to eq(1) - expect(route_file.string).to match(/^192\.168\.1\.0\/24 via 192\.168\.0\.1$/) + expect(route_file.string).to match(%r{^192\.168\.1\.0/24 via 192\.168\.0\.1$}) end end @@ -150,12 +150,12 @@ describe Chef::Provider::Route do describe Chef::Provider::Route, "generate_command for action_add" do it "should include a netmask when a one is specified" do @new_resource.netmask("255.255.0.0") - expect(@provider.generate_command(:add).join(" ")).to match(/\/\d{1,2}/) + expect(@provider.generate_command(:add).join(" ")).to match(%r{/\d{1,2}}) end it "should not include a netmask when a one is specified" do @new_resource.netmask(nil) - expect(@provider.generate_command(:add).join(" ")).not_to match(/\/\d{1,2}/) + expect(@provider.generate_command(:add).join(" ")).not_to match(%r{/\d{1,2}}) end it "should include ' via $gateway ' when a gateway is specified" do @@ -176,12 +176,12 @@ describe Chef::Provider::Route do describe Chef::Provider::Route, "generate_command for action_delete" do it "should include a netmask when a one is specified" do @new_resource.netmask("255.255.0.0") - expect(@provider.generate_command(:delete).join(" ")).to match(/\/\d{1,2}/) + expect(@provider.generate_command(:delete).join(" ")).to match(%r{/\d{1,2}}) end it "should not include a netmask when a one is specified" do @new_resource.netmask(nil) - expect(@provider.generate_command(:delete).join(" ")).not_to match(/\/\d{1,2}/) + expect(@provider.generate_command(:delete).join(" ")).not_to match(%r{/\d{1,2}}) end it "should include ' via $gateway ' when a gateway is specified" do @@ -197,11 +197,11 @@ describe Chef::Provider::Route do describe Chef::Provider::Route, "config_file_contents for action_add" do it "should include a netmask when a one is specified" do @new_resource.netmask("255.255.0.0") - expect(@provider.config_file_contents(:add, target: @new_resource.target, netmask: @new_resource.netmask)).to match(/\/\d{1,2}.*\n$/) + expect(@provider.config_file_contents(:add, target: @new_resource.target, netmask: @new_resource.netmask)).to match(%r{/\d{1,2}.*\n$}) end it "should not include a netmask when a one is specified" do - expect(@provider.config_file_contents(:add, target: @new_resource.target)).not_to match(/\/\d{1,2}.*\n$/) + expect(@provider.config_file_contents(:add, target: @new_resource.target)).not_to match(%r{/\d{1,2}.*\n$}) end it "should include ' via $gateway ' when a gateway is specified" do @@ -261,10 +261,10 @@ describe Chef::Provider::Route do @provider.action = :add @provider.generate_config expect(route_file.string.split("\n").size).to eq(4) - expect(route_file.string).to match(/^192\.168\.1\.0\/24 via 192\.168\.0\.1$/) - expect(route_file.string).to match(/^192\.168\.2\.0\/24 via 192\.168\.0\.1$/) - expect(route_file.string).to match(/^192\.168\.3\.0\/24 via 192\.168\.0\.1$/) - expect(route_file.string).to match(/^192\.168\.4\.0\/24 via 192\.168\.0\.1$/) + expect(route_file.string).to match(%r{^192\.168\.1\.0/24 via 192\.168\.0\.1$}) + expect(route_file.string).to match(%r{^192\.168\.2\.0/24 via 192\.168\.0\.1$}) + expect(route_file.string).to match(%r{^192\.168\.3\.0/24 via 192\.168\.0\.1$}) + expect(route_file.string).to match(%r{^192\.168\.4\.0/24 via 192\.168\.0\.1$}) end end end diff --git a/spec/unit/provider/service/arch_service_spec.rb b/spec/unit/provider/service/arch_service_spec.rb index faec7ff645..de2bb16a6a 100644 --- a/spec/unit/provider/service/arch_service_spec.rb +++ b/spec/unit/provider/service/arch_service_spec.rb @@ -181,7 +181,7 @@ describe Chef::Provider::Service::Arch, "load_current_resource" do 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(%w{network chef}) - @provider.enable_service() + @provider.enable_service end end @@ -202,7 +202,7 @@ describe Chef::Provider::Service::Arch, "load_current_resource" do it "should remove chef from DAEMONS array" do allow(::File).to receive(:read).with("/etc/rc.conf").and_return("DAEMONS=(network chef)") expect(@provider).to receive(:update_daemons).with(["network", "!chef"]) - @provider.disable_service() + @provider.disable_service end end @@ -223,12 +223,12 @@ describe Chef::Provider::Service::Arch, "load_current_resource" do it "should call the start command if one is specified" do @new_resource.start_command("/etc/rc.d/chef startyousillysally") expect(@provider).to receive(:shell_out!).with("/etc/rc.d/chef startyousillysally", default_env: false) - @provider.start_service() + @provider.start_service end it "should call '/etc/rc.d/service_name start' if no start command is specified" do expect(@provider).to receive(:shell_out!).with("/etc/rc.d/#{@new_resource.service_name} start", default_env: false) - @provider.start_service() + @provider.start_service end end @@ -249,12 +249,12 @@ describe Chef::Provider::Service::Arch, "load_current_resource" do it "should call the stop command if one is specified" do @new_resource.stop_command("/etc/rc.d/chef itoldyoutostop") expect(@provider).to receive(:shell_out!).with("/etc/rc.d/chef itoldyoutostop", default_env: false) - @provider.stop_service() + @provider.stop_service end it "should call '/etc/rc.d/service_name stop' if no stop command is specified" do expect(@provider).to receive(:shell_out!).with("/etc/rc.d/#{@new_resource.service_name} stop", default_env: false) - @provider.stop_service() + @provider.stop_service end end @@ -276,20 +276,20 @@ describe Chef::Provider::Service::Arch, "load_current_resource" do it "should call 'restart' on the service_name if the resource supports it" do @new_resource.supports({ restart: true }) expect(@provider).to receive(:shell_out!).with("/etc/rc.d/#{@new_resource.service_name} restart", default_env: false) - @provider.restart_service() + @provider.restart_service end it "should call the restart_command if one has been specified" do @new_resource.restart_command("/etc/rc.d/chef restartinafire") expect(@provider).to receive(:shell_out!).with("/etc/rc.d/#{@new_resource.service_name} restartinafire", default_env: false) - @provider.restart_service() + @provider.restart_service end it "should just call stop, then start when the resource doesn't support restart and no restart_command is specified" do expect(@provider).to receive(:stop_service) expect(@provider).to receive(:sleep).with(1) expect(@provider).to receive(:start_service) - @provider.restart_service() + @provider.restart_service end end @@ -311,13 +311,13 @@ describe Chef::Provider::Service::Arch, "load_current_resource" do it "should call 'reload' on the service if it supports it" do @new_resource.supports({ reload: true }) expect(@provider).to receive(:shell_out!).with("/etc/rc.d/#{@new_resource.service_name} reload", default_env: false) - @provider.reload_service() + @provider.reload_service end it "should should run the user specified reload command if one is specified and the service doesn't support reload" do @new_resource.reload_command("/etc/rc.d/chef lollerpants") expect(@provider).to receive(:shell_out!).with("/etc/rc.d/#{@new_resource.service_name} lollerpants", default_env: false) - @provider.reload_service() + @provider.reload_service end end end diff --git a/spec/unit/provider/service/debian_service_spec.rb b/spec/unit/provider/service/debian_service_spec.rb index 626abb10f7..5f89605b2e 100644 --- a/spec/unit/provider/service/debian_service_spec.rb +++ b/spec/unit/provider/service/debian_service_spec.rb @@ -89,7 +89,8 @@ describe Chef::Provider::Service::Debian do "0" => [:stop, "20"], "1" => [:stop, "20"], "6" => [:stop, "20"], - }) + } + ) end end diff --git a/spec/unit/provider/service/freebsd_service_spec.rb b/spec/unit/provider/service/freebsd_service_spec.rb index d33b97d63d..4392786edc 100644 --- a/spec/unit/provider/service/freebsd_service_spec.rb +++ b/spec/unit/provider/service/freebsd_service_spec.rb @@ -261,7 +261,8 @@ describe Chef::Provider::Service::Freebsd do [ %Q{thing_#{new_resource.service_name}_enable="YES"}, %Q{#{new_resource.service_name}_enable="NO"}, - ] end + ] + end it "sets enabled based on the exact match (false)" do provider.determine_enabled_status! expect(current_resource.enabled).to be false @@ -273,7 +274,8 @@ describe Chef::Provider::Service::Freebsd do [ %Q{#{new_resource.service_name}_thing_enable="YES"}, %Q{#{new_resource.service_name}_enable="NO"}, - ] end + ] + end it "sets enabled based on the exact match (false)" do provider.determine_enabled_status! expect(current_resource.enabled).to be false @@ -285,7 +287,8 @@ describe Chef::Provider::Service::Freebsd do [ %Q{thing_#{new_resource.service_name}_enable="NO"}, %Q{#{new_resource.service_name}_enable="YES"}, - ] end + ] + end it "sets enabled based on the exact match (true)" do provider.determine_enabled_status! expect(current_resource.enabled).to be true @@ -297,7 +300,8 @@ describe Chef::Provider::Service::Freebsd do [ %Q{#{new_resource.service_name}_thing_enable="NO"}, %Q{#{new_resource.service_name}_enable="YES"}, - ] end + ] + end it "sets enabled based on the exact match (true)" do provider.determine_enabled_status! expect(current_resource.enabled).to be true @@ -445,12 +449,12 @@ describe Chef::Provider::Service::Freebsd do it "should call the start command if one is specified" do new_resource.start_command("/etc/rc.d/chef startyousillysally") expect(provider).to receive(:shell_out!).with("/etc/rc.d/chef startyousillysally", default_env: false) - provider.start_service() + provider.start_service end it "should call '/usr/local/etc/rc.d/service_name faststart' if no start command is specified" do expect(provider).to receive(:shell_out!).with("/usr/local/etc/rc.d/#{new_resource.service_name} faststart", default_env: false) - provider.start_service() + provider.start_service end end @@ -458,12 +462,12 @@ describe Chef::Provider::Service::Freebsd do it "should call the stop command if one is specified" do new_resource.stop_command("/etc/init.d/chef itoldyoutostop") expect(provider).to receive(:shell_out!).with("/etc/init.d/chef itoldyoutostop", default_env: false) - provider.stop_service() + provider.stop_service end it "should call '/usr/local/etc/rc.d/service_name faststop' if no stop command is specified" do expect(provider).to receive(:shell_out!).with("/usr/local/etc/rc.d/#{new_resource.service_name} faststop", default_env: false) - provider.stop_service() + provider.stop_service end end @@ -471,19 +475,19 @@ describe Chef::Provider::Service::Freebsd do it "should call 'restart' on the service_name if the resource supports it" do new_resource.supports({ restart: true }) expect(provider).to receive(:shell_out!).with("/usr/local/etc/rc.d/#{new_resource.service_name} fastrestart", default_env: false) - provider.restart_service() + provider.restart_service end it "should call the restart_command if one has been specified" do new_resource.restart_command("/etc/init.d/chef restartinafire") expect(provider).to receive(:shell_out!).with("/etc/init.d/chef restartinafire", default_env: false) - provider.restart_service() + provider.restart_service end it "otherwise it should call stop and start" do expect(provider).to receive(:stop_service) expect(provider).to receive(:start_service) - provider.restart_service() + provider.restart_service end end end @@ -550,21 +554,21 @@ describe Chef::Provider::Service::Freebsd do allow(current_resource).to receive(:enabled).and_return(false) expect(provider).to receive(:read_rc_conf).and_return([ "foo", "#{new_resource.service_name}_enable=\"NO\"", "bar" ]) expect(provider).to receive(:write_rc_conf).with(["foo", "bar", "#{new_resource.service_name}_enable=\"YES\""]) - provider.enable_service() + provider.enable_service end it "should not partial match an already enabled service" do allow(current_resource).to receive(:enabled).and_return(false) expect(provider).to receive(:read_rc_conf).and_return([ "foo", "thing_#{new_resource.service_name}_enable=\"NO\"", "bar" ]) expect(provider).to receive(:write_rc_conf).with(["foo", "thing_#{new_resource.service_name}_enable=\"NO\"", "bar", "#{new_resource.service_name}_enable=\"YES\""]) - provider.enable_service() + provider.enable_service end 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(%w{foo bar}) expect(provider).to receive(:write_rc_conf).with(["foo", "bar", "#{new_resource.service_name}_enable=\"YES\""]) - provider.enable_service() + provider.enable_service end it "should not enable the service if it is already enabled" do @@ -577,7 +581,7 @@ describe Chef::Provider::Service::Freebsd do allow(current_resource).to receive(:enabled).and_return(false) expect(provider).to receive(:read_rc_conf).and_return([ "foo", "bar", "\# #{new_resource.service_name}_enable=\"YES\"", "\# #{new_resource.service_name}_enable=\"NO\""]) expect(provider).to receive(:write_rc_conf).with(["foo", "bar", "#{new_resource.service_name}_enable=\"YES\""]) - provider.enable_service() + provider.enable_service end end @@ -591,27 +595,27 @@ describe Chef::Provider::Service::Freebsd do allow(current_resource).to receive(:enabled).and_return(true) expect(provider).to receive(:read_rc_conf).and_return([ "foo", "#{new_resource.service_name}_enable=\"YES\"", "bar" ]) expect(provider).to receive(:write_rc_conf).with(["foo", "bar", "#{new_resource.service_name}_enable=\"NO\""]) - provider.disable_service() + provider.disable_service end it "should not disable an enabled service that partially matches" do allow(current_resource).to receive(:enabled).and_return(true) expect(provider).to receive(:read_rc_conf).and_return([ "foo", "thing_#{new_resource.service_name}_enable=\"YES\"", "bar" ]) expect(provider).to receive(:write_rc_conf).with(["foo", "thing_#{new_resource.service_name}_enable=\"YES\"", "bar", "#{new_resource.service_name}_enable=\"NO\""]) - provider.disable_service() + provider.disable_service end it "should not disable the service if it is already disabled" do allow(current_resource).to receive(:enabled).and_return(false) expect(provider).not_to receive(:write_rc_conf) - provider.disable_service() + provider.disable_service end it "should remove commented out versions of it being disabled or enabled" do allow(current_resource).to receive(:enabled).and_return(true) expect(provider).to receive(:read_rc_conf).and_return([ "foo", "bar", "\# #{new_resource.service_name}_enable=\"YES\"", "\# #{new_resource.service_name}_enable=\"NO\""]) expect(provider).to receive(:write_rc_conf).with(["foo", "bar", "#{new_resource.service_name}_enable=\"NO\""]) - provider.disable_service() + provider.disable_service end end end diff --git a/spec/unit/provider/service/gentoo_service_spec.rb b/spec/unit/provider/service/gentoo_service_spec.rb index 6a928d849b..bc3d0b5c04 100644 --- a/spec/unit/provider/service/gentoo_service_spec.rb +++ b/spec/unit/provider/service/gentoo_service_spec.rb @@ -129,14 +129,14 @@ describe Chef::Provider::Service::Gentoo do describe Chef::Provider::Service::Gentoo, "enable_service" do it "should call rc-update add *service* default" do expect(@provider).to receive(:shell_out!).with("/sbin/rc-update add chef default") - @provider.enable_service() + @provider.enable_service end end describe Chef::Provider::Service::Gentoo, "disable_service" do it "should call rc-update del *service* default" do expect(@provider).to receive(:shell_out!).with("/sbin/rc-update del chef default") - @provider.disable_service() + @provider.disable_service end end end diff --git a/spec/unit/provider/service/init_service_spec.rb b/spec/unit/provider/service/init_service_spec.rb index 38e9ad37de..b75d7c4981 100644 --- a/spec/unit/provider/service/init_service_spec.rb +++ b/spec/unit/provider/service/init_service_spec.rb @@ -165,12 +165,12 @@ describe Chef::Provider::Service::Init, "load_current_resource" do it "should call the start command if one is specified" do @new_resource.start_command("/etc/init.d/chef startyousillysally") expect(@provider).to receive(:shell_out!).with("/etc/init.d/chef startyousillysally", default_env: false) - @provider.start_service() + @provider.start_service end it "should call '/etc/init.d/service_name start' if no start command is specified" do expect(@provider).to receive(:shell_out!).with("/etc/init.d/#{@new_resource.service_name} start", default_env: false) - @provider.start_service() + @provider.start_service end end @@ -178,12 +178,12 @@ describe Chef::Provider::Service::Init, "load_current_resource" do it "should call the stop command if one is specified" do @new_resource.stop_command("/etc/init.d/chef itoldyoutostop") expect(@provider).to receive(:shell_out!).with("/etc/init.d/chef itoldyoutostop", default_env: false) - @provider.stop_service() + @provider.stop_service end it "should call '/etc/init.d/service_name stop' if no stop command is specified" do expect(@provider).to receive(:shell_out!).with("/etc/init.d/#{@new_resource.service_name} stop", default_env: false) - @provider.stop_service() + @provider.stop_service end end @@ -191,20 +191,20 @@ describe Chef::Provider::Service::Init, "load_current_resource" do it "should call 'restart' on the service_name if the resource supports it" do @new_resource.supports({ restart: true }) expect(@provider).to receive(:shell_out!).with("/etc/init.d/#{@new_resource.service_name} restart", default_env: false) - @provider.restart_service() + @provider.restart_service end it "should call the restart_command if one has been specified" do @new_resource.restart_command("/etc/init.d/chef restartinafire") expect(@provider).to receive(:shell_out!).with("/etc/init.d/#{@new_resource.service_name} restartinafire", default_env: false) - @provider.restart_service() + @provider.restart_service end it "should just call stop, then start when the resource doesn't support restart and no restart_command is specified" do expect(@provider).to receive(:stop_service) expect(@provider).to receive(:sleep).with(1) expect(@provider).to receive(:start_service) - @provider.restart_service() + @provider.restart_service end end @@ -212,13 +212,13 @@ describe Chef::Provider::Service::Init, "load_current_resource" do it "should call 'reload' on the service if it supports it" do @new_resource.supports({ reload: true }) expect(@provider).to receive(:shell_out!).with("/etc/init.d/chef reload", default_env: false) - @provider.reload_service() + @provider.reload_service end it "should should run the user specified reload command if one is specified and the service doesn't support reload" do @new_resource.reload_command("/etc/init.d/chef lollerpants") expect(@provider).to receive(:shell_out!).with("/etc/init.d/chef lollerpants", default_env: false) - @provider.reload_service() + @provider.reload_service end end diff --git a/spec/unit/provider/service/invokercd_service_spec.rb b/spec/unit/provider/service/invokercd_service_spec.rb index fb1a29fa43..1b3344e77b 100644 --- a/spec/unit/provider/service/invokercd_service_spec.rb +++ b/spec/unit/provider/service/invokercd_service_spec.rb @@ -152,12 +152,12 @@ describe Chef::Provider::Service::Invokercd, "load_current_resource" do it "should call the start command if one is specified" do @new_resource.start_command("/usr/sbin/invoke-rc.d chef startyousillysally") expect(@provider).to receive(:shell_out!).with("/usr/sbin/invoke-rc.d chef startyousillysally", default_env: false) - @provider.start_service() + @provider.start_service end it "should call '/usr/sbin/invoke-rc.d service_name start' if no start command is specified" do expect(@provider).to receive(:shell_out!).with("/usr/sbin/invoke-rc.d #{@new_resource.service_name} start", default_env: false) - @provider.start_service() + @provider.start_service end end @@ -165,12 +165,12 @@ describe Chef::Provider::Service::Invokercd, "load_current_resource" do it "should call the stop command if one is specified" do @new_resource.stop_command("/usr/sbin/invoke-rc.d chef itoldyoutostop") expect(@provider).to receive(:shell_out!).with("/usr/sbin/invoke-rc.d chef itoldyoutostop", default_env: false) - @provider.stop_service() + @provider.stop_service end it "should call '/usr/sbin/invoke-rc.d service_name stop' if no stop command is specified" do expect(@provider).to receive(:shell_out!).with("/usr/sbin/invoke-rc.d #{@new_resource.service_name} stop", default_env: false) - @provider.stop_service() + @provider.stop_service end end @@ -178,20 +178,20 @@ describe Chef::Provider::Service::Invokercd, "load_current_resource" do it "should call 'restart' on the service_name if the resource supports it" do @new_resource.supports({ restart: true }) expect(@provider).to receive(:shell_out!).with("/usr/sbin/invoke-rc.d #{@new_resource.service_name} restart", default_env: false) - @provider.restart_service() + @provider.restart_service end it "should call the restart_command if one has been specified" do @new_resource.restart_command("/usr/sbin/invoke-rc.d chef restartinafire") expect(@provider).to receive(:shell_out!).with("/usr/sbin/invoke-rc.d #{@new_resource.service_name} restartinafire", default_env: false) - @provider.restart_service() + @provider.restart_service end it "should just call stop, then start when the resource doesn't support restart and no restart_command is specified" do expect(@provider).to receive(:stop_service) expect(@provider).to receive(:sleep).with(1) expect(@provider).to receive(:start_service) - @provider.restart_service() + @provider.restart_service end end @@ -199,13 +199,13 @@ describe Chef::Provider::Service::Invokercd, "load_current_resource" do it "should call 'reload' on the service if it supports it" do @new_resource.supports({ reload: true }) expect(@provider).to receive(:shell_out!).with("/usr/sbin/invoke-rc.d chef reload", default_env: false) - @provider.reload_service() + @provider.reload_service end it "should should run the user specified reload command if one is specified and the service doesn't support reload" do @new_resource.reload_command("/usr/sbin/invoke-rc.d chef lollerpants") expect(@provider).to receive(:shell_out!).with("/usr/sbin/invoke-rc.d chef lollerpants", default_env: false) - @provider.reload_service() + @provider.reload_service end end end diff --git a/spec/unit/provider/service/openbsd_service_spec.rb b/spec/unit/provider/service/openbsd_service_spec.rb index 913fddc1cf..dfa491fc38 100644 --- a/spec/unit/provider/service/openbsd_service_spec.rb +++ b/spec/unit/provider/service/openbsd_service_spec.rb @@ -178,7 +178,8 @@ describe Chef::Provider::Service::Openbsd do [ %Q{thing_#{provider.builtin_service_enable_variable_name}="YES"}, %Q{#{provider.builtin_service_enable_variable_name}="NO"}, - ] end + ] + end it "sets enabled based on the exact match (false)" do provider.determine_enabled_status! expect(current_resource.enabled).to be false @@ -190,7 +191,8 @@ describe Chef::Provider::Service::Openbsd do [ %Q{#{provider.builtin_service_enable_variable_name}_thing="YES"}, (provider.builtin_service_enable_variable_name).to_s, - ] end + ] + end it "sets enabled based on the exact match (false)" do provider.determine_enabled_status! expect(current_resource.enabled).to be false @@ -202,7 +204,8 @@ describe Chef::Provider::Service::Openbsd do [ %Q{thing_#{provider.builtin_service_enable_variable_name}="NO"}, %Q{#{provider.builtin_service_enable_variable_name}="YES"}, - ] end + ] + end it "sets enabled based on the exact match (true)" do provider.determine_enabled_status! expect(current_resource.enabled).to be true @@ -214,7 +217,8 @@ describe Chef::Provider::Service::Openbsd do [ %Q{#{provider.builtin_service_enable_variable_name}_thing="NO"}, %Q{#{provider.builtin_service_enable_variable_name}="YES"}, - ] end + ] + end it "sets enabled based on the exact match (true)" do provider.determine_enabled_status! expect(current_resource.enabled).to be true @@ -286,12 +290,12 @@ describe Chef::Provider::Service::Openbsd do it "should call the start command if one is specified" do new_resource.start_command("/etc/rc.d/chef startyousillysally") expect(provider).to receive(:shell_out!).with("/etc/rc.d/chef startyousillysally", default_env: false) - provider.start_service() + provider.start_service end it "should call '/usr/local/etc/rc.d/service_name start' if no start command is specified" do expect(provider).to receive(:shell_out!).with("/etc/rc.d/#{new_resource.service_name} start", default_env: false) - provider.start_service() + provider.start_service end end @@ -299,12 +303,12 @@ describe Chef::Provider::Service::Openbsd do it "should call the stop command if one is specified" do new_resource.stop_command("/etc/init.d/chef itoldyoutostop") expect(provider).to receive(:shell_out!).with("/etc/init.d/chef itoldyoutostop", default_env: false) - provider.stop_service() + provider.stop_service end it "should call '/usr/local/etc/rc.d/service_name stop' if no stop command is specified" do expect(provider).to receive(:shell_out!).with("/etc/rc.d/#{new_resource.service_name} stop", default_env: false) - provider.stop_service() + provider.stop_service end end @@ -313,20 +317,20 @@ describe Chef::Provider::Service::Openbsd do let(:supports) { { restart: true } } it "should call 'restart' on the service_name if the resource supports it" do expect(provider).to receive(:shell_out!).with("/etc/rc.d/#{new_resource.service_name} restart", default_env: false) - provider.restart_service() + provider.restart_service end end it "should call the restart_command if one has been specified" do new_resource.restart_command("/etc/init.d/chef restartinafire") expect(provider).to receive(:shell_out!).with("/etc/init.d/chef restartinafire", default_env: false) - provider.restart_service() + provider.restart_service end it "otherwise it should call stop and start" do expect(provider).to receive(:stop_service) expect(provider).to receive(:start_service) - provider.restart_service() + provider.restart_service end end end diff --git a/spec/unit/provider/service/simple_service_spec.rb b/spec/unit/provider/service/simple_service_spec.rb index 2a0ebea1dc..2546f9cef7 100644 --- a/spec/unit/provider/service/simple_service_spec.rb +++ b/spec/unit/provider/service/simple_service_spec.rb @@ -108,7 +108,7 @@ describe Chef::Provider::Service::Simple, "load_current_resource" do it "should call the start command if one is specified" do @new_resource.start_command((@new_resource.start_command).to_s) expect(@provider).to receive(:shell_out!).with((@new_resource.start_command).to_s, default_env: false) - @provider.start_service() + @provider.start_service end it "should raise an exception if no start command is specified" do @@ -122,7 +122,7 @@ describe Chef::Provider::Service::Simple, "load_current_resource" do it "should call the stop command if one is specified" do @new_resource.stop_command("/etc/init.d/themadness stop") expect(@provider).to receive(:shell_out!).with("/etc/init.d/themadness stop", default_env: false) - @provider.stop_service() + @provider.stop_service end it "should raise an exception if no stop command is specified" do @@ -136,7 +136,7 @@ describe Chef::Provider::Service::Simple, "load_current_resource" do it "should call the restart command if one has been specified" do @new_resource.restart_command("/etc/init.d/foo restart") expect(@provider).to receive(:shell_out!).with("/etc/init.d/foo restart", default_env: false) - @provider.restart_service() + @provider.restart_service end it "should raise an exception if the resource doesn't support restart, no restart command is provided, and no stop command is provided" do @@ -149,7 +149,7 @@ describe Chef::Provider::Service::Simple, "load_current_resource" do expect(@provider).to receive(:stop_service) expect(@provider).to receive(:sleep).with(1) expect(@provider).to receive(:start_service) - @provider.restart_service() + @provider.restart_service end end @@ -163,7 +163,7 @@ describe Chef::Provider::Service::Simple, "load_current_resource" do it "should should run the user specified reload command if one is specified" do @new_resource.reload_command("kill -9 1") expect(@provider).to receive(:shell_out!).with("kill -9 1", default_env: false) - @provider.reload_service() + @provider.reload_service end end end diff --git a/spec/unit/provider/service/upstart_service_spec.rb b/spec/unit/provider/service/upstart_service_spec.rb index 365201cb38..572246a807 100644 --- a/spec/unit/provider/service/upstart_service_spec.rb +++ b/spec/unit/provider/service/upstart_service_spec.rb @@ -242,7 +242,7 @@ describe Chef::Provider::Service::Upstart do allow(@current_resource).to receive(:enabled).and_return(false) expect(@file).to receive(:search_file_replace) expect(@file).to receive(:write_file) - @provider.enable_service() + @provider.enable_service end it "should disable the service if it is enabled" do @@ -251,7 +251,7 @@ describe Chef::Provider::Service::Upstart do allow(@current_resource).to receive(:enabled).and_return(true) expect(@file).to receive(:search_file_replace) expect(@file).to receive(:write_file) - @provider.disable_service() + @provider.disable_service end end @@ -268,19 +268,19 @@ describe Chef::Provider::Service::Upstart do @provider.upstart_service_running = false @new_resource.start_command("/sbin/rsyslog startyousillysally") expect(@provider).to receive(:shell_out!).with("/sbin/rsyslog startyousillysally", default_env: false) - @provider.start_service() + @provider.start_service end it "should call '/sbin/start service_name' if no start command is specified" do @provider.upstart_service_running = false expect(@provider).to receive(:shell_out!).with("/sbin/start #{@new_resource.service_name}", default_env: false).and_return(shell_out_success) - @provider.start_service() + @provider.start_service end it "should not call '/sbin/start service_name' if it is already running" do @provider.upstart_service_running = true expect(@provider).not_to receive(:shell_out!) - @provider.start_service() + @provider.start_service end it "should pass parameters to the start command if they are provided" do @@ -289,14 +289,14 @@ describe Chef::Provider::Service::Upstart do @provider = Chef::Provider::Service::Upstart.new(@new_resource, @run_context) @provider.current_resource = @current_resource expect(@provider).to receive(:shell_out!).with("/sbin/start rsyslog OSD_ID=2", default_env: false).and_return(shell_out_success) - @provider.start_service() + @provider.start_service end it "should call the restart command if one is specified" do allow(@current_resource).to receive(:running).and_return(true) @new_resource.restart_command("/sbin/rsyslog restartyousillysally") expect(@provider).to receive(:shell_out!).with("/sbin/rsyslog restartyousillysally", default_env: false) - @provider.restart_service() + @provider.restart_service end it "should call start/sleep/stop if no restart command is specified" do @@ -304,47 +304,47 @@ describe Chef::Provider::Service::Upstart do expect(@provider).to receive(:stop_service) expect(@provider).to receive(:sleep).with(1) expect(@provider).to receive(:start_service) - @provider.restart_service() + @provider.restart_service end it "should call '/sbin/start service_name' if restart_service is called for a stopped service" do @provider.upstart_service_running = false allow(@current_resource).to receive(:running).and_return(false) expect(@provider).to receive(:shell_out!).with("/sbin/start #{@new_resource.service_name}", default_env: false).and_return(shell_out_success) - @provider.restart_service() + @provider.restart_service end it "should call the reload command if one is specified" do allow(@current_resource).to receive(:running).and_return(true) @new_resource.reload_command("/sbin/rsyslog reloadyousillysally") expect(@provider).to receive(:shell_out!).with("/sbin/rsyslog reloadyousillysally", default_env: false) - @provider.reload_service() + @provider.reload_service end it "should call '/sbin/reload service_name' if no reload command is specified" do allow(@current_resource).to receive(:running).and_return(true) expect(@provider).to receive(:shell_out!).with("/sbin/reload #{@new_resource.service_name}", default_env: false).and_return(shell_out_success) - @provider.reload_service() + @provider.reload_service end it "should call the stop command if one is specified" do @provider.upstart_service_running = true @new_resource.stop_command("/sbin/rsyslog stopyousillysally") expect(@provider).to receive(:shell_out!).with("/sbin/rsyslog stopyousillysally", default_env: false) - @provider.stop_service() + @provider.stop_service end it "should call '/sbin/stop service_name' if no stop command is specified" do @provider.upstart_service_running = true expect(@provider).to receive(:shell_out!).with("/sbin/stop #{@new_resource.service_name}", default_env: false).and_return(shell_out_success) - @provider.stop_service() + @provider.stop_service end it "should not call '/sbin/stop service_name' if it is already stopped" do @provider.upstart_service_running = false allow(@current_resource).to receive(:running).and_return(false) expect(@provider).not_to receive(:shell_out!).with("/sbin/stop #{@new_resource.service_name}", default_env: false) - @provider.stop_service() + @provider.stop_service expect(@upstart_service_running).to be_falsey end end diff --git a/spec/unit/provider/service/windows_spec.rb b/spec/unit/provider/service/windows_spec.rb index 9145a0caf4..860c0b1d6a 100644 --- a/spec/unit/provider/service/windows_spec.rb +++ b/spec/unit/provider/service/windows_spec.rb @@ -41,8 +41,7 @@ describe Chef::Provider::Service::Windows, "load_current_resource", :windows_onl tag_id: 0, dependencies: ["Winmgmt"], service_start_name: "LocalSystem", - display_name: "Chef Client Service" - ) + display_name: "Chef Client Service") end # Actual response from Win32::Service.services @@ -73,8 +72,7 @@ describe Chef::Provider::Service::Windows, "load_current_resource", :windows_onl command: nil, num_actions: 0, actions: nil, - delayed_start: 1 - ) + delayed_start: 1) end let(:provider) do @@ -98,7 +96,8 @@ describe Chef::Provider::Service::Windows, "load_current_resource", :windows_onl allow(Win32::Service).to receive(:start).with(any_args).and_return(Win32::Service) allow(Win32::Service).to receive(:status).with(new_resource.service_name).and_return( - double("StatusStruct", current_state: "running")) + double("StatusStruct", current_state: "running") + ) allow(Win32::Service).to receive(:config_info).with(new_resource.service_name) .and_return(chef_service_config_info) @@ -155,8 +154,8 @@ describe Chef::Provider::Service::Windows, "load_current_resource", :windows_onl tag_id: 0, dependencies: %w{NSI Tdx Afd}, service_start_name: 'NT Authority\\LocalService', - display_name: "DHCP Client" - )) + display_name: "DHCP Client") + ) end context "startup_type is neither :automatic or :disabled" do @@ -171,8 +170,8 @@ describe Chef::Provider::Service::Windows, "load_current_resource", :windows_onl tag_id: 0, dependencies: %w{NSI Tdx Afd}, service_start_name: 'NT Authority\\LocalService', - display_name: "DHCP Client" - )) + display_name: "DHCP Client") + ) end it "does not set the current resources enabled" do @@ -357,14 +356,14 @@ describe Chef::Provider::Service::Windows, "load_current_resource", :windows_onl # properties that are Strings %i{binary_path_name load_order_group dependencies run_as_user display_name description}.each do |attr| - it "configures service if #{attr} has changed" do - provider.current_resource.send("#{attr}=", "old value") - provider.new_resource.send("#{attr}=", "new value") + it "configures service if #{attr} has changed" do + provider.current_resource.send("#{attr}=", "old value") + provider.new_resource.send("#{attr}=", "new value") - expect(Win32::Service).to receive(:configure) - provider.action_configure - end - end + expect(Win32::Service).to receive(:configure) + provider.action_configure + end + end # properties that are Integers %i{service_type error_control}.each do |attr| @@ -473,7 +472,8 @@ describe Chef::Provider::Service::Windows, "load_current_resource", :windows_onl before(:each) do allow(Win32::Service).to receive(:status).with(new_resource.service_name).and_return( double("StatusStruct", current_state: "stopped"), - double("StatusStruct", current_state: "running")) + double("StatusStruct", current_state: "running") + ) end context "run_as_user user is specified" do @@ -555,7 +555,8 @@ describe Chef::Provider::Service::Windows, "load_current_resource", :windows_onl it "does nothing if the service is running" do allow(Win32::Service).to receive(:status).with(new_resource.service_name).and_return( - double("StatusStruct", current_state: "running")) + double("StatusStruct", current_state: "running") + ) provider.load_current_resource expect(Win32::Service).not_to receive(:start).with(new_resource.service_name) provider.start_service @@ -565,7 +566,8 @@ describe Chef::Provider::Service::Windows, "load_current_resource", :windows_onl context "service is paused" do before do allow(Win32::Service).to receive(:status).with(new_resource.service_name).and_return( - double("StatusStruct", current_state: "paused")) + double("StatusStruct", current_state: "paused") + ) provider.load_current_resource end @@ -590,7 +592,8 @@ describe Chef::Provider::Service::Windows, "load_current_resource", :windows_onl allow(Win32::Service).to receive(:status).with(new_resource.service_name).and_return( double("StatusStruct", current_state: "start pending"), double("StatusStruct", current_state: "start pending"), - double("StatusStruct", current_state: "running")) + double("StatusStruct", current_state: "running") + ) provider.load_current_resource end @@ -614,7 +617,8 @@ describe Chef::Provider::Service::Windows, "load_current_resource", :windows_onl context "service is in stop_pending" do before do allow(Win32::Service).to receive(:status).with(new_resource.service_name).and_return( - double("StatusStruct", current_state: "stop pending")) + double("StatusStruct", current_state: "stop pending") + ) provider.load_current_resource end @@ -665,7 +669,8 @@ describe Chef::Provider::Service::Windows, "load_current_resource", :windows_onl before(:each) do allow(Win32::Service).to receive(:status).with(new_resource.service_name).and_return( double("StatusStruct", current_state: "running"), - double("StatusStruct", current_state: "stopped")) + double("StatusStruct", current_state: "stopped") + ) end it "calls the stop command if one is specified" do @@ -690,7 +695,8 @@ describe Chef::Provider::Service::Windows, "load_current_resource", :windows_onl it "does nothing if the service is stopped" do allow(Win32::Service).to receive(:status).with(new_resource.service_name).and_return( - double("StatusStruct", current_state: "stopped")) + double("StatusStruct", current_state: "stopped") + ) provider.load_current_resource expect(Win32::Service).not_to receive(:stop).with(new_resource.service_name) provider.stop_service @@ -699,7 +705,8 @@ describe Chef::Provider::Service::Windows, "load_current_resource", :windows_onl it "raises an error if the service is paused" do allow(Win32::Service).to receive(:status).with(new_resource.service_name).and_return( - double("StatusStruct", current_state: "paused")) + double("StatusStruct", current_state: "paused") + ) provider.load_current_resource expect(Win32::Service).not_to receive(:start).with(new_resource.service_name) expect { provider.stop_service }.to raise_error( Chef::Exceptions::Service ) @@ -710,7 +717,8 @@ describe Chef::Provider::Service::Windows, "load_current_resource", :windows_onl allow(Win32::Service).to receive(:status).with(new_resource.service_name).and_return( double("StatusStruct", current_state: "stop pending"), double("StatusStruct", current_state: "stop pending"), - double("StatusStruct", current_state: "stopped")) + double("StatusStruct", current_state: "stopped") + ) provider.load_current_resource expect(Win32::Service).not_to receive(:stop).with(new_resource.service_name) provider.stop_service @@ -719,7 +727,8 @@ describe Chef::Provider::Service::Windows, "load_current_resource", :windows_onl it "fails if the service is in start_pending" do allow(Win32::Service).to receive(:status).with(new_resource.service_name).and_return( - double("StatusStruct", current_state: "start pending")) + double("StatusStruct", current_state: "start pending") + ) provider.load_current_resource expect(Win32::Service).not_to receive(:stop).with(new_resource.service_name) expect { provider.stop_service }.to raise_error( Chef::Exceptions::Service ) @@ -728,7 +737,8 @@ describe Chef::Provider::Service::Windows, "load_current_resource", :windows_onl it "passes custom timeout to the stop command if provided" do allow(Win32::Service).to receive(:status).with(new_resource.service_name).and_return( - double("StatusStruct", current_state: "running")) + double("StatusStruct", current_state: "running") + ) new_resource.timeout 1 expect(Win32::Service).to receive(:stop).with(new_resource.service_name) Timeout.timeout(2) do @@ -753,7 +763,8 @@ describe Chef::Provider::Service::Windows, "load_current_resource", :windows_onl double("StatusStruct", current_state: "running"), double("StatusStruct", current_state: "stopped"), double("StatusStruct", current_state: "stopped"), - double("StatusStruct", current_state: "running")) + double("StatusStruct", current_state: "running") + ) expect(Win32::Service).to receive(:stop).with(new_resource.service_name) expect(Win32::Service).to receive(:start).with(new_resource.service_name) provider.restart_service @@ -764,7 +775,8 @@ describe Chef::Provider::Service::Windows, "load_current_resource", :windows_onl allow(Win32::Service).to receive(:status).with(new_resource.service_name).and_return( double("StatusStruct", current_state: "stopped"), double("StatusStruct", current_state: "stopped"), - double("StatusStruct", current_state: "running")) + double("StatusStruct", current_state: "running") + ) expect(Win32::Service).to receive(:start).with(new_resource.service_name) provider.restart_service expect(new_resource).to be_updated_by_last_action @@ -783,7 +795,8 @@ describe Chef::Provider::Service::Windows, "load_current_resource", :windows_onl describe Chef::Provider::Service::Windows, "enable_service" do before(:each) do allow(Win32::Service).to receive(:config_info).with(new_resource.service_name).and_return( - double("ConfigStruct", start_type: "disabled")) + double("ConfigStruct", start_type: "disabled") + ) end it "enables service" do @@ -803,14 +816,16 @@ describe Chef::Provider::Service::Windows, "load_current_resource", :windows_onl describe Chef::Provider::Service::Windows, "action_enable" do it "does nothing if the service is enabled" do allow(Win32::Service).to receive(:config_info).with(new_resource.service_name).and_return( - double("ConfigStruct", start_type: "auto start")) + double("ConfigStruct", start_type: "auto start") + ) expect(provider).not_to receive(:enable_service) provider.action_enable end it "enables the service if it is not set to automatic start" do allow(Win32::Service).to receive(:config_info).with(new_resource.service_name).and_return( - double("ConfigStruct", start_type: "disabled")) + double("ConfigStruct", start_type: "disabled") + ) expect(provider).to receive(:enable_service) provider.action_enable end @@ -819,14 +834,16 @@ describe Chef::Provider::Service::Windows, "load_current_resource", :windows_onl describe Chef::Provider::Service::Windows, "action_disable" do it "does nothing if the service is disabled" do allow(Win32::Service).to receive(:config_info).with(new_resource.service_name).and_return( - double("ConfigStruct", start_type: "disabled")) + double("ConfigStruct", start_type: "disabled") + ) expect(provider).not_to receive(:disable_service) provider.action_disable end it "disables the service if it is not set to disabled" do allow(Win32::Service).to receive(:config_info).with(new_resource.service_name).and_return( - double("ConfigStruct", start_type: "auto start")) + double("ConfigStruct", start_type: "auto start") + ) expect(provider).to receive(:disable_service) provider.action_disable end @@ -835,7 +852,8 @@ describe Chef::Provider::Service::Windows, "load_current_resource", :windows_onl describe Chef::Provider::Service::Windows, "disable_service" do before(:each) do allow(Win32::Service).to receive(:config_info).with(new_resource.service_name).and_return( - double("ConfigStruct", start_type: "auto start")) + double("ConfigStruct", start_type: "auto start") + ) end it "disables service" do diff --git a/spec/unit/provider/subversion_spec.rb b/spec/unit/provider/subversion_spec.rb index d3c5073b7e..a70b7cd48b 100644 --- a/spec/unit/provider/subversion_spec.rb +++ b/spec/unit/provider/subversion_spec.rb @@ -277,7 +277,8 @@ describe Chef::Provider::Subversion do allow(ChefConfig).to receive(:windows?) { false } expect(@provider).to receive(:svn_binary).and_return("svn") expect(@provider.export_command).to eql( - "svn export --force -q -r12345 http://svn.example.org/trunk/ /my/deploy/dir") + "svn export --force -q -r12345 http://svn.example.org/trunk/ /my/deploy/dir" + ) end it "selects an svn binary with an exe extension on windows" do @@ -285,21 +286,24 @@ describe Chef::Provider::Subversion do allow(ChefConfig).to receive(:windows?) { true } expect(@provider).to receive(:svn_binary).and_return("svn.exe") expect(@provider.export_command).to eql( - "svn.exe export --force -q -r12345 http://svn.example.org/trunk/ /my/deploy/dir") + "svn.exe export --force -q -r12345 http://svn.example.org/trunk/ /my/deploy/dir" + ) end it "uses a custom svn binary as part of the svn command" do @resource.svn_binary "teapot" expect(@provider).to receive(:svn_binary).and_return("teapot") expect(@provider.export_command).to eql( - "teapot export --force -q -r12345 http://svn.example.org/trunk/ /my/deploy/dir") + "teapot export --force -q -r12345 http://svn.example.org/trunk/ /my/deploy/dir" + ) end it "wraps custom svn binary with quotes if it contains whitespace" do @resource.svn_binary "c:/program files (x86)/subversion/svn.exe" expect(@provider).to receive(:svn_binary).and_return("c:/program files (x86)/subversion/svn.exe") expect(@provider.export_command).to eql( - '"c:/program files (x86)/subversion/svn.exe" export --force -q -r12345 http://svn.example.org/trunk/ /my/deploy/dir') + '"c:/program files (x86)/subversion/svn.exe" export --force -q -r12345 http://svn.example.org/trunk/ /my/deploy/dir' + ) end end diff --git a/spec/unit/provider/systemd_unit_spec.rb b/spec/unit/provider/systemd_unit_spec.rb index 00f39d0fd9..899d3dc87e 100644 --- a/spec/unit/provider/systemd_unit_spec.rb +++ b/spec/unit/provider/systemd_unit_spec.rb @@ -75,8 +75,8 @@ describe Chef::Provider::SystemdUnit do before(:each) do allow(Etc).to receive(:getpwnam).and_return(OpenStruct.new(uid: 1000)) allow(Chef::Resource::SystemdUnit).to receive(:new) - .with(unit_name) - .and_return(current_resource) + .with(unit_name) + .and_return(current_resource) end describe "define_resource_requirements" do @@ -113,8 +113,8 @@ describe Chef::Provider::SystemdUnit do it "should create a current resource with the name of the new resource" do expect(Chef::Resource::SystemdUnit).to receive(:new) - .with(unit_name) - .and_return(current_resource) + .with(unit_name) + .and_return(current_resource) provider.load_current_resource end @@ -188,26 +188,26 @@ describe Chef::Provider::SystemdUnit do it "loads the system unit content if the file exists and user is not set" do allow(File).to receive(:exist?) - .with(unit_path_system) - .and_return(true) + .with(unit_path_system) + .and_return(true) allow(File).to receive(:read) - .with(unit_path_system) - .and_return(unit_content_string) + .with(unit_path_system) + .and_return(unit_content_string) expect(File).to receive(:exist?) - .with(unit_path_system) + .with(unit_path_system) expect(File).to receive(:read) - .with(unit_path_system) + .with(unit_path_system) provider.load_current_resource expect(current_resource.content).to eq(unit_content_string) end it "does not load the system unit content if the unit file is not present and the user is not set" do allow(File).to receive(:exist?) - .with(unit_path_system) - .and_return(false) + .with(unit_path_system) + .and_return(false) expect(File).to_not receive(:read) - .with(unit_path_system) + .with(unit_path_system) provider.load_current_resource expect(current_resource.content).to eq(nil) end @@ -215,15 +215,15 @@ describe Chef::Provider::SystemdUnit do it "loads the user unit content if the file exists and user is set" do new_resource.user("joe") allow(File).to receive(:exist?) - .with(unit_path_user) - .and_return(true) + .with(unit_path_user) + .and_return(true) allow(File).to receive(:read) - .with(unit_path_user) - .and_return(unit_content_string) + .with(unit_path_user) + .and_return(unit_content_string) expect(File).to receive(:exist?) - .with(unit_path_user) + .with(unit_path_user) expect(File).to receive(:read) - .with(unit_path_user) + .with(unit_path_user) provider.load_current_resource expect(current_resource.content).to eq(unit_content_string) end @@ -231,10 +231,10 @@ describe Chef::Provider::SystemdUnit do it "does not load the user unit if the file does not exist and user is set" do new_resource.user("joe") allow(File).to receive(:exist?) - .with(unit_path_user) - .and_return(false) + .with(unit_path_user) + .and_return(false) expect(File).to_not receive(:read) - .with(unit_path_user) + .with(unit_path_user) provider.load_current_resource expect(current_resource.content).to eq(nil) end @@ -245,27 +245,27 @@ describe Chef::Provider::SystemdUnit do before(:each) do provider.current_resource = current_resource allow(provider).to receive(:which) - .with("systemctl") - .and_return(systemctl_path) + .with("systemctl") + .and_return(systemctl_path) end describe "creates/deletes/presets/reverts the unit" do it "creates the unit file when it does not exist" do allow(provider).to receive(:manage_unit_file) - .with(:create) - .and_return(true) + .with(:create) + .and_return(true) allow(provider).to receive(:daemon_reload) - .and_return(true) + .and_return(true) expect(provider).to receive(:manage_unit_file).with(:create) provider.action_create end it "creates the file when the unit content is different" do allow(provider).to receive(:manage_unit_file) - .with(:create) - .and_return(true) + .with(:create) + .and_return(true) allow(provider).to receive(:daemon_reload) - .and_return(true) + .and_return(true) expect(provider).to receive(:manage_unit_file).with(:create) provider.action_create end @@ -274,7 +274,7 @@ describe Chef::Provider::SystemdUnit do current_resource.content(unit_content_string) allow(provider).to receive(:manage_unit_file).with(:create) allow(provider).to receive(:daemon_reload) - .and_return(true) + .and_return(true) expect(provider).to_not receive(:manage_unit_file) provider.action_create end @@ -286,20 +286,20 @@ describe Chef::Provider::SystemdUnit do expect(new_resource.triggers_reload).to eq true allow(provider).to receive(:shell_out_compacted!) expect(provider).to receive(:shell_out_compacted!) - .with(systemctl_path, "--user", "daemon-reload", **user_cmd_opts, default_env: false) + .with(systemctl_path, "--user", "daemon-reload", **user_cmd_opts, default_env: false) provider.action_create end it "triggers a daemon-reload when deleting a unit with triggers_reload" do new_resource.user("joe") allow(File).to receive(:exist?) - .with(unit_path_user) - .and_return(true) + .with(unit_path_user) + .and_return(true) allow(provider).to receive(:manage_unit_file).with(:delete) expect(new_resource.triggers_reload).to eq true allow(provider).to receive(:shell_out_compacted!) expect(provider).to receive(:shell_out_compacted!) - .with(systemctl_path, "--user", "daemon-reload", **user_cmd_opts, default_env: false) + .with(systemctl_path, "--user", "daemon-reload", **user_cmd_opts, default_env: false) provider.action_delete end @@ -309,7 +309,7 @@ describe Chef::Provider::SystemdUnit do allow(provider).to receive(:manage_unit_file).with(:create) allow(provider).to receive(:shell_out_compacted!) expect(provider).to_not receive(:shell_out_compacted!) - .with(systemctl_path, "--user", "daemon-reload", **user_cmd_opts, default_env: false) + .with(systemctl_path, "--user", "daemon-reload", **user_cmd_opts, default_env: false) provider.action_create end @@ -317,23 +317,23 @@ describe Chef::Provider::SystemdUnit do new_resource.user("joe") new_resource.triggers_reload(false) allow(File).to receive(:exist?) - .with(unit_path_user) - .and_return(true) + .with(unit_path_user) + .and_return(true) allow(provider).to receive(:manage_unit_file).with(:delete) allow(provider).to receive(:shell_out_compacted!) expect(provider).to_not receive(:shell_out_compacted!) - .with(systemctl_path, "--user", "daemon-reload", **user_cmd_opts, default_env: false) + .with(systemctl_path, "--user", "daemon-reload", **user_cmd_opts, default_env: false) provider.action_delete end it "deletes the file when it exists" do new_resource.user("joe") allow(File).to receive(:exist?) - .with(unit_path_user) - .and_return(true) + .with(unit_path_user) + .and_return(true) allow(provider).to receive(:manage_unit_file) - .with(:delete) - .and_return(true) + .with(:delete) + .and_return(true) allow(provider).to receive(:daemon_reload) expect(provider).to receive(:manage_unit_file).with(:delete) provider.action_delete @@ -342,8 +342,8 @@ describe Chef::Provider::SystemdUnit do it "does not delete the file when it is absent" do new_resource.user("joe") allow(File).to receive(:exist?) - .with(unit_path_user) - .and_return(false) + .with(unit_path_user) + .and_return(false) allow(provider).to receive(:manage_unit_file).with(:delete) expect(provider).to_not receive(:manage_unit_file) provider.action_delete @@ -352,16 +352,16 @@ describe Chef::Provider::SystemdUnit do it "presets the unit" do new_resource.user("joe") expect(provider).to receive(:shell_out_compacted!) - .with(systemctl_path, "--user", "preset", unit_name, **user_cmd_opts) - .and_return(shell_out_success) + .with(systemctl_path, "--user", "preset", unit_name, **user_cmd_opts) + .and_return(shell_out_success) provider.action_preset end it "reverts the unit" do new_resource.user("joe") expect(provider).to receive(:shell_out_compacted!) - .with(systemctl_path, "--user", "revert", unit_name, **user_cmd_opts) - .and_return(shell_out_success) + .with(systemctl_path, "--user", "revert", unit_name, **user_cmd_opts) + .and_return(shell_out_success) provider.action_revert end end @@ -372,19 +372,19 @@ describe Chef::Provider::SystemdUnit do expect(new_resource.triggers_reload).to eq true allow(provider).to receive(:shell_out_compacted!) expect(provider).to receive(:shell_out_compacted!) - .with(systemctl_path, "--system", "daemon-reload", default_env: false) + .with(systemctl_path, "--system", "daemon-reload", default_env: false) provider.action_create end it "triggers a daemon-reload when deleting a unit with triggers_reload" do allow(File).to receive(:exist?) - .with(unit_path_system) - .and_return(true) + .with(unit_path_system) + .and_return(true) allow(provider).to receive(:manage_unit_file).with(:delete) expect(new_resource.triggers_reload).to eq true allow(provider).to receive(:shell_out_compacted!) expect(provider).to receive(:shell_out_compacted!) - .with(systemctl_path, "--system", "daemon-reload", default_env: false) + .with(systemctl_path, "--system", "daemon-reload", default_env: false) provider.action_delete end @@ -393,27 +393,27 @@ describe Chef::Provider::SystemdUnit do allow(provider).to receive(:manage_unit_file).with(:create) allow(provider).to receive(:shell_out_compacted!) expect(provider).to_not receive(:shell_out_compacted!) - .with(systemctl_path, "--system", "daemon-reload", default_env: false) + .with(systemctl_path, "--system", "daemon-reload", default_env: false) provider.action_create end it "does not trigger a daemon-reload when deleting a unit without triggers_reload" do new_resource.triggers_reload(false) allow(File).to receive(:exist?) - .with(unit_path_system) - .and_return(true) + .with(unit_path_system) + .and_return(true) allow(provider).to receive(:manage_unit_file).with(:delete) allow(provider).to receive(:shell_out_compacted!) expect(provider).to_not receive(:shell_out_compacted!) - .with(systemctl_path, "--system", "daemon-reload", default_env: false) + .with(systemctl_path, "--system", "daemon-reload", default_env: false) provider.action_delete end it "deletes the file when it exists" do allow(File).to receive(:exist?) - .with(unit_path_system) - .and_return(true) + .with(unit_path_system) + .and_return(true) allow(provider).to receive(:manage_unit_file) - .with(:delete) + .with(:delete) allow(provider).to receive(:daemon_reload) expect(provider).to receive(:manage_unit_file).with(:delete) provider.action_delete @@ -421,8 +421,8 @@ describe Chef::Provider::SystemdUnit do it "does not delete the file when it is absent" do allow(File).to receive(:exist?) - .with(unit_path_system) - .and_return(false) + .with(unit_path_system) + .and_return(false) allow(provider).to receive(:manage_unit_file).with(:delete) allow(provider).to receive(:daemon_reload) expect(provider).to_not receive(:manage_unit_file) @@ -431,15 +431,15 @@ describe Chef::Provider::SystemdUnit do it "presets the unit" do expect(provider).to receive(:shell_out_compacted!) - .with(systemctl_path, "--system", "preset", unit_name) - .and_return(shell_out_success) + .with(systemctl_path, "--system", "preset", unit_name) + .and_return(shell_out_success) provider.action_preset end it "reverts the unit" do expect(provider).to receive(:shell_out_compacted!) - .with(systemctl_path, "--system", "revert", unit_name) - .and_return(shell_out_success) + .with(systemctl_path, "--system", "revert", unit_name) + .and_return(shell_out_success) provider.action_revert end end @@ -450,8 +450,8 @@ describe Chef::Provider::SystemdUnit do it "reenables the unit" do current_resource.user(user_name) expect(provider).to receive(:shell_out_compacted!) - .with(systemctl_path, "--user", "reenable", unit_name, **user_cmd_opts) - .and_return(shell_out_success) + .with(systemctl_path, "--user", "reenable", unit_name, **user_cmd_opts) + .and_return(shell_out_success) provider.action_reenable end @@ -459,8 +459,8 @@ describe Chef::Provider::SystemdUnit do current_resource.user(user_name) current_resource.enabled(false) expect(provider).to receive(:shell_out_compacted!) - .with(systemctl_path, "--user", "enable", unit_name, **user_cmd_opts) - .and_return(shell_out_success) + .with(systemctl_path, "--user", "enable", unit_name, **user_cmd_opts) + .and_return(shell_out_success) provider.action_enable end @@ -482,8 +482,8 @@ describe Chef::Provider::SystemdUnit do current_resource.user(user_name) current_resource.enabled(true) expect(provider).to receive(:shell_out_compacted!) - .with(systemctl_path, "--user", "disable", unit_name, **user_cmd_opts) - .and_return(shell_out_success) + .with(systemctl_path, "--user", "disable", unit_name, **user_cmd_opts) + .and_return(shell_out_success) provider.action_disable end @@ -505,16 +505,16 @@ describe Chef::Provider::SystemdUnit do context "when no user is specified" do it "reenables the unit" do expect(provider).to receive(:shell_out_compacted!) - .with(systemctl_path, "--system", "reenable", unit_name) - .and_return(shell_out_success) + .with(systemctl_path, "--system", "reenable", unit_name) + .and_return(shell_out_success) provider.action_reenable end it "enables the unit when it is disabled" do current_resource.enabled(false) expect(provider).to receive(:shell_out_compacted!) - .with(systemctl_path, "--system", "enable", unit_name) - .and_return(shell_out_success) + .with(systemctl_path, "--system", "enable", unit_name) + .and_return(shell_out_success) provider.action_enable end @@ -533,8 +533,8 @@ describe Chef::Provider::SystemdUnit do it "disables the unit when it is enabled" do current_resource.enabled(true) expect(provider).to receive(:shell_out_compacted!) - .with(systemctl_path, "--system", "disable", unit_name) - .and_return(shell_out_success) + .with(systemctl_path, "--system", "disable", unit_name) + .and_return(shell_out_success) provider.action_disable end @@ -559,8 +559,8 @@ describe Chef::Provider::SystemdUnit do current_resource.user(user_name) current_resource.masked(false) expect(provider).to receive(:shell_out_compacted!) - .with(systemctl_path, "--user", "mask", unit_name, **user_cmd_opts) - .and_return(shell_out_success) + .with(systemctl_path, "--user", "mask", unit_name, **user_cmd_opts) + .and_return(shell_out_success) provider.action_mask end @@ -575,8 +575,8 @@ describe Chef::Provider::SystemdUnit do current_resource.user(user_name) current_resource.masked(true) expect(provider).to receive(:shell_out_compacted!) - .with(systemctl_path, "--user", "unmask", unit_name, **user_cmd_opts) - .and_return(shell_out_success) + .with(systemctl_path, "--user", "unmask", unit_name, **user_cmd_opts) + .and_return(shell_out_success) provider.action_unmask end @@ -592,8 +592,8 @@ describe Chef::Provider::SystemdUnit do it "masks the unit when it is unmasked" do current_resource.masked(false) expect(provider).to receive(:shell_out_compacted!) - .with(systemctl_path, "--system", "mask", unit_name) - .and_return(shell_out_success) + .with(systemctl_path, "--system", "mask", unit_name) + .and_return(shell_out_success) provider.action_mask end @@ -606,8 +606,8 @@ describe Chef::Provider::SystemdUnit do it "unmasks the unit when it is masked" do current_resource.masked(true) expect(provider).to receive(:shell_out_compacted!) - .with(systemctl_path, "--system", "unmask", unit_name) - .and_return(shell_out_success) + .with(systemctl_path, "--system", "unmask", unit_name) + .and_return(shell_out_success) provider.action_unmask end @@ -625,8 +625,8 @@ describe Chef::Provider::SystemdUnit do current_resource.user(user_name) current_resource.active(false) expect(provider).to receive(:shell_out_compacted!) - .with(systemctl_path, "--user", "start", unit_name, **user_cmd_opts, default_env: false) - .and_return(shell_out_success) + .with(systemctl_path, "--user", "start", unit_name, **user_cmd_opts, default_env: false) + .and_return(shell_out_success) provider.action_start end @@ -641,8 +641,8 @@ describe Chef::Provider::SystemdUnit do current_resource.user(user_name) current_resource.active(true) expect(provider).to receive(:shell_out_compacted!) - .with(systemctl_path, "--user", "stop", unit_name, **user_cmd_opts, default_env: false) - .and_return(shell_out_success) + .with(systemctl_path, "--user", "stop", unit_name, **user_cmd_opts, default_env: false) + .and_return(shell_out_success) provider.action_stop end @@ -658,8 +658,8 @@ describe Chef::Provider::SystemdUnit do it "starts the unit when it is inactive" do current_resource.active(false) expect(provider).to receive(:shell_out_compacted!) - .with(systemctl_path, "--system", "start", unit_name, default_env: false) - .and_return(shell_out_success) + .with(systemctl_path, "--system", "start", unit_name, default_env: false) + .and_return(shell_out_success) provider.action_start end @@ -672,8 +672,8 @@ describe Chef::Provider::SystemdUnit do it "stops the unit when it is active" do current_resource.active(true) expect(provider).to receive(:shell_out_compacted!) - .with(systemctl_path, "--system", "stop", unit_name, default_env: false) - .and_return(shell_out_success) + .with(systemctl_path, "--system", "stop", unit_name, default_env: false) + .and_return(shell_out_success) provider.action_stop end @@ -690,8 +690,8 @@ describe Chef::Provider::SystemdUnit do it "restarts the unit" do current_resource.user(user_name) expect(provider).to receive(:shell_out_compacted!) - .with(systemctl_path, "--user", "restart", unit_name, **user_cmd_opts, default_env: false) - .and_return(shell_out_success) + .with(systemctl_path, "--user", "restart", unit_name, **user_cmd_opts, default_env: false) + .and_return(shell_out_success) provider.action_restart end @@ -699,8 +699,8 @@ describe Chef::Provider::SystemdUnit do current_resource.user(user_name) current_resource.active(true) expect(provider).to receive(:shell_out_compacted!) - .with(systemctl_path, "--user", "reload", unit_name, **user_cmd_opts, default_env: false) - .and_return(shell_out_success) + .with(systemctl_path, "--user", "reload", unit_name, **user_cmd_opts, default_env: false) + .and_return(shell_out_success) provider.action_reload end @@ -715,16 +715,16 @@ describe Chef::Provider::SystemdUnit do context "when no user is specified" do it "restarts the unit" do expect(provider).to receive(:shell_out_compacted!) - .with(systemctl_path, "--system", "restart", unit_name, default_env: false) - .and_return(shell_out_success) + .with(systemctl_path, "--system", "restart", unit_name, default_env: false) + .and_return(shell_out_success) provider.action_restart end it "reloads the unit if active" do current_resource.active(true) expect(provider).to receive(:shell_out_compacted!) - .with(systemctl_path, "--system", "reload", unit_name, default_env: false) - .and_return(shell_out_success) + .with(systemctl_path, "--system", "reload", unit_name, default_env: false) + .and_return(shell_out_success) provider.action_reload end @@ -741,8 +741,8 @@ describe Chef::Provider::SystemdUnit do it "try-restarts the unit" do current_resource.user(user_name) expect(provider).to receive(:shell_out_compacted!) - .with(systemctl_path, "--user", "try-restart", unit_name, **user_cmd_opts, default_env: false) - .and_return(shell_out_success) + .with(systemctl_path, "--user", "try-restart", unit_name, **user_cmd_opts, default_env: false) + .and_return(shell_out_success) provider.action_try_restart end end @@ -750,8 +750,8 @@ describe Chef::Provider::SystemdUnit do context "when no user is specified" do it "try-restarts the unit" do expect(provider).to receive(:shell_out_compacted!) - .with(systemctl_path, "--system", "try-restart", unit_name, default_env: false) - .and_return(shell_out_success) + .with(systemctl_path, "--system", "try-restart", unit_name, default_env: false) + .and_return(shell_out_success) provider.action_try_restart end end @@ -762,8 +762,8 @@ describe Chef::Provider::SystemdUnit do it "reload-or-restarts the unit" do current_resource.user(user_name) expect(provider).to receive(:shell_out_compacted!) - .with(systemctl_path, "--user", "reload-or-restart", unit_name, **user_cmd_opts, default_env: false) - .and_return(shell_out_success) + .with(systemctl_path, "--user", "reload-or-restart", unit_name, **user_cmd_opts, default_env: false) + .and_return(shell_out_success) provider.action_reload_or_restart end end @@ -771,8 +771,8 @@ describe Chef::Provider::SystemdUnit do context "when no user is specified" do it "reload-or-restarts the unit" do expect(provider).to receive(:shell_out_compacted!) - .with(systemctl_path, "--system", "reload-or-restart", unit_name, default_env: false) - .and_return(shell_out_success) + .with(systemctl_path, "--system", "reload-or-restart", unit_name, default_env: false) + .and_return(shell_out_success) provider.action_reload_or_restart end end @@ -783,8 +783,8 @@ describe Chef::Provider::SystemdUnit do it "reload-or-try-restarts the unit" do current_resource.user(user_name) expect(provider).to receive(:shell_out_compacted!) - .with(systemctl_path, "--user", "reload-or-try-restart", unit_name, **user_cmd_opts, default_env: false) - .and_return(shell_out_success) + .with(systemctl_path, "--user", "reload-or-try-restart", unit_name, **user_cmd_opts, default_env: false) + .and_return(shell_out_success) provider.action_reload_or_try_restart end end @@ -792,8 +792,8 @@ describe Chef::Provider::SystemdUnit do context "when no user is specified" do it "reload-or-try-restarts the unit" do expect(provider).to receive(:shell_out_compacted!) - .with(systemctl_path, "--system", "reload-or-try-restart", unit_name, default_env: false) - .and_return(shell_out_success) + .with(systemctl_path, "--system", "reload-or-try-restart", unit_name, default_env: false) + .and_return(shell_out_success) provider.action_reload_or_try_restart end end @@ -809,16 +809,16 @@ describe Chef::Provider::SystemdUnit do it "returns true when unit is active" do current_resource.user(user_name) expect(provider).to receive(:shell_out_compacted) - .with(systemctl_path, "--user", "is-active", unit_name, user_cmd_opts) - .and_return(shell_out_success) + .with(systemctl_path, "--user", "is-active", unit_name, user_cmd_opts) + .and_return(shell_out_success) expect(provider.active?).to be true end it "returns false when unit is inactive" do current_resource.user(user_name) expect(provider).to receive(:shell_out_compacted) - .with(systemctl_path, "--user", "is-active", unit_name, user_cmd_opts) - .and_return(shell_out_failure) + .with(systemctl_path, "--user", "is-active", unit_name, user_cmd_opts) + .and_return(shell_out_failure) expect(provider.active?).to be false end end @@ -826,15 +826,15 @@ describe Chef::Provider::SystemdUnit do context "when no user is specified" do it "returns true when unit is active" do expect(provider).to receive(:shell_out_compacted) - .with(systemctl_path, "--system", "is-active", unit_name) - .and_return(shell_out_success) + .with(systemctl_path, "--system", "is-active", unit_name) + .and_return(shell_out_success) expect(provider.active?).to be true end it "returns false when unit is not active" do expect(provider).to receive(:shell_out_compacted) - .with(systemctl_path, "--system", "is-active", unit_name) - .and_return(shell_out_failure) + .with(systemctl_path, "--system", "is-active", unit_name) + .and_return(shell_out_failure) expect(provider.active?).to be false end end @@ -850,16 +850,16 @@ describe Chef::Provider::SystemdUnit do it "returns true when unit is enabled" do current_resource.user(user_name) expect(provider).to receive(:shell_out_compacted) - .with(systemctl_path, "--user", "is-enabled", unit_name, user_cmd_opts) - .and_return(shell_out_success) + .with(systemctl_path, "--user", "is-enabled", unit_name, user_cmd_opts) + .and_return(shell_out_success) expect(provider.enabled?).to be true end it "returns false when unit is not enabled" do current_resource.user(user_name) expect(provider).to receive(:shell_out_compacted) - .with(systemctl_path, "--user", "is-enabled", unit_name, user_cmd_opts) - .and_return(shell_out_failure) + .with(systemctl_path, "--user", "is-enabled", unit_name, user_cmd_opts) + .and_return(shell_out_failure) expect(provider.enabled?).to be false end end @@ -867,15 +867,15 @@ describe Chef::Provider::SystemdUnit do context "when no user is specified" do it "returns true when unit is enabled" do expect(provider).to receive(:shell_out_compacted) - .with(systemctl_path, "--system", "is-enabled", unit_name) - .and_return(shell_out_success) + .with(systemctl_path, "--system", "is-enabled", unit_name) + .and_return(shell_out_success) expect(provider.enabled?).to be true end it "returns false when unit is not enabled" do expect(provider).to receive(:shell_out_compacted) - .with(systemctl_path, "--system", "is-enabled", unit_name) - .and_return(shell_out_failure) + .with(systemctl_path, "--system", "is-enabled", unit_name) + .and_return(shell_out_failure) expect(provider.enabled?).to be false end end @@ -891,16 +891,16 @@ describe Chef::Provider::SystemdUnit do it "returns true when the unit is masked" do current_resource.user(user_name) expect(provider).to receive(:shell_out_compacted) - .with(systemctl_path, "--user", "status", unit_name, user_cmd_opts) - .and_return(shell_out_masked) + .with(systemctl_path, "--user", "status", unit_name, user_cmd_opts) + .and_return(shell_out_masked) expect(provider.masked?).to be true end it "returns false when the unit is not masked" do current_resource.user(user_name) expect(provider).to receive(:shell_out_compacted) - .with(systemctl_path, "--user", "status", unit_name, user_cmd_opts) - .and_return(shell_out_static) + .with(systemctl_path, "--user", "status", unit_name, user_cmd_opts) + .and_return(shell_out_static) expect(provider.masked?).to be false end end @@ -908,15 +908,15 @@ describe Chef::Provider::SystemdUnit do context "when no user is specified" do it "returns true when the unit is masked" do expect(provider).to receive(:shell_out_compacted) - .with(systemctl_path, "--system", "status", unit_name) - .and_return(shell_out_masked) + .with(systemctl_path, "--system", "status", unit_name) + .and_return(shell_out_masked) expect(provider.masked?).to be true end it "returns false when the unit is not masked" do expect(provider).to receive(:shell_out_compacted) - .with(systemctl_path, "--system", "status", unit_name) - .and_return(shell_out_static) + .with(systemctl_path, "--system", "status", unit_name) + .and_return(shell_out_static) expect(provider.masked?).to be false end end @@ -932,16 +932,16 @@ describe Chef::Provider::SystemdUnit do it "returns true when the unit is static" do current_resource.user(user_name) expect(provider).to receive(:shell_out_compacted) - .with(systemctl_path, "--user", "is-enabled", unit_name, user_cmd_opts) - .and_return(shell_out_static) + .with(systemctl_path, "--user", "is-enabled", unit_name, user_cmd_opts) + .and_return(shell_out_static) expect(provider.static?).to be true end it "returns false when the unit is not static" do current_resource.user(user_name) expect(provider).to receive(:shell_out_compacted) - .with(systemctl_path, "--user", "is-enabled", unit_name, user_cmd_opts) - .and_return(shell_out_masked) + .with(systemctl_path, "--user", "is-enabled", unit_name, user_cmd_opts) + .and_return(shell_out_masked) expect(provider.static?).to be false end end @@ -949,15 +949,15 @@ describe Chef::Provider::SystemdUnit do context "when no user is specified" do it "returns true when the unit is static" do expect(provider).to receive(:shell_out_compacted) - .with(systemctl_path, "--system", "is-enabled", unit_name) - .and_return(shell_out_static) + .with(systemctl_path, "--system", "is-enabled", unit_name) + .and_return(shell_out_static) expect(provider.static?).to be true end it "returns false when the unit is not static" do expect(provider).to receive(:shell_out_compacted) - .with(systemctl_path, "--system", "is-enabled", unit_name) - .and_return(shell_out_masked) + .with(systemctl_path, "--system", "is-enabled", unit_name) + .and_return(shell_out_masked) expect(provider.static?).to be false end end diff --git a/spec/unit/provider/windows_task_spec.rb b/spec/unit/provider/windows_task_spec.rb index 8cce861f2a..74e1dc1de7 100644 --- a/spec/unit/provider/windows_task_spec.rb +++ b/spec/unit/provider/windows_task_spec.rb @@ -20,7 +20,7 @@ require "spec_helper" describe Chef::Provider::WindowsTask, :windows_only do let(:new_resource) { Chef::Resource::WindowsTask.new("sample_task") } - let(:current_resource) { Chef::Resource::WindowsTask.new() } + let(:current_resource) { Chef::Resource::WindowsTask.new } let(:provider) do node = Chef::Node.new diff --git a/spec/unit/provider_resolver_spec.rb b/spec/unit/provider_resolver_spec.rb index 9014b873de..94e0d6074b 100644 --- a/spec/unit/provider_resolver_spec.rb +++ b/spec/unit/provider_resolver_spec.rb @@ -869,7 +869,7 @@ describe Chef::ProviderResolver do def self.create_provider_tests(providers, test, expected, filter) expected = expected.merge(providers.select { |key, value| key.is_a?(Symbol) }) providers.each do |key, value| - if !key.is_a?(Symbol) + unless key.is_a?(Symbol) next_test = test.merge({ filter => key }) next_filter = case filter @@ -888,7 +888,7 @@ describe Chef::ProviderResolver do end end # If there is no filter, we're as deep as we need to go - if !filter + unless filter on_platform test.delete(:platform), test do expect_providers(expected) end diff --git a/spec/unit/provider_spec.rb b/spec/unit/provider_spec.rb index 496871614a..d7db8e8c1c 100644 --- a/spec/unit/provider_spec.rb +++ b/spec/unit/provider_spec.rb @@ -24,8 +24,7 @@ class NoWhyrunDemonstrator < Chef::Provider false end - def load_current_resource - end + def load_current_resource; end def action_foo @system_state_altered = true @@ -39,8 +38,7 @@ class ConvergeActionDemonstrator < Chef::Provider true end - def load_current_resource - end + def load_current_resource; end def action_foo converge_by("running a state changing action") do diff --git a/spec/unit/recipe_spec.rb b/spec/unit/recipe_spec.rb index 1bc84745ad..f2ec175243 100644 --- a/spec/unit/recipe_spec.rb +++ b/spec/unit/recipe_spec.rb @@ -94,7 +94,7 @@ describe Chef::Recipe do end end - expect(run_context.resource_collection.map { |r| r.name }).to eql(%w{monkey dog cat}) + expect(run_context.resource_collection.map(&:name)).to eql(%w{monkey dog cat}) end it "should return the new resource after creating it" do @@ -115,7 +115,7 @@ describe Chef::Recipe do node.automatic[:platform_version] = "123" res = recipe.laughter "timmy" expect(res.name).to eql("timmy") - res.kind_of?(ShaunTheSheep) + res.is_a?(ShaunTheSheep) end it "locate a resource for all platforms" do @@ -124,7 +124,7 @@ describe Chef::Recipe do YourMom.provides :love_and_caring res = recipe.love_and_caring "mommy" expect(res.name).to eql("mommy") - res.kind_of?(YourMom) + res.is_a?(YourMom) end describe "when there is more than one resource that resolves on a node" do diff --git a/spec/unit/resource/batch_spec.rb b/spec/unit/resource/batch_spec.rb index c161428a13..dd3082100e 100644 --- a/spec/unit/resource/batch_spec.rb +++ b/spec/unit/resource/batch_spec.rb @@ -22,7 +22,7 @@ describe Chef::Resource::Batch do let(:node) { Chef::Node.new } before(:each) do - node.default["kernel"] = Hash.new + node.default["kernel"] = {} node.default["kernel"][:machine] = :x86_64.to_s node.automatic[:os] = "windows" diff --git a/spec/unit/resource/cab_package_spec.rb b/spec/unit/resource/cab_package_spec.rb index 7e80abf41a..e534748a0c 100644 --- a/spec/unit/resource/cab_package_spec.rb +++ b/spec/unit/resource/cab_package_spec.rb @@ -1,6 +1,6 @@ # # Author:: Vasundhara Jagdale (<vasundhara.jagdale@msystechnologies.com>) -# Copyright:: Copyright 2008-2016, Chef Software, Inc. +# Copyright:: Copyright 2008-2019, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/spec/unit/resource/chef_gem_spec.rb b/spec/unit/resource/chef_gem_spec.rb index a8429d0812..b512b8b17f 100644 --- a/spec/unit/resource/chef_gem_spec.rb +++ b/spec/unit/resource/chef_gem_spec.rb @@ -53,7 +53,7 @@ describe Chef::Resource::ChefGem, "gem_binary" do end it "sets the gem_binary based on computing it from RbConfig" do - expect(resource.gem_binary).to eql("#{RbConfig::CONFIG['bindir']}/gem") + expect(resource.gem_binary).to eql("#{RbConfig::CONFIG["bindir"]}/gem") end it "sets compile_time to false by default" do diff --git a/spec/unit/resource/directory_spec.rb b/spec/unit/resource/directory_spec.rb index 3dd68211db..0c0c0d8287 100644 --- a/spec/unit/resource/directory_spec.rb +++ b/spec/unit/resource/directory_spec.rb @@ -38,7 +38,7 @@ describe Chef::Resource::Directory do it "accepts a string as the path" do expect { resource.path "/tmp" }.not_to raise_error expect(resource.path).to eql("/tmp") - expect { resource.path Hash.new }.to raise_error(ArgumentError) + expect { resource.path({}) }.to raise_error(ArgumentError) end it "allows you to have specify whether the action is recursive with true/false" do diff --git a/spec/unit/resource/dnf_package_spec.rb b/spec/unit/resource/dnf_package_spec.rb index f4262a0396..70d949c340 100644 --- a/spec/unit/resource/dnf_package_spec.rb +++ b/spec/unit/resource/dnf_package_spec.rb @@ -64,7 +64,7 @@ describe Chef::Resource::DnfPackage, "flush_cache" do end it "allows you to set the flush timing with an array" do - flush_array = [ :before, :after ] + flush_array = %i{before after} flush_hash = { before: true, after: true } resource.flush_cache(flush_array) expect(resource.flush_cache).to eq(flush_hash) diff --git a/spec/unit/resource/dsc_resource_spec.rb b/spec/unit/resource/dsc_resource_spec.rb index 04e1305163..e0beb309ab 100644 --- a/spec/unit/resource/dsc_resource_spec.rb +++ b/spec/unit/resource/dsc_resource_spec.rb @@ -41,7 +41,7 @@ describe Chef::Resource::DscResource do end it "has an ed_actions property with only the `:run` and `:nothing` properties" do - expect(dsc_test_resource.allowed_actions.to_set).to eq([:run, :nothing].to_set) + expect(dsc_test_resource.allowed_actions.to_set).to eq(%i{run nothing}.to_set) end it "allows the resource property to be set" do diff --git a/spec/unit/resource/file/verification_spec.rb b/spec/unit/resource/file/verification_spec.rb index f0ec999019..57c58249eb 100644 --- a/spec/unit/resource/file/verification_spec.rb +++ b/spec/unit/resource/file/verification_spec.rb @@ -128,8 +128,7 @@ describe Chef::Resource::File::Verification do before(:each) do class Chef::Resource::File::Verification::Turtle < Chef::Resource::File::Verification provides :cats - def verify(path, opts) - end + def verify(path, opts); end end allow(Chef::Resource::File::Verification::Turtle).to receive(:new).and_return(registered_verification) end diff --git a/spec/unit/resource/file_spec.rb b/spec/unit/resource/file_spec.rb index 54dc8ab92b..b49fc4564b 100644 --- a/spec/unit/resource/file_spec.rb +++ b/spec/unit/resource/file_spec.rb @@ -85,7 +85,7 @@ describe Chef::Resource::File do it "accepts a string as the path" do expect { resource.path "/tmp" }.not_to raise_error expect(resource.path).to eql("/tmp") - expect { resource.path Hash.new }.to raise_error(ArgumentError) + expect { resource.path({}) }.to raise_error(ArgumentError) end describe "when it has a path, owner, group, mode, and checksum" do diff --git a/spec/unit/resource/group_spec.rb b/spec/unit/resource/group_spec.rb index 6d9df79299..ae7103b9b5 100644 --- a/spec/unit/resource/group_spec.rb +++ b/spec/unit/resource/group_spec.rb @@ -96,7 +96,7 @@ end describe Chef::Resource::Group, "members" do let(:resource) { Chef::Resource::Group.new("fakey_fakerton") } - [ :users, :members].each do |method| + %i{users members}.each do |method| it "(#{method}) allows a String and coerces it to an Array" do resource.send(method, "some_user") expect(resource.send(method)).to eql(["some_user"]) diff --git a/spec/unit/resource/link_spec.rb b/spec/unit/resource/link_spec.rb index 05a39835d8..ae32e4aa30 100644 --- a/spec/unit/resource/link_spec.rb +++ b/spec/unit/resource/link_spec.rb @@ -63,7 +63,7 @@ describe Chef::Resource::Link do end it "does not accept a Hash for the link source via 'to'" do - expect { resource.to Hash.new }.to raise_error(ArgumentError) + expect { resource.to({}) }.to raise_error(ArgumentError) end it "allows you to set a link source via 'to'" do diff --git a/spec/unit/resource/locale_spec.rb b/spec/unit/resource/locale_spec.rb index 544f6342c5..9d0061eb5b 100644 --- a/spec/unit/resource/locale_spec.rb +++ b/spec/unit/resource/locale_spec.rb @@ -91,7 +91,7 @@ describe Chef::Resource::Locale do end context "without lang" do it "returns an empty array" do - resource.lang() + resource.lang resource.lc_env({ "LC_TIME" => "en_AG.utf8", "LC_MESSAGES" => "en_AG.utf8" }) expect(provider.unavailable_locales).to eq([]) end @@ -99,14 +99,14 @@ describe Chef::Resource::Locale do context "without lc_env" do it "returns an empty array" do resource.lang("en_US") - resource.lc_env() + resource.lc_env expect(provider.unavailable_locales).to eq([]) end end context "without both" do it "returns an empty array" do - resource.lang() - resource.lc_env() + resource.lang + resource.lc_env expect(provider.unavailable_locales).to eq([]) end end @@ -122,7 +122,7 @@ describe Chef::Resource::Locale do end context "without lang" do it "returns list" do - resource.lang() + resource.lang resource.lc_env({ "LC_TIME" => "en_AG.utf8", "LC_MESSAGES" => "en_US.utf8" }) expect(provider.unavailable_locales).to eq(["en_US.utf8"]) end @@ -130,14 +130,14 @@ describe Chef::Resource::Locale do context "without lc_env" do it "returns list" do resource.lang("de_DE") - resource.lc_env() + resource.lc_env expect(provider.unavailable_locales).to eq(["de_DE"]) end end context "without both" do it "returns an empty array" do - resource.lang() - resource.lc_env() + resource.lang + resource.lc_env expect(provider.unavailable_locales).to eq([]) end end @@ -166,7 +166,7 @@ describe Chef::Resource::Locale do end context "without lang" do it "returns a valid string" do - resource.lang() + resource.lang resource.lc_env({ "LC_TIME" => "en_AG.utf8", "LC_MESSAGES" => "en_AG.utf8" }) expect(provider.new_content).to eq("LC_MESSAGES=en_AG.utf8\nLC_TIME=en_AG.utf8\n") end @@ -174,14 +174,14 @@ describe Chef::Resource::Locale do context "without lc_env" do it "returns a valid string" do resource.lang("en_US") - resource.lc_env() + resource.lc_env expect(provider.new_content).to eq("LANG=en_US\n") end end context "without both" do it "returns string with only new-line character" do - resource.lang() - resource.lc_env() + resource.lang + resource.lc_env expect(provider.new_content).to eq("\n") end end diff --git a/spec/unit/resource/osx_profile_spec.rb b/spec/unit/resource/osx_profile_spec.rb index 41a6071893..5653044358 100644 --- a/spec/unit/resource/osx_profile_spec.rb +++ b/spec/unit/resource/osx_profile_spec.rb @@ -21,7 +21,8 @@ require "spec_helper" describe Chef::Resource::OsxProfile do let(:resource) do Chef::Resource::OsxProfile.new( - "fakey_fakerton") + "fakey_fakerton" + ) end it "has a resource name of profile" do diff --git a/spec/unit/resource/powershell_script_spec.rb b/spec/unit/resource/powershell_script_spec.rb index dc9b62b16c..5566f32725 100644 --- a/spec/unit/resource/powershell_script_spec.rb +++ b/spec/unit/resource/powershell_script_spec.rb @@ -23,7 +23,7 @@ describe Chef::Resource::PowershellScript do before(:each) do node = Chef::Node.new - node.default["kernel"] = Hash.new + node.default["kernel"] = {} node.default["kernel"][:machine] = :x86_64.to_s node.automatic[:os] = "windows" @@ -61,7 +61,7 @@ describe Chef::Resource::PowershellScript do it "inherits exactly the :cwd, :environment, :group, :path, :user, :umask, :architecture, :elevated properties from a parent resource class" do inherited_difference = Chef::Resource::PowershellScript.guard_inherited_attributes - - [:cwd, :environment, :group, :path, :user, :umask, :architecture, :elevated ] + %i{cwd environment group path user umask architecture elevated} expect(inherited_difference).to eq([]) end @@ -87,7 +87,8 @@ describe Chef::Resource::PowershellScript do it "enables convert_boolean_return by default for guards in the context of powershell_script when no guard params are specified" do allow_any_instance_of(Chef::GuardInterpreter::ResourceGuardInterpreter).to receive(:evaluate_action).and_return(true) allow_any_instance_of(Chef::GuardInterpreter::ResourceGuardInterpreter).to receive(:block_from_attributes).with( - { convert_boolean_return: true, code: "$true" }).and_return(Proc.new {}) + { convert_boolean_return: true, code: "$true" } + ).and_return(Proc.new {}) resource.only_if("$true") end @@ -98,21 +99,24 @@ describe Chef::Resource::PowershellScript do file_resource.guard_interpreter :powershell_script allow_any_instance_of(Chef::GuardInterpreter::ResourceGuardInterpreter).to receive(:block_from_attributes).with( - { convert_boolean_return: true, code: "$true" }).and_return(Proc.new {}) + { convert_boolean_return: true, code: "$true" } + ).and_return(Proc.new {}) resource.only_if("$true") end it "enables convert_boolean_return by default for guards in the context of powershell_script when guard params are specified" do guard_parameters = { cwd: "/etc/chef", architecture: :x86_64 } allow_any_instance_of(Chef::GuardInterpreter::ResourceGuardInterpreter).to receive(:block_from_attributes).with( - { convert_boolean_return: true, code: "$true" }.merge(guard_parameters)).and_return(Proc.new {}) + { convert_boolean_return: true, code: "$true" }.merge(guard_parameters) + ).and_return(Proc.new {}) resource.only_if("$true", guard_parameters) end it "passes convert_boolean_return as true if it was specified as true in a guard parameter" do guard_parameters = { cwd: "/etc/chef", convert_boolean_return: true, architecture: :x86_64 } allow_any_instance_of(Chef::GuardInterpreter::ResourceGuardInterpreter).to receive(:block_from_attributes).with( - { convert_boolean_return: true, code: "$true" }.merge(guard_parameters)).and_return(Proc.new {}) + { convert_boolean_return: true, code: "$true" }.merge(guard_parameters) + ).and_return(Proc.new {}) resource.only_if("$true", guard_parameters) end @@ -120,7 +124,8 @@ describe Chef::Resource::PowershellScript do other_guard_parameters = { cwd: "/etc/chef", architecture: :x86_64 } parameters_with_boolean_disabled = other_guard_parameters.merge({ convert_boolean_return: false, code: "$true" }) allow_any_instance_of(Chef::GuardInterpreter::ResourceGuardInterpreter).to receive(:block_from_attributes).with( - parameters_with_boolean_disabled).and_return(Proc.new {}) + parameters_with_boolean_disabled + ).and_return(Proc.new {}) resource.only_if("$true", parameters_with_boolean_disabled) end end diff --git a/spec/unit/resource/registry_key_spec.rb b/spec/unit/resource/registry_key_spec.rb index 47d624a758..c674e3eddd 100644 --- a/spec/unit/resource/registry_key_spec.rb +++ b/spec/unit/resource/registry_key_spec.rb @@ -152,7 +152,7 @@ describe Chef::Resource::RegistryKey, "recursive" do end it "does not allow an array" do - expect { resource.recursive([:nose, :chin]) }.to raise_error(ArgumentError) + expect { resource.recursive(%i{nose chin}) }.to raise_error(ArgumentError) end it "does not allow a string" do @@ -167,7 +167,7 @@ end describe Chef::Resource::RegistryKey, "architecture" do let(:resource) { Chef::Resource::RegistryKey.new('HKCU\Software\Raxicoricofallapatorius') } - [ :i386, :x86_64, :machine ].each do |arch| + %i{i386 x86_64 machine}.each do |arch| it "allows #{arch} as a symbol" do resource.architecture(arch) expect(resource.architecture).to eql(arch) @@ -183,7 +183,7 @@ describe Chef::Resource::RegistryKey, "architecture" do end it "does not allow an array" do - expect { resource.architecture([:nose, :chin]) }.to raise_error(ArgumentError) + expect { resource.architecture(%i{nose chin}) }.to raise_error(ArgumentError) end it "does not allow a string" do diff --git a/spec/unit/resource/service_spec.rb b/spec/unit/resource/service_spec.rb index 7c2b46a0dc..be88d82f3b 100644 --- a/spec/unit/resource/service_spec.rb +++ b/spec/unit/resource/service_spec.rb @@ -167,7 +167,7 @@ describe Chef::Resource::Service do end it "allows you to set what features this resource supports as an array" do - support_array = [ :status, :restart ] + support_array = %i{status restart} support_hash = { status: true, restart: true } resource.supports(support_array) expect(resource.supports).to eq(support_hash) diff --git a/spec/unit/resource/template_spec.rb b/spec/unit/resource/template_spec.rb index 9ca1f7617f..2f8e234c85 100644 --- a/spec/unit/resource/template_spec.rb +++ b/spec/unit/resource/template_spec.rb @@ -147,7 +147,7 @@ describe Chef::Resource::Template do end it "compiles helper methods with arguments into a module" do - resource.helper(:shout) { |quiet| quiet.upcase } + resource.helper(:shout, &:upcase) modules = resource.helper_modules o = Object.new modules.each { |m| o.extend(m) } @@ -186,7 +186,7 @@ describe Chef::Resource::Template do end it "raises an error when no block or module name is given for helpers definition" do - expect { resource.helpers() }.to raise_error(Chef::Exceptions::ValidationFailed) + expect { resource.helpers }.to raise_error(Chef::Exceptions::ValidationFailed) end it "raises an error when a non-module is given for helpers definition" do diff --git a/spec/unit/resource/windows_env_spec.rb b/spec/unit/resource/windows_env_spec.rb index 06b5af630a..3ba5b18881 100644 --- a/spec/unit/resource/windows_env_spec.rb +++ b/spec/unit/resource/windows_env_spec.rb @@ -47,7 +47,7 @@ describe Chef::Resource::WindowsEnv do end it "does not accept a Hash for the env value via 'to'" do - expect { resource.value Hash.new }.to raise_error(ArgumentError) + expect { resource.value({}) }.to raise_error(ArgumentError) end it "allows you to set an env value via 'to'" do diff --git a/spec/unit/resource/windows_service_spec.rb b/spec/unit/resource/windows_service_spec.rb index b44a86d04a..a416ca0a05 100644 --- a/spec/unit/resource/windows_service_spec.rb +++ b/spec/unit/resource/windows_service_spec.rb @@ -48,7 +48,7 @@ describe Chef::Resource::WindowsService, "initialize" do expect { resource.action :unmask }.not_to raise_error end - [:automatic, :manual, :disabled].each do |type| + %i{automatic manual disabled}.each do |type| it "supports setting startup_type property to #{type.inspect}" do resource.startup_type type expect(resource.startup_type).to eql(type) @@ -69,7 +69,7 @@ describe Chef::Resource::WindowsService, "initialize" do end end - [:automatic, :manual, :disabled].each do |type| + %i{automatic manual disabled}.each do |type| it "supports setting startup_type property to #{type.inspect}" do resource.startup_type type expect(resource.startup_type).to eql(type) @@ -84,11 +84,11 @@ describe Chef::Resource::WindowsService, "initialize" do # Properties that are Strings %i{description service_name binary_path_name load_order_group dependencies run_as_user run_as_password display_name}.each do |prop| - it "support setting #{prop} property with a String" do - resource.send("#{prop}=", "some value") - expect(resource.send(prop)).to eq("some value") - end - end + it "support setting #{prop} property with a String" do + resource.send("#{prop}=", "some value") + expect(resource.send(prop)).to eq("some value") + end + end # Properties that are Integers %i{desired_access error_control service_type}.each do |prop| diff --git a/spec/unit/resource/windows_task_spec.rb b/spec/unit/resource/windows_task_spec.rb index b152d879f6..d08849d4be 100644 --- a/spec/unit/resource/windows_task_spec.rb +++ b/spec/unit/resource/windows_task_spec.rb @@ -356,7 +356,7 @@ describe Chef::Resource::WindowsTask, :windows_only do context "#validate_idle_time" do it "raises error if frequency is not :on_idle" do - [:minute, :hourly, :daily, :weekly, :monthly, :once, :on_logon, :onstart, :none].each do |frequency| + %i{minute hourly daily weekly monthly once on_logon onstart none}.each do |frequency| expect { resource.send(:validate_idle_time, 5, frequency) }.to raise_error(ArgumentError, "idle_time property is only valid for tasks that run on_idle") end end @@ -374,7 +374,7 @@ describe Chef::Resource::WindowsTask, :windows_only do end it "does not raises error if idle_time is not set for other frequencies" do - [:minute, :hourly, :daily, :weekly, :monthly, :once, :on_logon, :onstart, :none].each do |frequency| + %i{minute hourly daily weekly monthly once on_logon onstart none}.each do |frequency| expect { resource.send(:validate_idle_time, nil, frequency) }.not_to raise_error end end diff --git a/spec/unit/resource/windows_uac_spec.rb b/spec/unit/resource/windows_uac_spec.rb index 05c1cad4a0..6f9137c341 100644 --- a/spec/unit/resource/windows_uac_spec.rb +++ b/spec/unit/resource/windows_uac_spec.rb @@ -24,7 +24,7 @@ describe Chef::Resource::WindowsUac do expect(resource.resource_name).to eql(:windows_uac) end - [:no_prompt, :secure_prompt_for_creds, :secure_prompt_for_consent, :prompt_for_creds, :prompt_for_consent, :prompt_for_consent_non_windows_binaries].each do |val| + %i{no_prompt secure_prompt_for_creds secure_prompt_for_consent prompt_for_creds prompt_for_consent prompt_for_consent_non_windows_binaries}.each do |val| it "the consent_behavior_admins property accepts :#{val}" do expect { resource.consent_behavior_admins val }.not_to raise_error(ArgumentError) end @@ -34,7 +34,7 @@ describe Chef::Resource::WindowsUac do expect { resource.consent_behavior_admins :bogus }.to raise_error(ArgumentError) end - [:auto_deny, :secure_prompt_for_creds, :prompt_for_creds].each do |val| + %i{auto_deny secure_prompt_for_creds prompt_for_creds}.each do |val| it "the consent_behavior_users property accepts :#{val}" do expect { resource.consent_behavior_users val }.not_to raise_error(ArgumentError) end diff --git a/spec/unit/resource/yum_package_spec.rb b/spec/unit/resource/yum_package_spec.rb index 0b79a447a3..d0383a8cec 100644 --- a/spec/unit/resource/yum_package_spec.rb +++ b/spec/unit/resource/yum_package_spec.rb @@ -95,7 +95,7 @@ describe Chef::Resource::YumPackage, "flush_cache" do end it "should allow you to set the flush timing with an array" do - flush_array = [ :before, :after ] + flush_array = %i{before after} flush_hash = { before: true, after: true } @resource.flush_cache(flush_array) expect(@resource.flush_cache).to eq(flush_hash) diff --git a/spec/unit/resource_collection/resource_list_spec.rb b/spec/unit/resource_collection/resource_list_spec.rb index dabb8f037d..05363c20b1 100644 --- a/spec/unit/resource_collection/resource_list_spec.rb +++ b/spec/unit/resource_collection/resource_list_spec.rb @@ -19,7 +19,7 @@ require "spec_helper" describe Chef::ResourceCollection::ResourceList do - let(:resource_list) { Chef::ResourceCollection::ResourceList.new() } + let(:resource_list) { Chef::ResourceCollection::ResourceList.new } let(:resource) { Chef::Resource::ZenMaster.new("makoto") } let(:second_resource) { Chef::Resource::ZenMaster.new("hattori") } diff --git a/spec/unit/resource_collection/resource_set_spec.rb b/spec/unit/resource_collection/resource_set_spec.rb index 60053d2b71..30a55cd3e1 100644 --- a/spec/unit/resource_collection/resource_set_spec.rb +++ b/spec/unit/resource_collection/resource_set_spec.rb @@ -172,7 +172,7 @@ describe Chef::ResourceCollection::ResourceSet do end it "should raise an exception if you pass something other than a string or hash to resource" do - expect { collection.find([Array.new]) }.to raise_error(ArgumentError) + expect { collection.find([[]]) }.to raise_error(ArgumentError) end it "raises an error when attempting to find a resource that does not exist" do diff --git a/spec/unit/resource_collection/stepable_iterator_spec.rb b/spec/unit/resource_collection/stepable_iterator_spec.rb index 6354b1b7fb..ec831c9afe 100644 --- a/spec/unit/resource_collection/stepable_iterator_spec.rb +++ b/spec/unit/resource_collection/stepable_iterator_spec.rb @@ -72,7 +72,7 @@ describe Chef::ResourceCollection::StepableIterator do @collection << lambda { @snitch_var = 42 } @iterator = CRSI.for_collection(@collection) - @iterator.each { |proc| proc.call } + @iterator.each(&:call) end it "allows the iteration to be paused" do @@ -124,7 +124,7 @@ describe Chef::ResourceCollection::StepableIterator do it "allows the iteration to start by being stepped" do @snitch_var = nil @iterator = CRSI.for_collection(@collection) - @iterator.iterate_on(:element) { |proc| proc.call } + @iterator.iterate_on(:element, &:call) @iterator.step expect(@iterator.position).to eq(1) expect(@snitch_var).to eq(23) diff --git a/spec/unit/resource_collection_spec.rb b/spec/unit/resource_collection_spec.rb index 7f59246a88..60f17b6934 100644 --- a/spec/unit/resource_collection_spec.rb +++ b/spec/unit/resource_collection_spec.rb @@ -20,7 +20,7 @@ require "spec_helper" describe Chef::ResourceCollection do - let(:rc) { Chef::ResourceCollection.new() } + let(:rc) { Chef::ResourceCollection.new } let(:resource) { Chef::Resource::ZenMaster.new("makoto") } it "should throw an error when calling a non-delegated method" do @@ -97,7 +97,7 @@ describe Chef::ResourceCollection do describe "each" do it "should allow you to iterate over every resource in the collection" do load_up_resources - results = Array.new + results = [] expect do rc.each do |r| results << r.name @@ -119,7 +119,7 @@ describe Chef::ResourceCollection do describe "each_index" do it "should allow you to iterate over every resource by index" do load_up_resources - results = Array.new + results = [] expect do rc.each_index do |i| results << rc[i].name @@ -246,7 +246,7 @@ describe Chef::ResourceCollection do end it "should raise an exception if you pass something other than a string or hash to resource" do - expect { rc.resources([Array.new]) }.to raise_error(ArgumentError) + expect { rc.resources([[]]) }.to raise_error(ArgumentError) end it "raises an error when attempting to find a resource that does not exist" do diff --git a/spec/unit/resource_definition_spec.rb b/spec/unit/resource_definition_spec.rb index 5be3e59009..a1c59eaaca 100644 --- a/spec/unit/resource_definition_spec.rb +++ b/spec/unit/resource_definition_spec.rb @@ -19,7 +19,7 @@ require "spec_helper" describe Chef::ResourceDefinition do - let(:defn) { Chef::ResourceDefinition.new() } + let(:defn) { Chef::ResourceDefinition.new } describe "initialize" do it "should be a Chef::ResourceDefinition" do @@ -92,7 +92,7 @@ describe Chef::ResourceDefinition do it "should raise an exception if prototype_params is not a hash" do expect do - defn.define :monkey, Array.new do + defn.define :monkey, [] do end end.to raise_error(ArgumentError) end diff --git a/spec/unit/resource_inspector_spec.rb b/spec/unit/resource_inspector_spec.rb index aef92732b3..c0852be3b2 100644 --- a/spec/unit/resource_inspector_spec.rb +++ b/spec/unit/resource_inspector_spec.rb @@ -39,7 +39,7 @@ describe ResourceInspector do it "returns a hash with required data" do expect(subject[:description]).to eq "A dummy resource" - expect(subject[:actions]).to match_array [:nothing, :dummy] + expect(subject[:actions]).to match_array %i{nothing dummy} end context "excluding built in properties" do diff --git a/spec/unit/resource_spec.rb b/spec/unit/resource_spec.rb index 1c8e991566..6745dd448d 100644 --- a/spec/unit/resource_spec.rb +++ b/spec/unit/resource_spec.rb @@ -115,14 +115,14 @@ describe Chef::Resource do it "sets a list of state attributes" do resource_class = Class.new(Chef::Resource) resource_class.state_attrs(:checksum, :owner, :group, :mode) - expect(resource_class.state_attrs).to match_array([:checksum, :owner, :group, :mode]) + expect(resource_class.state_attrs).to match_array(%i{checksum owner group mode}) end it "inherits state attributes from the superclass" do resource_class = Class.new(Chef::Resource) resource_subclass = Class.new(resource_class) resource_class.state_attrs(:checksum, :owner, :group, :mode) - expect(resource_subclass.state_attrs).to match_array([:checksum, :owner, :group, :mode]) + expect(resource_subclass.state_attrs).to match_array(%i{checksum owner group mode}) end it "combines inherited state attributes with non-inherited state attributes" do @@ -130,7 +130,7 @@ describe Chef::Resource do resource_subclass = Class.new(resource_class) resource_class.state_attrs(:checksum, :owner) resource_subclass.state_attrs(:group, :mode) - expect(resource_subclass.state_attrs).to match_array([:checksum, :owner, :group, :mode]) + expect(resource_subclass.state_attrs).to match_array(%i{checksum owner group mode}) end end @@ -157,7 +157,7 @@ describe Chef::Resource do it "describes its state" do resource_state = file_resource.state_for_resource_reporter - expect(resource_state.keys).to match_array([:checksum, :owner, :group, :mode]) + expect(resource_state.keys).to match_array(%i{checksum owner group mode}) expect(resource_state[:checksum]).to eq("abc123") expect(resource_state[:owner]).to eq("root") expect(resource_state[:group]).to eq("wheel") @@ -510,11 +510,11 @@ describe Chef::Resource do context "when the resource has a property with a default" do let(:resource_class) { Class.new(Chef::Resource) { property :a, default: 1 } } it "should include the default in the hash" do - expect(resource.to_hash.keys.sort).to eq([:a, :allowed_actions, :params, :provider, :updated, - :updated_by_last_action, :before, - :name, :source_line, - :action, :elapsed_time, - :default_guard_interpreter, :guard_interpreter].sort) + expect(resource.to_hash.keys.sort).to eq(%i{a allowed_actions params provider updated + updated_by_last_action before + name source_line + action elapsed_time + default_guard_interpreter guard_interpreter}.sort) expect(resource.to_hash[:name]).to eq "funk" expect(resource.to_hash[:a]).to eq 1 end @@ -522,11 +522,11 @@ describe Chef::Resource do it "should convert to a hash" do hash = resource.to_hash - expected_keys = [ :allowed_actions, :params, :provider, :updated, - :updated_by_last_action, :before, - :name, :source_line, - :action, :elapsed_time, - :default_guard_interpreter, :guard_interpreter ] + expected_keys = %i{allowed_actions params provider updated + updated_by_last_action before + name source_line + action elapsed_time + default_guard_interpreter guard_interpreter} expect(hash.keys - expected_keys).to eq([]) expect(expected_keys - hash.keys).to eq([]) expect(hash[:name]).to eql("funk") @@ -838,7 +838,7 @@ describe Chef::Resource do it "should print \"skipped due to action :nothing\" message for doc formatter when action is :nothing" do fdoc = Chef::Formatters.new(:doc, STDOUT, STDERR) allow(run_context).to receive(:events).and_return(fdoc) - expect(fdoc).to receive(:puts).with(" (skipped due to action :nothing)", anything()) + expect(fdoc).to receive(:puts).with(" (skipped due to action :nothing)", anything) resource.should_skip?(:nothing) end @@ -1118,8 +1118,8 @@ describe Chef::Resource do end context "with an array action" do - before { resource.action([:two, :one]) } - it { is_expected.to eq [:two, :one] } + before { resource.action(%i{two one}) } + it { is_expected.to eq %i{two one} } end context "with an assignment" do @@ -1128,8 +1128,8 @@ describe Chef::Resource do end context "with an array assignment" do - before { resource.action = [:two, :one] } - it { is_expected.to eq [:two, :one] } + before { resource.action = %i{two one} } + it { is_expected.to eq %i{two one} } end context "with an invalid action" do @@ -1166,8 +1166,8 @@ describe Chef::Resource do end context "with an array default action" do - let(:default_action) { [:two, :one] } - it { is_expected.to eq [:two, :one] } + let(:default_action) { %i{two one} } + it { is_expected.to eq %i{two one} } end end diff --git a/spec/unit/role_spec.rb b/spec/unit/role_spec.rb index 46ee71bb1c..13932ab3ee 100644 --- a/spec/unit/role_spec.rb +++ b/spec/unit/role_spec.rb @@ -113,7 +113,7 @@ describe Chef::Role do end it "should throw an ArgumentError if we aren't a kind of hash" do - expect { @role.default_attributes(Array.new) }.to raise_error(ArgumentError) + expect { @role.default_attributes([]) }.to raise_error(ArgumentError) end end @@ -128,7 +128,7 @@ describe Chef::Role do end it "should throw an ArgumentError if we aren't a kind of hash" do - expect { @role.override_attributes(Array.new) }.to raise_error(ArgumentError) + expect { @role.override_attributes([]) }.to raise_error(ArgumentError) end end diff --git a/spec/unit/run_context/cookbook_compiler_spec.rb b/spec/unit/run_context/cookbook_compiler_spec.rb index 607333416d..cc9330a1b6 100644 --- a/spec/unit/run_context/cookbook_compiler_spec.rb +++ b/spec/unit/run_context/cookbook_compiler_spec.rb @@ -217,14 +217,14 @@ describe Chef::RunContext::CookbookCompiler do it "should return an array of cookbook names as symbols without duplicates" do node.run_list("test-with-circular-deps::default", "circular-dep1::default", "circular-dep2::default") - expect(compiler.cookbook_order).to eq([:"circular-dep2", - :"circular-dep1", - :"test-with-circular-deps"]) + expect(compiler.cookbook_order).to eq(%i{circular-dep2 + circular-dep1 + test-with-circular-deps}) end it "determines if a cookbook is in the list of cookbooks reachable by dependency" do node.run_list("test-with-deps::default", "test-with-deps::server") - expect(compiler.cookbook_order).to eq([:dependency1, :dependency2, :"test-with-deps"]) + expect(compiler.cookbook_order).to eq(%i{dependency1 dependency2 test-with-deps}) expect(compiler.unreachable_cookbook?(:dependency1)).to be_falsey expect(compiler.unreachable_cookbook?(:dependency2)).to be_falsey expect(compiler.unreachable_cookbook?(:'test-with-deps')).to be_falsey diff --git a/spec/unit/run_list/run_list_expansion_spec.rb b/spec/unit/run_list/run_list_expansion_spec.rb index 3a39bc79cc..4ddc75f002 100644 --- a/spec/unit/run_list/run_list_expansion_spec.rb +++ b/spec/unit/run_list/run_list_expansion_spec.rb @@ -94,12 +94,15 @@ describe Chef::RunList::RunListExpansion do allow(@expansion).to receive(:fetch_role).and_return(@first_role, @second_role) @expansion.expand @json = '{"id":"_default","run_list":[{"type":"recipe","name":"lobster::mastercookbook","version":"0.1.0",' - .concat( -'"skipped":false},{"type":"role","name":"rage","children":[{"type":"role","name":"mollusk","children":[],"missing":null,' - .concat( -'"error":null,"skipped":null},{"type":"recipe","name":"crabrevenge","version":null,"skipped":false}],"missing":null,' - .concat( -'"error":null,"skipped":null},{"type":"recipe","name":"fist","version":"0.1","skipped":false}]}'))) + .concat( + '"skipped":false},{"type":"role","name":"rage","children":[{"type":"role","name":"mollusk","children":[],"missing":null,' + .concat( + '"error":null,"skipped":null},{"type":"recipe","name":"crabrevenge","version":null,"skipped":false}],"missing":null,' + .concat( + '"error":null,"skipped":null},{"type":"recipe","name":"fist","version":"0.1","skipped":false}]}' + ) + ) + ) end diff --git a/spec/unit/run_list_spec.rb b/spec/unit/run_list_spec.rb index ac062c665d..5dc877ad9a 100644 --- a/spec/unit/run_list_spec.rb +++ b/spec/unit/run_list_spec.rb @@ -133,7 +133,7 @@ describe Chef::RunList do it "should yield each member to your block" do @run_list << "foo" @run_list << "bar" - seen = Array.new + seen = [] @run_list.each { |r| seen << r } expect(seen).to be_include("recipe[foo]") expect(seen).to be_include("recipe[bar]") diff --git a/spec/unit/runner_spec.rb b/spec/unit/runner_spec.rb index 1effe3157c..ffb0cd523f 100644 --- a/spec/unit/runner_spec.rb +++ b/spec/unit/runner_spec.rb @@ -295,7 +295,7 @@ describe Chef::Runner do # execution, and schedule delayed actions :second and :third on the first # resource. The duplicate actions should "collapse" to a single notification # and order should be preserved. - expect(SnitchyProvider.all_actions_called).to eq([:first, :first, :second, :third]) + expect(SnitchyProvider.all_actions_called).to eq(%i{first first second third}) end it "executes delayed notifications in the order they were declared" do @@ -321,7 +321,7 @@ describe Chef::Runner do third_resource.notifies(:third_action, first_resource, :delayed) runner.converge - expect(SnitchyProvider.all_actions_called).to eq([:first, :first, :second, :third]) + expect(SnitchyProvider.all_actions_called).to eq(%i{first first second third}) end it "does not fire notifications if the resource was not updated by the last action executed" do @@ -347,7 +347,7 @@ describe Chef::Runner do runner.converge # All of the resources should only fire once: - expect(SnitchyProvider.all_actions_called).to eq([:first, :second, :third]) + expect(SnitchyProvider.all_actions_called).to eq(%i{first second third}) # all of the resources should be marked as updated for reporting purposes expect(first_resource).to be_updated diff --git a/spec/unit/search/query_spec.rb b/spec/unit/search/query_spec.rb index 151fcb51b3..83f988911c 100644 --- a/spec/unit/search/query_spec.rb +++ b/spec/unit/search/query_spec.rb @@ -149,7 +149,8 @@ describe Chef::Search::Query do ], "start" => 0, "total" => 4, - } end + } + end let(:big_response_empty) do { @@ -169,7 +170,7 @@ describe Chef::Search::Query do it "accepts a type as the first argument" do expect { query.search("node") }.not_to raise_error expect { query.search(:node) }.not_to raise_error - expect { query.search(Hash.new) }.to raise_error(Chef::Exceptions::InvalidSearchQuery, /(Hash)/) + expect { query.search({}) }.to raise_error(Chef::Exceptions::InvalidSearchQuery, /(Hash)/) end it "queries for every object of a type by default" do diff --git a/spec/unit/shell/model_wrapper_spec.rb b/spec/unit/shell/model_wrapper_spec.rb index bcce7c1a08..7ca5f74bef 100644 --- a/spec/unit/shell/model_wrapper_spec.rb +++ b/spec/unit/shell/model_wrapper_spec.rb @@ -57,7 +57,7 @@ describe Shell::ModelWrapper do end it "maps the listed nodes when given a block" do - expect(@wrapper.all { |n| n.name }.sort.reverse).to eq(%w{yummy sammich}) + expect(@wrapper.all(&:name).sort.reverse).to eq(%w{yummy sammich}) end end diff --git a/spec/unit/shell/shell_session_spec.rb b/spec/unit/shell/shell_session_spec.rb index 6644ff6e0c..c98989491d 100644 --- a/spec/unit/shell/shell_session_spec.rb +++ b/spec/unit/shell/shell_session_spec.rb @@ -57,8 +57,7 @@ describe Shell::ClientSession do load_node: true, build_node: true, register: true, - sync_cookbooks: {} - ) + sync_cookbooks: {}) end before do @@ -94,8 +93,7 @@ describe Shell::SoloSession do load_node: true, build_node: true, register: true, - sync_cookbooks: {} - ) + sync_cookbooks: {}) end before do @@ -132,8 +130,7 @@ describe Shell::StandAloneSession do load_node: true, build_node: true, register: true, - sync_cookbooks: {} - ) + sync_cookbooks: {}) end let(:recipe) { Chef::Recipe.new(nil, nil, run_context) } let(:run_context) { Chef::RunContext.new(node, {}, events) } diff --git a/spec/unit/shell_spec.rb b/spec/unit/shell_spec.rb index 8ba1afa72a..aa573706b1 100644 --- a/spec/unit/shell_spec.rb +++ b/spec/unit/shell_spec.rb @@ -30,8 +30,7 @@ ObjectTestHarness = Proc.new do end desc "rspecin'" - def rspec_method - end + def rspec_method; end end class TestJobManager diff --git a/spec/unit/user_spec.rb b/spec/unit/user_spec.rb index 48dbf010e9..492dc147d9 100644 --- a/spec/unit/user_spec.rb +++ b/spec/unit/user_spec.rb @@ -65,7 +65,7 @@ describe Chef::User do end it "should throw an ArgumentError if you feed it anything but a string" do - expect { @user.name Hash.new }.to raise_error(ArgumentError) + expect { @user.name({}) }.to raise_error(ArgumentError) end end @@ -84,7 +84,7 @@ describe Chef::User do end it "should throw an ArgumentError if you feed it anything but true or false" do - expect { @user.name Hash.new }.to raise_error(ArgumentError) + expect { @user.name({}) }.to raise_error(ArgumentError) end end @@ -99,7 +99,7 @@ describe Chef::User do end it "should throw an ArgumentError if you feed it something lame" do - expect { @user.public_key Hash.new }.to raise_error(ArgumentError) + expect { @user.public_key({}) }.to raise_error(ArgumentError) end end @@ -114,7 +114,7 @@ describe Chef::User do end it "should throw an ArgumentError if you feed it something lame" do - expect { @user.private_key Hash.new }.to raise_error(ArgumentError) + expect { @user.private_key({}) }.to raise_error(ArgumentError) end end diff --git a/spec/unit/user_v1_spec.rb b/spec/unit/user_v1_spec.rb index 37b2252492..4bde7278fe 100644 --- a/spec/unit/user_v1_spec.rb +++ b/spec/unit/user_v1_spec.rb @@ -37,7 +37,7 @@ describe Chef::UserV1 do end it "should throw an ArgumentError if you feed it something lame" do - expect { @user.send(method, Hash.new) }.to raise_error(ArgumentError) + expect { @user.send(method, {}) }.to raise_error(ArgumentError) end end @@ -57,7 +57,7 @@ describe Chef::UserV1 do end it "should throw an ArgumentError if you feed it anything but true or false" do - expect { @user.send(method, Hash.new) }.to raise_error(ArgumentError) + expect { @user.send(method, {}) }.to raise_error(ArgumentError) end end @@ -95,7 +95,7 @@ describe Chef::UserV1 do end it "should throw an ArgumentError if you feed it anything but a string" do - expect { @user.username Hash.new }.to raise_error(ArgumentError) + expect { @user.username({}) }.to raise_error(ArgumentError) end end diff --git a/spec/unit/util/backup_spec.rb b/spec/unit/util/backup_spec.rb index 8bc68ec160..3a9a45b841 100644 --- a/spec/unit/util/backup_spec.rb +++ b/spec/unit/util/backup_spec.rb @@ -110,7 +110,7 @@ describe Chef::Util::Backup do end it "should strip the drive letter off for windows" do expect(@backup).to receive(:path).and_return('c:\a\b\c.txt') - expect(@backup.send(:backup_filename)).to match(%r|^\\a\\b\\c.txt.chef-\d{14}.\d{6}$|) + expect(@backup.send(:backup_filename)).to match(/^\\a\\b\\c.txt.chef-\d{14}.\d{6}$/) end it "should strip the drive letter off for windows (with forwardslashes)" do expect(@backup).to receive(:path).and_return("c:/a/b/c.txt") diff --git a/spec/unit/util/editor_spec.rb b/spec/unit/util/editor_spec.rb index e53bc9662a..ac851a835e 100644 --- a/spec/unit/util/editor_spec.rb +++ b/spec/unit/util/editor_spec.rb @@ -9,7 +9,7 @@ describe Chef::Util::Editor do end it "makes a copy of an Array" do - array = Array.new + array = [] editor = described_class.new(array) expect(editor.lines).to_not be(array) end diff --git a/spec/unit/util/powershell/ps_credential_spec.rb b/spec/unit/util/powershell/ps_credential_spec.rb index 6f65174d15..65207d5dfb 100644 --- a/spec/unit/util/powershell/ps_credential_spec.rb +++ b/spec/unit/util/powershell/ps_credential_spec.rb @@ -29,8 +29,9 @@ describe Chef::Util::Powershell::PSCredential do it "should create the script to create a PSCredential when calling" do allow(ps_credential).to receive(:encrypt).with(password).and_return("encrypted") expect(ps_credential.to_psobject).to eq( - "New-Object System.Management.Automation.PSCredential("\ - "'#{username}',('encrypted' | ConvertTo-SecureString))") + "New-Object System.Management.Automation.PSCredential("\ + "'#{username}',('encrypted' | ConvertTo-SecureString))" + ) end end diff --git a/spec/unit/util/threaded_job_queue_spec.rb b/spec/unit/util/threaded_job_queue_spec.rb index 8a89943a8a..48a34bce31 100644 --- a/spec/unit/util/threaded_job_queue_spec.rb +++ b/spec/unit/util/threaded_job_queue_spec.rb @@ -22,7 +22,7 @@ describe Chef::Util::ThreadedJobQueue do let(:queue) { Chef::Util::ThreadedJobQueue.new } it "should pass mutex to jobs with an arity of 1" do - job = double() + job = double expect(job).to receive(:arity).at_least(:once).and_return(1) expect(job).to receive(:call).exactly(5).times.with(an_instance_of(Mutex)) @@ -31,7 +31,7 @@ describe Chef::Util::ThreadedJobQueue do end it "should pass nothing to jobs with an arity of 0" do - job = double() + job = double expect(job).to receive(:arity).at_least(:once).and_return(0) expect(job).to receive(:call).exactly(5).times.with(no_args) diff --git a/spec/unit/version_class_spec.rb b/spec/unit/version_class_spec.rb index 9dc981bd4c..c6848491ee 100644 --- a/spec/unit/version_class_spec.rb +++ b/spec/unit/version_class_spec.rb @@ -105,7 +105,7 @@ describe Chef::Version do a = %w{0.0.0 0.0.1 0.1.0 0.1.1 1.0.0 1.1.0 1.1.1}.map do |s| Chef::Version.new(s) end - got = a.sort.map { |v| v.to_s } + got = a.sort.map(&:to_s) expect(got).to eq(%w{0.0.0 0.0.1 0.1.0 0.1.1 1.0.0 1.1.0 1.1.1}) end @@ -113,7 +113,7 @@ describe Chef::Version do a = %w{9.8.7 1.0.0 1.2.3 4.4.6 4.5.6 0.8.6 4.5.5 5.9.8 3.5.7}.map do |s| Chef::Version.new(s) end - got = a.sort.map { |v| v.to_s } + got = a.sort.map(&:to_s) expect(got).to eq(%w{0.8.6 1.0.0 1.2.3 3.5.7 4.4.6 4.5.5 4.5.6 5.9.8 9.8.7}) end @@ -160,7 +160,7 @@ describe Chef::Version do [ "1.2.2", :<=, "1.2.1", false ], [ "1.2.2", :<, "1.2.1", false ], ].each do |spec| - it "(#{spec.first(3).join(' ')}) should be #{spec[3]}" do + it "(#{spec.first(3).join(" ")}) should be #{spec[3]}" do got = Chef::Version.new(spec[0]).send(spec[1], Chef::Version.new(spec[2])) expect(got).to eq(spec[3]) diff --git a/spec/unit/win32/registry_spec.rb b/spec/unit/win32/registry_spec.rb index 574f38d8e2..2485d9ee47 100644 --- a/spec/unit/win32/registry_spec.rb +++ b/spec/unit/win32/registry_spec.rb @@ -29,7 +29,7 @@ describe Chef::Win32::Registry do let(:key_to_delete) { "OpscodeNumbers" } let(:sub_key) { "OpscodePrimes" } let(:missing_key_path) { 'HKCU\Software' } - let(:registry) { Chef::Win32::Registry.new() } + let(:registry) { Chef::Win32::Registry.new } let(:hive_mock) { double("::Win32::Registry::KHKEY_CURRENT_USER") } let(:reg_mock) { double("reg") } @@ -252,7 +252,7 @@ describe Chef::Win32::Registry do expect(registry).to receive(:key_exists!).with(key_path).and_return(true) expect(registry).to receive(:get_hive_and_key).with(key_path).and_return([hive_mock, key]) expect(hive_mock).to receive(:open).with(key, ::Win32::Registry::KEY_READ | registry.registry_system_architecture).and_yield(reg_mock) - expect(reg_mock).to receive(:each_key).and_return(no_args()) + expect(reg_mock).to receive(:each_key).and_return(no_args) expect(registry.has_subkeys?(key_path)).to eq(false) end @@ -290,7 +290,7 @@ describe Chef::Win32::Registry do expect(registry).to receive(:key_exists!).with(key_path).and_return(true) expect(registry).to receive(:get_hive_and_key).with(key_path).and_return([hive_mock, key]) expect(hive_mock).to receive(:open).with(key, ::Win32::Registry::KEY_READ | registry.registry_system_architecture).and_yield(reg_mock) - expect(reg_mock).to receive(:any?).and_yield(no_args()) + expect(reg_mock).to receive(:any?).and_yield(no_args) registry.value_exists?(key_path, value1) == false end end @@ -305,7 +305,7 @@ describe Chef::Win32::Registry do expect(registry).to receive(:key_exists!).with(key_path).and_return(true) expect(registry).to receive(:get_hive_and_key).with(key_path).and_return([hive_mock, key]) expect(registry).to receive(:get_type_from_name).with(:string).and_return(1) - expect(reg_mock).to receive(:each).with(no_args()).and_yield("one", 1, "1") + expect(reg_mock).to receive(:each).with(no_args).and_yield("one", 1, "1") expect(hive_mock).to receive(:open).with(key, ::Win32::Registry::KEY_READ | registry.registry_system_architecture).and_yield(reg_mock) expect(registry.data_exists?(key_path, value1)).to eq(true) end @@ -315,7 +315,7 @@ describe Chef::Win32::Registry do expect(registry).to receive(:get_hive_and_key).with(key_path).and_return([hive_mock, key]) expect(hive_mock).to receive(:open).with(key, ::Win32::Registry::KEY_READ | registry.registry_system_architecture).and_yield(reg_mock) expect(registry).to receive(:get_type_from_name).with(:string).and_return(1) - expect(reg_mock).to receive(:each).with(no_args()).and_yield("one", 1, "2") + expect(reg_mock).to receive(:each).with(no_args).and_yield("one", 1, "2") expect(registry.data_exists?(key_path, value1)).to eq(false) end end diff --git a/spec/unit/win32/security_spec.rb b/spec/unit/win32/security_spec.rb index 3c612aef10..efbb290adf 100644 --- a/spec/unit/win32/security_spec.rb +++ b/spec/unit/win32/security_spec.rb @@ -98,7 +98,8 @@ describe "Chef::Win32::Security", :windows_only do let(:token) do Chef::ReservedNames::Win32::Security.open_process_token( Chef::ReservedNames::Win32::Process.get_current_process, - token_rights) + token_rights + ) end it "raises error if GetTokenInformation fails" do |