diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2016-08-17 12:15:26 -0700 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2016-08-17 13:25:02 -0700 |
commit | a0c32511bc6634538374ca4b433032b8acd05f96 (patch) | |
tree | 15c7cfbd0d773488ab814e7c24f0c58505c9134b /spec/unit | |
parent | 3d0379a2ad531a0b3db5ed2827bf30ef07b26100 (diff) | |
download | chef-a0c32511bc6634538374ca4b433032b8acd05f96.tar.gz |
fix Style/BlockDelimiters, Style/MultilineBlockLayout and 0.42.0 engine upgrade
Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
Diffstat (limited to 'spec/unit')
113 files changed, 992 insertions, 936 deletions
diff --git a/spec/unit/api_client_v1_spec.rb b/spec/unit/api_client_v1_spec.rb index 8c90d5ad38..9c643fa492 100644 --- a/spec/unit/api_client_v1_spec.rb +++ b/spec/unit/api_client_v1_spec.rb @@ -326,13 +326,13 @@ describe Chef::ApiClientV1 do describe "Versioned API Interactions" do let(:response_406) { OpenStruct.new(:code => "406") } let(:exception_406) { Net::HTTPServerException.new("406 Not Acceptable", response_406) } - let(:payload) { + let(:payload) do { :name => "some_name", :validator => true, :admin => true, } - } + end before do @client = Chef::ApiClientV1.new diff --git a/spec/unit/application_spec.rb b/spec/unit/application_spec.rb index 8ab6e13204..867cd3f9c2 100644 --- a/spec/unit/application_spec.rb +++ b/spec/unit/application_spec.rb @@ -361,7 +361,7 @@ describe Chef::Application do end end - context 'when called with an Array-like argument (#size)' do + context "when called with an Array-like argument (#size)" do before do allow(app).to receive(:fork_chef_client).and_return(true) allow(app).to receive(:run_with_graceful_exit_option).and_return(true) diff --git a/spec/unit/audit/audit_event_proxy_spec.rb b/spec/unit/audit/audit_event_proxy_spec.rb index 2496aef3e7..820e670f1c 100644 --- a/spec/unit/audit/audit_event_proxy_spec.rb +++ b/spec/unit/audit/audit_event_proxy_spec.rb @@ -34,8 +34,9 @@ describe Chef::Audit::AuditEventProxy do describe "#example_group_started" do let(:description) { "poots" } - let(:group) { double("ExampleGroup", :parent_groups => parents, - :description => description) } + let(:group) do + double("ExampleGroup", :parent_groups => parents, + :description => description) end let(:notification) { double("Notification", :group => group) } context "when notified from a top-level example group" do @@ -120,35 +121,36 @@ describe Chef::Audit::AuditEventProxy do let(:examples) { [example] } - let(:example) { double("Example", :metadata => metadata, - :description => example_description, - :full_description => full_description, :exception => nil) } + let(:example) do + double("Example", :metadata => metadata, + :description => example_description, + :full_description => full_description, :exception => nil) end - let(:metadata) { + let(:metadata) do { :described_class => described_class, :example_group => example_group, :line_number => line, } - } + end - let(:example_group) { + let(:example_group) do { :description => group_description, :parent_example_group => parent_group, } - } + end - let(:parent_group) { + let(:parent_group) do { :description => control_group_name, :parent_example_group => nil, } - } + end let(:line) { 27 } - let(:control_data) { + let(:control_data) do { :name => example_description, :desc => full_description, @@ -157,7 +159,7 @@ describe Chef::Audit::AuditEventProxy do :context => context, :line_number => line, } - } + end shared_examples "built control" do @@ -218,12 +220,14 @@ describe Chef::Audit::AuditEventProxy do let(:control_group_name) { "application ports" } let(:group_description) { "#{resource_type} #{resource_name}" } let(:example_description) { "should not be listening" } - let(:full_description) { [control_group_name, group_description, - example_description].join(" ") } + let(:full_description) do + [control_group_name, group_description, + example_description].join(" ") end # Metadata fields - let(:described_class) { double("Serverspec::Type::Port", - :class => "Serverspec::Type::Port", :name => resource_name) } + let(:described_class) do + double("Serverspec::Type::Port", + :class => "Serverspec::Type::Port", :name => resource_name) end # Control data fields let(:resource_type) { "Port" } @@ -246,8 +250,9 @@ describe Chef::Audit::AuditEventProxy do let(:control_group_name) { "application ports" } let(:group_description) { "port 111" } let(:example_description) { "is not listening" } - let(:full_description) { [control_group_name, group_description, - example_description].join(" ") } + let(:full_description) do + [control_group_name, group_description, + example_description].join(" ") end # Metadata fields let(:described_class) { nil } @@ -276,27 +281,29 @@ describe Chef::Audit::AuditEventProxy do let(:outer_group_description) { "File \"tmp/audit\"" } let(:group_description) { "#{resource_type} #{resource_name}" } let(:example_description) { "is a file" } - let(:full_description) { [control_group_name, outer_group_description, - group_description, example_description].join(" ") } + let(:full_description) do + [control_group_name, outer_group_description, + group_description, example_description].join(" ") end # Metadata parts - let(:described_class) { double("Serverspec::Type::File", - :class => "Serverspec::Type::File", :name => resource_name) } + let(:described_class) do + double("Serverspec::Type::File", + :class => "Serverspec::Type::File", :name => resource_name) end # Example group parts - let(:parent_group) { + let(:parent_group) do { :description => outer_group_description, :parent_example_group => control_group, } - } + end - let(:control_group) { + let(:control_group) do { :description => control_group_name, :parent_example_group => nil, } - } + end # Control data parts let(:resource_type) { "File" } diff --git a/spec/unit/audit/audit_reporter_spec.rb b/spec/unit/audit/audit_reporter_spec.rb index 1db56a550e..cf916266d8 100644 --- a/spec/unit/audit/audit_reporter_spec.rb +++ b/spec/unit/audit/audit_reporter_spec.rb @@ -28,8 +28,9 @@ describe Chef::Audit::AuditReporter do let(:run_id) { 0 } let(:start_time) { Time.new(2014, 12, 3, 9, 31, 05, "-08:00") } let(:end_time) { Time.new(2014, 12, 3, 9, 36, 14, "-08:00") } - let(:run_status) { instance_double(Chef::RunStatus, :node => node, :run_id => run_id, - :start_time => start_time, :end_time => end_time) } + let(:run_status) do + instance_double(Chef::RunStatus, :node => node, :run_id => run_id, + :start_time => start_time, :end_time => end_time) end describe "#audit_phase_start" do @@ -85,9 +86,10 @@ describe Chef::Audit::AuditReporter do context "when audit phase failed" do - let(:audit_error) { double("AuditError", :class => "Chef::Exceptions::AuditError", - :message => "Audit phase failed with error message: derpderpderp", - :backtrace => ["/path/recipe.rb:57", "/path/library.rb:106"]) } + let(:audit_error) do + double("AuditError", :class => "Chef::Exceptions::AuditError", + :message => "Audit phase failed with error message: derpderpderp", + :backtrace => ["/path/recipe.rb:57", "/path/library.rb:106"]) end before do reporter.instance_variable_set(:@audit_phase_error, audit_error) @@ -233,13 +235,15 @@ EOM let(:audit_data) { Chef::Audit::AuditData.new(node.name, run_id) } let(:run_data) { audit_data.to_hash } - let(:audit_error) { double("AuditError", :class => "Chef::Exceptions::AuditError", - :message => "Audit phase failed with error message: derpderpderp", - :backtrace => ["/path/recipe.rb:57", "/path/library.rb:106"]) } + let(:audit_error) do + double("AuditError", :class => "Chef::Exceptions::AuditError", + :message => "Audit phase failed with error message: derpderpderp", + :backtrace => ["/path/recipe.rb:57", "/path/library.rb:106"]) end - let(:run_error) { double("RunError", :class => "Chef::Exceptions::RunError", - :message => "This error shouldn't be reported.", - :backtrace => ["fix it", "fix it", "fix it"]) } + let(:run_error) do + double("RunError", :class => "Chef::Exceptions::RunError", + :message => "This error shouldn't be reported.", + :backtrace => ["fix it", "fix it", "fix it"]) end before do allow(reporter).to receive(:auditing_enabled?).and_return(true) @@ -276,23 +280,27 @@ EOM shared_context "audit data" do - let(:control_group_foo) { instance_double(Chef::Audit::ControlGroupData, - :metadata => double("foo metadata")) } - let(:control_group_bar) { instance_double(Chef::Audit::ControlGroupData, - :metadata => double("bar metadata")) } + let(:control_group_foo) do + instance_double(Chef::Audit::ControlGroupData, + :metadata => double("foo metadata")) end + let(:control_group_bar) do + instance_double(Chef::Audit::ControlGroupData, + :metadata => double("bar metadata")) end - let(:ordered_control_groups) { + let(:ordered_control_groups) do { "foo" => control_group_foo, "bar" => control_group_bar, } - } + end - let(:audit_data) { instance_double(Chef::Audit::AuditData, - :add_control_group => true) } + let(:audit_data) do + instance_double(Chef::Audit::AuditData, + :add_control_group => true) end - let(:run_context) { instance_double(Chef::RunContext, - :audits => ordered_control_groups) } + let(:run_context) do + instance_double(Chef::RunContext, + :audits => ordered_control_groups) end before do allow(reporter).to receive(:ordered_control_groups).and_return(ordered_control_groups) @@ -340,8 +348,9 @@ EOM include_context "audit data" let(:name) { "bat" } - let(:control_group) { instance_double(Chef::Audit::ControlGroupData, - :metadata => double("metadata")) } + let(:control_group) do + instance_double(Chef::Audit::ControlGroupData, + :metadata => double("metadata")) end before do allow(Chef::Audit::ControlGroupData).to receive(:new). diff --git a/spec/unit/audit/control_group_data_spec.rb b/spec/unit/audit/control_group_data_spec.rb index a7c8850350..ea4ac260f9 100644 --- a/spec/unit/audit/control_group_data_spec.rb +++ b/spec/unit/audit/control_group_data_spec.rb @@ -122,9 +122,10 @@ describe Chef::Audit::ControlData do let(:context) { nil } let(:line_number) { 27 } - let(:control_data) { described_class.new(name: name, - resource_type: resource_type, resource_name: resource_name, - context: context, line_number: line_number) } + let(:control_data) do + described_class.new(name: name, + resource_type: resource_type, resource_name: resource_name, + context: context, line_number: line_number) end describe "#to_hash" do @@ -171,7 +172,7 @@ describe Chef::Audit::ControlGroupData do let(:context) { nil } let(:line_number) { 0 } - let(:control_data) { + let(:control_data) do { :name => name, :resource_type => resource_type, @@ -179,16 +180,17 @@ describe Chef::Audit::ControlGroupData do :context => context, :line_number => line_number, } - } + end end shared_context "control" do include_context "control data" - let(:control) { Chef::Audit::ControlData.new(name: name, - resource_type: resource_type, resource_name: resource_name, - context: context, line_number: line_number) } + let(:control) do + Chef::Audit::ControlData.new(name: name, + resource_type: resource_type, resource_name: resource_name, + context: context, line_number: line_number) end before do allow(Chef::Audit::ControlData).to receive(:new). @@ -436,15 +438,18 @@ describe Chef::Audit::ControlGroupData do let(:control_hash_2) { { :line_number => 13 } } let(:control_hash_3) { { :line_number => 35 } } - let(:control_1) { double("control 1", + let(:control_1) do + double("control 1", :line_number => control_hash_1[:line_number], - :to_hash => control_hash_1) } - let(:control_2) { double("control 2", + :to_hash => control_hash_1) end + let(:control_2) do + double("control 2", :line_number => control_hash_2[:line_number], - :to_hash => control_hash_2) } - let(:control_3) { double("control 3", + :to_hash => control_hash_2) end + let(:control_3) do + double("control 3", :line_number => control_hash_3[:line_number], - :to_hash => control_hash_3) } + :to_hash => control_hash_3) end let(:control_list) { [control_1, control_2, control_3] } let(:ordered_control_hashes) { [control_hash_2, control_hash_1, control_hash_3] } diff --git a/spec/unit/chef_class_spec.rb b/spec/unit/chef_class_spec.rb index 3c8411ef2a..21987c01ab 100644 --- a/spec/unit/chef_class_spec.rb +++ b/spec/unit/chef_class_spec.rb @@ -85,7 +85,7 @@ describe "Chef class" do end end - context '#event_handler' do + context "#event_handler" do it "adds a new handler" do x = 1 Chef.event_handler do diff --git a/spec/unit/chef_fs/data_handler/group_handler_spec.rb b/spec/unit/chef_fs/data_handler/group_handler_spec.rb index 849bc84f92..ac0252162f 100644 --- a/spec/unit/chef_fs/data_handler/group_handler_spec.rb +++ b/spec/unit/chef_fs/data_handler/group_handler_spec.rb @@ -29,7 +29,7 @@ class TestEntry < Mash end describe Chef::ChefFS::DataHandler::GroupDataHandler do - describe '#normalize_for_post' do + describe "#normalize_for_post" do let(:entry) do TestEntry.new("workers.json", "hive") end diff --git a/spec/unit/chef_fs/diff_spec.rb b/spec/unit/chef_fs/diff_spec.rb index c1c9050101..d946fcb9e7 100644 --- a/spec/unit/chef_fs/diff_spec.rb +++ b/spec/unit/chef_fs/diff_spec.rb @@ -32,7 +32,7 @@ describe "diff", :uses_diff => true do include FileSystemSupport context "with two filesystems with all types of difference" do - let(:a) { + let(:a) do memory_fs("a", { :both_dirs => { :sub_both_dirs => { :subsub => nil }, @@ -58,8 +58,8 @@ describe "diff", :uses_diff => true do :dir_in_a_file_in_b => {}, :file_in_a_dir_in_b => nil, }, /cannot_be_in_a/) - } - let(:b) { + end + let(:b) do memory_fs("b", { :both_dirs => { :sub_both_dirs => { :subsub => nil }, @@ -85,7 +85,7 @@ describe "diff", :uses_diff => true do :dir_in_a_file_in_b => nil, :file_in_a_dir_in_b => {}, }, /cannot_be_in_b/) - } + end it "Chef::ChefFS::CommandLine.diff_print(/)" do results = [] Chef::ChefFS::CommandLine.diff_print(pattern("/"), a, b, nil, nil) do |diff| diff --git a/spec/unit/chef_fs/file_system/operation_failed_error_spec.rb b/spec/unit/chef_fs/file_system/operation_failed_error_spec.rb index b0b5a547cd..7f3eb6efe2 100644 --- a/spec/unit/chef_fs/file_system/operation_failed_error_spec.rb +++ b/spec/unit/chef_fs/file_system/operation_failed_error_spec.rb @@ -30,17 +30,17 @@ describe Chef::ChefFS::FileSystem::OperationFailedError do allow(@response).to receive(:code).and_return("400") allow(@response).to receive(:body).and_return(response_body) exception = Net::HTTPServerException.new("(exception) unauthorized", @response) - expect { + expect do raise Chef::ChefFS::FileSystem::OperationFailedError.new(:write, self, exception), error_message - }.to raise_error(Chef::ChefFS::FileSystem::OperationFailedError, "#{error_message} cause: #{response_body}") + end.to raise_error(Chef::ChefFS::FileSystem::OperationFailedError, "#{error_message} cause: #{response_body}") end end context "does not have a cause attribute" do it "does not include error cause" do - expect { + expect do raise Chef::ChefFS::FileSystem::OperationFailedError.new(:write, self), error_message - }.to raise_error(Chef::ChefFS::FileSystem::OperationFailedError, error_message) + end.to raise_error(Chef::ChefFS::FileSystem::OperationFailedError, error_message) end end end diff --git a/spec/unit/chef_fs/file_system_spec.rb b/spec/unit/chef_fs/file_system_spec.rb index 429e039dda..5c74729557 100644 --- a/spec/unit/chef_fs/file_system_spec.rb +++ b/spec/unit/chef_fs/file_system_spec.rb @@ -55,7 +55,7 @@ describe Chef::ChefFS::FileSystem do end context "with a populated filesystem" do - let(:fs) { + let(:fs) do memory_fs("", { :a => { :aa => { @@ -69,7 +69,7 @@ describe Chef::ChefFS::FileSystem do :x => "", :y => {}, }) - } + end context "list" do it "/**" do list_should_yield_paths(fs, "/**", "/", "/a", "/x", "/y", "/a/aa", "/a/aa/c", "/a/aa/zz", "/a/ab", "/a/ab/c") diff --git a/spec/unit/cookbook/metadata_spec.rb b/spec/unit/cookbook/metadata_spec.rb index c6d7e41283..27666eb338 100644 --- a/spec/unit/cookbook/metadata_spec.rb +++ b/spec/unit/cookbook/metadata_spec.rb @@ -461,21 +461,21 @@ describe Chef::Cookbook::Metadata do expect(metadata.grouping("/db/mysql/databases/tuning", group)).to eq(group) end it "should not accept anything but a string for display_name" do - expect { + expect do metadata.grouping("db/mysql/databases", :title => "foo") - }.not_to raise_error - expect { + end.not_to raise_error + expect do metadata.grouping("db/mysql/databases", :title => Hash.new) - }.to raise_error(ArgumentError) + end.to raise_error(ArgumentError) end it "should not accept anything but a string for the description" do - expect { + expect do metadata.grouping("db/mysql/databases", :description => "foo") - }.not_to raise_error - expect { + end.not_to raise_error + expect do metadata.grouping("db/mysql/databases", :description => Hash.new) - }.to raise_error(ArgumentError) + end.to raise_error(ArgumentError) end end @@ -498,63 +498,63 @@ describe Chef::Cookbook::Metadata do end it "should not accept anything but a string for display_name" do - expect { + expect do metadata.attribute("db/mysql/databases", :display_name => "foo") - }.not_to raise_error - expect { + end.not_to raise_error + expect do metadata.attribute("db/mysql/databases", :display_name => Hash.new) - }.to raise_error(ArgumentError) + end.to raise_error(ArgumentError) end it "should not accept anything but a string for the description" do - expect { + expect do metadata.attribute("db/mysql/databases", :description => "foo") - }.not_to raise_error - expect { + end.not_to raise_error + expect do metadata.attribute("db/mysql/databases", :description => Hash.new) - }.to raise_error(ArgumentError) + end.to raise_error(ArgumentError) end it "should not accept anything but a string for the source_url" do - expect { + expect do metadata.attribute("db/mysql/databases", :source_url => "foo") - }.not_to raise_error - expect { + end.not_to raise_error + expect do metadata.attribute("db/mysql/databases", :source_url => Hash.new) - }.to raise_error(ArgumentError) + end.to raise_error(ArgumentError) end it "should not accept anything but a string for the issues_url" do - expect { + expect do metadata.attribute("db/mysql/databases", :issues_url => "foo") - }.not_to raise_error - expect { + end.not_to raise_error + expect do metadata.attribute("db/mysql/databases", :issues_url => Hash.new) - }.to raise_error(ArgumentError) + end.to raise_error(ArgumentError) end it "should not accept anything but true or false for the privacy flag" do - expect { + expect do metadata.attribute("db/mysql/databases", :privacy => true) - }.not_to raise_error - expect { + end.not_to raise_error + expect do metadata.attribute("db/mysql/databases", :privacy => false) - }.not_to raise_error - expect { + end.not_to raise_error + expect do metadata.attribute("db/mysql/databases", :privacy => "true") - }.to raise_error(ArgumentError) + end.to raise_error(ArgumentError) end it "should not accept anything but an array of strings for choice" do - expect { + expect do metadata.attribute("db/mysql/databases", :choice => %w{dedicated shared}) - }.not_to raise_error - expect { + end.not_to raise_error + expect do metadata.attribute("db/mysql/databases", :choice => [10, "shared"]) - }.to raise_error(ArgumentError) - expect { + end.to raise_error(ArgumentError) + expect do metadata.attribute("db/mysql/databases", :choice => Hash.new) - }.to raise_error(ArgumentError) + end.to raise_error(ArgumentError) end it "should set choice to empty array by default" do @@ -563,15 +563,15 @@ describe Chef::Cookbook::Metadata do end it "should let calculated be true or false" do - expect { + expect do metadata.attribute("db/mysql/databases", :calculated => true) - }.not_to raise_error - expect { + end.not_to raise_error + expect do metadata.attribute("db/mysql/databases", :calculated => false) - }.not_to raise_error - expect { + end.not_to raise_error + expect do metadata.attribute("db/mysql/databases", :calculated => Hash.new) - }.to raise_error(ArgumentError) + end.to raise_error(ArgumentError) end it "should set calculated to false by default" do @@ -580,55 +580,55 @@ describe Chef::Cookbook::Metadata do end it "accepts String for the attribute type" do - expect { + expect do metadata.attribute("db/mysql/databases", :type => "string") - }.not_to raise_error + end.not_to raise_error end it "accepts Array for the attribute type" do - expect { + expect do metadata.attribute("db/mysql/databases", :type => "array") - }.not_to raise_error - expect { + end.not_to raise_error + expect do metadata.attribute("db/mysql/databases", :type => Array.new) - }.to raise_error(ArgumentError) + end.to raise_error(ArgumentError) end it "accepts symbol for the attribute type" do - expect { + expect do metadata.attribute("db/mysql/databases", :type => "symbol") - }.not_to raise_error + end.not_to raise_error end it "should let type be hash (backwards compatibility only)" do - expect { + expect do metadata.attribute("db/mysql/databases", :type => "hash") - }.not_to raise_error + end.not_to raise_error end it "should let required be required, recommended or optional" do - expect { + expect do metadata.attribute("db/mysql/databases", :required => "required") - }.not_to raise_error - expect { + end.not_to raise_error + expect do metadata.attribute("db/mysql/databases", :required => "recommended") - }.not_to raise_error - expect { + end.not_to raise_error + expect do metadata.attribute("db/mysql/databases", :required => "optional") - }.not_to raise_error + end.not_to raise_error end it "should convert required true to required" do - expect { + expect do metadata.attribute("db/mysql/databases", :required => true) - }.not_to raise_error + end.not_to raise_error #attrib = metadata.attributes["db/mysql/databases"][:required].should == "required" end it "should convert required false to optional" do - expect { + expect do metadata.attribute("db/mysql/databases", :required => false) - }.not_to raise_error + end.not_to raise_error #attrib = metadata.attributes["db/mysql/databases"][:required].should == "optional" end @@ -638,12 +638,12 @@ describe Chef::Cookbook::Metadata do end it "should make sure recipes is an array" do - expect { + expect do metadata.attribute("db/mysql/databases", :recipes => []) - }.not_to raise_error - expect { + end.not_to raise_error + expect do metadata.attribute("db/mysql/databases", :required => Hash.new) - }.to raise_error(ArgumentError) + end.to raise_error(ArgumentError) end it "should set recipes to an empty array by default" do @@ -652,24 +652,24 @@ describe Chef::Cookbook::Metadata do end it "should allow the default value to be a string, array, hash, boolean or numeric" do - expect { + expect do metadata.attribute("db/mysql/databases", :default => []) - }.not_to raise_error - expect { + end.not_to raise_error + expect do metadata.attribute("db/mysql/databases", :default => {}) - }.not_to raise_error - expect { + end.not_to raise_error + expect do metadata.attribute("db/mysql/databases", :default => "alice in chains") - }.not_to raise_error - expect { + end.not_to raise_error + expect do metadata.attribute("db/mysql/databases", :default => 1337) - }.not_to raise_error - expect { + end.not_to raise_error + expect do metadata.attribute("db/mysql/databases", :default => true) - }.not_to raise_error - expect { + end.not_to raise_error + expect do metadata.attribute("db/mysql/databases", :required => :not_gonna_do_it) - }.to raise_error(ArgumentError) + end.to raise_error(ArgumentError) end it "should limit the types allowed in the choice array" do @@ -678,87 +678,87 @@ describe Chef::Cookbook::Metadata do :choice => %w{test1 test2}, :default => "test1", } - expect { + expect do metadata.attribute("test_cookbook/test", options) - }.not_to raise_error + end.not_to raise_error options = { :type => "boolean", :choice => [ true, false ], :default => true, } - expect { + expect do metadata.attribute("test_cookbook/test", options) - }.not_to raise_error + end.not_to raise_error options = { :type => "numeric", :choice => [ 1337, 420 ], :default => 1337, } - expect { + expect do metadata.attribute("test_cookbook/test", options) - }.not_to raise_error + end.not_to raise_error options = { :type => "numeric", :choice => [ true, "false" ], :default => false, } - expect { + expect do metadata.attribute("test_cookbook/test", options) - }.to raise_error(Chef::Exceptions::ValidationFailed) + end.to raise_error(Chef::Exceptions::ValidationFailed) end it "should error if default used with calculated" do - expect { + expect do attrs = { :calculated => true, :default => [ "I thought you said calculated" ], } metadata.attribute("db/mysql/databases", attrs) - }.to raise_error(ArgumentError) - expect { + end.to raise_error(ArgumentError) + expect do attrs = { :calculated => true, :default => "I thought you said calculated", } metadata.attribute("db/mysql/databases", attrs) - }.to raise_error(ArgumentError) + end.to raise_error(ArgumentError) end it "should allow a default that is a choice" do - expect { + expect do attrs = { :choice => %w{a b c}, :default => "b", } metadata.attribute("db/mysql/databases", attrs) - }.not_to raise_error - expect { + end.not_to raise_error + expect do attrs = { :choice => %w{a b c d e}, :default => %w{b d}, } metadata.attribute("db/mysql/databases", attrs) - }.not_to raise_error + end.not_to raise_error end it "should error if default is not a choice" do - expect { + expect do attrs = { :choice => %w{a b c}, :default => "d", } metadata.attribute("db/mysql/databases", attrs) - }.to raise_error(ArgumentError) - expect { + end.to raise_error(ArgumentError) + expect do attrs = { :choice => %w{a b c d e}, :default => %w{b z}, } metadata.attribute("db/mysql/databases", attrs) - }.to raise_error(ArgumentError) + end.to raise_error(ArgumentError) end end diff --git a/spec/unit/cookbook_loader_spec.rb b/spec/unit/cookbook_loader_spec.rb index db10a4eb4f..eef5d2afd5 100644 --- a/spec/unit/cookbook_loader_spec.rb +++ b/spec/unit/cookbook_loader_spec.rb @@ -112,63 +112,63 @@ describe Chef::CookbookLoader do end it "should allow you to override an attribute file via cookbook_path" do - expect(cookbook_loader[:openldap].attribute_filenames.detect { |f| + expect(cookbook_loader[:openldap].attribute_filenames.detect do |f| f =~ /cookbooks\/openldap\/attributes\/default.rb/ - }).not_to eql(nil) - expect(cookbook_loader[:openldap].attribute_filenames.detect { |f| + end).not_to eql(nil) + expect(cookbook_loader[:openldap].attribute_filenames.detect do |f| f =~ /kitchen\/openldap\/attributes\/default.rb/ - }).to eql(nil) + end).to eql(nil) end it "should load different attribute files from deeper paths" do - expect(cookbook_loader[:openldap].attribute_filenames.detect { |f| + expect(cookbook_loader[:openldap].attribute_filenames.detect do |f| f =~ /kitchen\/openldap\/attributes\/robinson.rb/ - }).not_to eql(nil) + end).not_to eql(nil) end it "should allow you to override a definition file via cookbook_path" do - expect(cookbook_loader[:openldap].definition_filenames.detect { |f| + expect(cookbook_loader[:openldap].definition_filenames.detect do |f| f =~ /cookbooks\/openldap\/definitions\/client.rb/ - }).not_to eql(nil) - expect(cookbook_loader[:openldap].definition_filenames.detect { |f| + end).not_to eql(nil) + expect(cookbook_loader[:openldap].definition_filenames.detect do |f| f =~ /kitchen\/openldap\/definitions\/client.rb/ - }).to eql(nil) + end).to eql(nil) end it "should load definition files from deeper paths" do - expect(cookbook_loader[:openldap].definition_filenames.detect { |f| + expect(cookbook_loader[:openldap].definition_filenames.detect do |f| f =~ /kitchen\/openldap\/definitions\/drewbarrymore.rb/ - }).not_to eql(nil) + end).not_to eql(nil) end it "should allow you to override a recipe file via cookbook_path" do - expect(cookbook_loader[:openldap].recipe_filenames.detect { |f| + expect(cookbook_loader[:openldap].recipe_filenames.detect do |f| f =~ /cookbooks\/openldap\/recipes\/gigantor.rb/ - }).not_to eql(nil) - expect(cookbook_loader[:openldap].recipe_filenames.detect { |f| + end).not_to eql(nil) + expect(cookbook_loader[:openldap].recipe_filenames.detect do |f| f =~ /kitchen\/openldap\/recipes\/gigantor.rb/ - }).to eql(nil) + end).to eql(nil) end it "should load recipe files from deeper paths" do - expect(cookbook_loader[:openldap].recipe_filenames.detect { |f| + expect(cookbook_loader[:openldap].recipe_filenames.detect do |f| f =~ /kitchen\/openldap\/recipes\/woot.rb/ - }).not_to eql(nil) + end).not_to eql(nil) end it "should allow you to have an 'ignore' file, which skips loading files in later cookbooks" do - expect(cookbook_loader[:openldap].recipe_filenames.detect { |f| + expect(cookbook_loader[:openldap].recipe_filenames.detect do |f| f =~ /kitchen\/openldap\/recipes\/ignoreme.rb/ - }).to eql(nil) + end).to eql(nil) end it "should find files that start with a ." do - expect(cookbook_loader[:openldap].file_filenames.detect { |f| + expect(cookbook_loader[:openldap].file_filenames.detect do |f| f =~ /\.dotfile$/ - }).to match(/\.dotfile$/) - expect(cookbook_loader[:openldap].file_filenames.detect { |f| + end).to match(/\.dotfile$/) + expect(cookbook_loader[:openldap].file_filenames.detect do |f| f =~ /\.ssh\/id_rsa$/ - }).to match(/\.ssh\/id_rsa$/) + end).to match(/\.ssh\/id_rsa$/) end it "should load the metadata for the cookbook" do diff --git a/spec/unit/cookbook_version_file_specificity_spec.rb b/spec/unit/cookbook_version_file_specificity_spec.rb index df9e6571d8..3b5450cb2d 100644 --- a/spec/unit/cookbook_version_file_specificity_spec.rb +++ b/spec/unit/cookbook_version_file_specificity_spec.rb @@ -304,24 +304,24 @@ describe Chef::CookbookVersion, "file specificity" do it "should raise a FileNotFound exception without match" do node = Chef::Node.new - expect { + expect do @cookbook.preferred_manifest_record(node, :files, "doesn't_exist.rb") - }.to raise_error(Chef::Exceptions::FileNotFound) + end.to raise_error(Chef::Exceptions::FileNotFound) end it "should raise a FileNotFound exception consistently without match" do node = Chef::Node.new - expect { + expect do @cookbook.preferred_manifest_record(node, :files, "doesn't_exist.rb") - }.to raise_error(Chef::Exceptions::FileNotFound) + end.to raise_error(Chef::Exceptions::FileNotFound) - expect { + expect do @cookbook.preferred_manifest_record(node, :files, "doesn't_exist.rb") - }.to raise_error(Chef::Exceptions::FileNotFound) + end.to raise_error(Chef::Exceptions::FileNotFound) - expect { + expect do @cookbook.preferred_manifest_record(node, :files, "doesn't_exist.rb") - }.to raise_error(Chef::Exceptions::FileNotFound) + end.to raise_error(Chef::Exceptions::FileNotFound) end describe "when fetching the contents of a directory by file specificity" do diff --git a/spec/unit/data_bag_item_spec.rb b/spec/unit/data_bag_item_spec.rb index 2711fcae03..e83f0ca0ec 100644 --- a/spec/unit/data_bag_item_spec.rb +++ b/spec/unit/data_bag_item_spec.rb @@ -91,12 +91,12 @@ describe Chef::DataBagItem do end describe "object_name" do - let(:data_bag_item) { + let(:data_bag_item) do data_bag_item = Chef::DataBagItem.new data_bag_item.data_bag("dreams") data_bag_item.raw_data = { "id" => "the_beatdown" } data_bag_item - } + end it "should return an object name based on the bag name and the raw_data id" do expect(data_bag_item.object_name).to eq("data_bag_item_dreams_the_beatdown") @@ -110,12 +110,12 @@ describe Chef::DataBagItem do end describe "class method name" do - let(:data_bag_item) { + let(:data_bag_item) do data_bag_item = Chef::DataBagItem.new data_bag_item.data_bag("dreams") data_bag_item.raw_data = { "id" => "the_beatdown", "name" => "Bruce" } data_bag_item - } + end it "should return the object name" do expect(data_bag_item.name).to eq(data_bag_item.object_name) @@ -128,11 +128,11 @@ describe Chef::DataBagItem do end describe "when used like a Hash" do - let(:data_bag_item) { + let(:data_bag_item) do data_bag_item = Chef::DataBagItem.new data_bag_item.raw_data = { "id" => "journey", "trials" => "been through" } data_bag_item - } + end it "responds to keys" do expect(data_bag_item.keys).to include("id") @@ -158,9 +158,9 @@ describe Chef::DataBagItem do describe "from_hash" do context "when hash contains raw_data" do - let(:data_bag_item) { + let(:data_bag_item) do Chef::DataBagItem.from_hash({ "raw_data" => { "id" => "whoa", "name" => "Bruce", "i_know" => "kung_fu" } }) - } + end it "should have the id key set" do expect(data_bag_item["id"]).to eq("whoa") @@ -172,9 +172,9 @@ describe Chef::DataBagItem do end context "when hash does not contain raw_data" do - let(:data_bag_item) { + let(:data_bag_item) do Chef::DataBagItem.from_hash({ "id" => "whoa", "name" => "Bruce", "i_know" => "kung_fu" }) - } + end it "should have the id key set" do expect(data_bag_item["id"]).to eq("whoa") @@ -187,12 +187,12 @@ describe Chef::DataBagItem do end describe "to_hash" do - let(:data_bag_item) { + let(:data_bag_item) do data_bag_item = Chef::DataBagItem.new data_bag_item.data_bag("still_lost") data_bag_item.raw_data = { "id" => "whoa", "name" => "Bruce", "i_know" => "kung_fu" } data_bag_item - } + end let!(:original_data_bag_keys) { data_bag_item.keys } @@ -223,12 +223,12 @@ describe Chef::DataBagItem do end describe "when deserializing from JSON" do - let(:data_bag_item) { + let(:data_bag_item) do data_bag_item = Chef::DataBagItem.new data_bag_item.data_bag("mars_volta") data_bag_item.raw_data = { "id" => "octahedron", "name" => "Bruce", "snooze" => { "finally" => :world_will } } data_bag_item - } + end let(:deserial) { Chef::DataBagItem.from_hash(Chef::JSONCompat.parse(Chef::JSONCompat.to_json(data_bag_item))) } @@ -275,13 +275,13 @@ describe Chef::DataBagItem do describe "save" do let(:server) { instance_double(Chef::ServerAPI) } - let(:data_bag_item) { + let(:data_bag_item) do data_bag_item = Chef::DataBagItem.new data_bag_item["id"] = "heart of darkness" data_bag_item.raw_data = { "id" => "heart_of_darkness", "author" => "Conrad" } data_bag_item.data_bag("books") data_bag_item - } + end before do expect(Chef::ServerAPI).to receive(:new).and_return(server) @@ -320,12 +320,12 @@ describe Chef::DataBagItem do describe "destroy" do let(:server) { instance_double(Chef::ServerAPI) } - let(:data_bag_item) { + let(:data_bag_item) do data_bag_item = Chef::DataBagItem.new data_bag_item.data_bag("a_baggy_bag") data_bag_item.raw_data = { "id" => "some_id" } data_bag_item - } + end it "should set default parameters" do expect(Chef::ServerAPI).to receive(:new).and_return(server) diff --git a/spec/unit/data_bag_spec.rb b/spec/unit/data_bag_spec.rb index 84aa724927..cadd60936e 100644 --- a/spec/unit/data_bag_spec.rb +++ b/spec/unit/data_bag_spec.rb @@ -241,9 +241,9 @@ describe Chef::DataBag do it "should raise an error if the configured data_bag_path is invalid" do file_dir_stub(@paths.first, false) - expect { + expect do Chef::DataBag.load("foo") - }.to raise_error Chef::Exceptions::InvalidDataBagPath, "Data bag path '/var/chef/data_bags' is invalid" + end.to raise_error Chef::Exceptions::InvalidDataBagPath, "Data bag path '/var/chef/data_bags' is invalid" end end diff --git a/spec/unit/data_collector/messages/helpers_spec.rb b/spec/unit/data_collector/messages/helpers_spec.rb index 26f7dbacfa..b0d9f4d09d 100644 --- a/spec/unit/data_collector/messages/helpers_spec.rb +++ b/spec/unit/data_collector/messages/helpers_spec.rb @@ -25,7 +25,7 @@ class TestMessage end describe Chef::DataCollector::Messages::Helpers do - describe '#organization' do + describe "#organization" do context "when the run is a solo run" do it "returns the data collector organization" do allow(TestMessage).to receive(:solo_run?).and_return(true) @@ -43,7 +43,7 @@ describe Chef::DataCollector::Messages::Helpers do end end - describe '#data_collector_organization' do + describe "#data_collector_organization" do context "when the org is specified in the config" do it "returns the org from the config" do Chef::Config[:data_collector][:organization] = "org1" @@ -58,7 +58,7 @@ describe Chef::DataCollector::Messages::Helpers do end end - describe '#chef_server_organization' do + describe "#chef_server_organization" do context "when the URL is properly formatted" do it "returns the org from the parsed URL" do Chef::Config[:chef_server_url] = "http://mycompany.com/organizations/myorg" @@ -74,7 +74,7 @@ describe Chef::DataCollector::Messages::Helpers do end end - describe '#collector_source' do + describe "#collector_source" do context "when the run is a solo run" do it "returns chef_solo" do allow(TestMessage).to receive(:solo_run?).and_return(true) @@ -90,7 +90,7 @@ describe Chef::DataCollector::Messages::Helpers do end end - describe '#solo_run?' do + describe "#solo_run?" do context "when :solo is set in Chef::Config" do it "returns true" do Chef::Config[:solo] = true @@ -116,7 +116,7 @@ describe Chef::DataCollector::Messages::Helpers do end end - describe '#node_uuid' do + describe "#node_uuid" do context "when the node UUID can be read" do it "returns the read-in node UUID" do allow(TestMessage).to receive(:read_node_uuid).and_return("read_uuid") @@ -133,7 +133,7 @@ describe Chef::DataCollector::Messages::Helpers do end end - describe '#generate_node_uuid' do + describe "#generate_node_uuid" do it "generates a new UUID, stores it, and returns it" do expect(SecureRandom).to receive(:uuid).and_return("generated_uuid") expect(TestMessage).to receive(:update_metadata).with("node_uuid", "generated_uuid") @@ -141,7 +141,7 @@ describe Chef::DataCollector::Messages::Helpers do end end - describe '#read_node_uuid' do + describe "#read_node_uuid" do it "reads the node UUID from metadata" do expect(TestMessage).to receive(:metadata).and_return({ "node_uuid" => "read_uuid" }) expect(TestMessage.read_node_uuid).to eq("read_uuid") @@ -170,7 +170,7 @@ describe Chef::DataCollector::Messages::Helpers do end end - describe '#update_metadata' do + describe "#update_metadata" do it "updates the file" do allow(TestMessage).to receive(:metadata_filename).and_return("fake_metadata_file.json") allow(TestMessage).to receive(:metadata).and_return({ "key" => "current_value" }) diff --git a/spec/unit/data_collector/messages_spec.rb b/spec/unit/data_collector/messages_spec.rb index b0c7e692d2..394f18dce0 100644 --- a/spec/unit/data_collector/messages_spec.rb +++ b/spec/unit/data_collector/messages_spec.rb @@ -22,7 +22,7 @@ require "ffi_yajl" require "chef/data_collector/messages/helpers" describe Chef::DataCollector::Messages do - describe '#run_start_message' do + describe "#run_start_message" do let(:run_status) { Chef::RunStatus.new(Chef::Node.new, Chef::EventDispatch::Dispatcher.new) } let(:required_fields) do %w{ @@ -61,7 +61,7 @@ describe Chef::DataCollector::Messages do end end - describe '#run_end_message' do + describe "#run_end_message" do let(:node) { Chef::Node.new } let(:run_status) { Chef::RunStatus.new(node, Chef::EventDispatch::Dispatcher.new) } let(:report1) { double("report1", report_data: { "status" => "updated" }) } diff --git a/spec/unit/data_collector_spec.rb b/spec/unit/data_collector_spec.rb index 764510d0ad..37df758ff2 100644 --- a/spec/unit/data_collector_spec.rb +++ b/spec/unit/data_collector_spec.rb @@ -160,7 +160,7 @@ describe Chef::DataCollector::Reporter do Chef::Config[:data_collector][:server_url] = "http://my-data-collector-server.mycompany.com" end - describe '#run_started' do + describe "#run_started" do before do allow(reporter).to receive(:update_run_status) allow(reporter).to receive(:send_to_data_collector) @@ -182,7 +182,7 @@ describe Chef::DataCollector::Reporter do end end - describe '#run_completed' do + describe "#run_completed" do it "sends the run completion" do node = Chef::Node.new @@ -191,35 +191,35 @@ describe Chef::DataCollector::Reporter do end end - describe '#run_failed' do + describe "#run_failed" do it "updates the exception and sends the run completion" do expect(reporter).to receive(:send_run_completion).with(status: "failure") reporter.run_failed("test_exception") end end - describe '#converge_start' do + describe "#converge_start" do it "stashes the run_context for later use" do reporter.converge_start("test_context") expect(reporter.run_context).to eq("test_context") end end - describe '#converge_complete' do + describe "#converge_complete" do it "detects and processes any unprocessed resources" do expect(reporter).to receive(:detect_unprocessed_resources) reporter.converge_complete end end - describe '#converge_failed' do + describe "#converge_failed" do it "detects and processes any unprocessed resources" do expect(reporter).to receive(:detect_unprocessed_resources) reporter.converge_failed("exception") end end - describe '#resource_current_state_loaded' do + describe "#resource_current_state_loaded" do let(:new_resource) { double("new_resource") } let(:action) { double("action") } let(:current_resource) { double("current_resource") } @@ -245,7 +245,7 @@ describe Chef::DataCollector::Reporter do end end - describe '#resource_up_to_date' do + describe "#resource_up_to_date" do let(:new_resource) { double("new_resource") } let(:action) { double("action") } let(:resource_report) { double("resource_report") } @@ -273,7 +273,7 @@ describe Chef::DataCollector::Reporter do end end - describe '#resource_skipped' do + describe "#resource_skipped" do let(:new_resource) { double("new_resource") } let(:action) { double("action") } let(:conditional) { double("conditional") } @@ -311,7 +311,7 @@ describe Chef::DataCollector::Reporter do end end - describe '#resource_updated' do + describe "#resource_updated" do let(:resource_report) { double("resource_report") } before do @@ -325,7 +325,7 @@ describe Chef::DataCollector::Reporter do end end - describe '#resource_failed' do + describe "#resource_failed" do let(:new_resource) { double("new_resource") } let(:action) { double("action") } let(:exception) { double("exception") } @@ -368,7 +368,7 @@ describe Chef::DataCollector::Reporter do end end - describe '#resource_completed' do + describe "#resource_completed" do let(:new_resource) { double("new_resource") } let(:resource_report) { double("resource_report") } @@ -418,14 +418,14 @@ describe Chef::DataCollector::Reporter do end end - describe '#run_list_expanded' do + describe "#run_list_expanded" do it "sets the expanded run list" do reporter.run_list_expanded("test_run_list") expect(reporter.expanded_run_list).to eq("test_run_list") end end - describe '#run_list_expand_failed' do + describe "#run_list_expand_failed" do let(:node) { double("node") } let(:error_mapper) { double("error_mapper") } let(:exception) { double("exception") } @@ -441,7 +441,7 @@ describe Chef::DataCollector::Reporter do end end - describe '#cookbook_resolution_failed' do + describe "#cookbook_resolution_failed" do let(:error_mapper) { double("error_mapper") } let(:exception) { double("exception") } let(:expanded_run_list) { double("expanded_run_list") } @@ -458,7 +458,7 @@ describe Chef::DataCollector::Reporter do end - describe '#cookbook_sync_failed' do + describe "#cookbook_sync_failed" do let(:cookbooks) { double("cookbooks") } let(:error_mapper) { double("error_mapper") } let(:exception) { double("exception") } @@ -474,7 +474,7 @@ describe Chef::DataCollector::Reporter do end end - describe '#disable_reporter_on_error' do + describe "#disable_reporter_on_error" do context "when no exception is raise by the block" do it "does not disable the reporter" do expect(reporter).not_to receive(:disable_data_collector_reporter) @@ -521,7 +521,7 @@ describe Chef::DataCollector::Reporter do end end - describe '#validate_data_collector_server_url!' do + describe "#validate_data_collector_server_url!" do context "when server_url is empty" do it "raises an exception" do Chef::Config[:data_collector][:server_url] = "" diff --git a/spec/unit/dsl/audit_spec.rb b/spec/unit/dsl/audit_spec.rb index a8227f6c99..42e543fdb2 100644 --- a/spec/unit/dsl/audit_spec.rb +++ b/spec/unit/dsl/audit_spec.rb @@ -21,14 +21,14 @@ describe Chef::DSL::Audit do end it "raises an error when no audit name is given" do - expect { auditor.control_group do end }.to raise_error(Chef::Exceptions::AuditNameMissing) + expect { auditor.control_group {} }.to raise_error(Chef::Exceptions::AuditNameMissing) end context "audits already populated" do let(:audits) { { "unique" => {} } } it "raises an error if the audit name is a duplicate" do - expect { auditor.control_group "unique" do end }.to raise_error(Chef::Exceptions::AuditControlGroupDuplicate) + expect { auditor.control_group("unique") {} }.to raise_error(Chef::Exceptions::AuditControlGroupDuplicate) end end @@ -36,7 +36,7 @@ describe Chef::DSL::Audit do let(:auditor) { BadAuditDSLTester.new } it "fails because it relies on the recipe DSL existing" do - expect { auditor.control_group "unique" do end }.to raise_error(NoMethodError, /undefined method `cookbook_name'/) + expect { auditor.control_group("unique") {} }.to raise_error(NoMethodError, /undefined method `cookbook_name'/) end end diff --git a/spec/unit/dsl/data_query_spec.rb b/spec/unit/dsl/data_query_spec.rb index 55c6e5f578..f93f07bc52 100644 --- a/spec/unit/dsl/data_query_spec.rb +++ b/spec/unit/dsl/data_query_spec.rb @@ -60,14 +60,15 @@ describe Chef::DSL::DataQuery do let(:item_name) { "item_name" } - let(:raw_data) {{ + let(:raw_data) do + { "id" => item_name, "greeting" => "hello", "nested" => { "a1" => [1, 2, 3], "a2" => { "b1" => true }, }, - }} + } 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 692e57d2e1..57a7fd7f18 100644 --- a/spec/unit/dsl/declare_resource_spec.rb +++ b/spec/unit/dsl/declare_resource_spec.rb @@ -50,17 +50,17 @@ describe Chef::ResourceCollection do describe "#edit_resource!" do it "raises if nothing is found" do - expect { + expect do recipe.edit_resource!(:zen_master, "monkey") do something true end - }.to raise_error(Chef::Exceptions::ResourceNotFound) + end.to raise_error(Chef::Exceptions::ResourceNotFound) end it "raises if nothing is found and no block is given" do - expect { + expect do recipe.edit_resource!(:zen_master, "monkey") - }.to raise_error(Chef::Exceptions::ResourceNotFound) + end.to raise_error(Chef::Exceptions::ResourceNotFound) end it "edits the resource if it finds one" do @@ -131,20 +131,20 @@ describe Chef::ResourceCollection do describe "#find_resource!" do it "raises if nothing is found" do - expect { + expect do recipe.find_resource!(:zen_master, "monkey") - }.to raise_error(Chef::Exceptions::ResourceNotFound) + end.to raise_error(Chef::Exceptions::ResourceNotFound) end it "raises if given a block" do resource = recipe.declare_resource(:zen_master, "monkey") do something false end - expect { + expect do recipe.find_resource!(:zen_master, "monkey") do something false end - }.to raise_error(ArgumentError) + end.to raise_error(ArgumentError) end it "returns the resource if it finds one" do @@ -221,9 +221,9 @@ describe Chef::ResourceCollection do describe "#delete_resource!" do it "raises if nothing is found" do - expect { + expect do recipe.delete_resource!(:zen_master, "monkey") - }.to raise_error(Chef::Exceptions::ResourceNotFound) + end.to raise_error(Chef::Exceptions::ResourceNotFound) end it "deletes and returns the resource if it finds one" do 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 c2cb275f9d..7e885f8818 100644 --- a/spec/unit/encrypted_data_bag_item/check_encrypted_spec.rb +++ b/spec/unit/encrypted_data_bag_item/check_encrypted_spec.rb @@ -39,14 +39,15 @@ describe Chef::EncryptedDataBagItem::CheckEncrypted do let(:default_secret) { "abc123SECRET" } let(:item_name) { "item_name" } - let(:raw_data) {{ + let(:raw_data) do + { "id" => item_name, "greeting" => "hello", "nested" => { "a1" => [1, 2, 3], "a2" => { "b1" => true }, }, - }} + } 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 e17f7a2331..a8fb144bf7 100644 --- a/spec/unit/encrypted_data_bag_item_spec.rb +++ b/spec/unit/encrypted_data_bag_item_spec.rb @@ -320,11 +320,12 @@ end describe Chef::EncryptedDataBagItem do subject { described_class } let(:encrypted_data_bag_item) { subject.new(encoded_data, secret) } - let(:plaintext_data) {{ + let(:plaintext_data) do + { "id" => "item_name", "greeting" => "hello", "nested" => { "a1" => [1, 2, 3], "a2" => { "b1" => true } }, - }} + } 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 5557b5dc11..63c96ad93e 100644 --- a/spec/unit/environment_spec.rb +++ b/spec/unit/environment_spec.rb @@ -296,9 +296,9 @@ describe Chef::Environment do end it "should raise and exception" do - expect { + expect do Chef::Environment.validate_cookbook_version("= 1.2.3.4") - }.to raise_error Chef::Exceptions::IllegalVersionConstraint, + end.to raise_error Chef::Exceptions::IllegalVersionConstraint, "Environment cookbook version constraints not allowed in chef-solo" end end @@ -450,9 +450,9 @@ describe Chef::Environment do it "should raise an error if the configured environment_path is invalid" do expect(File).to receive(:directory?).with(Chef::Config[:environment_path]).and_return(false) - expect { + expect do Chef::Environment.load("foo") - }.to raise_error Chef::Exceptions::InvalidEnvironmentPath, "Environment path '/var/chef/environments' is invalid" + end.to raise_error Chef::Exceptions::InvalidEnvironmentPath, "Environment path '/var/chef/environments' is invalid" end it "should raise an error if the file does not exist" do @@ -460,9 +460,9 @@ describe Chef::Environment do expect(File).to receive(:exists?).with(File.join(Chef::Config[:environment_path], "foo.json")).and_return(false) expect(File).to receive(:exists?).with(File.join(Chef::Config[:environment_path], "foo.rb")).and_return(false) - expect { + expect do Chef::Environment.load("foo") - }.to raise_error Chef::Exceptions::EnvironmentNotFound, "Environment 'foo' could not be loaded from disk" + end.to raise_error Chef::Exceptions::EnvironmentNotFound, "Environment 'foo' could not be loaded from disk" end end end diff --git a/spec/unit/file_access_control_spec.rb b/spec/unit/file_access_control_spec.rb index 4118133692..ee806b5c3a 100644 --- a/spec/unit/file_access_control_spec.rb +++ b/spec/unit/file_access_control_spec.rb @@ -43,7 +43,7 @@ describe Chef::FileAccessControl do end describe "class methods" do - it 'responds to #writable?' do + it "responds to #writable?" do expect(Chef::FileAccessControl).to respond_to(:writable?) end end diff --git a/spec/unit/file_content_management/tempfile_spec.rb b/spec/unit/file_content_management/tempfile_spec.rb index a833e21fac..4b27fc8cc9 100644 --- a/spec/unit/file_content_management/tempfile_spec.rb +++ b/spec/unit/file_content_management/tempfile_spec.rb @@ -19,11 +19,11 @@ require "spec_helper" describe Chef::FileContentManagement::Tempfile do - let(:resource) { + let(:resource) do r = Chef::Resource::File.new("new_file") r.path "/foo/bar/new_file" r - } + end subject { described_class.new(resource) } diff --git a/spec/unit/formatters/error_inspectors/api_error_formatting_spec.rb b/spec/unit/formatters/error_inspectors/api_error_formatting_spec.rb index 97fa92ca52..0e5104a0db 100644 --- a/spec/unit/formatters/error_inspectors/api_error_formatting_spec.rb +++ b/spec/unit/formatters/error_inspectors/api_error_formatting_spec.rb @@ -32,13 +32,13 @@ describe Chef::Formatters::APIErrorFormatting do let(:min_version) { "2" } let(:max_version) { "5" } let(:request_version) { "30" } - let(:return_hash) { + let(:return_hash) do { "min_version" => min_version, "max_version" => max_version, "request_version" => request_version, } - } + end before do # mock out the header diff --git a/spec/unit/guard_interpreter/resource_guard_interpreter_spec.rb b/spec/unit/guard_interpreter/resource_guard_interpreter_spec.rb index e76e69d2cd..746b343e9c 100644 --- a/spec/unit/guard_interpreter/resource_guard_interpreter_spec.rb +++ b/spec/unit/guard_interpreter/resource_guard_interpreter_spec.rb @@ -105,9 +105,9 @@ describe Chef::GuardInterpreter::ResourceGuardInterpreter do parent_resource end - let(:shell_out) { + let(:shell_out) do instance_double(Mixlib::ShellOut, :live_stream => true, :run_command => true, :error! => nil) - } + end before do # TODO for some reason Windows is failing on executing a ruby script diff --git a/spec/unit/http/validate_content_length_spec.rb b/spec/unit/http/validate_content_length_spec.rb index 85f8d92f78..5067d36d38 100644 --- a/spec/unit/http/validate_content_length_spec.rb +++ b/spec/unit/http/validate_content_length_spec.rb @@ -37,25 +37,25 @@ describe Chef::HTTP::ValidateContentLength do let(:content_length_value) { 23 } let(:streaming_length) { 23 } let(:response_body) { "Thanks for checking in." } - let(:response_headers) { + let(:response_headers) do { "content-length" => content_length_value, } - } + end - let(:response) { + let(:response) do m = double("HttpResponse", :body => response_body) allow(m).to receive(:[]) do |key| response_headers[key] end m - } + end - let(:middleware) { + let(:middleware) do client = TestClient.new(url) client.middlewares[0] - } + end def run_content_length_validation stream_handler = middleware.stream_response_handler(response) @@ -169,12 +169,12 @@ describe Chef::HTTP::ValidateContentLength do end describe "when Transfer-Encoding & Content-Length is set" do - let(:response_headers) { + let(:response_headers) do { "content-length" => content_length_value, "transfer-encoding" => "chunked", } - } + end %w{direct streaming}.each do |req_type| describe "when running #{req_type} request" do diff --git a/spec/unit/knife/bootstrap/chef_vault_handler_spec.rb b/spec/unit/knife/bootstrap/chef_vault_handler_spec.rb index 734b27216d..d822fe8f98 100644 --- a/spec/unit/knife/bootstrap/chef_vault_handler_spec.rb +++ b/spec/unit/knife/bootstrap/chef_vault_handler_spec.rb @@ -29,10 +29,10 @@ describe Chef::Knife::Bootstrap::ChefVaultHandler do let(:client) { Chef::ApiClient.new } - let(:chef_vault_handler) { + let(:chef_vault_handler) do chef_vault_handler = Chef::Knife::Bootstrap::ChefVaultHandler.new(knife_config: knife_config, ui: ui) chef_vault_handler - } + end context "when there's no vault option" do it "should report its not doing anything" do diff --git a/spec/unit/knife/bootstrap/client_builder_spec.rb b/spec/unit/knife/bootstrap/client_builder_spec.rb index 491d0ca754..97ba0fc48e 100644 --- a/spec/unit/knife/bootstrap/client_builder_spec.rb +++ b/spec/unit/knife/bootstrap/client_builder_spec.rb @@ -33,12 +33,12 @@ describe Chef::Knife::Bootstrap::ClientBuilder do let(:rest) { double("Chef::ServerAPI") } - let(:client_builder) { + let(:client_builder) do client_builder = Chef::Knife::Bootstrap::ClientBuilder.new(knife_config: knife_config, chef_config: chef_config, ui: ui) allow(client_builder).to receive(:rest).and_return(rest) allow(client_builder).to receive(:node_name).and_return(node_name) client_builder - } + end context "#sanity_check!" do let(:response_404) { OpenStruct.new(:code => "404") } diff --git a/spec/unit/knife/bootstrap_spec.rb b/spec/unit/knife/bootstrap_spec.rb index 5f1ba9f781..9f944b82d9 100644 --- a/spec/unit/knife/bootstrap_spec.rb +++ b/spec/unit/knife/bootstrap_spec.rb @@ -236,11 +236,11 @@ describe Chef::Knife::Bootstrap do end context "with bootstrap_attribute options" do - let(:jsonfile) { + let(:jsonfile) do file = Tempfile.new (["node", ".json"]) File.open(file.path, "w") { |f| f.puts '{"foo":{"bar":"baz"}}' } file - } + end it "should have foo => {bar => baz} in the first_boot from cli" do knife.parse_options(["-j", '{"foo":{"bar":"baz"}}']) @@ -478,8 +478,9 @@ describe Chef::Knife::Bootstrap do end context "when client_d_dir is set" do - let(:client_d_dir) { Chef::Util::PathHelper.cleanpath( - File.join(File.dirname(__FILE__), "../../data/client.d_00")) } + let(:client_d_dir) do + Chef::Util::PathHelper.cleanpath( + 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") @@ -497,8 +498,9 @@ describe Chef::Knife::Bootstrap do end context "a nested directory structure" do - let(:client_d_dir) { Chef::Util::PathHelper.cleanpath( - File.join(File.dirname(__FILE__), "../../data/client.d_01")) } + let(:client_d_dir) do + Chef::Util::PathHelper.cleanpath( + 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") diff --git a/spec/unit/knife/client_bulk_delete_spec.rb b/spec/unit/knife/client_bulk_delete_spec.rb index a9b18c9086..994f4d33a4 100644 --- a/spec/unit/knife/client_bulk_delete_spec.rb +++ b/spec/unit/knife/client_bulk_delete_spec.rb @@ -24,7 +24,7 @@ describe Chef::Knife::ClientBulkDelete do let(:stderr_io) { StringIO.new } let(:stderr) { stderr_io.string } - let(:knife) { + let(:knife) do k = Chef::Knife::ClientBulkDelete.new k.name_args = name_args k.config = option_args @@ -33,7 +33,7 @@ describe Chef::Knife::ClientBulkDelete do allow(k.ui).to receive(:confirm).and_return(knife_confirm) allow(k.ui).to receive(:confirm_without_exit).and_return(knife_confirm) k - } + end let(:name_args) { [ "." ] } let(:option_args) { {} } @@ -41,7 +41,7 @@ describe Chef::Knife::ClientBulkDelete do let(:knife_confirm) { true } let(:nonvalidator_client_names) { %w{tim dan stephen} } - let(:nonvalidator_clients) { + let(:nonvalidator_clients) do clients = Hash.new nonvalidator_client_names.each do |client_name| @@ -52,10 +52,10 @@ describe Chef::Knife::ClientBulkDelete do end clients - } + end let(:validator_client_names) { %w{myorg-validator} } - let(:validator_clients) { + let(:validator_clients) do clients = Hash.new validator_client_names.each do |validator_client_name| @@ -67,12 +67,12 @@ describe Chef::Knife::ClientBulkDelete do end clients - } + end let(:client_names) { nonvalidator_client_names + validator_client_names } - let(:clients) { + let(:clients) do nonvalidator_clients.merge(validator_clients) - } + end before(:each) do allow(Chef::ApiClientV1).to receive(:list).and_return(clients) diff --git a/spec/unit/knife/client_edit_spec.rb b/spec/unit/knife/client_edit_spec.rb index 584a94014c..e7c9030883 100644 --- a/spec/unit/knife/client_edit_spec.rb +++ b/spec/unit/knife/client_edit_spec.rb @@ -27,7 +27,7 @@ describe Chef::Knife::ClientEdit do end describe "run" do - let(:data) { + let(:data) do { "name" => "adam", "validator" => false, @@ -35,7 +35,7 @@ describe Chef::Knife::ClientEdit do "chef_type" => "client", "create_key" => true, } - } + end it "should edit the client" do allow(Chef::ApiClientV1).to receive(:load).with("adam").and_return(data) diff --git a/spec/unit/knife/configure_client_spec.rb b/spec/unit/knife/configure_client_spec.rb index 192da862d7..3ecb89f827 100644 --- a/spec/unit/knife/configure_client_spec.rb +++ b/spec/unit/knife/configure_client_spec.rb @@ -33,9 +33,9 @@ describe Chef::Knife::ConfigureClient do it "should print usage and exit when a directory is not provided" do expect(@knife).to receive(:show_usage) expect(@knife.ui).to receive(:fatal).with(/must provide the directory/) - expect { + expect do @knife.run - }.to raise_error SystemExit + end.to raise_error SystemExit end describe "when specifing a directory" do diff --git a/spec/unit/knife/cookbook_metadata_spec.rb b/spec/unit/knife/cookbook_metadata_spec.rb index 0e3fccfa7e..4b405d0842 100644 --- a/spec/unit/knife/cookbook_metadata_spec.rb +++ b/spec/unit/knife/cookbook_metadata_spec.rb @@ -128,9 +128,9 @@ describe Chef::Knife::CookbookMetadata do it "should print an error and exit when an #{description} syntax exception is encountered" do exception = klass.new("#{description} blah") allow(Chef::Cookbook::Metadata).to receive(:new).and_raise(exception) - expect { + expect do @knife.generate_metadata_from_file("foobar", "#{@cookbook_dir}/foobar/metadata.rb") - }.to raise_error(SystemExit) + end.to raise_error(SystemExit) expect(@stderr.string).to match /error: the cookbook 'foobar' contains invalid or obsolete metadata syntax/im expect(@stderr.string).to match /in #{@cookbook_dir}\/foobar\/metadata\.rb/im expect(@stderr.string).to match /#{description} blah/im @@ -166,9 +166,9 @@ describe Chef::Knife::CookbookMetadata do and_return(@json_data) exception = klass.new("#{description} blah") allow(Chef::Cookbook::Metadata).to receive(:validate_json).and_raise(exception) - expect { + expect do @knife.validate_metadata_json(@cookbook_dir, "foobar") - }.to raise_error(SystemExit) + end.to raise_error(SystemExit) expect(@stderr.string).to match /error: the cookbook 'foobar' contains invalid or obsolete metadata syntax/im expect(@stderr.string).to match /in #{@cookbook_dir}\/foobar\/metadata\.json/im expect(@stderr.string).to match /#{description} blah/im diff --git a/spec/unit/knife/cookbook_site_install_spec.rb b/spec/unit/knife/cookbook_site_install_spec.rb index 1549245ea3..d93af10761 100644 --- a/spec/unit/knife/cookbook_site_install_spec.rb +++ b/spec/unit/knife/cookbook_site_install_spec.rb @@ -24,16 +24,17 @@ describe Chef::Knife::CookbookSiteInstall do let(:stderr) { StringIO.new } let(:downloader) { Hash.new } let(:archive) { double(Mixlib::Archive, extract: true) } - let(:repo) { double(:sanity_check => true, :reset_to_default_state => true, - :prepare_to_import => true, :finalize_updates_to => true, - :merge_updates_from => true) } - let(:install_path) { + 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 + let(:install_path) do if Chef::Platform.windows? "C:/tmp/chef" else "/var/tmp/chef" end - } + end before(:each) do require "chef/knife/core/cookbook_scm_repo" diff --git a/spec/unit/knife/core/hashed_command_loader_spec.rb b/spec/unit/knife/core/hashed_command_loader_spec.rb index 081f9deae5..53bd81f4f7 100644 --- a/spec/unit/knife/core/hashed_command_loader_spec.rb +++ b/spec/unit/knife/core/hashed_command_loader_spec.rb @@ -22,7 +22,7 @@ describe Chef::Knife::SubcommandLoader::HashedCommandLoader do allow(ChefConfig).to receive(:windows?) { false } end - let(:plugin_manifest) { + let(:plugin_manifest) do { "_autogenerated_command_paths" => { "plugins_paths" => { @@ -39,11 +39,12 @@ describe Chef::Knife::SubcommandLoader::HashedCommandLoader do }, }, } - } + end - let(:loader) { Chef::Knife::SubcommandLoader::HashedCommandLoader.new( + let(:loader) do + Chef::Knife::SubcommandLoader::HashedCommandLoader.new( File.join(CHEF_SPEC_DATA, "knife-site-subcommands"), - plugin_manifest)} + 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 19af419632..ce169a77dd 100644 --- a/spec/unit/knife/core/node_editor_spec.rb +++ b/spec/unit/knife/core/node_editor_spec.rb @@ -41,7 +41,7 @@ describe Chef::Knife::NodeEditor do subject { described_class.new(node, ui, config) } - describe '#view' 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,| @@ -61,7 +61,7 @@ describe Chef::Knife::NodeEditor do end end - describe '#apply_updates' do + describe "#apply_updates" do context "when the node name is changed" do before(:each) do allow(ui).to receive(:warn) @@ -143,7 +143,7 @@ describe Chef::Knife::NodeEditor do end end - describe '#updated?' do + describe "#updated?" do context "before the node has been edited" do it "returns false" do expect(subject.updated?).to be false diff --git a/spec/unit/knife/core/ui_spec.rb b/spec/unit/knife/core/ui_spec.rb index 0b9547fc1f..9f525f22f0 100644 --- a/spec/unit/knife/core/ui_spec.rb +++ b/spec/unit/knife/core/ui_spec.rb @@ -500,9 +500,9 @@ EOM shared_examples_for "confirm with negative answer" do it "confirm should exit 3" do - expect { + expect do run_confirm - }.to raise_error(SystemExit) { |e| expect(e.status).to eq(3) } + end.to raise_error(SystemExit) { |e| expect(e.status).to eq(3) } end it "confirm_without_exit should return false" do diff --git a/spec/unit/knife/data_bag_from_file_spec.rb b/spec/unit/knife/data_bag_from_file_spec.rb index bf6bd82a68..3bea392ae2 100644 --- a/spec/unit/knife/data_bag_from_file_spec.rb +++ b/spec/unit/knife/data_bag_from_file_spec.rb @@ -72,11 +72,12 @@ describe Chef::Knife::DataBagFromFile do let(:loader) { double("Knife::Core::ObjectLoader") } let(:data_bags_path) { "data_bags" } - let(:plain_data) { { + let(:plain_data) do + { "id" => "item_name", "greeting" => "hello", "nested" => { "a1" => [1, 2, 3], "a2" => { "b1" => true } }, - } } + } 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 0672b8bb33..ece7f5bf78 100644 --- a/spec/unit/knife/data_bag_show_spec.rb +++ b/spec/unit/knife/data_bag_show_spec.rb @@ -45,8 +45,9 @@ describe Chef::Knife::DataBagShow do let(:bag_name) { "sudoing_admins" } let(:item_name) { "ME" } - let(:data_bag_contents) { { "id" => "id", "baz" => "http://localhost:4000/data/bag_o_data/baz", - "qux" => "http://localhost:4000/data/bag_o_data/qux" } } + 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 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 146b6a904b..5b00c6ea31 100644 --- a/spec/unit/knife/key_create_spec.rb +++ b/spec/unit/knife/key_create_spec.rb @@ -73,7 +73,7 @@ describe "key create commands that inherit knife" do end describe Chef::Knife::KeyCreate do - let(:public_key) { + let(:public_key) do "-----BEGIN PUBLIC KEY----- MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvPo+oNPB7uuNkws0fC02 KxSwdyqPLu0fhI1pOweNKAZeEIiEz2PkybathHWy8snSXGNxsITkf3eyvIIKa8OZ @@ -83,15 +83,15 @@ IjSmiN/ihHtlhV/VSnBJ5PzT/lRknlrJ4kACoz7Pq9jv+aAx5ft/xE9yDa2DYs0q Tfuc9dUYsFjptWYrV6pfEQ+bgo1OGBXORBFcFL+2D7u9JYquKrMgosznHoEkQNLo 0wIDAQAB -----END PUBLIC KEY-----" - } + end let(:config) { Hash.new } let(:actor) { "charmander" } let(:ui) { instance_double("Chef::Knife::UI") } shared_examples_for "key create run command" do - let(:key_create_object) { + let(:key_create_object) do described_class.new(actor, actor_field_name, ui, config) - } + end context "when public_key and key_name weren't passed" do it "raises a Chef::Exceptions::KeyCommandInputError with the proper error message" do @@ -100,11 +100,11 @@ Tfuc9dUYsFjptWYrV6pfEQ+bgo1OGBXORBFcFL+2D7u9JYquKrMgosznHoEkQNLo end context "when the command is run" do - let(:expected_hash) { + let(:expected_hash) do { actor_field_name => "charmander", } - } + end before do allow(File).to receive(:read).and_return(public_key) @@ -120,14 +120,14 @@ Tfuc9dUYsFjptWYrV6pfEQ+bgo1OGBXORBFcFL+2D7u9JYquKrMgosznHoEkQNLo context "when a valid hash is passed" do let(:key_name) { "charmander-key" } let(:valid_expiration_date) { "2020-12-24T21:00:00Z" } - let(:expected_hash) { + let(:expected_hash) do { actor_field_name => "charmander", "public_key" => public_key, "expiration_date" => valid_expiration_date, "key_name" => key_name, } - } + end before do key_create_object.config[:public_key] = "public_key_path" key_create_object.config[:expiration_Date] = valid_expiration_date, @@ -141,12 +141,12 @@ Tfuc9dUYsFjptWYrV6pfEQ+bgo1OGBXORBFcFL+2D7u9JYquKrMgosznHoEkQNLo end context "when public_key is passed" do - let(:expected_hash) { + let(:expected_hash) do { actor_field_name => "charmander", "public_key" => public_key, } - } + end before do key_create_object.config[:public_key] = "public_key_path" end @@ -158,13 +158,13 @@ Tfuc9dUYsFjptWYrV6pfEQ+bgo1OGBXORBFcFL+2D7u9JYquKrMgosznHoEkQNLo end # when public_key is passed context "when public_key isn't passed and key_name is" do - let(:expected_hash) { + let(:expected_hash) do { actor_field_name => "charmander", "name" => "charmander-key", "create_key" => true, } - } + end before do key_create_object.config[:key_name] = "charmander-key" end @@ -176,13 +176,13 @@ Tfuc9dUYsFjptWYrV6pfEQ+bgo1OGBXORBFcFL+2D7u9JYquKrMgosznHoEkQNLo end context "when the server returns a private key" do - let(:expected_hash) { + let(:expected_hash) do { actor_field_name => "charmander", "public_key" => public_key, "private_key" => "super_private", } - } + end before do key_create_object.config[:public_key] = "public_key_path" diff --git a/spec/unit/knife/key_delete_spec.rb b/spec/unit/knife/key_delete_spec.rb index 3da5a9762a..0176f3c71e 100644 --- a/spec/unit/knife/key_delete_spec.rb +++ b/spec/unit/knife/key_delete_spec.rb @@ -80,9 +80,9 @@ describe Chef::Knife::KeyDelete do let(:ui) { instance_double("Chef::Knife::UI") } shared_examples_for "key delete run command" do - let(:key_delete_object) { + let(:key_delete_object) do described_class.new(keyname, actor, actor_field_name, ui) - } + end before do allow_any_instance_of(Chef::Key).to receive(:destroy) diff --git a/spec/unit/knife/key_edit_spec.rb b/spec/unit/knife/key_edit_spec.rb index 9195e97135..244d8bdcc7 100644 --- a/spec/unit/knife/key_edit_spec.rb +++ b/spec/unit/knife/key_edit_spec.rb @@ -75,7 +75,7 @@ describe "key edit commands that inherit knife" do end describe Chef::Knife::KeyEdit do - let(:public_key) { + let(:public_key) do "-----BEGIN PUBLIC KEY----- MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvPo+oNPB7uuNkws0fC02 KxSwdyqPLu0fhI1pOweNKAZeEIiEz2PkybathHWy8snSXGNxsITkf3eyvIIKa8OZ @@ -85,23 +85,23 @@ IjSmiN/ihHtlhV/VSnBJ5PzT/lRknlrJ4kACoz7Pq9jv+aAx5ft/xE9yDa2DYs0q Tfuc9dUYsFjptWYrV6pfEQ+bgo1OGBXORBFcFL+2D7u9JYquKrMgosznHoEkQNLo 0wIDAQAB -----END PUBLIC KEY-----" - } + end let(:config) { Hash.new } let(:actor) { "charmander" } let(:keyname) { "charmander-key" } let(:ui) { instance_double("Chef::Knife::UI") } shared_examples_for "key edit run command" do - let(:key_edit_object) { + let(:key_edit_object) do described_class.new(keyname, actor, actor_field_name, ui, config) - } + end context "when the command is run" do - let(:expected_hash) { + let(:expected_hash) do { actor_field_name => "charmander", } - } + end let(:new_keyname) { "charizard-key" } before do @@ -126,12 +126,12 @@ Tfuc9dUYsFjptWYrV6pfEQ+bgo1OGBXORBFcFL+2D7u9JYquKrMgosznHoEkQNLo end context "when key_name is passed" do - let(:expected_hash) { + let(:expected_hash) do { actor_field_name => "charmander", "name" => new_keyname, } - } + end before do key_edit_object.config[:key_name] = new_keyname allow_any_instance_of(Chef::Key).to receive(:update) @@ -155,14 +155,14 @@ Tfuc9dUYsFjptWYrV6pfEQ+bgo1OGBXORBFcFL+2D7u9JYquKrMgosznHoEkQNLo end context "when public_key, key_name, and expiration_date are passed" do - let(:expected_hash) { + let(:expected_hash) do { actor_field_name => "charmander", "public_key" => public_key, "name" => new_keyname, "expiration_date" => "infinity", } - } + end before do key_edit_object.config[:public_key] = "this-public-key" key_edit_object.config[:key_name] = new_keyname @@ -177,12 +177,12 @@ Tfuc9dUYsFjptWYrV6pfEQ+bgo1OGBXORBFcFL+2D7u9JYquKrMgosznHoEkQNLo end context "when create_key is passed" do - let(:expected_hash) { + let(:expected_hash) do { actor_field_name => "charmander", "create_key" => true, } - } + end before do key_edit_object.config[:create_key] = true @@ -196,12 +196,12 @@ Tfuc9dUYsFjptWYrV6pfEQ+bgo1OGBXORBFcFL+2D7u9JYquKrMgosznHoEkQNLo end context "when public_key is passed" do - let(:expected_hash) { + let(:expected_hash) do { actor_field_name => "charmander", "public_key" => public_key, } - } + end before do allow(key_edit_object).to receive(:update_key_from_hash).and_return(Chef::Key.from_hash(expected_hash)) key_edit_object.config[:public_key] = "public_key_path" @@ -214,13 +214,13 @@ Tfuc9dUYsFjptWYrV6pfEQ+bgo1OGBXORBFcFL+2D7u9JYquKrMgosznHoEkQNLo end # when public_key is passed context "when the server returns a private key" do - let(:expected_hash) { + let(:expected_hash) do { actor_field_name => "charmander", "public_key" => public_key, "private_key" => "super_private", } - } + end before do allow(key_edit_object).to receive(:update_key_from_hash).and_return(Chef::Key.from_hash(expected_hash)) diff --git a/spec/unit/knife/key_list_spec.rb b/spec/unit/knife/key_list_spec.rb index 2d4f0a07bb..82fd1e4a09 100644 --- a/spec/unit/knife/key_list_spec.rb +++ b/spec/unit/knife/key_list_spec.rb @@ -78,9 +78,9 @@ describe Chef::Knife::KeyList do let(:ui) { instance_double("Chef::Knife::UI") } shared_examples_for "key list run command" do - let(:key_list_object) { + let(:key_list_object) do described_class.new(actor, list_method, ui, config) - } + end before do allow(Chef::Key).to receive(list_method).and_return(http_response) @@ -191,26 +191,26 @@ describe Chef::Knife::KeyList do context "when list_method is :list_by_user" do it_should_behave_like "key list run command" do let(:list_method) { :list_by_user } - let(:http_response) { + let(:http_response) do [ { "uri" => "https://api.opscode.piab/users/charmander/keys/non-expired1", "name" => "non-expired1", "expired" => false }, { "uri" => "https://api.opscode.piab/users/charmander/keys/non-expired2", "name" => "non-expired2", "expired" => false }, { "uri" => "https://api.opscode.piab/users/mary/keys/out-of-date", "name" => "out-of-date", "expired" => true }, ] - } + end end end context "when list_method is :list_by_client" do it_should_behave_like "key list run command" do let(:list_method) { :list_by_client } - let(:http_response) { + let(:http_response) do [ { "uri" => "https://api.opscode.piab/organizations/pokemon/clients/charmander/keys/non-expired1", "name" => "non-expired1", "expired" => false }, { "uri" => "https://api.opscode.piab/organizations/pokemon/clients/charmander/keys/non-expired2", "name" => "non-expired2", "expired" => false }, { "uri" => "https://api.opscode.piab/organizations/pokemon/clients/mary/keys/out-of-date", "name" => "out-of-date", "expired" => true }, ] - } + end end end end diff --git a/spec/unit/knife/key_show_spec.rb b/spec/unit/knife/key_show_spec.rb index c161efbe0d..139d4f91a2 100644 --- a/spec/unit/knife/key_show_spec.rb +++ b/spec/unit/knife/key_show_spec.rb @@ -78,19 +78,19 @@ describe Chef::Knife::KeyShow do let(:actor) { "charmander" } let(:keyname) { "charmander" } let(:ui) { instance_double("Chef::Knife::UI") } - let(:expected_hash) { + let(:expected_hash) do { actor_field_name => "charmander", "name" => "charmander-key", "public_key" => "some-public-key", "expiration_date" => "infinity", } - } + end shared_examples_for "key show run command" do - let(:key_show_object) { + let(:key_show_object) do described_class.new(keyname, actor, load_method, ui) - } + end before do allow(key_show_object).to receive(:display_output) diff --git a/spec/unit/knife/status_spec.rb b/spec/unit/knife/status_spec.rb index 473598fd85..c87ea3ad17 100644 --- a/spec/unit/knife/status_spec.rb +++ b/spec/unit/knife/status_spec.rb @@ -34,10 +34,11 @@ describe Chef::Knife::Status do end describe "run" do - let(:opts) {{ filter_result: + let(:opts) 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"] } }} + 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/user_create_spec.rb b/spec/unit/knife/user_create_spec.rb index e708d2d1ad..07d72fd05a 100644 --- a/spec/unit/knife/user_create_spec.rb +++ b/spec/unit/knife/user_create_spec.rb @@ -24,13 +24,13 @@ Chef::Knife::UserCreate.load_deps describe Chef::Knife::UserCreate do let(:knife) { Chef::Knife::UserCreate.new } - let(:stderr) { + let(:stderr) do StringIO.new - } + end - let(:stdout) { + let(:stdout) do StringIO.new - } + end before(:each) do allow(knife.ui).to receive(:stdout).and_return(stdout) diff --git a/spec/unit/knife_spec.rb b/spec/unit/knife_spec.rb index ec1e59d863..f0ec45d59a 100644 --- a/spec/unit/knife_spec.rb +++ b/spec/unit/knife_spec.rb @@ -159,12 +159,13 @@ describe Chef::Knife do describe "the headers include X-Remote-Request-Id" do - let(:headers) {{ "Accept" => "application/json", - "Accept-Encoding" => "gzip;q=1.0,deflate;q=0.6,identity;q=0.3", - "X-Chef-Version" => Chef::VERSION, - "Host" => "api.opscode.piab", - "X-REMOTE-REQUEST-ID" => request_id, - }} + let(:headers) do + { "Accept" => "application/json", + "Accept-Encoding" => "gzip;q=1.0,deflate;q=0.6,identity;q=0.3", + "X-Chef-Version" => Chef::VERSION, + "Host" => "api.opscode.piab", + "X-REMOTE-REQUEST-ID" => request_id, + } end let(:request_id) { "1234" } diff --git a/spec/unit/lwrp_spec.rb b/spec/unit/lwrp_spec.rb index ab7a6302ee..0689d99647 100644 --- a/spec/unit/lwrp_spec.rb +++ b/spec/unit/lwrp_spec.rb @@ -232,9 +232,9 @@ describe "LWRP" do end it "allows to user to user the resource_name" do - expect { + expect do klass.resource_name(:foo) - }.to_not raise_error + end.to_not raise_error end it "returns the set value for the resource" do @@ -741,7 +741,7 @@ describe "LWRP" do end end - let(:recipe) { + let(:recipe) do cookbook_repo = File.expand_path(File.join(File.dirname(__FILE__), "..", "data", "cookbooks")) cookbook_loader = Chef::CookbookLoader.new(cookbook_repo) cookbook_loader.load_cookbooks @@ -750,7 +750,7 @@ describe "LWRP" do events = Chef::EventDispatch::Dispatcher.new run_context = Chef::RunContext.new(node, cookbook_collection, events) Chef::Recipe.new("hjk", "test", run_context) - } + end it "lets you extend the recipe DSL" do expect(Chef::Recipe).to receive(:include).with(MyAwesomeDSLExensionClass) diff --git a/spec/unit/mixin/api_version_request_handling_spec.rb b/spec/unit/mixin/api_version_request_handling_spec.rb index 13b729538c..191dee643b 100644 --- a/spec/unit/mixin/api_version_request_handling_spec.rb +++ b/spec/unit/mixin/api_version_request_handling_spec.rb @@ -50,12 +50,12 @@ describe Chef::Mixin::ApiVersionRequestHandling do context "when x-ops-server-api-version header exists" do let(:min_server_version) { 2 } let(:max_server_version) { 4 } - let(:return_hash) { + let(:return_hash) do { "min_version" => min_server_version, "max_version" => max_server_version, } - } + end before(:each) do allow(response).to receive(:[]).with("x-ops-server-api-version").and_return(Chef::JSONCompat.to_json(return_hash)) diff --git a/spec/unit/mixin/command_spec.rb b/spec/unit/mixin/command_spec.rb index 0c2f6da188..e9f0dacad6 100644 --- a/spec/unit/mixin/command_spec.rb +++ b/spec/unit/mixin/command_spec.rb @@ -49,22 +49,24 @@ describe Chef::Mixin::Command, :volatile do end it "should end when the child process reads from STDIN and a block is given" do - expect {Timeout.timeout(10) do - popen4("ruby -e 'while gets; end'", :waitlast => true) do |pid, stdin, stdout, stderr| - (1..5).each { |i| stdin.puts "#{i}" } + expect do + Timeout.timeout(10) do + popen4("ruby -e 'while gets; end'", :waitlast => true) do |pid, stdin, stdout, stderr| + (1..5).each { |i| stdin.puts "#{i}" } + end end - end - }.not_to raise_error + end.not_to raise_error end describe "when a process detaches but doesn't close STDOUT and STDERR [CHEF-584]" do it "returns immediately after the first child process exits" do - expect {Timeout.timeout(10) do - evil_forker = "exit if fork; 10.times { sleep 1}" - popen4("ruby -e '#{evil_forker}'") do |pid, stdin, stdout, stderr| - end - end}.not_to raise_error + expect do + Timeout.timeout(10) do + evil_forker = "exit if fork; 10.times { sleep 1}" + popen4("ruby -e '#{evil_forker}'") do |pid, stdin, stdout, stderr| + end + end end.not_to raise_error end end @@ -92,10 +94,11 @@ describe Chef::Mixin::Command, :volatile do # btm # Serdar - During Solaris tests, we've seen that processes # are taking a long time to exit. Bumping timeout now to 10. - expect {Timeout.timeout(10) do - evil_forker = "exit if fork; 10.times { sleep 1}" - run_command(:command => "ruby -e '#{evil_forker}'") - end}.not_to raise_error + expect do + Timeout.timeout(10) do + evil_forker = "exit if fork; 10.times { sleep 1}" + run_command(:command => "ruby -e '#{evil_forker}'") + end end.not_to raise_error end end diff --git a/spec/unit/mixin/homebrew_user_spec.rb b/spec/unit/mixin/homebrew_user_spec.rb index de72f6b935..c9a6e6e909 100644 --- a/spec/unit/mixin/homebrew_user_spec.rb +++ b/spec/unit/mixin/homebrew_user_spec.rb @@ -51,11 +51,11 @@ describe Chef::Mixin::HomebrewUser do let(:user) { nil } let(:brew_owner) { 2001 } let(:default_brew_path) { "/usr/local/bin/brew" } - let(:stat_double) { + let(:stat_double) do d = double() expect(d).to receive(:uid).and_return(brew_owner) d - } + end context "debug statement prints owner name" do diff --git a/spec/unit/mixin/params_validate_spec.rb b/spec/unit/mixin/params_validate_spec.rb index dcee123982..0cafb925c8 100644 --- a/spec/unit/mixin/params_validate_spec.rb +++ b/spec/unit/mixin/params_validate_spec.rb @@ -56,7 +56,7 @@ describe Chef::Mixin::ParamsValidate do end it "should allow you to check what kind_of? thing an argument is with kind_of" do - expect { + expect do @vo.validate( { :one => "string" }, { @@ -65,9 +65,9 @@ describe Chef::Mixin::ParamsValidate do }, } ) - }.not_to raise_error + end.not_to raise_error - expect { + expect do @vo.validate( { :one => "string" }, { @@ -76,11 +76,11 @@ describe Chef::Mixin::ParamsValidate do }, } ) - }.to raise_error(ArgumentError) + end.to raise_error(ArgumentError) end it "should allow you to specify an argument is required with required" do - expect { + expect do @vo.validate( { :one => "string" }, { @@ -89,9 +89,9 @@ describe Chef::Mixin::ParamsValidate do }, } ) - }.not_to raise_error + end.not_to raise_error - expect { + expect do @vo.validate( { :two => "string" }, { @@ -100,9 +100,9 @@ describe Chef::Mixin::ParamsValidate do }, } ) - }.to raise_error(ArgumentError) + end.to raise_error(ArgumentError) - expect { + expect do @vo.validate( { :two => "string" }, { @@ -111,11 +111,11 @@ describe Chef::Mixin::ParamsValidate do }, } ) - }.not_to raise_error + end.not_to raise_error end it "should allow you to specify whether an object has a method with respond_to" do - expect { + expect do @vo.validate( { :one => @vo }, { @@ -124,9 +124,9 @@ describe Chef::Mixin::ParamsValidate do }, } ) - }.not_to raise_error + end.not_to raise_error - expect { + expect do @vo.validate( { :one => @vo }, { @@ -135,11 +135,11 @@ describe Chef::Mixin::ParamsValidate do }, } ) - }.to raise_error(ArgumentError) + end.to raise_error(ArgumentError) end it "should allow you to specify whether an object has all the given methods with respond_to and an array" do - expect { + expect do @vo.validate( { :one => @vo }, { @@ -148,9 +148,9 @@ describe Chef::Mixin::ParamsValidate do }, } ) - }.not_to raise_error + end.not_to raise_error - expect { + expect do @vo.validate( { :one => @vo }, { @@ -159,7 +159,7 @@ describe Chef::Mixin::ParamsValidate do }, } ) - }.to raise_error(ArgumentError) + end.to raise_error(ArgumentError) end it "should let you set a default value with default => value" do @@ -173,7 +173,7 @@ describe Chef::Mixin::ParamsValidate do end it "should let you check regular expressions" do - expect { + expect do @vo.validate( { :one => "is good" }, { @@ -182,9 +182,9 @@ describe Chef::Mixin::ParamsValidate do }, } ) - }.not_to raise_error + end.not_to raise_error - expect { + expect do @vo.validate( { :one => "is good" }, { @@ -193,44 +193,44 @@ describe Chef::Mixin::ParamsValidate do }, } ) - }.to raise_error(ArgumentError) + end.to raise_error(ArgumentError) end it "should let you specify your own callbacks" do - expect { + expect do @vo.validate( { :one => "is good" }, { :one => { :callbacks => { - "should be equal to is good" => lambda { |a| + "should be equal to is good" => lambda do |a| a == "is good" - }, + end, }, }, } ) - }.not_to raise_error + end.not_to raise_error - expect { + expect do @vo.validate( { :one => "is bad" }, { :one => { :callbacks => { - "should be equal to 'is good'" => lambda { |a| + "should be equal to 'is good'" => lambda do |a| a == "is good" - }, + end, }, }, } ) - }.to raise_error(ArgumentError) + end.to raise_error(ArgumentError) end it "should let you combine checks" do args = { :one => "is good", :two => "is bad" } - expect { + expect do @vo.validate( args, { @@ -239,9 +239,9 @@ describe Chef::Mixin::ParamsValidate do :respond_to => [ :to_s, :upcase ], :regex => /^is good/, :callbacks => { - "should be your friend" => lambda { |a| + "should be your friend" => lambda do |a| a == "is good" - }, + end, }, :required => true, }, @@ -252,9 +252,9 @@ describe Chef::Mixin::ParamsValidate do :three => { :default => "neato mosquito" }, } ) - }.not_to raise_error + end.not_to raise_error expect(args[:three]).to eq("neato mosquito") - expect { + expect do @vo.validate( args, { @@ -263,9 +263,9 @@ describe Chef::Mixin::ParamsValidate do :respond_to => [ :to_s, :upcase ], :regex => /^is good/, :callbacks => { - "should be your friend" => lambda { |a| + "should be your friend" => lambda do |a| a == "is good" - }, + end, }, :required => true, }, @@ -276,11 +276,12 @@ describe Chef::Mixin::ParamsValidate do :three => { :default => "neato mosquito" }, } ) - }.to raise_error(ArgumentError) + end.to raise_error(ArgumentError) end it "should raise an ArgumentError if the validation map has an unknown check" do - expect { @vo.validate( + expect do + @vo.validate( { :one => "two" }, { :one => { @@ -288,17 +289,17 @@ describe Chef::Mixin::ParamsValidate do }, } ) - }.to raise_error(ArgumentError) + end.to raise_error(ArgumentError) end it "should accept keys that are strings in the options" do - expect { + expect do @vo.validate({ "one" => "two" }, { :one => { :regex => /^two$/ } }) - }.not_to raise_error + end.not_to raise_error end it "should allow an array to kind_of" do - expect { + expect do @vo.validate( { :one => "string" }, { @@ -307,8 +308,8 @@ describe Chef::Mixin::ParamsValidate do }, } ) - }.not_to raise_error - expect { + end.not_to raise_error + expect do @vo.validate( { :one => ["string"] }, { @@ -317,8 +318,8 @@ describe Chef::Mixin::ParamsValidate do }, } ) - }.not_to raise_error - expect { + end.not_to raise_error + expect do @vo.validate( { :one => Hash.new }, { @@ -327,7 +328,7 @@ describe Chef::Mixin::ParamsValidate do }, } ) - }.to raise_error(ArgumentError) + end.to raise_error(ArgumentError) end it "asserts that a value returns false from a predicate method" do @@ -354,15 +355,15 @@ describe Chef::Mixin::ParamsValidate do end it "should raise an ArgumentError when argument is nil and required is true" do - expect { + expect do @vo.set_or_return(:test, nil, { :required => true }) - }.to raise_error(ArgumentError) + end.to raise_error(ArgumentError) end it "should not raise an error when argument is nil and required is false" do - expect { + expect do @vo.set_or_return(:test, nil, { :required => false }) - }.not_to raise_error + end.not_to raise_error end it "should set and return @name, then return @name for foo when argument is nil" do diff --git a/spec/unit/mixin/powershell_out_spec.rb b/spec/unit/mixin/powershell_out_spec.rb index eae5b033f1..8e5f3588ce 100644 --- a/spec/unit/mixin/powershell_out_spec.rb +++ b/spec/unit/mixin/powershell_out_spec.rb @@ -22,9 +22,9 @@ describe Chef::Mixin::PowershellOut do let(:shell_out_class) { Class.new { include Chef::Mixin::PowershellOut } } subject(:object) { shell_out_class.new } let(:architecture) { "something" } - let(:flags) { + let(:flags) do "-NoLogo -NonInteractive -NoProfile -ExecutionPolicy Unrestricted -InputFormat None" - } + end describe "#powershell_out" do it "runs a command and returns the shell_out object" do diff --git a/spec/unit/mixin/powershell_type_coercions_spec.rb b/spec/unit/mixin/powershell_type_coercions_spec.rb index 7f2ecb94e2..6f52abccfb 100644 --- a/spec/unit/mixin/powershell_type_coercions_spec.rb +++ b/spec/unit/mixin/powershell_type_coercions_spec.rb @@ -27,12 +27,12 @@ end describe Chef::Mixin::PowershellTypeCoercions do let (:test_class) { Chef::PSTypeTester.new } - describe '#translate_type' do + describe "#translate_type" do it "single quotes a string" do expect(test_class.translate_type("foo")).to eq("'foo'") end - ["'", '"', '#', "`"].each do |c| + ["'", '"', "#", "`"].each do |c| it "base64 encodes a string that contains #{c}" do expect(test_class.translate_type("#{c}")).to match(Base64.strict_encode64(c)) end diff --git a/spec/unit/mixin/shell_out_spec.rb b/spec/unit/mixin/shell_out_spec.rb index 191ea920c0..bf74ff410e 100644 --- a/spec/unit/mixin/shell_out_spec.rb +++ b/spec/unit/mixin/shell_out_spec.rb @@ -25,7 +25,7 @@ require "spec_helper" describe Chef::Mixin::ShellOut do let(:shell_out_class) { Class.new { include Chef::Mixin::ShellOut } } subject(:shell_out_obj) { shell_out_class.new } - describe '#run_command_compatible_options' do + describe "#run_command_compatible_options" do subject { shell_out_obj.run_command_compatible_options(command_args) } let(:command_args) { [ cmd, options ] } let(:cmd) { "echo '#{rand(1000)}'" } diff --git a/spec/unit/mixin/xml_escape_spec.rb b/spec/unit/mixin/xml_escape_spec.rb index 903c91164e..495ad0662c 100644 --- a/spec/unit/mixin/xml_escape_spec.rb +++ b/spec/unit/mixin/xml_escape_spec.rb @@ -37,7 +37,7 @@ describe Chef::Mixin::XMLEscape do end it "does not modify ASCII strings" do - expect(@escaper.xml_escape('foobarbaz!@#$%^*()')).to eq('foobarbaz!@#$%^*()') + expect(@escaper.xml_escape("foobarbaz!@\#$%^*()")).to eq("foobarbaz!@\#$%^*()") end it "converts invalid bytes to asterisks" do @@ -45,10 +45,10 @@ describe Chef::Mixin::XMLEscape do end it "converts UTF-8 correctly" do - expect(@escaper.xml_escape("\xC2\xA9")).to eq('©') + expect(@escaper.xml_escape("\xC2\xA9")).to eq("©") end it "converts win 1252 characters correctly" do - expect(@escaper.xml_escape("#{0x80.chr}")).to eq('€') + expect(@escaper.xml_escape("#{0x80.chr}")).to eq("€") end end diff --git a/spec/unit/node_spec.rb b/spec/unit/node_spec.rb index 72731c927f..2c8fc4408b 100644 --- a/spec/unit/node_spec.rb +++ b/spec/unit/node_spec.rb @@ -1359,10 +1359,10 @@ describe Chef::Node do end include_examples "to_json equivalent to Chef::JSONCompat.to_json" do - let(:jsonable) { + let(:jsonable) do node.from_file(File.expand_path("nodes/test.example.com.rb", CHEF_SPEC_DATA)) node - } + end end end diff --git a/spec/unit/platform/query_helpers_spec.rb b/spec/unit/platform/query_helpers_spec.rb index 49da6a95f0..aa2b3c1f11 100644 --- a/spec/unit/platform/query_helpers_spec.rb +++ b/spec/unit/platform/query_helpers_spec.rb @@ -151,7 +151,7 @@ describe "Chef::Platform#supports_msi?" do end end -describe 'Chef::Platform#supports_dsc?' do +describe "Chef::Platform#supports_dsc?" do it "returns false if powershell is not present" do node = Chef::Node.new expect(Chef::Platform.supports_dsc?(node)).to be_falsey @@ -174,7 +174,7 @@ describe 'Chef::Platform#supports_dsc?' do end end -describe 'Chef::Platform#supports_dsc_invoke_resource?' do +describe "Chef::Platform#supports_dsc_invoke_resource?" do it "returns false if powershell is not present" do node = Chef::Node.new expect(Chef::Platform.supports_dsc_invoke_resource?(node)).to be_falsey @@ -195,7 +195,7 @@ describe 'Chef::Platform#supports_dsc_invoke_resource?' do end end -describe 'Chef::Platform#dsc_refresh_mode_disabled?' do +describe "Chef::Platform#dsc_refresh_mode_disabled?" do let(:node) { instance_double("Chef::Node") } let(:cmdlet) { instance_double("Chef::Util::Powershell::Cmdlet") } let(:cmdlet_result) { instance_double("Chef::Util::Powershell::CmdletResult") } diff --git a/spec/unit/property_spec.rb b/spec/unit/property_spec.rb index f5eb361426..50ff3434f6 100644 --- a/spec/unit/property_spec.rb +++ b/spec/unit/property_spec.rb @@ -1103,18 +1103,18 @@ describe "Chef::Resource.property" do context "property_type" do it "property_types validate their defaults" do - expect { + expect do module ::PropertySpecPropertyTypes include Chef::Mixin::Properties property_type(is: [:a, :b], default: :c) end - }.to raise_error(Chef::Exceptions::DeprecatedFeatureError, /Default value :c is invalid for property <property type>./) - expect { + end.to raise_error(Chef::Exceptions::DeprecatedFeatureError, /Default value :c is invalid for property <property type>./) + expect do module ::PropertySpecPropertyTypes include Chef::Mixin::Properties property_type(is: [:a, :b], default: :b) end - }.not_to raise_error + end.not_to raise_error end context "With property_type ABType (is: [:a, :b]) and CDType (is: [:c, :d])" do diff --git a/spec/unit/provider/cookbook_file_spec.rb b/spec/unit/provider/cookbook_file_spec.rb index b375784d00..f49cc7d3da 100644 --- a/spec/unit/provider/cookbook_file_spec.rb +++ b/spec/unit/provider/cookbook_file_spec.rb @@ -26,12 +26,12 @@ describe Chef::Provider::CookbookFile do let(:node) { double("Chef::Node") } let(:events) { double("Chef::Events").as_null_object } # mock all the methods let(:run_context) { double("Chef::RunContext", :node => node, :events => events) } - let(:enclosing_directory) { + let(:enclosing_directory) do canonicalize_path(File.expand_path(File.join(CHEF_SPEC_DATA, "templates"))) - } - let(:resource_path) { + end + let(:resource_path) do canonicalize_path(File.expand_path(File.join(enclosing_directory, "seattle.txt"))) - } + end # Subject diff --git a/spec/unit/provider/cron/unix_spec.rb b/spec/unit/provider/cron/unix_spec.rb index 83e0f431bf..5e1fcb35ab 100644 --- a/spec/unit/provider/cron/unix_spec.rb +++ b/spec/unit/provider/cron/unix_spec.rb @@ -91,9 +91,9 @@ describe Chef::Provider::Cron::Unix do let (:exitstatus) { 2 } it "should raise an exception if another error occurs" do - expect { + expect do provider.send(:read_crontab) - }.to raise_error(Chef::Exceptions::Cron, "Error determining state of #{new_resource.name}, exit: 2") + end.to raise_error(Chef::Exceptions::Cron, "Error determining state of #{new_resource.name}, exit: 2") end it "logs the crontab output to debug" do @@ -130,9 +130,9 @@ describe Chef::Provider::Cron::Unix do context "when writing the crontab fails" do let(:exitstatus) { 1 } it "should raise an exception if the command returns non-zero" do - expect { + expect do provider.send(:write_crontab, "Foo") - }.to raise_error(Chef::Exceptions::Cron, /Error updating state of #{new_resource.name}, exit: 1/) + end.to raise_error(Chef::Exceptions::Cron, /Error updating state of #{new_resource.name}, exit: 1/) end end end diff --git a/spec/unit/provider/cron_spec.rb b/spec/unit/provider/cron_spec.rb index 9e849743e7..64916ef454 100644 --- a/spec/unit/provider/cron_spec.rb +++ b/spec/unit/provider/cron_spec.rb @@ -199,9 +199,9 @@ CRONTAB # Chef Name: foo[bar] (baz) 21 */4 * * * some_prog 1234567 CRONTAB - expect { + expect do @provider.load_current_resource - }.not_to raise_error + end.not_to raise_error end end diff --git a/spec/unit/provider/deploy_spec.rb b/spec/unit/provider/deploy_spec.rb index 62d9123e7b..e69714280c 100644 --- a/spec/unit/provider/deploy_spec.rb +++ b/spec/unit/provider/deploy_spec.rb @@ -167,9 +167,9 @@ describe Chef::Provider::Deploy do allow(@provider).to receive(:deploy) { raise "Unexpected error" } allow(@provider).to receive(:previous_release_path).and_return("previous_release") expect(@provider).not_to receive(:rollback) - expect { + expect do @provider.run_action(:deploy) - }.to raise_exception(RuntimeError, "Unexpected error") + end.to raise_exception(RuntimeError, "Unexpected error") end it "rollbacks to previous release if error happens on deploy" do @@ -178,9 +178,9 @@ describe Chef::Provider::Deploy do allow(@provider).to receive(:deploy) { raise "Unexpected error" } allow(@provider).to receive(:previous_release_path).and_return("previous_release") expect(@provider).to receive(:rollback) - expect { + expect do @provider.run_action(:deploy) - }.to raise_exception(RuntimeError, "Unexpected error") + end.to raise_exception(RuntimeError, "Unexpected error") end describe "on systems without broken Dir.glob results" do @@ -232,17 +232,17 @@ describe Chef::Provider::Deploy do #FileUtils.should_receive(:rm_rf).with("/my/deploy/dir/releases/20040815162342") #@provider.run_action(:rollback) #@provider.release_path.should eql(NIL) -- no check needed since assertions will fail - expect { + expect do @provider.run_action(:rollback) - }.to raise_exception(RuntimeError, "There is no release to rollback to!") + end.to raise_exception(RuntimeError, "There is no release to rollback to!") end it "an exception is raised when there are no releases" do all_releases = [] allow(Dir).to receive(:glob).with("/my/deploy/dir/releases/*").and_return(all_releases) - expect { + expect do @provider.run_action(:rollback) - }.to raise_exception(RuntimeError, "There is no release to rollback to!") + end.to raise_exception(RuntimeError, "There is no release to rollback to!") end end end diff --git a/spec/unit/provider/dsc_resource_spec.rb b/spec/unit/provider/dsc_resource_spec.rb index 2a00c2ed7f..34eb9727f8 100644 --- a/spec/unit/provider/dsc_resource_spec.rb +++ b/spec/unit/provider/dsc_resource_spec.rb @@ -28,11 +28,11 @@ describe Chef::Provider::DscResource do end context "when Powershell does not support Invoke-DscResource" do - let (:node) { + let (:node) do node = Chef::Node.new node.automatic[:languages][:powershell][:version] = "4.0" node - } + end it "raises a ProviderNotFound exception" do expect(provider).not_to receive(:meta_configuration) expect { provider.run_action(:run) }.to raise_error( @@ -44,11 +44,11 @@ describe Chef::Provider::DscResource do context "when RefreshMode is not set to Disabled" do context "and the WMF 5 is a preview release" do - let (:node) { + let (:node) do node = Chef::Node.new node.automatic[:languages][:powershell][:version] = "5.0.10018.0" node - } + end it "raises an exception" do expect(provider).to receive(:dsc_refresh_mode_disabled?).and_return(false) expect { provider.run_action(:run) }.to raise_error( @@ -56,11 +56,11 @@ describe Chef::Provider::DscResource do end end context "and the WMF is 5 RTM or newer" do - let (:node) { + let (:node) do node = Chef::Node.new node.automatic[:languages][:powershell][:version] = "5.0.10586.0" node - } + end it "does not raises an exception" do expect(provider).to receive(:test_resource) expect(provider).to receive(:set_resource) @@ -72,11 +72,11 @@ describe Chef::Provider::DscResource do end context "when the LCM supports Invoke-DscResource" do - let (:node) { + let (:node) do node = Chef::Node.new node.automatic[:languages][:powershell][:version] = "5.0.10018.0" node - } + end let (:resource_result) { double("CmdletResult", return_value: { "InDesiredState" => true }, stream: "description") } let (:invoke_dsc_resource) { double("cmdlet", run!: resource_result) } let (:store) { double("ResourceStore", find: resource_records) } @@ -153,10 +153,11 @@ describe Chef::Provider::DscResource do end context "multiple resource are found" do - let (:resource_records) { [ + let (:resource_records) do + [ { "Module" => { "Name" => "ModuleName1" } }, { "Module" => { "Name" => "ModuleName2" } }, - ] } + ] 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 3877a37e61..5f091b8813 100644 --- a/spec/unit/provider/dsc_script_spec.rb +++ b/spec/unit/provider/dsc_script_spec.rb @@ -23,11 +23,11 @@ require "spec_helper" describe Chef::Provider::DscScript do context "when DSC is available" do - let (:node) { + let (:node) do node = Chef::Node.new node.automatic[:languages][:powershell][:version] = "4.0" node - } + end let (:events) { Chef::EventDispatch::Dispatcher.new } let (:run_context) { Chef::RunContext.new(node, {}, events) } let (:resource) { Chef::Resource::DscScript.new("script", run_context) } @@ -35,7 +35,7 @@ describe Chef::Provider::DscScript do Chef::Provider::DscScript.new(resource, run_context) end - describe '#load_current_resource' do + describe "#load_current_resource" do it "describes the resource as converged if there were 0 DSC resources" do allow(provider).to receive(:run_configuration).with(:test).and_return([]) provider.load_current_resource @@ -75,7 +75,7 @@ describe Chef::Provider::DscScript do end end - describe '#generate_configuration_document' do + describe "#generate_configuration_document" do # I think integration tests should cover these cases it "uses configuration_document_from_script_path when a dsc script file is given" do @@ -123,7 +123,7 @@ describe Chef::Provider::DscScript do end end - describe '#generate_description' do + describe "#generate_description" do it "removes the resource name from the beginning of any log line from the LCM" do dsc_resource_info = Chef::Util::DSC::ResourceInfo.new("resourcename", true, ["resourcename doing something", "lastline"]) provider.instance_variable_set("@dsc_resources_info", [dsc_resource_info]) @@ -156,16 +156,16 @@ describe Chef::Provider::DscScript do it "raises an exception for powershell version '#{version}'" do node.automatic[:languages][:powershell][:version] = version - expect { + expect do provider.run_action(:run) - }.to raise_error(Chef::Exceptions::ProviderNotFound) + end.to raise_error(Chef::Exceptions::ProviderNotFound) end end it "raises an exception if Powershell is not present" do - expect { + expect do provider.run_action(:run) - }.to raise_error(Chef::Exceptions::ProviderNotFound) + end.to raise_error(Chef::Exceptions::ProviderNotFound) end end diff --git a/spec/unit/provider/env/windows_spec.rb b/spec/unit/provider/env/windows_spec.rb index abe2344443..5ddc1d6f91 100644 --- a/spec/unit/provider/env/windows_spec.rb +++ b/spec/unit/provider/env/windows_spec.rb @@ -24,16 +24,16 @@ describe Chef::Provider::Env::Windows, :windows_only do let(:run_context) { Chef::RunContext.new(node, {}, events) } context "when environment variable is not PATH" do - let(:new_resource) { + let(:new_resource) do new_resource = Chef::Resource::Env.new("CHEF_WINDOWS_ENV_TEST") new_resource.value("foo") new_resource - } - let(:provider) { + end + let(:provider) do provider = Chef::Provider::Env::Windows.new(new_resource, run_context) allow(provider).to receive(:env_obj).and_return(double("null object").as_null_object) provider - } + end describe "action_create" do before do @@ -76,16 +76,16 @@ describe Chef::Provider::Env::Windows, :windows_only do describe "for PATH" do let(:system_root) { "%SystemRoot%" } let(:system_root_value) { 'D:\Windows' } - let(:new_resource) { + let(:new_resource) do new_resource = Chef::Resource::Env.new("PATH") new_resource.value(system_root) new_resource - } - let(:provider) { + end + let(:provider) do provider = Chef::Provider::Env::Windows.new(new_resource, run_context) allow(provider).to receive(:env_obj).and_return(double("null object").as_null_object) provider - } + end before do stub_const("ENV", { "PATH" => "" }) diff --git a/spec/unit/provider/file/content_spec.rb b/spec/unit/provider/file/content_spec.rb index a31c75baf4..f840d92dbb 100644 --- a/spec/unit/provider/file/content_spec.rb +++ b/spec/unit/provider/file/content_spec.rb @@ -28,12 +28,12 @@ describe Chef::Provider::File::Content do double("Chef::Provider::File::Resource (current)") end - let(:enclosing_directory) { + let(:enclosing_directory) do canonicalize_path(File.expand_path(File.join(CHEF_SPEC_DATA, "templates"))) - } - let(:resource_path) { + end + let(:resource_path) do canonicalize_path(File.expand_path(File.join(enclosing_directory, "seattle.txt"))) - } + end let(:new_resource) do double("Chef::Provider::File::Resource (new)", :name => "seattle.txt", :path => resource_path) @@ -77,9 +77,9 @@ describe Chef::Provider::File::Content do end context "when creating a tempfiles in destdir fails" do - let(:enclosing_directory) { + let(:enclosing_directory) do canonicalize_path("/nonexisting/path") - } + end it "returns a tempfile in the tempdir when :file_deployment_uses_destdir is set to :auto" do Chef::Config[:file_staging_uses_destdir] = :auto diff --git a/spec/unit/provider/file_spec.rb b/spec/unit/provider/file_spec.rb index 11bef8a44d..d8d4ed2286 100644 --- a/spec/unit/provider/file_spec.rb +++ b/spec/unit/provider/file_spec.rb @@ -35,12 +35,12 @@ describe Chef::Provider::File do let(:node) { double("Chef::Node") } let(:events) { double("Chef::Events").as_null_object } # mock all the methods let(:run_context) { double("Chef::RunContext", :node => node, :events => events) } - let(:enclosing_directory) { + let(:enclosing_directory) do canonicalize_path(File.expand_path(File.join(CHEF_SPEC_DATA, "templates"))) - } - let(:resource_path) { + end + let(:resource_path) do canonicalize_path(File.expand_path(File.join(enclosing_directory, "seattle.txt"))) - } + end # Subject diff --git a/spec/unit/provider/launchd_spec.rb b/spec/unit/provider/launchd_spec.rb index 4286405ef5..2893044833 100644 --- a/spec/unit/provider/launchd_spec.rb +++ b/spec/unit/provider/launchd_spec.rb @@ -51,7 +51,8 @@ describe Chef::Provider::Launchd do </plist> XML - let(:test_hash) do { + let(:test_hash) do + { "Label" => "call.mom.weekly", "Program" => "/Library/scripts/call_mom.sh", "StartCalendarInterval" => { diff --git a/spec/unit/provider/mount/solaris_spec.rb b/spec/unit/provider/mount/solaris_spec.rb index 51ace83470..264c8b9b36 100644 --- a/spec/unit/provider/mount/solaris_spec.rb +++ b/spec/unit/provider/mount/solaris_spec.rb @@ -41,7 +41,7 @@ describe Chef::Provider::Mount::Solaris, :unix_only do let(:options) { nil } - let(:new_resource) { + let(:new_resource) do new_resource = Chef::Resource::Mount.new(mountpoint) new_resource.device device new_resource.device_type device_type @@ -50,13 +50,13 @@ describe Chef::Provider::Mount::Solaris, :unix_only do new_resource.options options new_resource.supports :remount => false new_resource - } + end - let(:provider) { + let(:provider) do Chef::Provider::Mount::Solaris.new(new_resource, run_context) - } + end - let(:vfstab_file_contents) { + let(:vfstab_file_contents) do <<-EOF.gsub /^\s*/, "" #device device mount FS fsck mount mount #to mount to fsck point type pass at boot options @@ -74,21 +74,21 @@ describe Chef::Provider::Mount::Solaris, :unix_only do # ufs /dev/dsk/c0t2d0s7 /dev/rdsk/c0t2d0s7 /mnt/foo ufs 2 yes - EOF - } + end - let(:vfstab_file) { + let(:vfstab_file) do t = Tempfile.new("rspec-vfstab") t.write(vfstab_file_contents) t.close t - } + end - let(:mount_output) { + let(:mount_output) do <<-EOF.gsub /^\s*/, "" /dev/dsk/c0t0d0s0 on / type ufs read/write/setuid/intr/largefiles/xattr/onerror=panic/dev=2200000 on Tue Jul 31 22:34:46 2012 /dev/dsk/c0t2d0s7 on /mnt/foo type ufs read/write/setuid/intr/largefiles/xattr/onerror=panic/dev=2200007 on Tue Jul 31 22:34:46 2012 EOF - } + end before do stub_const("Chef::Provider::Mount::Solaris::VFSTAB", vfstab_file.path ) @@ -214,7 +214,7 @@ describe Chef::Provider::Mount::Solaris, :unix_only do describe "#load_current_resource" do context "when loading a normal UFS filesystem with noauto, don't mount at boot" do - let(:vfstab_file_contents) { + let(:vfstab_file_contents) do <<-EOF.gsub /^\s*/, "" #device device mount FS fsck mount mount #to mount to fsck point type pass at boot options @@ -232,7 +232,7 @@ describe Chef::Provider::Mount::Solaris, :unix_only do # ufs /dev/dsk/c0t2d0s7 /dev/rdsk/c0t2d0s7 /mnt/foo ufs 2 no - EOF - } + end before do provider.load_current_resource @@ -244,16 +244,16 @@ describe Chef::Provider::Mount::Solaris, :unix_only do end context "when the device is an smbfs mount" do - let(:mount_output) { + let(:mount_output) do <<-EOF.gsub /^\s*/, "" //solarsystem/tmp on /mnt type smbfs read/write/setuid/devices/dev=5080000 on Tue Mar 29 11:40:18 2011 EOF - } - let(:vfstab_file_contents) { + end + let(:vfstab_file_contents) do <<-EOF.gsub /^\s*/, "" //WORKGROUP;username:password@host/share - /mountpoint smbfs - no fileperms=0777,dirperms=0777 EOF - } + end let(:fsck_device) { "-" } @@ -263,17 +263,17 @@ describe Chef::Provider::Mount::Solaris, :unix_only do end context "when the device is an NFS mount" do - let(:mount_output) { + let(:mount_output) do <<-EOF.gsub /^\s*/, "" cartman:/share2 on /cartman type nfs rsize=32768,wsize=32768,NFSv4,dev=4000004 on Tue Mar 29 11:40:18 2011 EOF - } + end - let(:vfstab_file_contents) { + let(:vfstab_file_contents) do <<-EOF.gsub /^\s*/, "" cartman:/share2 - /cartman nfs - yes rw,soft EOF - } + end let(:fsck_device) { "-" } @@ -334,17 +334,17 @@ describe Chef::Provider::Mount::Solaris, :unix_only do let(:target) { "/dev/mapper/target" } - let(:mount_output) { + let(:mount_output) do <<-EOF.gsub /^\s*/, "" #{target} on /mnt/foo type ufs read/write/setuid/intr/largefiles/xattr/onerror=panic/dev=2200007 on Tue Jul 31 22:34:46 2012 EOF - } + end - let(:vfstab_file_contents) { + let(:vfstab_file_contents) do <<-EOF.gsub /^\s*/, "" #{target} /dev/rdsk/c0t2d0s7 /mnt/foo ufs 2 yes - EOF - } + end before do expect(File).to receive(:symlink?).with(device).at_least(:once).and_return(true) @@ -371,17 +371,17 @@ describe Chef::Provider::Mount::Solaris, :unix_only do let(:absolute_target) { File.expand_path(target, File.dirname(device)) } - let(:mount_output) { + let(:mount_output) do <<-EOF.gsub /^\s*/, "" #{absolute_target} on /mnt/foo type ufs read/write/setuid/intr/largefiles/xattr/onerror=panic/dev=2200007 on Tue Jul 31 22:34:46 2012 EOF - } + end - let(:vfstab_file_contents) { + let(:vfstab_file_contents) do <<-EOF.gsub /^\s*/, "" #{absolute_target} /dev/rdsk/c0t2d0s7 /mnt/foo ufs 2 yes - EOF - } + end before do expect(File).to receive(:symlink?).with(device).at_least(:once).and_return(true) @@ -404,12 +404,12 @@ describe Chef::Provider::Mount::Solaris, :unix_only do end context "when the matching mount point is last in the mounts list" do - let(:mount_output) { + let(:mount_output) do <<-EOF.gsub /^\s*/, "" /dev/dsk/c0t0d0s0 on /mnt/foo type ufs read/write/setuid/intr/largefiles/xattr/onerror=panic/dev=2200000 on Tue Jul 31 22:34:46 2012 /dev/dsk/c0t2d0s7 on /mnt/foo type ufs read/write/setuid/intr/largefiles/xattr/onerror=panic/dev=2200007 on Tue Jul 31 22:34:46 2012 EOF - } + end it "should set mounted true" do provider.load_current_resource() expect(provider.current_resource.mounted).to be_truthy @@ -417,12 +417,12 @@ describe Chef::Provider::Mount::Solaris, :unix_only do end context "when the matching mount point is not last in the mounts list" do - let(:mount_output) { + let(:mount_output) do <<-EOF.gsub /^\s*/, "" /dev/dsk/c0t2d0s7 on /mnt/foo type ufs read/write/setuid/intr/largefiles/xattr/onerror=panic/dev=2200007 on Tue Jul 31 22:34:46 2012 /dev/dsk/c0t0d0s0 on /mnt/foo type ufs read/write/setuid/intr/largefiles/xattr/onerror=panic/dev=2200000 on Tue Jul 31 22:34:46 2012 EOF - } + end it "should set mounted false" do provider.load_current_resource() expect(provider.current_resource.mounted).to be_falsey @@ -430,11 +430,11 @@ describe Chef::Provider::Mount::Solaris, :unix_only do end context "when the matching mount point is not in the mounts list (mountpoint wrong)" do - let(:mount_output) { + let(:mount_output) do <<-EOF.gsub /^\s*/, "" /dev/dsk/c0t2d0s7 on /mnt/foob type ufs read/write/setuid/intr/largefiles/xattr/onerror=panic/dev=2200007 on Tue Jul 31 22:34:46 2012 EOF - } + end it "should set mounted false" do provider.load_current_resource() expect(provider.current_resource.mounted).to be_falsey @@ -442,11 +442,11 @@ describe Chef::Provider::Mount::Solaris, :unix_only do end context "when the matching mount point is not in the mounts list (raw device wrong)" do - let(:mount_output) { + let(:mount_output) do <<-EOF.gsub /^\s*/, "" /dev/dsk/c0t2d0s72 on /mnt/foo type ufs read/write/setuid/intr/largefiles/xattr/onerror=panic/dev=2200007 on Tue Jul 31 22:34:46 2012 EOF - } + end it "should set mounted false" do provider.load_current_resource() expect(provider.current_resource.mounted).to be_falsey @@ -454,12 +454,12 @@ describe Chef::Provider::Mount::Solaris, :unix_only do end context "when the mount point is last in fstab" do - let(:vfstab_file_contents) { + let(:vfstab_file_contents) do <<-EOF.gsub /^\s*/, "" /dev/dsk/c0t2d0s72 /dev/rdsk/c0t2d0s7 /mnt/foo ufs 2 yes - /dev/dsk/c0t2d0s7 /dev/rdsk/c0t2d0s7 /mnt/foo ufs 2 yes - EOF - } + end it "should set enabled to true" do provider.load_current_resource @@ -468,12 +468,12 @@ describe Chef::Provider::Mount::Solaris, :unix_only do end context "when the mount point is not last in fstab and is a substring of another mount" do - let(:vfstab_file_contents) { + let(:vfstab_file_contents) do <<-EOF.gsub /^\s*/, "" /dev/dsk/c0t2d0s7 /dev/rdsk/c0t2d0s7 /mnt/foo ufs 2 yes - /dev/dsk/c0t2d0s72 /dev/rdsk/c0t2d0s7 /mnt/foo/bar ufs 2 yes - EOF - } + end it "should set enabled to true" do provider.load_current_resource @@ -482,12 +482,12 @@ describe Chef::Provider::Mount::Solaris, :unix_only do end context "when the mount point is not last in fstab" do - let(:vfstab_file_contents) { + let(:vfstab_file_contents) do <<-EOF.gsub /^\s*/, "" /dev/dsk/c0t2d0s7 /dev/rdsk/c0t2d0s7 /mnt/foo ufs 2 yes - /dev/dsk/c0t2d0s72 /dev/rdsk/c0t2d0s72 /mnt/foo ufs 2 yes - EOF - } + end it "should set enabled to false" do provider.load_current_resource @@ -496,11 +496,11 @@ describe Chef::Provider::Mount::Solaris, :unix_only do end context "when the mount point is not in fstab, but the mountpoint is a substring of one that is" do - let(:vfstab_file_contents) { + let(:vfstab_file_contents) do <<-EOF.gsub /^\s*/, "" /dev/dsk/c0t2d0s7 /dev/rdsk/c0t2d0s7 /mnt/foob ufs 2 yes - EOF - } + end it "should set enabled to false" do provider.load_current_resource @@ -509,11 +509,11 @@ describe Chef::Provider::Mount::Solaris, :unix_only do end context "when the mount point is not in fstab, but the device is a substring of one that is" do - let(:vfstab_file_contents) { + let(:vfstab_file_contents) do <<-EOF.gsub /^\s*/, "" /dev/dsk/c0t2d0s72 /dev/rdsk/c0t2d0s7 /mnt/foo ufs 2 yes - EOF - } + end it "should set enabled to false" do provider.load_current_resource @@ -522,11 +522,11 @@ describe Chef::Provider::Mount::Solaris, :unix_only do end context "when the mountpoint line is commented out" do - let(:vfstab_file_contents) { + let(:vfstab_file_contents) do <<-EOF.gsub /^\s*/, "" #/dev/dsk/c0t2d0s7 /dev/rdsk/c0t2d0s7 /mnt/foo ufs 2 yes - EOF - } + end it "should set enabled to false" do provider.load_current_resource diff --git a/spec/unit/provider/package/chocolatey_spec.rb b/spec/unit/provider/package/chocolatey_spec.rb index 8344c3d0ec..704ef1aef2 100644 --- a/spec/unit/provider/package/chocolatey_spec.rb +++ b/spec/unit/provider/package/chocolatey_spec.rb @@ -462,18 +462,18 @@ describe "behavior when Chocolatey is not installed" do Chef::Provider::Package::Chocolatey.new(new_resource, run_context) end - before { + before do # the shellout sometimes returns "", but test nil to be safe. allow(provider).to receive(:choco_install_path).and_return(nil) provider.instance_variable_set("@choco_install_path", nil) # we don't care what this returns, but we have to let it be called. allow(provider).to receive(:shell_out!).and_return(double(:stdout => "")) - } + end - let(:error_regex) { + let(:error_regex) do /Could not locate.*install.*cookbook.*PowerShell.*GetEnvironmentVariable/m - } + end context "#choco_exe" do it "triggers a MissingLibrary exception when Chocolatey is not installed" do diff --git a/spec/unit/provider/package/yum_spec.rb b/spec/unit/provider/package/yum_spec.rb index 4bc28f130a..e9aec933e2 100644 --- a/spec/unit/provider/package/yum_spec.rb +++ b/spec/unit/provider/package/yum_spec.rb @@ -312,7 +312,8 @@ describe Chef::Provider::Package::Yum do end context "when the package name isn't found" do - let(:yum_cache) { double( + let(:yum_cache) do + double( "Chef::Provider::Yum::YumCache", :reload_installed => true, :reset => true, @@ -322,7 +323,7 @@ describe Chef::Provider::Package::Yum do :version_available? => true, :disable_extra_repo_control => true ) - } + end before do allow(Chef::Provider::Package::Yum::YumCache).to receive(:instance).and_return(yum_cache) @@ -1063,21 +1064,21 @@ describe Chef::Provider::Package::Yum::RPMVersion do end it "should raise an error unless passed 1 or 3 args" do - expect { + expect do Chef::Provider::Package::Yum::RPMVersion.new() - }.to raise_error(ArgumentError) - expect { + end.to raise_error(ArgumentError) + expect do Chef::Provider::Package::Yum::RPMVersion.new("1:1.6.5-9.36.el5") - }.not_to raise_error - expect { + end.not_to raise_error + expect do Chef::Provider::Package::Yum::RPMVersion.new("1:1.6.5-9.36.el5", "extra") - }.to raise_error(ArgumentError) - expect { + end.to raise_error(ArgumentError) + expect do Chef::Provider::Package::Yum::RPMVersion.new("1", "1.6.5", "9.36.el5") - }.not_to raise_error - expect { + end.not_to raise_error + expect do Chef::Provider::Package::Yum::RPMVersion.new("1", "1.6.5", "9.36.el5", "extra") - }.to raise_error(ArgumentError) + end.to raise_error(ArgumentError) end # thanks version_class_spec.rb! @@ -1260,30 +1261,30 @@ describe Chef::Provider::Package::Yum::RPMPackage do end it "should raise an error unless passed 4 or 6 args" do - expect { + expect do Chef::Provider::Package::Yum::RPMPackage.new() - }.to raise_error(ArgumentError) - expect { + end.to raise_error(ArgumentError) + expect do Chef::Provider::Package::Yum::RPMPackage.new("testing") - }.to raise_error(ArgumentError) - expect { + end.to raise_error(ArgumentError) + expect do Chef::Provider::Package::Yum::RPMPackage.new("testing", "1:1.6.5-9.36.el5") - }.to raise_error(ArgumentError) - expect { + end.to raise_error(ArgumentError) + expect do Chef::Provider::Package::Yum::RPMPackage.new("testing", "1:1.6.5-9.36.el5", "x86_64") - }.to raise_error(ArgumentError) - expect { + end.to raise_error(ArgumentError) + expect do Chef::Provider::Package::Yum::RPMPackage.new("testing", "1:1.6.5-9.36.el5", "x86_64", []) - }.not_to raise_error - expect { + end.not_to raise_error + expect do Chef::Provider::Package::Yum::RPMPackage.new("testing", "1", "1.6.5", "9.36.el5", "x86_64") - }.to raise_error(ArgumentError) - expect { + end.to raise_error(ArgumentError) + expect do Chef::Provider::Package::Yum::RPMPackage.new("testing", "1", "1.6.5", "9.36.el5", "x86_64", []) - }.not_to raise_error - expect { + end.not_to raise_error + expect do Chef::Provider::Package::Yum::RPMPackage.new("testing", "1", "1.6.5", "9.36.el5", "x86_64", [], "extra") - }.to raise_error(ArgumentError) + end.to raise_error(ArgumentError) end describe "<=>" do @@ -1397,27 +1398,27 @@ describe Chef::Provider::Package::Yum::RPMDependency do end it "should raise an error unless passed 3 or 5 args" do - expect { + expect do Chef::Provider::Package::Yum::RPMDependency.new() - }.to raise_error(ArgumentError) - expect { + end.to raise_error(ArgumentError) + expect do Chef::Provider::Package::Yum::RPMDependency.new("testing") - }.to raise_error(ArgumentError) - expect { + end.to raise_error(ArgumentError) + expect do Chef::Provider::Package::Yum::RPMDependency.new("testing", "1:1.6.5-9.36.el5") - }.to raise_error(ArgumentError) - expect { + end.to raise_error(ArgumentError) + expect do Chef::Provider::Package::Yum::RPMDependency.new("testing", "1:1.6.5-9.36.el5", :==) - }.not_to raise_error - expect { + end.not_to raise_error + expect do Chef::Provider::Package::Yum::RPMDependency.new("testing", "1:1.6.5-9.36.el5", :==, "extra") - }.to raise_error(ArgumentError) - expect { + end.to raise_error(ArgumentError) + expect do Chef::Provider::Package::Yum::RPMDependency.new("testing", "1", "1.6.5", "9.36.el5", :==) - }.not_to raise_error - expect { + end.not_to raise_error + expect do Chef::Provider::Package::Yum::RPMDependency.new("testing", "1", "1.6.5", "9.36.el5", :==, "extra") - }.to raise_error(ArgumentError) + end.to raise_error(ArgumentError) end describe "parse" do @@ -1485,12 +1486,12 @@ describe Chef::Provider::Package::Yum::RPMDependency do it "should raise an error unless a RPMDependency is passed" do @rpmprovide = Chef::Provider::Package::Yum::RPMDependency.new("testing", "1:1.6.5-9.36.el5", :==) @rpmrequire = Chef::Provider::Package::Yum::RPMDependency.new("testing", "1:1.6.5-9.36.el5", :>=) - expect { + expect do @rpmprovide.satisfy?("hi") - }.to raise_error(ArgumentError) - expect { + end.to raise_error(ArgumentError) + expect do @rpmprovide.satisfy?(@rpmrequire) - }.not_to raise_error + end.not_to raise_error end it "should validate dependency satisfaction logic for standard examples" do @@ -1712,12 +1713,12 @@ describe Chef::Provider::Package::Yum::RPMDb do it "should raise an error unless a RPMDependency is passed" do @rpmprovide = Chef::Provider::Package::Yum::RPMDependency.new("testing", "1:1.6.5-9.36.el5", :==) @rpmrequire = Chef::Provider::Package::Yum::RPMDependency.new("testing", "1:1.6.5-9.36.el5", :>=) - expect { + expect do @rpmdb.whatprovides("hi") - }.to raise_error(ArgumentError) - expect { + end.to raise_error(ArgumentError) + expect do @rpmdb.whatprovides(@rpmrequire) - }.not_to raise_error + end.not_to raise_error end it "should return an Array of packages statisfying a RPMDependency" do @@ -1748,13 +1749,13 @@ describe Chef::Provider::Package::Yum::YumCache do end end - let(:yum_exe) { + let(:yum_exe) do StringIO.new("#!/usr/bin/python\n\naldsjfa\ldsajflkdsjf\lajsdfj") - } + end - let(:bin_exe) { + let(:bin_exe) do StringIO.new(SecureRandom.random_bytes) - } + end before(:each) do @stdin = double("STDIN", :nil_object => true) diff --git a/spec/unit/provider/package_spec.rb b/spec/unit/provider/package_spec.rb index 2ef58db9f3..40b7516b5c 100644 --- a/spec/unit/provider/package_spec.rb +++ b/spec/unit/provider/package_spec.rb @@ -396,13 +396,13 @@ describe Chef::Provider::Package do describe "when installing the preseed file to the cache location" do let(:response_file_destination) { Dir.tmpdir + "/preseed--java--java-6.seed" } - let(:response_file_resource) { + let(:response_file_resource) do response_file_resource = Chef::Resource::CookbookFile.new(response_file_destination, run_context) response_file_resource.cookbook_name = "java" response_file_resource.backup(false) response_file_resource.source("java.response") response_file_resource - } + end before do expect(provider).to receive(:preseed_resource).with("java", "6").and_return(response_file_resource) diff --git a/spec/unit/provider/powershell_script_spec.rb b/spec/unit/provider/powershell_script_spec.rb index 96869ff31c..4fd3f3534d 100644 --- a/spec/unit/provider/powershell_script_spec.rb +++ b/spec/unit/provider/powershell_script_spec.rb @@ -20,7 +20,7 @@ require "spec_helper" describe Chef::Provider::PowershellScript, "action_run" do let(:powershell_version) { nil } - let(:node) { + let(:node) do node = Chef::Node.new node.default["kernel"] = Hash.new node.default["kernel"][:machine] = :x86_64.to_s @@ -28,14 +28,14 @@ describe Chef::Provider::PowershellScript, "action_run" do node.default[:languages] = { :powershell => { :version => powershell_version } } end node - } + end - let(:provider) { + let(:provider) do empty_events = Chef::EventDispatch::Dispatcher.new run_context = Chef::RunContext.new(node, {}, empty_events) new_resource = Chef::Resource::PowershellScript.new("run some powershell code", run_context) Chef::Provider::PowershellScript.new(new_resource, run_context) - } + end context "when setting interpreter flags" do context "on nano" do diff --git a/spec/unit/provider/remote_file/ftp_spec.rb b/spec/unit/provider/remote_file/ftp_spec.rb index 9963c401d2..b2fbb7300c 100644 --- a/spec/unit/provider/remote_file/ftp_spec.rb +++ b/spec/unit/provider/remote_file/ftp_spec.rb @@ -19,12 +19,12 @@ require "spec_helper" describe Chef::Provider::RemoteFile::FTP do - let(:enclosing_directory) { + let(:enclosing_directory) do canonicalize_path(File.expand_path(File.join(CHEF_SPEC_DATA, "templates"))) - } - let(:resource_path) { + end + let(:resource_path) do canonicalize_path(File.expand_path(File.join(enclosing_directory, "seattle.txt"))) - } + end let(:new_resource) do r = Chef::Resource::RemoteFile.new("remote file ftp backend test (new resource)") diff --git a/spec/unit/provider/remote_file/sftp_spec.rb b/spec/unit/provider/remote_file/sftp_spec.rb index 673ea015c0..7be507dc89 100644 --- a/spec/unit/provider/remote_file/sftp_spec.rb +++ b/spec/unit/provider/remote_file/sftp_spec.rb @@ -20,12 +20,12 @@ require "spec_helper" describe Chef::Provider::RemoteFile::SFTP do #built out dependencies - let(:enclosing_directory) { + let(:enclosing_directory) do canonicalize_path(File.expand_path(File.join(CHEF_SPEC_DATA, "templates"))) - } - let(:resource_path) { + end + let(:resource_path) do canonicalize_path(File.expand_path(File.join(enclosing_directory, "seattle.txt"))) - } + end let(:new_resource) do r = Chef::Resource::RemoteFile.new("remote file sftp backend test (new resource)") diff --git a/spec/unit/provider/remote_file_spec.rb b/spec/unit/provider/remote_file_spec.rb index 6107f93c41..6ceb1d450d 100644 --- a/spec/unit/provider/remote_file_spec.rb +++ b/spec/unit/provider/remote_file_spec.rb @@ -37,12 +37,12 @@ describe Chef::Provider::RemoteFile do let(:node) { double("Chef::Node") } let(:events) { double("Chef::Events").as_null_object } # mock all the methods let(:run_context) { double("Chef::RunContext", :node => node, :events => events) } - let(:enclosing_directory) { + let(:enclosing_directory) do canonicalize_path(File.expand_path(File.join(CHEF_SPEC_DATA, "templates"))) - } - let(:resource_path) { + end + let(:resource_path) do canonicalize_path(File.expand_path(File.join(enclosing_directory, "seattle.txt"))) - } + end subject(:provider) do provider = described_class.new(resource, run_context) diff --git a/spec/unit/provider/script_spec.rb b/spec/unit/provider/script_spec.rb index 4e8d8bdf59..7e34a8f083 100644 --- a/spec/unit/provider/script_spec.rb +++ b/spec/unit/provider/script_spec.rb @@ -25,12 +25,12 @@ describe Chef::Provider::Script, "action_run" do let(:run_context) { Chef::RunContext.new(node, {}, events) } - let(:new_resource) { + let(:new_resource) do new_resource = Chef::Resource::Script.new("run some perl code") new_resource.code "$| = 1; print 'i like beans'" new_resource.interpreter "perl" new_resource - } + end let(:provider) { Chef::Provider::Script.new(new_resource, run_context) } @@ -87,9 +87,9 @@ describe Chef::Provider::Script, "action_run" do end describe "when running the script" do - let (:default_opts) { + let (:default_opts) do { timeout: 3600, returns: 0, log_level: :info, log_tag: "script[run some perl code]" } - } + end before do allow(STDOUT).to receive(:tty?).and_return(false) diff --git a/spec/unit/provider/service/debian_service_spec.rb b/spec/unit/provider/service/debian_service_spec.rb index 2192671370..799ed991a3 100644 --- a/spec/unit/provider/service/debian_service_spec.rb +++ b/spec/unit/provider/service/debian_service_spec.rb @@ -39,9 +39,9 @@ describe Chef::Provider::Service::Debian do expect(File).to receive(:exists?).with("/usr/sbin/update-rc.d") .and_return(false) @provider.define_resource_requirements - expect { + expect do @provider.process_resource_requirements - }.to raise_error(Chef::Exceptions::Service) + end.to raise_error(Chef::Exceptions::Service) end context "when update-rc.d shows init linked to rc*.d/" do @@ -108,9 +108,9 @@ describe Chef::Provider::Service::Debian do it "raises an error" do @provider.define_resource_requirements - expect { + expect do @provider.process_resource_requirements - }.to raise_error(Chef::Exceptions::Service) + end.to raise_error(Chef::Exceptions::Service) end end diff --git a/spec/unit/provider/service/freebsd_service_spec.rb b/spec/unit/provider/service/freebsd_service_spec.rb index 68d4d63991..10eb3c1a14 100644 --- a/spec/unit/provider/service/freebsd_service_spec.rb +++ b/spec/unit/provider/service/freebsd_service_spec.rb @@ -257,10 +257,11 @@ PS_SAMPLE end context "when the enable variable partial matches (left) some other service and we are disabled" do - let(:lines) { [ + let(:lines) do + [ %Q{thing_#{new_resource.service_name}_enable="YES"}, %Q{#{new_resource.service_name}_enable="NO"}, - ] } + ] end it "sets enabled based on the exact match (false)" do provider.determine_enabled_status! expect(current_resource.enabled).to be false @@ -268,10 +269,11 @@ PS_SAMPLE end context "when the enable variable partial matches (right) some other service and we are disabled" do - let(:lines) { [ + let(:lines) do + [ %Q{#{new_resource.service_name}_thing_enable="YES"}, %Q{#{new_resource.service_name}_enable="NO"}, - ] } + ] end it "sets enabled based on the exact match (false)" do provider.determine_enabled_status! expect(current_resource.enabled).to be false @@ -279,10 +281,11 @@ PS_SAMPLE end context "when the enable variable partial matches (left) some other disabled service and we are enabled" do - let(:lines) { [ + let(:lines) do + [ %Q{thing_#{new_resource.service_name}_enable="NO"}, %Q{#{new_resource.service_name}_enable="YES"}, - ] } + ] end it "sets enabled based on the exact match (true)" do provider.determine_enabled_status! expect(current_resource.enabled).to be true @@ -290,10 +293,11 @@ PS_SAMPLE end context "when the enable variable partial matches (right) some other disabled service and we are enabled" do - let(:lines) { [ + let(:lines) do + [ %Q{#{new_resource.service_name}_thing_enable="NO"}, %Q{#{new_resource.service_name}_enable="YES"}, - ] } + ] end it "sets enabled based on the exact match (true)" do provider.determine_enabled_status! expect(current_resource.enabled).to be true diff --git a/spec/unit/provider/service/openbsd_service_spec.rb b/spec/unit/provider/service/openbsd_service_spec.rb index b11015a63a..872a3bc400 100644 --- a/spec/unit/provider/service/openbsd_service_spec.rb +++ b/spec/unit/provider/service/openbsd_service_spec.rb @@ -174,10 +174,11 @@ describe Chef::Provider::Service::Openbsd do end context "when the enable variable partial matches (left) some other service and we are disabled" do - let(:lines) { [ + let(:lines) do + [ %Q{thing_#{provider.builtin_service_enable_variable_name}="YES"}, %Q{#{provider.builtin_service_enable_variable_name}="NO"}, - ] } + ] end it "sets enabled based on the exact match (false)" do provider.determine_enabled_status! expect(current_resource.enabled).to be false @@ -185,10 +186,11 @@ describe Chef::Provider::Service::Openbsd do end context "when the enable variable partial matches (right) some other service and we are disabled" do - let(:lines) { [ + let(:lines) do + [ %Q{#{provider.builtin_service_enable_variable_name}_thing="YES"}, %Q{#{provider.builtin_service_enable_variable_name}}, - ] } + ] end it "sets enabled based on the exact match (false)" do provider.determine_enabled_status! expect(current_resource.enabled).to be false @@ -196,10 +198,11 @@ describe Chef::Provider::Service::Openbsd do end context "when the enable variable partial matches (left) some other disabled service and we are enabled" do - let(:lines) { [ + let(:lines) do + [ %Q{thing_#{provider.builtin_service_enable_variable_name}="NO"}, %Q{#{provider.builtin_service_enable_variable_name}="YES"}, - ] } + ] end it "sets enabled based on the exact match (true)" do provider.determine_enabled_status! expect(current_resource.enabled).to be true @@ -207,10 +210,11 @@ describe Chef::Provider::Service::Openbsd do end context "when the enable variable partial matches (right) some other disabled service and we are enabled" do - let(:lines) { [ + let(:lines) do + [ %Q{#{provider.builtin_service_enable_variable_name}_thing="NO"}, %Q{#{provider.builtin_service_enable_variable_name}="YES"}, - ] } + ] end it "sets enabled based on the exact match (true)" do provider.determine_enabled_status! expect(current_resource.enabled).to be true diff --git a/spec/unit/provider/service/systemd_service_spec.rb b/spec/unit/provider/service/systemd_service_spec.rb index e0a94127b7..8574cbf772 100644 --- a/spec/unit/provider/service/systemd_service_spec.rb +++ b/spec/unit/provider/service/systemd_service_spec.rb @@ -21,7 +21,7 @@ require "spec_helper" describe Chef::Provider::Service::Systemd do - let(:node) { + let(:node) do node = Chef::Node.new node.default["etc"] = Hash.new node.default["etc"]["passwd"] = { @@ -30,7 +30,7 @@ describe Chef::Provider::Service::Systemd do }, } node - } + end let(:events) { Chef::EventDispatch::Dispatcher.new } diff --git a/spec/unit/provider/service/windows_spec.rb b/spec/unit/provider/service/windows_spec.rb index f944d8f6c6..d4c451511d 100644 --- a/spec/unit/provider/service/windows_spec.rb +++ b/spec/unit/provider/service/windows_spec.rb @@ -151,15 +151,15 @@ describe Chef::Provider::Service::Windows, "load_current_resource" do let(:old_run_as_user) { new_resource.run_as_user } let(:old_run_as_password) { new_resource.run_as_password } - before { + before do new_resource.run_as_user(".\\wallace") new_resource.run_as_password("Wensleydale") - } + end - after { + after do new_resource.run_as_user(old_run_as_user) new_resource.run_as_password(old_run_as_password) - } + end it "calls #grant_service_logon if the :run_as_user and :run_as_password attributes are present" do expect(Win32::Service).to receive(:start) @@ -409,17 +409,17 @@ describe Chef::Provider::Service::Windows, "load_current_resource" do shared_context "testing private methods" do - let(:private_methods) { + let(:private_methods) do described_class.private_instance_methods - } + end - before { + before do described_class.send(:public, *private_methods) - } + end - after { + after do described_class.send(:private, *private_methods) - } + end end describe "grant_service_logon" do diff --git a/spec/unit/provider/template/content_spec.rb b/spec/unit/provider/template/content_spec.rb index 0f936c8f11..8f30d8f868 100644 --- a/spec/unit/provider/template/content_spec.rb +++ b/spec/unit/provider/template/content_spec.rb @@ -20,13 +20,13 @@ require "spec_helper" describe Chef::Provider::Template::Content do - let(:enclosing_directory) { + let(:enclosing_directory) do canonicalize_path(Dir.mktmpdir) - } + end - let(:resource_path) { + let(:resource_path) do canonicalize_path(File.expand_path(File.join(enclosing_directory, "openldap_stuff.conf"))) - } + end let(:new_resource) do double("Chef::Resource::Template (new)", @@ -46,10 +46,10 @@ describe Chef::Provider::Template::Content do :helper_modules => []) end - let(:rendered_file_locations) { + let(:rendered_file_locations) do [Dir.tmpdir + "/openldap_stuff.conf", enclosing_directory + "/openldap_stuff.conf"] - } + end let(:run_context) do cookbook_repo = File.expand_path(File.join(CHEF_SPEC_DATA, "cookbooks")) @@ -101,9 +101,9 @@ describe Chef::Provider::Template::Content do end context "when creating a tempfile in destdir fails" do - let(:enclosing_directory) { + let(:enclosing_directory) do canonicalize_path("/nonexisting/path") - } + end it "returns a tempfile in the tempdir when :file_deployment_uses_destdir is set to :auto" do Chef::Config[:file_staging_uses_destdir] = :auto diff --git a/spec/unit/provider/template_spec.rb b/spec/unit/provider/template_spec.rb index 488039ad18..306fd6ea71 100644 --- a/spec/unit/provider/template_spec.rb +++ b/spec/unit/provider/template_spec.rb @@ -27,12 +27,12 @@ describe Chef::Provider::Template do let(:node) { double("Chef::Node") } let(:events) { double("Chef::Events").as_null_object } # mock all the methods let(:run_context) { double("Chef::RunContext", :node => node, :events => events) } - let(:enclosing_directory) { + let(:enclosing_directory) do canonicalize_path(File.expand_path(File.join(CHEF_SPEC_DATA, "templates"))) - } - let(:resource_path) { + end + let(:resource_path) do canonicalize_path(File.expand_path(File.join(enclosing_directory, "seattle.txt"))) - } + end # Subject @@ -61,12 +61,12 @@ describe Chef::Provider::Template do let(:node) { double("Chef::Node") } let(:events) { double("Chef::Events").as_null_object } # mock all the methods let(:run_context) { double("Chef::RunContext", :node => node, :events => events) } - let(:enclosing_directory) { + let(:enclosing_directory) do canonicalize_path(File.expand_path(File.join(CHEF_SPEC_DATA, "templates"))) - } - let(:resource_path) { + end + let(:resource_path) do canonicalize_path(File.expand_path(File.join(enclosing_directory, "seattle.txt"))) - } + end # Subject diff --git a/spec/unit/provider/user/dscl_spec.rb b/spec/unit/provider/user/dscl_spec.rb index bf8b3169d7..a309033161 100644 --- a/spec/unit/provider/user/dscl_spec.rb +++ b/spec/unit/provider/user/dscl_spec.rb @@ -24,52 +24,52 @@ describe Chef::Provider::User::Dscl do before do allow(ChefConfig).to receive(:windows?) { false } end - let(:shellcmdresult) { + let(:shellcmdresult) do Struct.new(:stdout, :stderr, :exitstatus) - } - let(:node) { + end + let(:node) do node = Chef::Node.new allow(node).to receive(:[]).with(:platform_version).and_return(mac_version) allow(node).to receive(:[]).with(:platform).and_return("mac_os_x") node - } + end - let(:events) { + let(:events) do Chef::EventDispatch::Dispatcher.new - } + end - let(:run_context) { + let(:run_context) do Chef::RunContext.new(node, {}, events) - } + end - let(:new_resource) { + let(:new_resource) do r = Chef::Resource::User.new("toor") r.password(password) r.salt(salt) r.iterations(iterations) r - } + end - let(:provider) { + let(:provider) do Chef::Provider::User::Dscl.new(new_resource, run_context) - } + end - let(:mac_version) { + let(:mac_version) do "10.9.1" - } + end let(:password) { nil } let(:salt) { nil } let(:iterations) { nil } - let(:salted_sha512_password) { + let(:salted_sha512_password) do "0f543f021c63255e64e121a3585601b8ecfedf6d2\ 705ddac69e682a33db5dbcdb9b56a2520bc8fff63a\ 2ba6b7984c0737ff0b7949455071581f7affcd536d\ 402b6cdb097" - } + end - let(:salted_sha512_pbkdf2_password) { + let(:salted_sha512_pbkdf2_password) do "c734b6e4787c3727bb35e29fdd92b97c\ 1de12df509577a045728255ec7c6c5f5\ c18efa05ed02b682ffa7ebc05119900e\ @@ -78,24 +78,24 @@ b1d4880833aa7a190afc13e2bf0936b8\ 9464a8c234f3919082400b4f939bb77b\ c5adbbac718b7eb99463a7b679571e0f\ 1c9fef2ef08d0b9e9c2bcf644eed2ffc" - } + end - let(:salted_sha512_pbkdf2_salt) { + let(:salted_sha512_pbkdf2_salt) do "2d942d8364a9ccf2b8e5cb7ed1ff58f78\ e29dbfee7f9db58859144d061fd0058" - } + end - let(:salted_sha512_pbkdf2_iterations) { + let(:salted_sha512_pbkdf2_iterations) do 25000 - } + end - let(:vagrant_sha_512) { + let(:vagrant_sha_512) do "6f75d7190441facc34291ebbea1fc756b242d4f\ e9bcff141bccb84f1979e27e539539aa31f9f7dcc92c0cea959\ ea18e18b720e358e7fbe3cfbeaa561456f6ba008937a30" - } + end - let(:vagrant_sha_512_pbkdf2) { + let(:vagrant_sha_512_pbkdf2) do "12601a90db17cbf\ 8ba4808e6382fb0d3b9d8a6c1a190477bf680ab21afb\ 6065467136e55cc208a6f74156e3daf20fb13369ef4b\ @@ -103,15 +103,15 @@ ea18e18b720e358e7fbe3cfbeaa561456f6ba008937a30" 47cca84341a7f93a27147343f89fb843fb46c0017d2\ 64afa4976baacf941b915bd1ec1ca24c30b3e759e02\ 403e02f59fe7ff5938a7636c" - } + end - let(:vagrant_sha_512_pbkdf2_salt) { + let(:vagrant_sha_512_pbkdf2_salt) do "ee954be472fdc60ddf89484781433993625f006af6ec810c08f49a7e413946a1" - } + end - let(:vagrant_sha_512_pbkdf2_iterations) { + let(:vagrant_sha_512_pbkdf2_iterations) do 34482 - } + end describe "when shelling out to dscl" do it "should run dscl with the supplied cmd /Path args" do @@ -214,9 +214,9 @@ ea18e18b720e358e7fbe3cfbeaa561456f6ba008937a30" end describe "when modifying the home directory" do - let(:current_resource) { + let(:current_resource) do new_resource.dup - } + end before do new_resource.supports({ :manage_home => true }) @@ -307,9 +307,9 @@ ea18e18b720e358e7fbe3cfbeaa561456f6ba008937a30" end describe "when on Mac 10.6" do - let(:mac_version) { + let(:mac_version) do "10.6.5" - } + end it "should raise an error" do expect { run_requirements }.to raise_error(Chef::Exceptions::User) @@ -317,9 +317,9 @@ ea18e18b720e358e7fbe3cfbeaa561456f6ba008937a30" end describe "when on Mac 10.7" do - let(:mac_version) { + let(:mac_version) do "10.7.5" - } + end describe "when password is SALTED-SHA512" do let(:password) { salted_sha512_password } @@ -340,9 +340,9 @@ ea18e18b720e358e7fbe3cfbeaa561456f6ba008937a30" [ "10.9", "10.10"].each do |version| describe "when on Mac #{version}" do - let(:mac_version) { + let(:mac_version) do "#{version}.2" - } + end describe "when password is SALTED-SHA512" do let(:password) { salted_sha512_password } @@ -413,9 +413,9 @@ ea18e18b720e358e7fbe3cfbeaa561456f6ba008937a30" let(:password) { "something" } # Load password during load_current_resource describe "on 10.7" do - let(:mac_version) { + let(:mac_version) do "10.7.5" - } + end let(:user_plist_file) { "10.7" } @@ -478,9 +478,9 @@ ea18e18b720e358e7fbe3cfbeaa561456f6ba008937a30" end describe "on 10.8" do - let(:mac_version) { + let(:mac_version) do "10.8.3" - } + end let(:user_plist_file) { "10.8" } @@ -504,9 +504,9 @@ e68d1f9821b26689312366") describe "on 10.7 upgraded to 10.8" do # In this scenario user password is still in 10.7 format - let(:mac_version) { + let(:mac_version) do "10.8.3" - } + end let(:user_plist_file) { "10.7-8" } @@ -542,9 +542,9 @@ ea18e18b720e358e7fbe3cfbeaa561456f6ba008937a30") end describe "on 10.9" do - let(:mac_version) { + let(:mac_version) do "10.9.1" - } + end let(:user_plist_file) { "10.9" } @@ -646,9 +646,9 @@ ea18e18b720e358e7fbe3cfbeaa561456f6ba008937a30") describe "prepare_password_shadow_info" do describe "when on Mac 10.7" do - let(:mac_version) { + let(:mac_version) do "10.7.1" - } + end describe "when the password is plain text" do let(:password) { "vagrant" } @@ -676,9 +676,9 @@ ea18e18b720e358e7fbe3cfbeaa561456f6ba008937a30") ["10.8", "10.9", "10.10"].each do |version| describe "when on Mac #{version}" do - let(:mac_version) { + let(:mac_version) do "#{version}.1" - } + end describe "when the password is plain text" do let(:password) { "vagrant" } diff --git a/spec/unit/provider/user/solaris_spec.rb b/spec/unit/provider/user/solaris_spec.rb index 07a39a1f0c..af16a6bd80 100644 --- a/spec/unit/provider/user/solaris_spec.rb +++ b/spec/unit/provider/user/solaris_spec.rb @@ -25,9 +25,9 @@ require "spec_helper" describe Chef::Provider::User::Solaris do - let(:shellcmdresult) { + let(:shellcmdresult) do Struct.new(:stdout, :stderr, :exitstatus) - } + end subject(:provider) do p = described_class.new(@new_resource, @run_context) diff --git a/spec/unit/provider/user_spec.rb b/spec/unit/provider/user_spec.rb index 1cdbe462f7..1a8ad6ad1b 100644 --- a/spec/unit/provider/user_spec.rb +++ b/spec/unit/provider/user_spec.rb @@ -190,7 +190,7 @@ describe Chef::Provider::User do end describe "compare_user" do - let(:mapping) { + let(:mapping) do { "username" => %w{adam Adam}, "comment" => ["Adam Jacob", "adam jacob"], @@ -200,7 +200,7 @@ describe Chef::Provider::User do "shell" => ["/usr/bin/zsh", "/bin/bash"], "password" => %w{abcd 12345}, } - } + end %w{uid gid comment home shell password}.each do |attribute| it "should return true if #{attribute} doesn't match" do diff --git a/spec/unit/recipe_spec.rb b/spec/unit/recipe_spec.rb index 3c30f96b20..f42b7563f5 100644 --- a/spec/unit/recipe_spec.rb +++ b/spec/unit/recipe_spec.rb @@ -75,15 +75,15 @@ describe Chef::Recipe do end it "should require a name argument" do - expect { + expect do recipe.cat - }.to raise_error(ArgumentError) + end.to raise_error(ArgumentError) end it "should allow regular errors (not NameErrors) to pass unchanged" do - expect { + expect do recipe.cat("felix") { raise ArgumentError, "You Suck" } - }.to raise_error(ArgumentError) + end.to raise_error(ArgumentError) end it "should add our zen_master to the collection" do @@ -288,9 +288,10 @@ describe Chef::Recipe do end it "validating resources via build_resource" do - expect {recipe.build_resource(:remote_file, "klopp") do - source Chef::DelayedEvaluator.new { "http://chef.io" } - end}.to_not raise_error + expect do + recipe.build_resource(:remote_file, "klopp") do + source Chef::DelayedEvaluator.new { "http://chef.io" } + end end.to_not raise_error end end diff --git a/spec/unit/resource/dsc_resource_spec.rb b/spec/unit/resource/dsc_resource_spec.rb index 00e667c9de..b610c262cc 100644 --- a/spec/unit/resource/dsc_resource_spec.rb +++ b/spec/unit/resource/dsc_resource_spec.rb @@ -24,16 +24,16 @@ describe Chef::Resource::DscResource do let(:dsc_test_timeout) { 101 } context "when Powershell supports Dsc" do - let(:dsc_test_run_context) { + let(:dsc_test_run_context) do node = Chef::Node.new node.automatic[:languages][:powershell][:version] = "5.0.10018.0" empty_events = Chef::EventDispatch::Dispatcher.new Chef::RunContext.new(node, {}, empty_events) - } + end - let(:dsc_test_resource) { + let(:dsc_test_resource) do Chef::Resource::DscResource.new(dsc_test_resource_name, dsc_test_run_context) - } + end it "has a default action of `:run`" do expect(dsc_test_resource.action).to eq([:run]) @@ -71,16 +71,16 @@ describe Chef::Resource::DscResource do end it "raises a TypeError if property_name is not a symbol" do - expect { + expect do dsc_test_resource.property("Foo", dsc_test_property_value) - }.to raise_error(TypeError) + end.to raise_error(TypeError) end context "when using DelayedEvaluators" do it "allows setting a dsc property with a property name of type Symbol" do - dsc_test_resource.property(dsc_test_property_name, Chef::DelayedEvaluator.new { + dsc_test_resource.property(dsc_test_property_name, Chef::DelayedEvaluator.new do dsc_test_property_value - }) + end) expect(dsc_test_resource.property(dsc_test_property_name)).to eq(dsc_test_property_value) expect(dsc_test_resource.properties[dsc_test_property_name]).to eq(dsc_test_property_value) end diff --git a/spec/unit/resource/dsc_script_spec.rb b/spec/unit/resource/dsc_script_spec.rb index 4892049884..f0c81e43b5 100644 --- a/spec/unit/resource/dsc_script_spec.rb +++ b/spec/unit/resource/dsc_script_spec.rb @@ -22,15 +22,15 @@ describe Chef::Resource::DscScript do let(:dsc_test_resource_name) { "DSCTest" } context "when Powershell supports Dsc" do - let(:dsc_test_run_context) { + let(:dsc_test_run_context) do node = Chef::Node.new node.automatic[:languages][:powershell][:version] = "4.0" empty_events = Chef::EventDispatch::Dispatcher.new Chef::RunContext.new(node, {}, empty_events) - } - let(:dsc_test_resource) { + end + let(:dsc_test_resource) do Chef::Resource::DscScript.new(dsc_test_resource_name, dsc_test_run_context) - } + end let(:configuration_code) { 'echo "This is supposed to create a configuration document."' } let(:configuration_path) { "c:/myconfigs/formatc.ps1" } let(:configuration_name) { "formatme" } diff --git a/spec/unit/resource/launchd_spec.rb b/spec/unit/resource/launchd_spec.rb index 95febc47cf..98d21a8234 100644 --- a/spec/unit/resource/launchd_spec.rb +++ b/spec/unit/resource/launchd_spec.rb @@ -4,10 +4,11 @@ require "spec_helper" describe Chef::Resource::Launchd do @launchd = Chef::Resource::Launchd.new("io.chef.chef-client") - let(:resource) { Chef::Resource::Launchd.new( + let(:resource) do + Chef::Resource::Launchd.new( "io.chef.chef-client", run_context - )} + ) end it "should create a new Chef::Resource::Launchd" do expect(resource).to be_a_kind_of(Chef::Resource) diff --git a/spec/unit/resource/osx_profile_spec.rb b/spec/unit/resource/osx_profile_spec.rb index 7bd504d414..513e570e7c 100644 --- a/spec/unit/resource/osx_profile_spec.rb +++ b/spec/unit/resource/osx_profile_spec.rb @@ -19,10 +19,11 @@ require "spec_helper" describe Chef::Resource::OsxProfile do - let(:resource) { Chef::Resource::OsxProfile.new( + let(:resource) do + Chef::Resource::OsxProfile.new( "Test Profile Resource", run_context) - } + end it "should create a new Chef::Resource::OsxProfile" do expect(resource).to be_a_kind_of(Chef::Resource) diff --git a/spec/unit/resource/remote_file_spec.rb b/spec/unit/resource/remote_file_spec.rb index 718129aba3..5fac457ebf 100644 --- a/spec/unit/resource/remote_file_spec.rb +++ b/spec/unit/resource/remote_file_spec.rb @@ -86,15 +86,15 @@ describe Chef::Resource::RemoteFile do end it "should only accept a single argument if a delayed evalutor is used" do - expect { + expect do @resource.source("http://opscode.com/", Chef::DelayedEvaluator.new { "http://opscode.com/" }) - }.to raise_error(Chef::Exceptions::InvalidRemoteFileURI) + end.to raise_error(Chef::Exceptions::InvalidRemoteFileURI) end it "should only accept a single array item if a delayed evalutor is used" do - expect { + expect do @resource.source(["http://opscode.com/", Chef::DelayedEvaluator.new { "http://opscode.com/" }]) - }.to raise_error(Chef::Exceptions::InvalidRemoteFileURI) + end.to raise_error(Chef::Exceptions::InvalidRemoteFileURI) end it "does not accept a non-URI as the source" do @@ -102,10 +102,10 @@ describe Chef::Resource::RemoteFile do end it "does not accept a non-URI as the source when read from a delayed evaluator" do - expect { + expect do @resource.source(Chef::DelayedEvaluator.new { "not-a-uri" }) @resource.source - }.to raise_error(Chef::Exceptions::InvalidRemoteFileURI) + end.to raise_error(Chef::Exceptions::InvalidRemoteFileURI) end it "should raise an exception when source is an empty array" do diff --git a/spec/unit/resource/service_spec.rb b/spec/unit/resource/service_spec.rb index e06f5bca5e..7aadc55532 100644 --- a/spec/unit/resource/service_spec.rb +++ b/spec/unit/resource/service_spec.rb @@ -53,9 +53,9 @@ describe Chef::Resource::Service do end it "should not accept a regexp for the service pattern" do - expect { + expect do @resource.pattern /.*/ - }.to raise_error(ArgumentError) + end.to raise_error(ArgumentError) end it "should accept a string for the service start command" do @@ -64,9 +64,9 @@ describe Chef::Resource::Service do end it "should not accept a regexp for the service start command" do - expect { + expect do @resource.start_command /.*/ - }.to raise_error(ArgumentError) + end.to raise_error(ArgumentError) end it "should accept a string for the service stop command" do @@ -75,9 +75,9 @@ describe Chef::Resource::Service do end it "should not accept a regexp for the service stop command" do - expect { + expect do @resource.stop_command /.*/ - }.to raise_error(ArgumentError) + end.to raise_error(ArgumentError) end it "should accept a string for the service status command" do @@ -86,9 +86,9 @@ describe Chef::Resource::Service do end it "should not accept a regexp for the service status command" do - expect { + expect do @resource.status_command /.*/ - }.to raise_error(ArgumentError) + end.to raise_error(ArgumentError) end it "should accept a string for the service restart command" do @@ -97,9 +97,9 @@ describe Chef::Resource::Service do end it "should not accept a regexp for the service restart command" do - expect { + expect do @resource.restart_command /.*/ - }.to raise_error(ArgumentError) + end.to raise_error(ArgumentError) end it "should accept a string for the service reload command" do @@ -108,9 +108,9 @@ describe Chef::Resource::Service do end it "should not accept a regexp for the service reload command" do - expect { + expect do @resource.reload_command /.*/ - }.to raise_error(ArgumentError) + end.to raise_error(ArgumentError) end it "should accept a string for the service init command" do @@ -119,9 +119,9 @@ describe Chef::Resource::Service do end it "should not accept a regexp for the service init command" do - expect { + expect do @resource.init_command /.*/ - }.to raise_error(ArgumentError) + end.to raise_error(ArgumentError) end %w{enabled running}.each do |attrib| diff --git a/spec/unit/resource_collection_spec.rb b/spec/unit/resource_collection_spec.rb index 3fec2d9477..5feb34833a 100644 --- a/spec/unit/resource_collection_spec.rb +++ b/spec/unit/resource_collection_spec.rb @@ -98,11 +98,11 @@ describe Chef::ResourceCollection do it "should allow you to iterate over every resource in the collection" do load_up_resources results = Array.new - expect { + expect do rc.each do |r| results << r.name end - }.not_to raise_error + end.not_to raise_error results.each_index do |i| case i when 0 @@ -120,11 +120,11 @@ describe Chef::ResourceCollection do it "should allow you to iterate over every resource by index" do load_up_resources results = Array.new - expect { + expect do rc.each_index do |i| results << rc[i].name end - }.not_to raise_error + end.not_to raise_error results.each_index do |i| case i when 0 diff --git a/spec/unit/resource_definition_spec.rb b/spec/unit/resource_definition_spec.rb index 45dfaffca7..cc19cc7a01 100644 --- a/spec/unit/resource_definition_spec.rb +++ b/spec/unit/resource_definition_spec.rb @@ -53,26 +53,26 @@ describe Chef::ResourceDefinition do end it "should accept a new definition with a symbol for a name" do - expect { + expect do defn.define :smoke do end - }.not_to raise_error - expect { + end.not_to raise_error + expect do defn.define "george washington" do end - }.to raise_error(ArgumentError) + end.to raise_error(ArgumentError) expect(defn.name).to eql(:smoke) end it "should accept a new definition with a hash" do - expect { + expect do defn.define :smoke, :cigar => "cuban", :cigarette => "marlboro" do end - }.not_to raise_error + end.not_to raise_error end it "should expose the prototype hash params in the params hash" do - defn.define :smoke, :cigar => "cuban", :cigarette => "marlboro" do; end + defn.define(:smoke, :cigar => "cuban", :cigarette => "marlboro") {} expect(defn.params[:cigar]).to eql("cuban") expect(defn.params[:cigarette]).to eql("marlboro") end @@ -91,16 +91,16 @@ describe Chef::ResourceDefinition do end it "should raise an exception if prototype_params is not a hash" do - expect { + expect do defn.define :monkey, Array.new do end - }.to raise_error(ArgumentError) + end.to raise_error(ArgumentError) end it "should raise an exception if define is called without a block" do - expect { + expect do defn.define :monkey - }.to raise_error(ArgumentError) + end.to raise_error(ArgumentError) end it "should load a description from a file" do diff --git a/spec/unit/resource_reporter_spec.rb b/spec/unit/resource_reporter_spec.rb index 0df3a165bd..51075a7d44 100644 --- a/spec/unit/resource_reporter_spec.rb +++ b/spec/unit/resource_reporter_spec.rb @@ -664,9 +664,9 @@ describe Chef::ResourceReporter do it "fails the run and prints an message about the error" do expect(Chef::Log).to receive(:error).with(/500/) - expect { + expect do @resource_reporter.run_started(@run_status) - }.to raise_error(Net::HTTPServerException) + end.to raise_error(Net::HTTPServerException) end end @@ -749,9 +749,9 @@ describe Chef::ResourceReporter do it "should raise if an unkwown error happens" do allow(@rest_client).to receive(:raw_request).and_raise(Exception.new) - expect { + expect do @resource_reporter.post_reporting_data - }.to raise_error(Exception) + end.to raise_error(Exception) end end end diff --git a/spec/unit/resource_resolver_spec.rb b/spec/unit/resource_resolver_spec.rb index f3a20ab0e3..d707ade009 100644 --- a/spec/unit/resource_resolver_spec.rb +++ b/spec/unit/resource_resolver_spec.rb @@ -20,11 +20,11 @@ require "spec_helper" require "chef/resource_resolver" describe Chef::ResourceResolver do - it '#resolve' do + it "#resolve" do expect(described_class.resolve(:execute)).to eq(Chef::Resource::Execute) end - it '#list' do + it "#list" do expect(described_class.list(:package)).to_not be_empty end @@ -33,19 +33,19 @@ describe Chef::ResourceResolver do described_class.new(Chef::Node.new, "execute") end - it '#resolve' do + it "#resolve" do expect(resolver.resolve).to eq Chef::Resource::Execute end - it '#list' do + it "#list" do expect(resolver.list).to eq [ Chef::Resource::Execute ] end - it '#provided_by? returns true when resource class is in the list' do + it "#provided_by? returns true when resource class is in the list" do expect(resolver.provided_by?(Chef::Resource::Execute)).to be_truthy end - it '#provided_by? returns false when resource class is not in the list' do + it "#provided_by? returns false when resource class is not in the list" do expect(resolver.provided_by?(Chef::Resource::File)).to be_falsey end end diff --git a/spec/unit/resource_spec.rb b/spec/unit/resource_spec.rb index e88931fa54..e35203c78a 100644 --- a/spec/unit/resource_spec.rb +++ b/spec/unit/resource_spec.rb @@ -95,7 +95,7 @@ describe Chef::Resource do end describe "when an identity attribute has been declared" do - let(:file_resource) { + let(:file_resource) do file_resource_class = Class.new(Chef::Resource) do identity_attr :path attr_accessor :path @@ -104,7 +104,7 @@ describe Chef::Resource do file_resource = file_resource_class.new("identity-attr-test") file_resource.path = "/tmp/foo.txt" file_resource - } + end it "gives the value of its identity attribute" do expect(file_resource.identity).to eq("/tmp/foo.txt") @@ -140,7 +140,7 @@ describe Chef::Resource do end describe "when a set of state attributes has been declared" do - let(:file_resource) { + let(:file_resource) do file_resource_class = Class.new(Chef::Resource) do state_attrs :checksum, :owner, :group, :mode @@ -157,7 +157,7 @@ describe Chef::Resource do file_resource.group = "wheel" file_resource.mode = "0644" file_resource - } + end it "describes its state" do resource_state = file_resource.state @@ -170,14 +170,14 @@ describe Chef::Resource do end describe "load_from" do - let(:prior_resource) { + let(:prior_resource) do prior_resource = Chef::Resource.new("funk") prior_resource.supports(:funky => true) prior_resource.source_line prior_resource.allowed_actions << :funkytown prior_resource.action(:funkytown) prior_resource - } + end before(:each) do resource.allowed_actions << :funkytown run_context.resource_collection << prior_resource @@ -236,9 +236,9 @@ describe Chef::Resource do it "should raise an exception if told to act in other than :delay or :immediate(ly)" do run_context.resource_collection << Chef::Resource::ZenMaster.new("coffee") - expect { + expect do resource.notifies :reload, run_context.resource_collection.find(:zen_master => "coffee"), :someday - }.to raise_error(ArgumentError) + end.to raise_error(ArgumentError) end it "should allow multiple notified resources appear in the actions hash" do @@ -503,12 +503,12 @@ describe Chef::Resource do end describe "retries" do - let(:retriable_resource) { + let(:retriable_resource) do retriable_resource = Chef::Resource::Cat.new("precious", run_context) retriable_resource.provider = Chef::Provider::SnakeOil retriable_resource.action = :purr retriable_resource - } + end before do node.automatic_attrs[:platform] = "fubuntu" @@ -563,11 +563,11 @@ describe Chef::Resource do end it "warns when setting provider_base" do - expect { + expect do class OverrideProviderBaseTest2 < Chef::Resource provider_base Chef::Provider::Package end - }.to raise_error(Chef::Exceptions::DeprecatedFeatureError) + end.to raise_error(Chef::Exceptions::DeprecatedFeatureError) end end @@ -607,11 +607,11 @@ describe Chef::Resource do end describe "when invoking its action" do - let(:resource) { + let(:resource) do resource = Chef::Resource.new("provided", run_context) resource.provider = Chef::Provider::SnakeOil resource - } + end before do node.automatic_attrs[:platform] = "fubuntu" node.automatic_attrs[:platform_version] = "10.04" @@ -797,11 +797,11 @@ describe Chef::Resource do end describe "when resource action is :nothing" do - let(:resource1) { + let(:resource1) do resource1 = Chef::Resource::Cat.new("sugar", run_context) resource1.action = :nothing resource1 - } + end before do node.automatic_attrs[:platform] = "fubuntu" node.automatic_attrs[:platform_version] = "10.04" diff --git a/spec/unit/run_context/child_run_context_spec.rb b/spec/unit/run_context/child_run_context_spec.rb index 13a035c871..47a6c84f7a 100644 --- a/spec/unit/run_context/child_run_context_spec.rb +++ b/spec/unit/run_context/child_run_context_spec.rb @@ -24,16 +24,16 @@ require "support/lib/library_load_order" describe Chef::RunContext::ChildRunContext do context "with a run context with stuff in it" do let(:chef_repo_path) { File.expand_path(File.join(CHEF_SPEC_DATA, "run_context", "cookbooks")) } - let(:cookbook_collection) { + let(:cookbook_collection) do cl = Chef::CookbookLoader.new(chef_repo_path) cl.load_cookbooks Chef::CookbookCollection.new(cl) - } - let(:node) { + end + let(:node) do node = Chef::Node.new node.run_list << "test" << "test::one" << "test::two" node - } + end let(:events) { Chef::EventDispatch::Dispatcher.new } let(:run_context) { Chef::RunContext.new(node, cookbook_collection, events) } diff --git a/spec/unit/run_context_spec.rb b/spec/unit/run_context_spec.rb index 234cd3c9e1..f1c3072b8e 100644 --- a/spec/unit/run_context_spec.rb +++ b/spec/unit/run_context_spec.rb @@ -23,16 +23,16 @@ require "support/lib/library_load_order" describe Chef::RunContext do let(:chef_repo_path) { File.expand_path(File.join(CHEF_SPEC_DATA, "run_context", "cookbooks")) } - let(:cookbook_collection) { + let(:cookbook_collection) do cl = Chef::CookbookLoader.new(chef_repo_path) cl.load_cookbooks Chef::CookbookCollection.new(cl) - } - let(:node) { + end + let(:node) do node = Chef::Node.new node.run_list << "test" << "test::one" << "test::two" node - } + end let(:events) { Chef::EventDispatch::Dispatcher.new } let(:run_context) { Chef::RunContext.new(node, cookbook_collection, events) } @@ -151,13 +151,13 @@ describe Chef::RunContext do describe "querying the contents of cookbooks" do let(:chef_repo_path) { File.expand_path(File.join(CHEF_SPEC_DATA, "cookbooks")) } - let(:node) { + let(:node) do node = Chef::Node.new node.normal[:platform] = "ubuntu" node.normal[:platform_version] = "13.04" node.name("testing") node - } + end it "queries whether a given cookbook has a specific template" do expect(run_context).to have_template_in_cookbook("openldap", "test.erb") @@ -212,11 +212,11 @@ describe Chef::RunContext do shared_context "notifying resource is a subclass of Chef::Resource" do let(:declared_type) { :alpaca } - let(:notifying_resource) { + let(:notifying_resource) do r = Class.new(Chef::Resource).new("guinea pig") r.declared_type = declared_type r - } + end it "should be keyed off the resource declared key" do run_context.send(setter, notification) diff --git a/spec/unit/runner_spec.rb b/spec/unit/runner_spec.rb index f15f3951e0..c1e10a78f4 100644 --- a/spec/unit/runner_spec.rb +++ b/spec/unit/runner_spec.rb @@ -392,12 +392,12 @@ Multiple failures occurred: it "should resolve resource references in notifications when resources are defined lazily" do first_resource.action = :nothing - lazy_resources = lambda { + lazy_resources = lambda do last_resource = Chef::Resource::Cat.new("peanut", run_context) run_context.resource_collection << last_resource last_resource.notifies(:purr, first_resource.to_s, :delayed) last_resource.action = :purr - } + end second_resource = Chef::Resource::RubyBlock.new("myblock", run_context) run_context.resource_collection << second_resource second_resource.block { lazy_resources.call } diff --git a/spec/unit/search/query_spec.rb b/spec/unit/search/query_spec.rb index 7f815f1757..51667784fb 100644 --- a/spec/unit/search/query_spec.rb +++ b/spec/unit/search/query_spec.rb @@ -27,13 +27,13 @@ describe Chef::Search::Query do let(:query_string) { "search/node?q=platform:rhel&sort=X_CHEF_id_CHEF_X%20asc&start=0" } let(:server_url) { "https://api.opscode.com/organizations/opscode/nodes" } let(:args) { { filter_key => filter_hash } } - let(:filter_hash) { + let(:filter_hash) do { "env" => [ "chef_environment" ], "ruby_plat" => %w{languages ruby platform}, } - } - let(:response) { + end + let(:response) do { "rows" => [ { "url" => "#{server_url}/my-name-is-node", @@ -64,15 +64,15 @@ describe Chef::Search::Query do "start" => 0, "total" => 4, } - } - let(:response_rows) { + end + let(:response_rows) do [ { "env" => "elysium", "ruby_plat" => "nudibranch" }, { "env" => "hades", "ruby_plat" => "i386-mingw32" }, { "env" => "elysium", "ruby_plat" => "centos" }, { "env" => "moon", "ruby_plat" => "solaris2" }, ] - } + end end before(:each) do @@ -86,7 +86,8 @@ describe Chef::Search::Query do let(:query_string_with_rows) { "search/node?q=platform:rhel&sort=X_CHEF_id_CHEF_X%20asc&start=0&rows=4" } let(:query_string_continue_with_rows) { "search/node?q=platform:rhel&sort=X_CHEF_id_CHEF_X%20asc&start=4&rows=4" } - let(:response) { { + let(:response) do + { "rows" => [ { "name" => "my-name-is-node", "chef_environment" => "elysium", @@ -147,28 +148,28 @@ describe Chef::Search::Query do ], "start" => 0, "total" => 4, - } } + } end - let(:big_response) { + let(:big_response) do r = response.dup r["total"] = 8 r - } + end - let(:big_response_empty) { + let(:big_response_empty) do { "start" => 0, "total" => 8, "rows" => [], } - } + end - let(:big_response_end) { + let(:big_response_end) do r = response.dup r["start"] = 4 r["total"] = 8 r - } + end it "accepts a type as the first argument" do expect { query.search("node") }.not_to raise_error diff --git a/spec/unit/user_v1_spec.rb b/spec/unit/user_v1_spec.rb index 51dc3c9118..16f0d0158b 100644 --- a/spec/unit/user_v1_spec.rb +++ b/spec/unit/user_v1_spec.rb @@ -332,7 +332,7 @@ describe Chef::UserV1 do @user.password "some_password" end - let(:payload) { + let(:payload) do { :username => "some_username", :display_name => "some_display_name", @@ -342,7 +342,7 @@ describe Chef::UserV1 do :email => "some_email", :password => "some_password", } - } + end context "when server API V1 is valid on the Chef Server receiving the request" do context "when the user submits valid data" do @@ -354,7 +354,7 @@ describe Chef::UserV1 do end context "when server API V1 is not valid on the Chef Server receiving the request" do - let(:payload) { + let(:payload) do { :username => "some_username", :display_name => "some_display_name", @@ -365,7 +365,7 @@ describe Chef::UserV1 do :password => "some_password", :public_key => "some_public_key", } - } + end before do @user.public_key "some_public_key" @@ -442,7 +442,7 @@ describe Chef::UserV1 do end # update describe "create" do - let(:payload) { + let(:payload) do { :username => "some_username", :display_name => "some_display_name", @@ -451,7 +451,7 @@ describe Chef::UserV1 do :email => "some_email", :password => "some_password", } - } + end before do @user.username "some_username" @user.display_name "some_display_name" @@ -506,11 +506,11 @@ describe Chef::UserV1 do # DEPRECATION # This can be removed after API V0 support is gone describe "reregister" do - let(:payload) { + let(:payload) do { "username" => "some_username", } - } + end before do @user.username "some_username" diff --git a/spec/unit/util/dsc/configuration_generator_spec.rb b/spec/unit/util/dsc/configuration_generator_spec.rb index 12f62deb5a..cfa7a4e264 100644 --- a/spec/unit/util/dsc/configuration_generator_spec.rb +++ b/spec/unit/util/dsc/configuration_generator_spec.rb @@ -25,7 +25,7 @@ describe Chef::Util::DSC::ConfigurationGenerator do Chef::Util::DSC::ConfigurationGenerator.new(node, "tmp") end - describe '#validate_configuration_name!' do + describe "#validate_configuration_name!" do it "should not raise an error if a name contains all upper case letters" do conf_man.send(:validate_configuration_name!, "HELLO") end @@ -40,9 +40,9 @@ describe Chef::Util::DSC::ConfigurationGenerator do %w{! @ # $ % ^ & * & * ( ) - = + \{ \} . ? < > \\ /}.each do |sym| it "raises an Argument error if it configuration name contains #{sym}" do - expect { + expect do conf_man.send(:validate_configuration_name!, "Hello#{sym}") - }.to raise_error(ArgumentError) + end.to raise_error(ArgumentError) end end end @@ -57,15 +57,15 @@ describe Chef::Util::DSC::ConfigurationGenerator do end it "should raise an ArgumentError if you try to override outputpath" do - expect { + expect do conf_man.send(:get_merged_configuration_flags!, { "outputpath" => "a" }, "hello") - }.to raise_error(ArgumentError) + end.to raise_error(ArgumentError) end it "should be case insensitive for switches that are not allowed" do - expect { + expect do conf_man.send(:get_merged_configuration_flags!, { "OutputPath" => "a" }, "hello") - }.to raise_error(ArgumentError) + end.to raise_error(ArgumentError) end it "should be case insensitive to switches that are allowed" do @@ -83,15 +83,15 @@ describe Chef::Util::DSC::ConfigurationGenerator do end it "should raise an ArgumentError if you try to override outputpath" do - expect { + expect do conf_man.send(:get_merged_configuration_flags!, { :outputpath => "a" }, "hello") - }.to raise_error(ArgumentError) + end.to raise_error(ArgumentError) end it "should be case insensitive for switches that are not allowed" do - expect { + expect do conf_man.send(:get_merged_configuration_flags!, { :OutputPath => "a" }, "hello") - }.to raise_error(ArgumentError) + end.to raise_error(ArgumentError) end it "should be case insensitive to switches that are allowed" do @@ -121,7 +121,7 @@ describe Chef::Util::DSC::ConfigurationGenerator do # end - describe '#write_document_generation_script' do + describe "#write_document_generation_script" do let(:file_like_object) { double("file like object") } it "should write the input to a file" do diff --git a/spec/unit/util/dsc/local_configuration_manager_spec.rb b/spec/unit/util/dsc/local_configuration_manager_spec.rb index 15cf38394e..45fe8df40d 100644 --- a/spec/unit/util/dsc/local_configuration_manager_spec.rb +++ b/spec/unit/util/dsc/local_configuration_manager_spec.rb @@ -23,15 +23,17 @@ describe Chef::Util::DSC::LocalConfigurationManager do let(:lcm) { Chef::Util::DSC::LocalConfigurationManager.new(nil, "tmp") } - let(:normal_lcm_output) { <<-EOH + let(:normal_lcm_output) do + <<-EOH logtype: [machinename]: LCM: [ Start Set ] logtype: [machinename]: LCM: [ Start Resource ] [name] logtype: [machinename]: LCM: [ End Resource ] [name] logtype: [machinename]: LCM: [ End Set ] EOH - } + end - let(:no_whatif_lcm_output) { <<-EOH + let(:no_whatif_lcm_output) do + <<-EOH Start-DscConfiguration : A parameter cannot be found\r\n that matches parameter name 'whatif'. At line:1 char:123 + run-somecommand -whatif @@ -39,16 +41,17 @@ At line:1 char:123 + CategoryInfo : InvalidArgument: (:) [Start-DscConfiguration], ParameterBindingException + FullyQualifiedErrorId : NamedParameterNotFound,SomeCompany.SomeAssembly.Commands.RunSomeCommand EOH - } + end - let(:dsc_resource_import_failure_output) { <<-EOH + let(:dsc_resource_import_failure_output) do + <<-EOH PowerShell provider MSFT_xWebsite failed to execute Test-TargetResource functionality with error message: Please ensure that WebAdministration module is installed. + CategoryInfo : InvalidOperation: (:) [], CimException + FullyQualifiedErrorId : ProviderOperationExecutionFailure + PSComputerName : . PowerShell provider MSFT_xWebsite failed to execute Test-TargetResource functionality with error message: Please ensure that WebAdministration module is installed. + CategoryInfo : InvalidOperation: (:) [], CimException + FullyQualifiedErrorId : ProviderOperationExecutionFailure + PSComputerName : . The SendConfigurationApply function did not succeed. + CategoryInfo : NotSpecified: (root/Microsoft/...gurationManager:String) [], CimException + FullyQualifiedErrorId : MI RESULT 1 + PSComputerName : . EOH - } + end - let(:lcm_status) { + let(:lcm_status) do double("LCM cmdlet status", :stderr => lcm_standard_error, :return_value => lcm_standard_output, :succeeded? => lcm_cmdlet_success) - } + end describe "test_configuration method invocation" do context "when interacting with the LCM using a PowerShell cmdlet" do @@ -77,7 +80,7 @@ EOH let(:lcm_standard_error) { no_whatif_lcm_output } let(:lcm_cmdlet_success) { false } - it 'returns true when passed to #whatif_not_supported?' do + it "returns true when passed to #whatif_not_supported?" do expect(lcm.send(:whatif_not_supported?, no_whatif_lcm_output)).to be_truthy end diff --git a/spec/unit/util/dsc/resource_store.rb b/spec/unit/util/dsc/resource_store.rb index 84b39190b2..a864a2c1da 100644 --- a/spec/unit/util/dsc/resource_store.rb +++ b/spec/unit/util/dsc/resource_store.rb @@ -21,28 +21,30 @@ require "chef/util/dsc/resource_store" describe Chef::Util::DSC::ResourceStore do let(:resource_store) { Chef::Util::DSC::ResourceStore.new } - let(:resource_a) { { + let(:resource_a) do + { "ResourceType" => "AFoo", "Name" => "Foo", "Module" => { "Name" => "ModuleA" }, } - } + end - let(:resource_b) { { + let(:resource_b) do + { "ResourceType" => "BFoo", "Name" => "Foo", "Module" => { "Name" => "ModuleB" }, } - } + end context "when resources are not cached" do - context 'when calling #resources' do + context "when calling #resources" do it "returns an empty array" do expect(resource_store.resources).to eql([]) end end - context 'when calling #find' do + context "when calling #find" do it "returns an empty list if it cannot find any matching resources" do expect(resource_store).to receive(:query_resource).and_return([]) expect(resource_store.find("foo")).to eql([]) diff --git a/spec/unit/util/editor_spec.rb b/spec/unit/util/editor_spec.rb index 7a0ec91533..e53bc9662a 100644 --- a/spec/unit/util/editor_spec.rb +++ b/spec/unit/util/editor_spec.rb @@ -2,7 +2,7 @@ require "spec_helper" require "chef/util/editor" describe Chef::Util::Editor do - describe '#initialize' do + describe "#initialize" do it "takes an Enumerable of lines" do editor = described_class.new(File.open(__FILE__)) expect(editor.lines).to be == IO.readlines(__FILE__) @@ -18,7 +18,7 @@ describe Chef::Util::Editor do subject(:editor) { described_class.new(input_lines) } let(:input_lines) { %w{one two two three} } - describe '#append_line_after' do + describe "#append_line_after" do context "when there is no match" do subject(:execute) { editor.append_line_after("missing", "new") } @@ -44,7 +44,7 @@ describe Chef::Util::Editor do end end - describe '#append_line_if_missing' do + describe "#append_line_if_missing" do context "when there is no match" do subject(:execute) { editor.append_line_if_missing("missing", "new") } @@ -70,7 +70,7 @@ describe Chef::Util::Editor do end end - describe '#remove_lines' do + describe "#remove_lines" do context "when there is no match" do subject(:execute) { editor.remove_lines("missing") } @@ -96,7 +96,7 @@ describe Chef::Util::Editor do end end - describe '#replace' do + describe "#replace" do context "when there is no match" do subject(:execute) { editor.replace("missing", "new") } @@ -123,7 +123,7 @@ describe Chef::Util::Editor do end end - describe '#replace_lines' do + describe "#replace_lines" do context "when there is no match" do subject(:execute) { editor.replace_lines("missing", "new") } diff --git a/spec/unit/util/powershell/cmdlet_spec.rb b/spec/unit/util/powershell/cmdlet_spec.rb index 5c0e66aee2..800e4cc9c0 100644 --- a/spec/unit/util/powershell/cmdlet_spec.rb +++ b/spec/unit/util/powershell/cmdlet_spec.rb @@ -25,7 +25,7 @@ describe Chef::Util::Powershell::Cmdlet do @cmdlet = Chef::Util::Powershell::Cmdlet.new(@node, "Some-Commandlet") end - describe '#validate_switch_name!' do + describe "#validate_switch_name!" do it "should not raise an error if a name contains all upper case letters" do @cmdlet.send(:validate_switch_name!, "HELLO") end @@ -40,14 +40,14 @@ describe Chef::Util::Powershell::Cmdlet do %w{! @ # $ % ^ & * & * ( ) - = + \{ \} . ? < > \\ /}.each do |sym| it "raises an Argument error if it configuration name contains #{sym}" do - expect { + expect do @cmdlet.send(:validate_switch_name!, "Hello#{sym}") - }.to raise_error(ArgumentError) + end.to raise_error(ArgumentError) end end end - describe '#escape_parameter_value' do + describe "#escape_parameter_value" do # Is this list really complete? %w{` " # '}.each do |c| it "escapse #{c}" do @@ -60,23 +60,23 @@ describe Chef::Util::Powershell::Cmdlet do end end - describe '#escape_string_parameter_value' do + describe "#escape_string_parameter_value" do it "surrounds a string with ''" do expect(@cmdlet.send(:escape_string_parameter_value, "stuff")).to eql("'stuff'") end end - describe '#command_switches_string' do + describe "#command_switches_string" do it "raises an ArgumentError if the key is not a symbol" do - expect { + expect do @cmdlet.send(:command_switches_string, { "foo" => "bar" }) - }.to raise_error(ArgumentError) + end.to raise_error(ArgumentError) end it "does not allow invalid switch names" do - expect { + expect do @cmdlet.send(:command_switches_string, { :foo! => "bar" }) - }.to raise_error(ArgumentError) + end.to raise_error(ArgumentError) end it "ignores switches with a false value" do |