diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2016-02-05 15:00:00 -0800 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2016-02-05 15:00:00 -0800 |
commit | 686113531d23f30e9973d659c456ae33eb9cff1f (patch) | |
tree | f225de7251a8b49b8d183dd168bab0a0addbe23f /spec/support/shared/unit | |
parent | d1cf34b059a16a81e0fc48de52ba29863bb41fe6 (diff) | |
download | chef-686113531d23f30e9973d659c456ae33eb9cff1f.tar.gz |
autofixing whitespace cops
4174 Style/SpaceInsideHashLiteralBraces
1860 Style/SpaceAroundOperators
1336 Style/SpaceInsideBlockBraces
1292 Style/AlignHash
997 Style/SpaceAfterComma
860 Style/SpaceAroundEqualsInParameterDefault
310 Style/EmptyLines
294 Style/IndentationConsistency
267 Style/TrailingWhitespace
238 Style/ExtraSpacing
212 Style/SpaceBeforeBlockBraces
166 Style/MultilineOperationIndentation
144 Style/TrailingBlankLines
120 Style/EmptyLineBetweenDefs
101 Style/IndentationWidth
82 Style/SpaceAroundBlockParameters
40 Style/EmptyLinesAroundMethodBody
29 Style/EmptyLinesAroundAccessModifier
1 Style/RescueEnsureAlignment
Diffstat (limited to 'spec/support/shared/unit')
-rw-r--r-- | spec/support/shared/unit/api_error_inspector.rb | 2 | ||||
-rw-r--r-- | spec/support/shared/unit/api_versioning.rb | 6 | ||||
-rw-r--r-- | spec/support/shared/unit/knife_shared.rb | 1 | ||||
-rw-r--r-- | spec/support/shared/unit/mock_shellout.rb | 3 | ||||
-rw-r--r-- | spec/support/shared/unit/platform_introspector.rb | 12 | ||||
-rw-r--r-- | spec/support/shared/unit/provider/file.rb | 28 | ||||
-rw-r--r-- | spec/support/shared/unit/provider/useradd_based_user_provider.rb | 37 | ||||
-rw-r--r-- | spec/support/shared/unit/resource/static_provider_resolution.rb | 5 | ||||
-rw-r--r-- | spec/support/shared/unit/script_resource.rb | 2 | ||||
-rw-r--r-- | spec/support/shared/unit/user_and_client_shared.rb | 7 | ||||
-rw-r--r-- | spec/support/shared/unit/windows_script_resource.rb | 1 |
11 files changed, 48 insertions, 56 deletions
diff --git a/spec/support/shared/unit/api_error_inspector.rb b/spec/support/shared/unit/api_error_inspector.rb index 6e074d38a7..45bfcc67da 100644 --- a/spec/support/shared/unit/api_error_inspector.rb +++ b/spec/support/shared/unit/api_error_inspector.rb @@ -16,8 +16,6 @@ # limitations under the License. # - - # == API Error Inspector Examples # These tests are work in progress. They exercise the code enough to ensure it # runs without error, but don't make assertions about the output. This is diff --git a/spec/support/shared/unit/api_versioning.rb b/spec/support/shared/unit/api_versioning.rb index 195b65ff5b..b61469a2d0 100644 --- a/spec/support/shared/unit/api_versioning.rb +++ b/spec/support/shared/unit/api_versioning.rb @@ -32,7 +32,7 @@ shared_examples_for "version handling" do end it "raises the original exception" do - expect{ object.send(method) }.to raise_error(exception_406) + expect { object.send(method) }.to raise_error(exception_406) end end # when the server does not support the min or max server API version that Chef::UserV1 supports end # version handling @@ -60,7 +60,7 @@ shared_examples_for "user and client reregister" do it "raises an error about only V0 being supported" do expect(object).to receive(:reregister_only_v0_supported_error_msg).with(max_version, min_version) - expect{ object.reregister }.to raise_error(Chef::Exceptions::OnlyApiVersion0SupportedForAction) + expect { object.reregister }.to raise_error(Chef::Exceptions::OnlyApiVersion0SupportedForAction) end end @@ -70,7 +70,7 @@ shared_examples_for "user and client reregister" do end it "raises the original error" do - expect{ object.reregister }.to raise_error(generic_exception) + expect { object.reregister }.to raise_error(generic_exception) end end end diff --git a/spec/support/shared/unit/knife_shared.rb b/spec/support/shared/unit/knife_shared.rb index 8f97cf60c0..0af05ffb80 100644 --- a/spec/support/shared/unit/knife_shared.rb +++ b/spec/support/shared/unit/knife_shared.rb @@ -16,7 +16,6 @@ # limitations under the License. # - shared_examples_for "mandatory field missing" do context "when field is nil" do before do diff --git a/spec/support/shared/unit/mock_shellout.rb b/spec/support/shared/unit/mock_shellout.rb index 05924e8a40..dac51be798 100644 --- a/spec/support/shared/unit/mock_shellout.rb +++ b/spec/support/shared/unit/mock_shellout.rb @@ -34,12 +34,15 @@ class MockShellout exitstatus: 0, }.merge(properties) end + def method_missing(name, *args) @properties[name.to_sym] end + def error? exitstatus != 0 end + def error! raise Mixlib::ShellOut::ShellCommandFailed, "Expected process to exit with 0, but received #{exitstatus}" if error? end diff --git a/spec/support/shared/unit/platform_introspector.rb b/spec/support/shared/unit/platform_introspector.rb index 30a2f61a70..2e6f74fb14 100644 --- a/spec/support/shared/unit/platform_introspector.rb +++ b/spec/support/shared/unit/platform_introspector.rb @@ -17,7 +17,6 @@ # limitations under the License. # - shared_examples_for "a platform introspector" do before(:each) do @platform_hash = {} @@ -27,12 +26,12 @@ shared_examples_for "a platform introspector" do "1.2.3" => "#{x}-1.2.3", } end - @platform_hash["debian"] = {["5", "6"] => "debian-5/6", "default" => "debian"} + @platform_hash["debian"] = { ["5", "6"] => "debian-5/6", "default" => "debian" } @platform_hash["default"] = "default" # The following @platform_hash keys are used for testing version constraints - @platform_hash["exact_match"] = { "1.2.3" => "exact", ">= 1.0" => "not exact"} + @platform_hash["exact_match"] = { "1.2.3" => "exact", ">= 1.0" => "not exact" } @platform_hash["multiple_matches"] = { "~> 2.3.4" => "matched ~> 2.3.4", ">= 2.3" => "matched >=2.3" } - @platform_hash["invalid_cookbook_version"] = {">= 21" => "Matches a single number"} + @platform_hash["invalid_cookbook_version"] = { ">= 21" => "Matches a single number" } @platform_hash["successful_matches"] = { "< 3.0" => "matched < 3.0", ">= 3.0" => "matched >= 3.0" } @platform_family_hash = { @@ -93,7 +92,7 @@ shared_examples_for "a platform introspector" do it "raises RuntimeError" do node.automatic_attrs[:platform] = "multiple_matches" node.automatic_attrs[:platform_version] = "2.3.4" - expect {platform_introspector.value_for_platform(@platform_hash)}.to raise_error(RuntimeError) + expect { platform_introspector.value_for_platform(@platform_hash) }.to raise_error(RuntimeError) end it "should not require .0 to match >= 21.0" do @@ -171,7 +170,7 @@ shared_examples_for "a platform introspector" do "centos" => { "default" => [ :restart, :reload, :status ] }, "redhat" => { "default" => [ :restart, :reload, :status ] }, "fedora" => { "default" => [ :restart, :reload, :status ] }, - "default" => { "default" => [:restart, :reload ] }} + "default" => { "default" => [:restart, :reload ] } } end it "returns the correct default for a given platform" do @@ -188,4 +187,3 @@ shared_examples_for "a platform introspector" do end end - diff --git a/spec/support/shared/unit/provider/file.rb b/spec/support/shared/unit/provider/file.rb index 8ed67eb5a8..5e5fc058e7 100644 --- a/spec/support/shared/unit/provider/file.rb +++ b/spec/support/shared/unit/provider/file.rb @@ -117,7 +117,7 @@ class BasicTempfile < ::File end def self.new(basename) - super(make_tmp_path(basename), File::RDWR|File::CREAT|File::EXCL, 0600) + super(make_tmp_path(basename), File::RDWR | File::CREAT | File::EXCL, 0600) end def unlink @@ -419,12 +419,12 @@ shared_examples_for Chef::Provider::File do [:create, :create_if_missing, :touch].each do |action| context "action #{action}" do it "raises EnclosingDirectoryDoesNotExist" do - expect {provider.run_action(action)}.to raise_error(Chef::Exceptions::EnclosingDirectoryDoesNotExist) + expect { provider.run_action(action) }.to raise_error(Chef::Exceptions::EnclosingDirectoryDoesNotExist) end it "does not raise an exception in why-run mode" do Chef::Config[:why_run] = true - expect {provider.run_action(action)}.not_to raise_error + expect { provider.run_action(action) }.not_to raise_error Chef::Config[:why_run] = false end end @@ -435,19 +435,19 @@ shared_examples_for Chef::Provider::File do before { setup_unwritable_file } it "action delete raises InsufficientPermissions" do - expect {provider.run_action(:delete)}.to raise_error(Chef::Exceptions::InsufficientPermissions) + expect { provider.run_action(:delete) }.to raise_error(Chef::Exceptions::InsufficientPermissions) end it "action delete also raises InsufficientPermissions in why-run mode" do Chef::Config[:why_run] = true - expect {provider.run_action(:delete)}.to raise_error(Chef::Exceptions::InsufficientPermissions) + expect { provider.run_action(:delete) }.to raise_error(Chef::Exceptions::InsufficientPermissions) Chef::Config[:why_run] = false end end end context "action create" do - it "should create the file, update its contents and then set the acls on the file" do + it "should create the file, update its contents and then set the acls on the file" do setup_missing_file expect(provider).to receive(:do_create_file) expect(provider).to receive(:do_contents_changes) @@ -476,7 +476,7 @@ shared_examples_for Chef::Provider::File do allow(File).to receive(:directory?).with("C:\\Windows\\system32/cmd.exe").and_return(false) provider.new_resource.verify windows? ? "REM" : "true" provider.new_resource.verify windows? ? "cmd.exe /c exit 1" : "false" - expect{provider.send(:do_validate_content)}.to raise_error(Chef::Exceptions::ValidationFailed) + expect { provider.send(:do_validate_content) }.to raise_error(Chef::Exceptions::ValidationFailed) end end end @@ -520,14 +520,14 @@ shared_examples_for Chef::Provider::File do let(:diff_for_reporting) { "+++\n---\n+foo\n-bar\n" } before do allow(provider).to receive(:contents_changed?).and_return(true) - diff = double("Diff", :for_output => ["+++","---","+foo","-bar"], + diff = double("Diff", :for_output => ["+++", "---", "+foo", "-bar"], :for_reporting => diff_for_reporting ) allow(diff).to receive(:diff).with(resource_path, tempfile_path).and_return(true) expect(provider).to receive(:diff).at_least(:once).and_return(diff) expect(provider).to receive(:checksum).with(tempfile_path).and_return(tempfile_sha256) allow(provider).to receive(:managing_content?).and_return(true) allow(provider).to receive(:checksum).with(resource_path).and_return(tempfile_sha256) - expect(resource).not_to receive(:checksum).with(tempfile_sha256) # do not mutate the new resource + expect(resource).not_to receive(:checksum).with(tempfile_sha256) # do not mutate the new resource expect(provider.deployment_strategy).to receive(:deploy).with(tempfile_path, normalized_path) end context "when the file was created" do @@ -549,7 +549,7 @@ shared_examples_for Chef::Provider::File do end context "when the file was not created" do before do - allow(provider).to receive(:do_backup) # stub do_backup + allow(provider).to receive(:do_backup) # stub do_backup expect(provider).to receive(:needs_creating?).at_least(:once).and_return(false) end @@ -570,7 +570,7 @@ shared_examples_for Chef::Provider::File do end end - it "does nothing when the contents have not changed" do + it "does nothing when the contents have not changed" do allow(provider).to receive(:contents_changed?).and_return(false) expect(provider).not_to receive(:diff) provider.send(:do_contents_changes) @@ -580,20 +580,20 @@ shared_examples_for Chef::Provider::File do it "does nothing when there is no content to deploy (tempfile returned from contents is nil)" do expect(provider.send(:content)).to receive(:tempfile).at_least(:once).and_return(nil) expect(provider).not_to receive(:diff) - expect{ provider.send(:do_contents_changes) }.not_to raise_error + expect { provider.send(:do_contents_changes) }.not_to raise_error end it "raises an exception when the content object returns a tempfile with a nil path" do tempfile = double("Tempfile", :path => nil) expect(provider.send(:content)).to receive(:tempfile).at_least(:once).and_return(tempfile) - expect{ provider.send(:do_contents_changes) }.to raise_error + expect { provider.send(:do_contents_changes) }.to raise_error end it "raises an exception when the content object returns a tempfile that does not exist" do tempfile = double("Tempfile", :path => "/tmp/foo-bar-baz") expect(provider.send(:content)).to receive(:tempfile).at_least(:once).and_return(tempfile) expect(File).to receive(:exists?).with("/tmp/foo-bar-baz").and_return(false) - expect{ provider.send(:do_contents_changes) }.to raise_error + expect { provider.send(:do_contents_changes) }.to raise_error end end diff --git a/spec/support/shared/unit/provider/useradd_based_user_provider.rb b/spec/support/shared/unit/provider/useradd_based_user_provider.rb index ccc6e3fec6..6694aa346c 100644 --- a/spec/support/shared/unit/provider/useradd_based_user_provider.rb +++ b/spec/support/shared/unit/provider/useradd_based_user_provider.rb @@ -46,7 +46,7 @@ shared_examples_for "a useradd-based user provider" do |supported_useradd_option @current_resource.manage_home false @current_resource.force false @current_resource.non_unique false - @current_resource.supports({:manage_home => false, :non_unique => false}) + @current_resource.supports({ :manage_home => false, :non_unique => false }) end describe "when setting option" do @@ -64,8 +64,8 @@ shared_examples_for "a useradd-based user provider" do |supported_useradd_option end it "should set the option for #{attribute} if the new resources #{attribute} is not nil, without homedir management" do - allow(@new_resource).to receive(:supports).and_return({:manage_home => false, - :non_unique => false}) + allow(@new_resource).to receive(:supports).and_return({ :manage_home => false, + :non_unique => false }) allow(@new_resource).to receive(attribute).and_return("hola") expect(provider.universal_options).to eql([option, "hola"]) end @@ -81,7 +81,7 @@ shared_examples_for "a useradd-based user provider" do |supported_useradd_option it "should combine all the possible options" do combined_opts = [] - supported_useradd_options.sort{ |a,b| a[0] <=> b[0] }.each do |attribute, option| + supported_useradd_options.sort { |a, b| a[0] <=> b[0] }.each do |attribute, option| allow(@new_resource).to receive(attribute).and_return("hola") combined_opts << option << "hola" end @@ -103,8 +103,8 @@ shared_examples_for "a useradd-based user provider" do |supported_useradd_option describe "when the resource has a different home directory and supports home directory management" do before do allow(@new_resource).to receive(:home).and_return("/wowaweea") - allow(@new_resource).to receive(:supports).and_return({:manage_home => true, - :non_unique => false}) + allow(@new_resource).to receive(:supports).and_return({ :manage_home => true, + :non_unique => false }) end it "should set -m -d /homedir" do @@ -128,8 +128,8 @@ shared_examples_for "a useradd-based user provider" do |supported_useradd_option describe "when the resource supports non_unique ids" do before do - allow(@new_resource).to receive(:supports).and_return({:manage_home => false, - :non_unique => true}) + allow(@new_resource).to receive(:supports).and_return({ :manage_home => false, + :non_unique => true }) end it "should set -m -o" do @@ -161,7 +161,7 @@ shared_examples_for "a useradd-based user provider" do |supported_useradd_option it "runs useradd with the computed command options" do command = ["useradd", - "-c", "Adam Jacob", + "-c", "Adam Jacob", "-g", "23" ] command.concat(["-p", "abracadabra"]) if supported_useradd_options.key?("password") command.concat([ "-s", "/usr/bin/zsh", @@ -247,14 +247,14 @@ shared_examples_for "a useradd-based user provider" do |supported_useradd_option it "should run userdel with the new resources user name and -r if manage_home is true" do @new_resource.supports({ :manage_home => true, - :non_unique => false}) + :non_unique => false }) expect(provider).to receive(:shell_out!).with("userdel", "-r", @new_resource.username).and_return(true) provider.remove_user end it "should run userdel with the new resources user name if non_unique is true" do @new_resource.supports({ :manage_home => false, - :non_unique => true}) + :non_unique => true }) expect(provider).to receive(:shell_out!).with("userdel", @new_resource.username).and_return(true) provider.remove_user end @@ -285,7 +285,7 @@ shared_examples_for "a useradd-based user provider" do |supported_useradd_option it "should return false if status begins with P" do expect(provider).to receive(:shell_out!). - with("passwd", "-S", @new_resource.username, {:returns=>[0, 1]}). + with("passwd", "-S", @new_resource.username, { :returns => [0, 1] }). and_return(passwd_s_status) expect(provider.check_lock).to eql(false) end @@ -293,7 +293,7 @@ shared_examples_for "a useradd-based user provider" do |supported_useradd_option it "should return false if status begins with N" do @stdout = "root N" expect(provider).to receive(:shell_out!). - with("passwd", "-S", @new_resource.username, {:returns=>[0, 1]}). + with("passwd", "-S", @new_resource.username, { :returns => [0, 1] }). and_return(passwd_s_status) expect(provider.check_lock).to eql(false) end @@ -301,7 +301,7 @@ shared_examples_for "a useradd-based user provider" do |supported_useradd_option it "should return true if status begins with L" do @stdout = "root L" expect(provider).to receive(:shell_out!). - with("passwd", "-S", @new_resource.username, {:returns=>[0, 1]}). + with("passwd", "-S", @new_resource.username, { :returns => [0, 1] }). and_return(passwd_s_status) expect(provider.check_lock).to eql(true) end @@ -309,7 +309,7 @@ shared_examples_for "a useradd-based user provider" do |supported_useradd_option it "should raise a Chef::Exceptions::User if passwd -S fails on anything other than redhat/centos" do @node.automatic_attrs[:platform] = "ubuntu" expect(provider).to receive(:shell_out!). - with("passwd", "-S", @new_resource.username, {:returns=>[0, 1]}). + with("passwd", "-S", @new_resource.username, { :returns => [0, 1] }). and_return(passwd_s_status) expect(passwd_s_status).to receive(:exitstatus).and_return(1) expect { provider.check_lock }.to raise_error(Chef::Exceptions::User) @@ -320,7 +320,7 @@ shared_examples_for "a useradd-based user provider" do |supported_useradd_option @node.automatic_attrs[:platform] = os expect(passwd_s_status).to receive(:exitstatus).and_return(1) expect(provider).to receive(:shell_out!). - with("passwd", "-S", @new_resource.username, {:returns=>[0, 1]}). + with("passwd", "-S", @new_resource.username, { :returns => [0, 1] }). and_return(passwd_s_status) rpm_status = double("Mixlib::ShellOut command", :exitstatus => 0, :stdout => "passwd-0.73-1\n", :stderr => "") expect(provider).to receive(:shell_out!).with("rpm -q passwd").and_return(rpm_status) @@ -331,7 +331,7 @@ shared_examples_for "a useradd-based user provider" do |supported_useradd_option @node.automatic_attrs[:platform] = os expect(passwd_s_status).to receive(:exitstatus).and_return(1) expect(provider).to receive(:shell_out!). - with("passwd", "-S", @new_resource.username, {:returns=>[0, 1]}). + with("passwd", "-S", @new_resource.username, { :returns => [0, 1] }). and_return(passwd_s_status) rpm_status = double("Mixlib::ShellOut command", :exitstatus => 0, :stdout => "passwd-0.73-2\n", :stderr => "") expect(provider).to receive(:shell_out!).with("rpm -q passwd").and_return(rpm_status) @@ -349,7 +349,7 @@ shared_examples_for "a useradd-based user provider" do |supported_useradd_option before do passwd_status = double("Mixlib::ShellOut command", :exitstatus => 0, :stdout => "", :stderr => "passwd: user 'chef-test' does not exist\n") expect(provider).to receive(:shell_out!). - with("passwd", "-S", @new_resource.username, {:returns=>[0, 1]}). + with("passwd", "-S", @new_resource.username, { :returns => [0, 1] }). and_return(passwd_status) Chef::Config[:why_run] = true end @@ -431,4 +431,3 @@ shared_examples_for "a useradd-based user provider" do |supported_useradd_option end end end - diff --git a/spec/support/shared/unit/resource/static_provider_resolution.rb b/spec/support/shared/unit/resource/static_provider_resolution.rb index 56ed49e00d..4ae5d4576f 100644 --- a/spec/support/shared/unit/resource/static_provider_resolution.rb +++ b/spec/support/shared/unit/resource/static_provider_resolution.rb @@ -16,8 +16,6 @@ # limitations under the License. # - - # # This is for typical "static" provider resolution which maps resources onto # providers based only on the node data. Its not really 'static' because it @@ -25,7 +23,7 @@ # a static mapping for the node (unlike the service resource which is # complicated). # -def static_provider_resolution(opts={}) +def static_provider_resolution(opts = {}) action = opts[:action] provider_class = opts[:provider] resource_class = opts[:resource] @@ -63,4 +61,3 @@ def static_provider_resolution(opts={}) end end end - diff --git a/spec/support/shared/unit/script_resource.rb b/spec/support/shared/unit/script_resource.rb index ba33d69a59..a80ab81fb9 100644 --- a/spec/support/shared/unit/script_resource.rb +++ b/spec/support/shared/unit/script_resource.rb @@ -74,7 +74,7 @@ shared_examples_for "a script resource" do it "inherits exactly the :cwd, :environment, :group, :path, :user, and :umask attributes from a parent resource class" do inherited_difference = Chef::Resource::Script.guard_inherited_attributes - - [:cwd, :environment, :group, :path, :user, :umask ] + [:cwd, :environment, :group, :path, :user, :umask ] expect(inherited_difference).to eq([]) end diff --git a/spec/support/shared/unit/user_and_client_shared.rb b/spec/support/shared/unit/user_and_client_shared.rb index c8208c149b..e3862943bc 100644 --- a/spec/support/shared/unit/user_and_client_shared.rb +++ b/spec/support/shared/unit/user_and_client_shared.rb @@ -27,7 +27,7 @@ shared_examples_for "user or client create" do it "creates a new object via the API with a public_key when it exists" do object.public_key "some_public_key" - expect(rest_v1).to receive(:post).with(url, payload.merge({:public_key => "some_public_key"})).and_return({}) + expect(rest_v1).to receive(:post).with(url, payload.merge({ :public_key => "some_public_key" })).and_return({}) object.create end @@ -49,7 +49,7 @@ shared_examples_for "user or client create" do end it "creates a new object via the API with create_key" do - expect(rest_v1).to receive(:post).with(url, payload.merge({:create_key => true})).and_return({}) + expect(rest_v1).to receive(:post).with(url, payload.merge({ :create_key => true })).and_return({}) object.create end end @@ -104,7 +104,7 @@ shared_examples_for "user or client create" do it "creates a new object via the API with a public_key when it exists" do object.public_key "some_public_key" - expect(rest_v0).to receive(:post).with(url, payload.merge({:public_key => "some_public_key"})).and_return({}) + expect(rest_v0).to receive(:post).with(url, payload.merge({ :public_key => "some_public_key" })).and_return({}) object.create end @@ -112,4 +112,3 @@ shared_examples_for "user or client create" do end # when server API V1 is not valid on the Chef Server receiving the request end # user or client create - diff --git a/spec/support/shared/unit/windows_script_resource.rb b/spec/support/shared/unit/windows_script_resource.rb index 1dcbae76aa..2dc0229c90 100644 --- a/spec/support/shared/unit/windows_script_resource.rb +++ b/spec/support/shared/unit/windows_script_resource.rb @@ -78,4 +78,3 @@ shared_examples_for "a Windows script resource" do end end - |