From 5fed7a65a2f024d964ecf2de1bcf2911cf8a600c Mon Sep 17 00:00:00 2001 From: Claire McQuin Date: Wed, 29 Oct 2014 15:14:22 -0700 Subject: Update to RSpec 3. --- spec/unit/mixin/checksum_spec.rb | 4 +- spec/unit/mixin/command_spec.rb | 26 +- spec/unit/mixin/convert_to_class_name_spec.rb | 12 +- spec/unit/mixin/deep_merge_spec.rb | 110 +++---- spec/unit/mixin/deprecation_spec.rb | 10 +- .../enforce_ownership_and_permissions_spec.rb | 28 +- spec/unit/mixin/homebrew_user_spec.rb | 6 +- spec/unit/mixin/params_validate_spec.rb | 142 ++++----- spec/unit/mixin/path_sanity_spec.rb | 28 +- spec/unit/mixin/securable_spec.rb | 354 ++++++++++----------- spec/unit/mixin/shell_out_spec.rb | 12 +- spec/unit/mixin/template_spec.rb | 62 ++-- .../unit/mixin/windows_architecture_helper_spec.rb | 10 +- spec/unit/mixin/xml_escape_spec.rb | 14 +- 14 files changed, 409 insertions(+), 409 deletions(-) (limited to 'spec/unit/mixin') diff --git a/spec/unit/mixin/checksum_spec.rb b/spec/unit/mixin/checksum_spec.rb index 54689c9992..864b15f2bc 100644 --- a/spec/unit/mixin/checksum_spec.rb +++ b/spec/unit/mixin/checksum_spec.rb @@ -30,11 +30,11 @@ describe Chef::Mixin::Checksum do @cache = Chef::Digester.instance @file = CHEF_SPEC_DATA + "/checksum/random.txt" @stat = double("File::Stat", { :mtime => Time.at(0) }) - File.stub(:stat).and_return(@stat) + allow(File).to receive(:stat).and_return(@stat) end it "gets the checksum of a file" do - @checksum_user.checksum(@file).should == "09ee9c8cc70501763563bcf9c218d71b2fbf4186bf8e1e0da07f0f42c80a3394" + expect(@checksum_user.checksum(@file)).to eq("09ee9c8cc70501763563bcf9c218d71b2fbf4186bf8e1e0da07f0f42c80a3394") end end diff --git a/spec/unit/mixin/command_spec.rb b/spec/unit/mixin/command_spec.rb index 96660be436..e198e3addd 100644 --- a/spec/unit/mixin/command_spec.rb +++ b/spec/unit/mixin/command_spec.rb @@ -31,41 +31,41 @@ describe Chef::Mixin::Command, :volatile do it "should be possible to read the child process's stdout and stderr" do popen4("sh -c 'echo hello && echo world >&2'") do |pid, stdin, stdout, stderr| - stdout.read.should == "hello\n" - stderr.read.should == "world\n" + expect(stdout.read).to eq("hello\n") + expect(stderr.read).to eq("world\n") end end it "should default all commands to be run in the POSIX standard C locale" do popen4("echo $LC_ALL") do |pid, stdin, stdout, stderr| - stdout.read.strip.should == "C" + expect(stdout.read.strip).to eq("C") end end it "should respect locale when specified explicitly" do popen4("echo $LC_ALL", :environment => {"LC_ALL" => "es"}) do |pid, stdin, stdout, stderr| - stdout.read.strip.should == "es" + expect(stdout.read.strip).to eq("es") end end it "should end when the child process reads from STDIN and a block is given" do - lambda {Timeout.timeout(10) 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}" } end end - }.should_not raise_error + }.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 - lambda {Timeout.timeout(10) do + expect {Timeout.timeout(10) do pid, stdin,stdout,stderr = nil,nil,nil,nil evil_forker="exit if fork; 10.times { sleep 1}" popen4("ruby -e '#{evil_forker}'") do |pid,stdin,stdout,stderr| end - end}.should_not raise_error + end}.not_to raise_error end end @@ -76,13 +76,13 @@ describe Chef::Mixin::Command, :volatile do include Chef::Mixin::Command it "logs the command's stderr and stdout output if the command failed" do - Chef::Log.stub(:level).and_return(:debug) + allow(Chef::Log).to receive(:level).and_return(:debug) begin run_command(:command => "sh -c 'echo hello; echo world >&2; false'") violated "Exception expected, but nothing raised." rescue => e - e.message.should =~ /STDOUT: hello/ - e.message.should =~ /STDERR: world/ + expect(e.message).to match(/STDOUT: hello/) + expect(e.message).to match(/STDERR: world/) end end @@ -93,10 +93,10 @@ 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. - lambda {Timeout.timeout(10) do + expect {Timeout.timeout(10) do evil_forker="exit if fork; 10.times { sleep 1}" run_command(:command => "ruby -e '#{evil_forker}'") - end}.should_not raise_error + end}.not_to raise_error end end diff --git a/spec/unit/mixin/convert_to_class_name_spec.rb b/spec/unit/mixin/convert_to_class_name_spec.rb index 0276a55fd7..4cf6728d64 100644 --- a/spec/unit/mixin/convert_to_class_name_spec.rb +++ b/spec/unit/mixin/convert_to_class_name_spec.rb @@ -29,26 +29,26 @@ describe Chef::Mixin::ConvertToClassName do end it "converts a_snake_case_word to a CamelCaseWord" do - @convert.convert_to_class_name("now_camelized").should == "NowCamelized" + expect(@convert.convert_to_class_name("now_camelized")).to eq("NowCamelized") end it "converts a CamelCaseWord to a snake_case_word" do - @convert.convert_to_snake_case("NowImASnake").should == "now_im_a_snake" + expect(@convert.convert_to_snake_case("NowImASnake")).to eq("now_im_a_snake") end it "removes the base classes before snake casing" do - @convert.convert_to_snake_case("NameSpaced::Class::ThisIsWin", "NameSpaced::Class").should == "this_is_win" + expect(@convert.convert_to_snake_case("NameSpaced::Class::ThisIsWin", "NameSpaced::Class")).to eq("this_is_win") end it "removes the base classes without explicitly naming them and returns snake case" do - @convert.snake_case_basename("NameSpaced::Class::ExtraWin").should == "extra_win" + expect(@convert.snake_case_basename("NameSpaced::Class::ExtraWin")).to eq("extra_win") end it "interprets non-alphanumeric characters in snake case as word boundaries" do - @convert.convert_to_class_name("now_camelized_without-hyphen").should == "NowCamelizedWithoutHyphen" + expect(@convert.convert_to_class_name("now_camelized_without-hyphen")).to eq("NowCamelizedWithoutHyphen") end it "interprets underscore" do - @convert.convert_to_class_name("_remove_leading_underscore").should == "RemoveLeadingUnderscore" + expect(@convert.convert_to_class_name("_remove_leading_underscore")).to eq("RemoveLeadingUnderscore") end end diff --git a/spec/unit/mixin/deep_merge_spec.rb b/spec/unit/mixin/deep_merge_spec.rb index dbc49e68f2..40e749ecc0 100644 --- a/spec/unit/mixin/deep_merge_spec.rb +++ b/spec/unit/mixin/deep_merge_spec.rb @@ -37,175 +37,175 @@ describe Chef::Mixin::DeepMerge, "deep_merge!" do hash_src = {'id' => '2'} hash_dst = {} @dm.deep_merge!(hash_src.dup, hash_dst) - hash_dst.should == hash_src + expect(hash_dst).to eq(hash_src) end it "tests merging an hash w/array into blank hash" do hash_src = {'region' => {'id' => ['227', '2']}} hash_dst = {} @dm.deep_merge!(hash_src, hash_dst) - hash_dst.should == hash_src + expect(hash_dst).to eq(hash_src) end it "tests merge from empty hash" do hash_src = {} hash_dst = {"property" => ["2","4"]} @dm.deep_merge!(hash_src, hash_dst) - hash_dst.should == {"property" => ["2","4"]} + expect(hash_dst).to eq({"property" => ["2","4"]}) end it "tests merge to empty hash" do hash_src = {"property" => ["2","4"]} hash_dst = {} @dm.deep_merge!(hash_src, hash_dst) - hash_dst.should == {"property" => ["2","4"]} + expect(hash_dst).to eq({"property" => ["2","4"]}) end it "tests simple string overwrite" do hash_src = {"name" => "value"} hash_dst = {"name" => "value1"} @dm.deep_merge!(hash_src, hash_dst) - hash_dst.should == {"name" => "value"} + expect(hash_dst).to eq({"name" => "value"}) end it "tests simple string overwrite of empty hash" do hash_src = {"name" => "value"} hash_dst = {} @dm.deep_merge!(hash_src, hash_dst) - hash_dst.should == hash_src + expect(hash_dst).to eq(hash_src) end it "tests hashes holding array" do hash_src = {"property" => ["1","3"]} hash_dst = {"property" => ["2","4"]} @dm.deep_merge!(hash_src, hash_dst) - hash_dst.should == {"property" => ["2","4","1","3"]} + expect(hash_dst).to eq({"property" => ["2","4","1","3"]}) end it "tests hashes holding hashes holding arrays (array with duplicate elements is merged with dest then src" do hash_src = {"property" => {"bedroom_count" => ["1", "2"], "bathroom_count" => ["1", "4+"]}} hash_dst = {"property" => {"bedroom_count" => ["3", "2"], "bathroom_count" => ["2"]}} @dm.deep_merge!(hash_src, hash_dst) - hash_dst.should == {"property" => {"bedroom_count" => ["3","2","1"], "bathroom_count" => ["2", "1", "4+"]}} + expect(hash_dst).to eq({"property" => {"bedroom_count" => ["3","2","1"], "bathroom_count" => ["2", "1", "4+"]}}) end it "tests hash holding hash holding array v string (string is overwritten by array)" do hash_src = {"property" => {"bedroom_count" => ["1", "2"], "bathroom_count" => ["1", "4+"]}} hash_dst = {"property" => {"bedroom_count" => "3", "bathroom_count" => ["2"]}} @dm.deep_merge!(hash_src, hash_dst) - hash_dst.should == {"property" => {"bedroom_count" => ["1", "2"], "bathroom_count" => ["2","1","4+"]}} + expect(hash_dst).to eq({"property" => {"bedroom_count" => ["1", "2"], "bathroom_count" => ["2","1","4+"]}}) end it "tests hash holding hash holding string v array (array is overwritten by string)" do hash_src = {"property" => {"bedroom_count" => "3", "bathroom_count" => ["1", "4+"]}} hash_dst = {"property" => {"bedroom_count" => ["1", "2"], "bathroom_count" => ["2"]}} @dm.deep_merge!(hash_src, hash_dst) - hash_dst.should == {"property" => {"bedroom_count" => "3", "bathroom_count" => ["2","1","4+"]}} + expect(hash_dst).to eq({"property" => {"bedroom_count" => "3", "bathroom_count" => ["2","1","4+"]}}) end it "tests hash holding hash holding hash v array (array is overwritten by hash)" do hash_src = {"property" => {"bedroom_count" => {"king_bed" => 3, "queen_bed" => 1}, "bathroom_count" => ["1", "4+"]}} hash_dst = {"property" => {"bedroom_count" => ["1", "2"], "bathroom_count" => ["2"]}} @dm.deep_merge!(hash_src, hash_dst) - hash_dst.should == {"property" => {"bedroom_count" => {"king_bed" => 3, "queen_bed" => 1}, "bathroom_count" => ["2","1","4+"]}} + expect(hash_dst).to eq({"property" => {"bedroom_count" => {"king_bed" => 3, "queen_bed" => 1}, "bathroom_count" => ["2","1","4+"]}}) end it "tests 3 hash layers holding integers (integers are overwritten by source)" do hash_src = {"property" => {"bedroom_count" => {"king_bed" => 3, "queen_bed" => 1}, "bathroom_count" => ["1", "4+"]}} hash_dst = {"property" => {"bedroom_count" => {"king_bed" => 2, "queen_bed" => 4}, "bathroom_count" => ["2"]}} @dm.deep_merge!(hash_src, hash_dst) - hash_dst.should == {"property" => {"bedroom_count" => {"king_bed" => 3, "queen_bed" => 1}, "bathroom_count" => ["2","1","4+"]}} + expect(hash_dst).to eq({"property" => {"bedroom_count" => {"king_bed" => 3, "queen_bed" => 1}, "bathroom_count" => ["2","1","4+"]}}) end it "tests 3 hash layers holding arrays of int (arrays are merged)" do hash_src = {"property" => {"bedroom_count" => {"king_bed" => [3], "queen_bed" => [1]}, "bathroom_count" => ["1", "4+"]}} hash_dst = {"property" => {"bedroom_count" => {"king_bed" => [2], "queen_bed" => [4]}, "bathroom_count" => ["2"]}} @dm.deep_merge!(hash_src, hash_dst) - hash_dst.should == {"property" => {"bedroom_count" => {"king_bed" => [2,3], "queen_bed" => [4,1]}, "bathroom_count" => ["2","1","4+"]}} + expect(hash_dst).to eq({"property" => {"bedroom_count" => {"king_bed" => [2,3], "queen_bed" => [4,1]}, "bathroom_count" => ["2","1","4+"]}}) end it "tests 1 hash overwriting 3 hash layers holding arrays of int" do hash_src = {"property" => "1"} hash_dst = {"property" => {"bedroom_count" => {"king_bed" => [2], "queen_bed" => [4]}, "bathroom_count" => ["2"]}} @dm.deep_merge!(hash_src, hash_dst) - hash_dst.should == {"property" => "1"} + expect(hash_dst).to eq({"property" => "1"}) end it "tests 3 hash layers holding arrays of int (arrays are merged) but second hash's array is overwritten" do hash_src = {"property" => {"bedroom_count" => {"king_bed" => [3], "queen_bed" => [1]}, "bathroom_count" => "1"}} hash_dst = {"property" => {"bedroom_count" => {"king_bed" => [2], "queen_bed" => [4]}, "bathroom_count" => ["2"]}} @dm.deep_merge!(hash_src, hash_dst) - hash_dst.should == {"property" => {"bedroom_count" => {"king_bed" => [2,3], "queen_bed" => [4,1]}, "bathroom_count" => "1"}} + expect(hash_dst).to eq({"property" => {"bedroom_count" => {"king_bed" => [2,3], "queen_bed" => [4,1]}, "bathroom_count" => "1"}}) end it "tests 3 hash layers holding arrays of int, but one holds int. This one overwrites, but the rest merge" do hash_src = {"property" => {"bedroom_count" => {"king_bed" => 3, "queen_bed" => [1]}, "bathroom_count" => ["1"]}} hash_dst = {"property" => {"bedroom_count" => {"king_bed" => [2], "queen_bed" => [4]}, "bathroom_count" => ["2"]}} @dm.deep_merge!(hash_src, hash_dst) - hash_dst.should == {"property" => {"bedroom_count" => {"king_bed" => 3, "queen_bed" => [4,1]}, "bathroom_count" => ["2","1"]}} + expect(hash_dst).to eq({"property" => {"bedroom_count" => {"king_bed" => 3, "queen_bed" => [4,1]}, "bathroom_count" => ["2","1"]}}) end it "tests 3 hash layers holding arrays of int, but source is incomplete." do hash_src = {"property" => {"bedroom_count" => {"king_bed" => [3]}, "bathroom_count" => ["1"]}} hash_dst = {"property" => {"bedroom_count" => {"king_bed" => [2], "queen_bed" => [4]}, "bathroom_count" => ["2"]}} @dm.deep_merge!(hash_src, hash_dst) - hash_dst.should == {"property" => {"bedroom_count" => {"king_bed" => [2,3], "queen_bed" => [4]}, "bathroom_count" => ["2","1"]}} + expect(hash_dst).to eq({"property" => {"bedroom_count" => {"king_bed" => [2,3], "queen_bed" => [4]}, "bathroom_count" => ["2","1"]}}) end it "tests 3 hash layers holding arrays of int, but source is shorter and has new 2nd level ints." do hash_src = {"property" => {"bedroom_count" => {2=>3, "king_bed" => [3]}, "bathroom_count" => ["1"]}} hash_dst = {"property" => {"bedroom_count" => {"king_bed" => [2], "queen_bed" => [4]}, "bathroom_count" => ["2"]}} @dm.deep_merge!(hash_src, hash_dst) - hash_dst.should == {"property" => {"bedroom_count" => {2=>3, "king_bed" => [2,3], "queen_bed" => [4]}, "bathroom_count" => ["2","1"]}} + expect(hash_dst).to eq({"property" => {"bedroom_count" => {2=>3, "king_bed" => [2,3], "queen_bed" => [4]}, "bathroom_count" => ["2","1"]}}) end it "tests 3 hash layers holding arrays of int, but source is empty" do hash_src = {} hash_dst = {"property" => {"bedroom_count" => {"king_bed" => [2], "queen_bed" => [4]}, "bathroom_count" => ["2"]}} @dm.deep_merge!(hash_src, hash_dst) - hash_dst.should == {"property" => {"bedroom_count" => {"king_bed" => [2], "queen_bed" => [4]}, "bathroom_count" => ["2"]}} + expect(hash_dst).to eq({"property" => {"bedroom_count" => {"king_bed" => [2], "queen_bed" => [4]}, "bathroom_count" => ["2"]}}) end it "tests 3 hash layers holding arrays of int, but dest is empty" do hash_src = {"property" => {"bedroom_count" => {2=>3, "king_bed" => [3]}, "bathroom_count" => ["1"]}} hash_dst = {} @dm.deep_merge!(hash_src, hash_dst) - hash_dst.should == {"property" => {"bedroom_count" => {2=>3, "king_bed" => [3]}, "bathroom_count" => ["1"]}} + expect(hash_dst).to eq({"property" => {"bedroom_count" => {2=>3, "king_bed" => [3]}, "bathroom_count" => ["1"]}}) end it "tests hash holding arrays of arrays" do hash_src = {["1", "2", "3"] => ["1", "2"]} hash_dst = {["4", "5"] => ["3"]} @dm.deep_merge!(hash_src, hash_dst) - hash_dst.should == {["1","2","3"] => ["1", "2"], ["4", "5"] => ["3"]} + expect(hash_dst).to eq({["1","2","3"] => ["1", "2"], ["4", "5"] => ["3"]}) end it "tests merging of hash with blank hash, and make sure that source array split does not function when turned off" do hash_src = {'property' => {'bedroom_count' => ["1","2,3"]}} hash_dst = {} @dm.deep_merge!(hash_src, hash_dst) - hash_dst.should == {'property' => {'bedroom_count' => ["1","2,3"]}} + expect(hash_dst).to eq({'property' => {'bedroom_count' => ["1","2,3"]}}) end it "tests merging into a blank hash" do hash_src = {"action"=>"browse", "controller"=>"results"} hash_dst = {} @dm.deep_merge!(hash_src, hash_dst) - hash_dst.should == hash_src + expect(hash_dst).to eq(hash_src) end it "tests are unmerged hashes passed unmodified w/out :unpack_arrays?" do hash_src = {"amenity"=>{"id"=>["26,27"]}} hash_dst = {} @dm.deep_merge!(hash_src, hash_dst) - hash_dst.should == {"amenity"=>{"id"=>["26,27"]}} + expect(hash_dst).to eq({"amenity"=>{"id"=>["26,27"]}}) end it "tests hash of array of hashes" do hash_src = {"item" => [{"1" => "3"}, {"2" => "4"}]} hash_dst = {"item" => [{"3" => "5"}]} @dm.deep_merge!(hash_src, hash_dst) - hash_dst.should == {"item" => [{"3" => "5"}, {"1" => "3"}, {"2" => "4"}]} + expect(hash_dst).to eq({"item" => [{"3" => "5"}, {"1" => "3"}, {"2" => "4"}]}) end # Additions since import @@ -213,42 +213,42 @@ describe Chef::Mixin::DeepMerge, "deep_merge!" do hash_src = {"valid" => false} hash_dst = {"valid" => true} @dm.deep_merge!(hash_src, hash_dst) - hash_dst.should == {"valid" => false} + expect(hash_dst).to eq({"valid" => false}) end it "should overwrite false with true when merging boolean values" do hash_src = {"valid" => true} hash_dst = {"valid" => false} @dm.deep_merge!(hash_src, hash_dst) - hash_dst.should == {"valid" => true} + expect(hash_dst).to eq({"valid" => true}) end it "should overwrite a string with an empty string when merging string values" do hash_src = {"item" => " "} hash_dst = {"item" => "orange"} @dm.deep_merge!(hash_src, hash_dst) - hash_dst.should == {"item" => " "} + expect(hash_dst).to eq({"item" => " "}) end it "should overwrite an empty string with a string when merging string values" do hash_src = {"item" => "orange"} hash_dst = {"item" => " "} @dm.deep_merge!(hash_src, hash_dst) - hash_dst.should == {"item" => "orange"} + expect(hash_dst).to eq({"item" => "orange"}) end it 'should overwrite hashes with nil' do hash_src = {"item" => { "1" => "2"}, "other" => true } hash_dst = {"item" => nil } @dm.deep_merge!(hash_src, hash_dst) - hash_dst.should == {"item" => nil, "other" => true } + expect(hash_dst).to eq({"item" => nil, "other" => true }) end it 'should overwrite strings with nil' do hash_src = {"item" => "to_overwrite", "other" => false } hash_dst = {"item" => nil } @dm.deep_merge!(hash_src, hash_dst) - hash_dst.should == {"item" => nil, "other" => false } + expect(hash_dst).to eq({"item" => nil, "other" => false }) end end # deep_merge! @@ -262,40 +262,40 @@ describe Chef::Mixin::DeepMerge do it "should merge a hash into an empty hash" do hash_dst = {} hash_src = {'id' => '2'} - @dm.merge(hash_dst, hash_src).should == hash_src + expect(@dm.merge(hash_dst, hash_src)).to eq(hash_src) end it "should merge a nested hash into an empty hash" do hash_dst = {} hash_src = {'region' => {'id' => ['227', '2']}} - @dm.merge(hash_dst, hash_src).should == hash_src + expect(@dm.merge(hash_dst, hash_src)).to eq(hash_src) end it "should overwrite as string value when merging hashes" do hash_dst = {"name" => "value1"} hash_src = {"name" => "value"} - @dm.merge(hash_dst, hash_src).should == {"name" => "value"} + expect(@dm.merge(hash_dst, hash_src)).to eq({"name" => "value"}) end it "should merge arrays within hashes" do hash_dst = {"property" => ["2","4"]} hash_src = {"property" => ["1","3"]} - @dm.merge(hash_dst, hash_src).should == {"property" => ["2","4","1","3"]} + expect(@dm.merge(hash_dst, hash_src)).to eq({"property" => ["2","4","1","3"]}) end it "should merge deeply nested hashes" do hash_dst = {"property" => {"values" => {"are" => "falling", "can" => "change"}}} hash_src = {"property" => {"values" => {"are" => "stable", "may" => "rise"}}} - @dm.merge(hash_dst, hash_src).should == {"property" => {"values" => {"are" => "stable", "can" => "change", "may" => "rise"}}} + expect(@dm.merge(hash_dst, hash_src)).to eq({"property" => {"values" => {"are" => "stable", "can" => "change", "may" => "rise"}}}) end it "should not modify the source or destination during the merge" do hash_dst = {"property" => ["1","2","3"]} hash_src = {"property" => ["4","5","6"]} ret = @dm.merge(hash_dst, hash_src) - hash_dst.should == {"property" => ["1","2","3"]} - hash_src.should == {"property" => ["4","5","6"]} - ret.should == {"property" => ["1","2","3","4","5","6"]} + expect(hash_dst).to eq({"property" => ["1","2","3"]}) + expect(hash_src).to eq({"property" => ["4","5","6"]}) + expect(ret).to eq({"property" => ["1","2","3","4","5","6"]}) end it "should not error merging un-dupable objects" do @@ -308,25 +308,25 @@ describe Chef::Mixin::DeepMerge do it "errors out if knockout merge use is detected in an array" do hash_dst = {"property" => ["2","4"]} hash_src = {"property" => ["1","!merge:4"]} - lambda {@dm.role_merge(hash_dst, hash_src)}.should raise_error(Chef::Mixin::DeepMerge::InvalidSubtractiveMerge) + expect {@dm.role_merge(hash_dst, hash_src)}.to raise_error(Chef::Mixin::DeepMerge::InvalidSubtractiveMerge) end it "errors out if knockout merge use is detected in an array (reversed merge order)" do hash_dst = {"property" => ["1","!merge:4"]} hash_src = {"property" => ["2","4"]} - lambda {@dm.role_merge(hash_dst, hash_src)}.should raise_error(Chef::Mixin::DeepMerge::InvalidSubtractiveMerge) + expect {@dm.role_merge(hash_dst, hash_src)}.to raise_error(Chef::Mixin::DeepMerge::InvalidSubtractiveMerge) end it "errors out if knockout merge use is detected in a string" do hash_dst = {"property" => ["2","4"]} hash_src = {"property" => "!merge"} - lambda {@dm.role_merge(hash_dst, hash_src)}.should raise_error(Chef::Mixin::DeepMerge::InvalidSubtractiveMerge) + expect {@dm.role_merge(hash_dst, hash_src)}.to raise_error(Chef::Mixin::DeepMerge::InvalidSubtractiveMerge) end it "errors out if knockout merge use is detected in a string (reversed merge order)" do hash_dst = {"property" => "!merge"} hash_src= {"property" => ["2","4"]} - lambda {@dm.role_merge(hash_dst, hash_src)}.should raise_error(Chef::Mixin::DeepMerge::InvalidSubtractiveMerge) + expect {@dm.role_merge(hash_dst, hash_src)}.to raise_error(Chef::Mixin::DeepMerge::InvalidSubtractiveMerge) end end @@ -337,10 +337,10 @@ describe Chef::Mixin::DeepMerge do merged_result = @dm.hash_only_merge(merge_ee_hash, merge_with_hash) - merged_result["top_level_b"].should == "top-level-b-merged-onto" - merged_result["top_level_a"]["1_deep_a"].should == "1-a-merge-ee" - merged_result["top_level_a"]["1_deep_b"].should == "1-deep-b-merged-onto" - merged_result["top_level_a"]["1_deep_c"].should == "1-deep-c-merged-onto" + expect(merged_result["top_level_b"]).to eq("top-level-b-merged-onto") + expect(merged_result["top_level_a"]["1_deep_a"]).to eq("1-a-merge-ee") + expect(merged_result["top_level_a"]["1_deep_b"]).to eq("1-deep-b-merged-onto") + expect(merged_result["top_level_a"]["1_deep_c"]).to eq("1-deep-c-merged-onto") end it "replaces arrays rather than merging them" do @@ -349,9 +349,9 @@ describe Chef::Mixin::DeepMerge do merged_result = @dm.hash_only_merge(merge_ee_hash, merge_with_hash) - merged_result["top_level_b"].should == "top-level-b-merged-onto" - merged_result["top_level_a"]["1_deep_a"].should == "1-a-merge-ee" - merged_result["top_level_a"]["1_deep_b"].should == %w[B B B] + expect(merged_result["top_level_b"]).to eq("top-level-b-merged-onto") + expect(merged_result["top_level_a"]["1_deep_a"]).to eq("1-a-merge-ee") + expect(merged_result["top_level_a"]["1_deep_b"]).to eq(%w[B B B]) end it "replaces non-hash items with hashes when there's a conflict" do @@ -360,17 +360,17 @@ describe Chef::Mixin::DeepMerge do merged_result = @dm.hash_only_merge(merge_ee_hash, merge_with_hash) - merged_result["top_level_a"].should be_a(Hash) - merged_result["top_level_a"]["1_deep_a"].should be_nil - merged_result["top_level_a"]["1_deep_b"].should == %w[B B B] + expect(merged_result["top_level_a"]).to be_a(Hash) + expect(merged_result["top_level_a"]["1_deep_a"]).to be_nil + expect(merged_result["top_level_a"]["1_deep_b"]).to eq(%w[B B B]) end it "does not mutate deeply-nested original hashes by default" do merge_ee_hash = {"top_level_a" => {"1_deep_a" => { "2_deep_a" => { "3_deep_a" => "foo" }}}} merge_with_hash = {"top_level_a" => {"1_deep_a" => { "2_deep_a" => { "3_deep_b" => "bar" }}}} @dm.hash_only_merge(merge_ee_hash, merge_with_hash) - merge_ee_hash.should == {"top_level_a" => {"1_deep_a" => { "2_deep_a" => { "3_deep_a" => "foo" }}}} - merge_with_hash.should == {"top_level_a" => {"1_deep_a" => { "2_deep_a" => { "3_deep_b" => "bar" }}}} + expect(merge_ee_hash).to eq({"top_level_a" => {"1_deep_a" => { "2_deep_a" => { "3_deep_a" => "foo" }}}}) + expect(merge_with_hash).to eq({"top_level_a" => {"1_deep_a" => { "2_deep_a" => { "3_deep_b" => "bar" }}}}) end it "does not error merging un-dupable items" do diff --git a/spec/unit/mixin/deprecation_spec.rb b/spec/unit/mixin/deprecation_spec.rb index 3ebf06e830..6d9f39af9f 100644 --- a/spec/unit/mixin/deprecation_spec.rb +++ b/spec/unit/mixin/deprecation_spec.rb @@ -28,16 +28,16 @@ describe Chef::Mixin do end it "has a list of deprecated constants" do - Chef::Mixin.deprecated_constants.should have_key(:DeprecatedClass) + expect(Chef::Mixin.deprecated_constants).to have_key(:DeprecatedClass) end it "returns the replacement when accessing the deprecated constant" do - Chef::Mixin::DeprecatedClass.should == Chef::Node + expect(Chef::Mixin::DeprecatedClass).to eq(Chef::Node) end it "warns when accessing the deprecated constant" do Chef::Mixin::DeprecatedClass - @log_io.string.should include("This is a test deprecation") + expect(@log_io.string).to include("This is a test deprecation") end end end @@ -50,8 +50,8 @@ describe Chef::Mixin::Deprecation::DeprecatedInstanceVariable do end it "forward method calls to the target object" do - @deprecated_ivar.length.should == 5 - @deprecated_ivar.to_sym.should == :value + expect(@deprecated_ivar.length).to eq(5) + expect(@deprecated_ivar.to_sym).to eq(:value) end end diff --git a/spec/unit/mixin/enforce_ownership_and_permissions_spec.rb b/spec/unit/mixin/enforce_ownership_and_permissions_spec.rb index fe72d53de5..aeef175ff9 100644 --- a/spec/unit/mixin/enforce_ownership_and_permissions_spec.rb +++ b/spec/unit/mixin/enforce_ownership_and_permissions_spec.rb @@ -40,15 +40,15 @@ describe Chef::Mixin::EnforceOwnershipAndPermissions do end it "should call set_all on the file access control object" do - Chef::FileAccessControl.any_instance.should_receive(:set_all) + expect_any_instance_of(Chef::FileAccessControl).to receive(:set_all) @provider.enforce_ownership_and_permissions end context "when nothing was updated" do before do - Chef::FileAccessControl.any_instance.stub(:uid_from_resource).and_return(0) - Chef::FileAccessControl.any_instance.stub(:requires_changes?).and_return(false) - Chef::FileAccessControl.any_instance.stub(:define_resource_requirements) + allow_any_instance_of(Chef::FileAccessControl).to receive(:uid_from_resource).and_return(0) + allow_any_instance_of(Chef::FileAccessControl).to receive(:requires_changes?).and_return(false) + allow_any_instance_of(Chef::FileAccessControl).to receive(:define_resource_requirements) passwd_struct = if windows? Struct::Passwd.new("root", "x", 0, 0, "/root", "/bin/bash") @@ -56,14 +56,14 @@ describe Chef::Mixin::EnforceOwnershipAndPermissions do Struct::Passwd.new("root", "x", 0, 0, "root", "/root", "/bin/bash") end group_struct = OpenStruct.new(:name => "root", :passwd => "x", :gid => 0) - Etc.stub(:getpwuid).and_return(passwd_struct) - Etc.stub(:getgrgid).and_return(group_struct) + allow(Etc).to receive(:getpwuid).and_return(passwd_struct) + allow(Etc).to receive(:getgrgid).and_return(group_struct) end it "does not set updated_by_last_action on the new resource" do - @provider.new_resource.should_not_receive(:updated_by_last_action) + expect(@provider.new_resource).not_to receive(:updated_by_last_action) - Chef::FileAccessControl.any_instance.stub(:set_all) + allow_any_instance_of(Chef::FileAccessControl).to receive(:set_all) @provider.run_action(:create) end @@ -71,8 +71,8 @@ describe Chef::Mixin::EnforceOwnershipAndPermissions do context "when something was modified" do before do - Chef::FileAccessControl.any_instance.stub(:requires_changes?).and_return(true) - Chef::FileAccessControl.any_instance.stub(:uid_from_resource).and_return(0) + allow_any_instance_of(Chef::FileAccessControl).to receive(:requires_changes?).and_return(true) + allow_any_instance_of(Chef::FileAccessControl).to receive(:uid_from_resource).and_return(0) passwd_struct = if windows? Struct::Passwd.new("root", "x", 0, 0, "/root", "/bin/bash") @@ -80,15 +80,15 @@ describe Chef::Mixin::EnforceOwnershipAndPermissions do Struct::Passwd.new("root", "x", 0, 0, "root", "/root", "/bin/bash") end group_struct = OpenStruct.new(:name => "root", :passwd => "x", :gid => 0) - Etc.stub(:getpwuid).and_return(passwd_struct) - Etc.stub(:getgrgid).and_return(group_struct) + allow(Etc).to receive(:getpwuid).and_return(passwd_struct) + allow(Etc).to receive(:getgrgid).and_return(group_struct) end it "sets updated_by_last_action on the new resource" do @provider.new_resource.owner(0) # CHEF-3557 hack - Set these because we don't for windows @provider.new_resource.group(0) # CHEF-3557 hack - Set these because we don't for windows - @provider.new_resource.should_receive(:updated_by_last_action) - Chef::FileAccessControl.any_instance.stub(:set_all) + expect(@provider.new_resource).to receive(:updated_by_last_action) + allow_any_instance_of(Chef::FileAccessControl).to receive(:set_all) @provider.run_action(:create) end end diff --git a/spec/unit/mixin/homebrew_user_spec.rb b/spec/unit/mixin/homebrew_user_spec.rb index 4e30455765..57b89720dc 100644 --- a/spec/unit/mixin/homebrew_user_spec.rb +++ b/spec/unit/mixin/homebrew_user_spec.rb @@ -41,7 +41,7 @@ describe Chef::Mixin::HomebrewUser do it 'returns the homebrew user without looking at the file when name is provided' do expect(File).to receive(:exist?).exactly(0).times - Etc.stub_chain(:getpwnam, :uid).and_return(uid) + allow(Etc).to receive_message_chain(:getpwnam, :uid).and_return(uid) expect(homebrew_user.find_homebrew_uid(user)).to eq(uid) end @@ -71,7 +71,7 @@ describe Chef::Mixin::HomebrewUser do it 'returns the owner of the brew executable when it is not at a default location' do expect(File).to receive(:exist?).with(default_brew_path).and_return(false) - homebrew_user.stub_chain(:shell_out, :stdout, :strip).and_return("/foo") + allow(homebrew_user).to receive_message_chain(:shell_out, :stdout, :strip).and_return("/foo") expect(File).to receive(:stat).with("/foo").and_return(stat_double) expect(homebrew_user.find_homebrew_uid(user)).to eq(brew_owner) end @@ -83,7 +83,7 @@ describe Chef::Mixin::HomebrewUser do it 'raises an error if no executable is found' do expect(File).to receive(:exist?).with(default_brew_path).and_return(false) - homebrew_user.stub_chain(:shell_out, :stdout, :strip).and_return("") + allow(homebrew_user).to receive_message_chain(:shell_out, :stdout, :strip).and_return("") expect { homebrew_user.find_homebrew_uid(user) }.to raise_error(Chef::Exceptions::CannotDetermineHomebrewOwner) end diff --git a/spec/unit/mixin/params_validate_spec.rb b/spec/unit/mixin/params_validate_spec.rb index cc2fe198ca..85e1c1abab 100644 --- a/spec/unit/mixin/params_validate_spec.rb +++ b/spec/unit/mixin/params_validate_spec.rb @@ -32,29 +32,29 @@ describe Chef::Mixin::ParamsValidate do end it "should allow a hash and a hash as arguments to validate" do - lambda { @vo.validate({:one => "two"}, {}) }.should_not raise_error + expect { @vo.validate({:one => "two"}, {}) }.not_to raise_error end it "should raise an argument error if validate is called incorrectly" do - lambda { @vo.validate("one", "two") }.should raise_error(ArgumentError) + expect { @vo.validate("one", "two") }.to raise_error(ArgumentError) end it "should require validation map keys to be symbols or strings" do - lambda { @vo.validate({:one => "two"}, { :one => true }) }.should_not raise_error - lambda { @vo.validate({:one => "two"}, { "one" => true }) }.should_not raise_error - lambda { @vo.validate({:one => "two"}, { Hash.new => true }) }.should raise_error(ArgumentError) + expect { @vo.validate({:one => "two"}, { :one => true }) }.not_to raise_error + expect { @vo.validate({:one => "two"}, { "one" => true }) }.not_to raise_error + expect { @vo.validate({:one => "two"}, { Hash.new => true }) }.to raise_error(ArgumentError) end it "should allow options to be required with true" do - lambda { @vo.validate({:one => "two"}, { :one => true }) }.should_not raise_error + expect { @vo.validate({:one => "two"}, { :one => true }) }.not_to raise_error end it "should allow options to be optional with false" do - lambda { @vo.validate({}, {:one => false})}.should_not raise_error + expect { @vo.validate({}, {:one => false})}.not_to raise_error end it "should allow you to check what kind_of? thing an argument is with kind_of" do - lambda { + expect { @vo.validate( {:one => "string"}, { @@ -63,9 +63,9 @@ describe Chef::Mixin::ParamsValidate do } } ) - }.should_not raise_error + }.not_to raise_error - lambda { + expect { @vo.validate( {:one => "string"}, { @@ -74,11 +74,11 @@ describe Chef::Mixin::ParamsValidate do } } ) - }.should raise_error(ArgumentError) + }.to raise_error(ArgumentError) end it "should allow you to specify an argument is required with required" do - lambda { + expect { @vo.validate( {:one => "string"}, { @@ -87,9 +87,9 @@ describe Chef::Mixin::ParamsValidate do } } ) - }.should_not raise_error + }.not_to raise_error - lambda { + expect { @vo.validate( {:two => "string"}, { @@ -98,9 +98,9 @@ describe Chef::Mixin::ParamsValidate do } } ) - }.should raise_error(ArgumentError) + }.to raise_error(ArgumentError) - lambda { + expect { @vo.validate( {:two => "string"}, { @@ -109,11 +109,11 @@ describe Chef::Mixin::ParamsValidate do } } ) - }.should_not raise_error + }.not_to raise_error end it "should allow you to specify whether an object has a method with respond_to" do - lambda { + expect { @vo.validate( {:one => @vo}, { @@ -122,9 +122,9 @@ describe Chef::Mixin::ParamsValidate do } } ) - }.should_not raise_error + }.not_to raise_error - lambda { + expect { @vo.validate( {:one => @vo}, { @@ -133,11 +133,11 @@ describe Chef::Mixin::ParamsValidate do } } ) - }.should raise_error(ArgumentError) + }.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 - lambda { + expect { @vo.validate( {:one => @vo}, { @@ -146,9 +146,9 @@ describe Chef::Mixin::ParamsValidate do } } ) - }.should_not raise_error + }.not_to raise_error - lambda { + expect { @vo.validate( {:one => @vo}, { @@ -157,7 +157,7 @@ describe Chef::Mixin::ParamsValidate do } } ) - }.should raise_error(ArgumentError) + }.to raise_error(ArgumentError) end it "should let you set a default value with default => value" do @@ -167,11 +167,11 @@ describe Chef::Mixin::ParamsValidate do :default => "is the loneliest number" } }) - arguments[:one].should == "is the loneliest number" + expect(arguments[:one]).to eq("is the loneliest number") end it "should let you check regular expressions" do - lambda { + expect { @vo.validate( { :one => "is good" }, { @@ -180,9 +180,9 @@ describe Chef::Mixin::ParamsValidate do } } ) - }.should_not raise_error + }.not_to raise_error - lambda { + expect { @vo.validate( { :one => "is good" }, { @@ -191,11 +191,11 @@ describe Chef::Mixin::ParamsValidate do } } ) - }.should raise_error(ArgumentError) + }.to raise_error(ArgumentError) end it "should let you specify your own callbacks" do - lambda { + expect { @vo.validate( { :one => "is good" }, { @@ -208,9 +208,9 @@ describe Chef::Mixin::ParamsValidate do } } ) - }.should_not raise_error + }.not_to raise_error - lambda { + expect { @vo.validate( { :one => "is bad" }, { @@ -223,12 +223,12 @@ describe Chef::Mixin::ParamsValidate do } } ) - }.should raise_error(ArgumentError) + }.to raise_error(ArgumentError) end it "should let you combine checks" do args = { :one => "is good", :two => "is bad" } - lambda { + expect { @vo.validate( args, { @@ -250,9 +250,9 @@ describe Chef::Mixin::ParamsValidate do :three => { :default => "neato mosquito" } } ) - }.should_not raise_error - args[:three].should == "neato mosquito" - lambda { + }.not_to raise_error + expect(args[:three]).to eq("neato mosquito") + expect { @vo.validate( args, { @@ -274,11 +274,11 @@ describe Chef::Mixin::ParamsValidate do :three => { :default => "neato mosquito" } } ) - }.should raise_error(ArgumentError) + }.to raise_error(ArgumentError) end it "should raise an ArgumentError if the validation map has an unknown check" do - lambda { @vo.validate( + expect { @vo.validate( { :one => "two" }, { :one => { @@ -286,17 +286,17 @@ describe Chef::Mixin::ParamsValidate do } } ) - }.should raise_error(ArgumentError) + }.to raise_error(ArgumentError) end it "should accept keys that are strings in the options" do - lambda { + expect { @vo.validate({ "one" => "two" }, { :one => { :regex => /^two$/ }}) - }.should_not raise_error + }.not_to raise_error end it "should allow an array to kind_of" do - lambda { + expect { @vo.validate( {:one => "string"}, { @@ -305,8 +305,8 @@ describe Chef::Mixin::ParamsValidate do } } ) - }.should_not raise_error - lambda { + }.not_to raise_error + expect { @vo.validate( {:one => ["string"]}, { @@ -315,8 +315,8 @@ describe Chef::Mixin::ParamsValidate do } } ) - }.should_not raise_error - lambda { + }.not_to raise_error + expect { @vo.validate( {:one => Hash.new}, { @@ -325,48 +325,48 @@ describe Chef::Mixin::ParamsValidate do } } ) - }.should raise_error(ArgumentError) + }.to raise_error(ArgumentError) end it "asserts that a value returns false from a predicate method" do - lambda do + expect do @vo.validate({:not_blank => "should pass"}, {:not_blank => {:cannot_be => :nil, :cannot_be => :empty}}) - end.should_not raise_error - lambda do + end.not_to raise_error + expect do @vo.validate({:not_blank => ""}, {:not_blank => {:cannot_be => :nil, :cannot_be => :empty}}) - end.should raise_error(Chef::Exceptions::ValidationFailed) + end.to raise_error(Chef::Exceptions::ValidationFailed) end it "should set and return a value, then return the same value" do value = "meow" - @vo.set_or_return(:test, value, {}).object_id.should == value.object_id - @vo.set_or_return(:test, nil, {}).object_id.should == value.object_id + expect(@vo.set_or_return(:test, value, {}).object_id).to eq(value.object_id) + expect(@vo.set_or_return(:test, nil, {}).object_id).to eq(value.object_id) end it "should set and return a default value when the argument is nil, then return the same value" do value = "meow" - @vo.set_or_return(:test, nil, { :default => value }).object_id.should == value.object_id - @vo.set_or_return(:test, nil, {}).object_id.should == value.object_id + expect(@vo.set_or_return(:test, nil, { :default => value }).object_id).to eq(value.object_id) + expect(@vo.set_or_return(:test, nil, {}).object_id).to eq(value.object_id) end it "should raise an ArgumentError when argument is nil and required is true" do - lambda { + expect { @vo.set_or_return(:test, nil, { :required => true }) - }.should raise_error(ArgumentError) + }.to raise_error(ArgumentError) end it "should not raise an error when argument is nil and required is false" do - lambda { + expect { @vo.set_or_return(:test, nil, { :required => false }) - }.should_not raise_error + }.not_to raise_error end it "should set and return @name, then return @name for foo when argument is nil" do value = "meow" - @vo.set_or_return(:name, value, { }).object_id.should == value.object_id - @vo.set_or_return(:foo, nil, { :name_attribute => true }).object_id.should == value.object_id + expect(@vo.set_or_return(:name, value, { }).object_id).to eq(value.object_id) + expect(@vo.set_or_return(:foo, nil, { :name_attribute => true }).object_id).to eq(value.object_id) end it "should allow DelayedEvaluator instance to be set for value regardless of restriction" do @@ -377,31 +377,31 @@ describe Chef::Mixin::ParamsValidate do it "should raise an error when delayed evaluated attribute is not valid" do value = Chef::DelayedEvaluator.new{ 'test' } @vo.set_or_return(:test, value, {:kind_of => Numeric}) - lambda do + expect do @vo.set_or_return(:test, nil, {:kind_of => Numeric}) - end.should raise_error(Chef::Exceptions::ValidationFailed) + end.to raise_error(Chef::Exceptions::ValidationFailed) end it "should create DelayedEvaluator instance when #lazy is used" do @vo.set_or_return(:delayed, @vo.lazy{ 'test' }, {}) - @vo.instance_variable_get(:@delayed).should be_a(Chef::DelayedEvaluator) + expect(@vo.instance_variable_get(:@delayed)).to be_a(Chef::DelayedEvaluator) end it "should execute block on each call when DelayedEvaluator" do value = 'fubar' @vo.set_or_return(:test, @vo.lazy{ value }, {}) - @vo.set_or_return(:test, nil, {}).should == 'fubar' + expect(@vo.set_or_return(:test, nil, {})).to eq('fubar') value = 'foobar' - @vo.set_or_return(:test, nil, {}).should == 'foobar' + expect(@vo.set_or_return(:test, nil, {})).to eq('foobar') value = 'fauxbar' - @vo.set_or_return(:test, nil, {}).should == 'fauxbar' + expect(@vo.set_or_return(:test, nil, {})).to eq('fauxbar') end it "should not evaluate non DelayedEvaluator instances" do value = lambda{ 'test' } @vo.set_or_return(:test, value, {}) - @vo.set_or_return(:test, nil, {}).object_id.should == value.object_id - @vo.set_or_return(:test, nil, {}).should be_a(Proc) + expect(@vo.set_or_return(:test, nil, {}).object_id).to eq(value.object_id) + expect(@vo.set_or_return(:test, nil, {})).to be_a(Proc) end end diff --git a/spec/unit/mixin/path_sanity_spec.rb b/spec/unit/mixin/path_sanity_spec.rb index 64c667b483..ec8e182e3d 100644 --- a/spec/unit/mixin/path_sanity_spec.rb +++ b/spec/unit/mixin/path_sanity_spec.rb @@ -33,54 +33,54 @@ describe Chef::Mixin::PathSanity do Chef::Config[:enforce_path_sanity] = true @ruby_bindir = '/some/ruby/bin' @gem_bindir = '/some/gem/bin' - Gem.stub(:bindir).and_return(@gem_bindir) - RbConfig::CONFIG.stub(:[]).with('bindir').and_return(@ruby_bindir) - Chef::Platform.stub(:windows?).and_return(false) + allow(Gem).to receive(:bindir).and_return(@gem_bindir) + allow(RbConfig::CONFIG).to receive(:[]).with('bindir').and_return(@ruby_bindir) + allow(Chef::Platform).to receive(:windows?).and_return(false) end it "adds all useful PATHs even if environment is an empty hash" do env={} @sanity.enforce_path_sanity(env) - env["PATH"].should == "#{@ruby_bindir}:#{@gem_bindir}:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" + expect(env["PATH"]).to eq("#{@ruby_bindir}:#{@gem_bindir}:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin") end it "adds all useful PATHs that are not yet in PATH to PATH" do env = {"PATH" => ""} @sanity.enforce_path_sanity(env) - env["PATH"].should == "#{@ruby_bindir}:#{@gem_bindir}:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" + expect(env["PATH"]).to eq("#{@ruby_bindir}:#{@gem_bindir}:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin") end it "does not re-add paths that already exist in PATH" do env = {"PATH" => "/usr/bin:/sbin:/bin"} @sanity.enforce_path_sanity(env) - env["PATH"].should == "/usr/bin:/sbin:/bin:#{@ruby_bindir}:#{@gem_bindir}:/usr/local/sbin:/usr/local/bin:/usr/sbin" + expect(env["PATH"]).to eq("/usr/bin:/sbin:/bin:#{@ruby_bindir}:#{@gem_bindir}:/usr/local/sbin:/usr/local/bin:/usr/sbin") end it "adds the current executing Ruby's bindir and Gem bindir to the PATH" do env = {"PATH" => ""} @sanity.enforce_path_sanity(env) - env["PATH"].should == "#{@ruby_bindir}:#{@gem_bindir}:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" + expect(env["PATH"]).to eq("#{@ruby_bindir}:#{@gem_bindir}:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin") end it "does not create entries for Ruby/Gem bindirs if they exist in SANE_PATH or PATH" do ruby_bindir = '/usr/bin' gem_bindir = '/yo/gabba/gabba' - Gem.stub(:bindir).and_return(gem_bindir) - RbConfig::CONFIG.stub(:[]).with('bindir').and_return(ruby_bindir) + allow(Gem).to receive(:bindir).and_return(gem_bindir) + allow(RbConfig::CONFIG).to receive(:[]).with('bindir').and_return(ruby_bindir) env = {"PATH" => gem_bindir} @sanity.enforce_path_sanity(env) - env["PATH"].should == "/yo/gabba/gabba:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" + expect(env["PATH"]).to eq("/yo/gabba/gabba:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin") end it "builds a valid windows path" do ruby_bindir = 'C:\ruby\bin' gem_bindir = 'C:\gems\bin' - Gem.stub(:bindir).and_return(gem_bindir) - RbConfig::CONFIG.stub(:[]).with('bindir').and_return(ruby_bindir) - Chef::Platform.stub(:windows?).and_return(true) + allow(Gem).to receive(:bindir).and_return(gem_bindir) + allow(RbConfig::CONFIG).to receive(:[]).with('bindir').and_return(ruby_bindir) + allow(Chef::Platform).to receive(:windows?).and_return(true) env = {"PATH" => 'C:\Windows\system32;C:\mr\softie'} @sanity.enforce_path_sanity(env) - env["PATH"].should == "C:\\Windows\\system32;C:\\mr\\softie;#{ruby_bindir};#{gem_bindir}" + expect(env["PATH"]).to eq("C:\\Windows\\system32;C:\\mr\\softie;#{ruby_bindir};#{gem_bindir}") end end end diff --git a/spec/unit/mixin/securable_spec.rb b/spec/unit/mixin/securable_spec.rb index 10954083d8..714d6dedae 100644 --- a/spec/unit/mixin/securable_spec.rb +++ b/spec/unit/mixin/securable_spec.rb @@ -28,19 +28,19 @@ describe Chef::Mixin::Securable do end it "should accept a group name or id for group" do - lambda { @securable.group "root" }.should_not raise_error - lambda { @securable.group 123 }.should_not raise_error - lambda { @securable.group "+bad:group" }.should raise_error(ArgumentError) + expect { @securable.group "root" }.not_to raise_error + expect { @securable.group 123 }.not_to raise_error + expect { @securable.group "+bad:group" }.to raise_error(ArgumentError) end it "should accept a user name or id for owner" do - lambda { @securable.owner "root" }.should_not raise_error - lambda { @securable.owner 123 }.should_not raise_error - lambda { @securable.owner "+bad:owner" }.should raise_error(ArgumentError) + expect { @securable.owner "root" }.not_to raise_error + expect { @securable.owner 123 }.not_to raise_error + expect { @securable.owner "+bad:owner" }.to raise_error(ArgumentError) end it "allows the owner to be specified as #user" do - @securable.should respond_to(:user) + expect(@securable).to respond_to(:user) end describe "unix-specific behavior" do @@ -54,69 +54,69 @@ describe Chef::Mixin::Securable do end it "should accept group/owner names with spaces and backslashes" do - lambda { @securable.group 'test\ group' }.should_not raise_error - lambda { @securable.owner 'test\ group' }.should_not raise_error + expect { @securable.group 'test\ group' }.not_to raise_error + expect { @securable.owner 'test\ group' }.not_to raise_error end it "should accept group/owner names that are a single character or digit" do - lambda { @securable.group 'v' }.should_not raise_error - lambda { @securable.group '1' }.should_not raise_error - lambda { @securable.owner 'v' }.should_not raise_error - lambda { @securable.owner '1' }.should_not raise_error + expect { @securable.group 'v' }.not_to raise_error + expect { @securable.group '1' }.not_to raise_error + expect { @securable.owner 'v' }.not_to raise_error + expect { @securable.owner '1' }.not_to raise_error end it "should not accept group/owner names starting with '-', '+', or '~'" do - lambda { @securable.group '-test' }.should raise_error(ArgumentError) - lambda { @securable.group '+test' }.should raise_error(ArgumentError) - lambda { @securable.group '~test' }.should raise_error(ArgumentError) - lambda { @securable.group 'te-st' }.should_not raise_error - lambda { @securable.group 'te+st' }.should_not raise_error - lambda { @securable.group 'te~st' }.should_not raise_error - lambda { @securable.owner '-test' }.should raise_error(ArgumentError) - lambda { @securable.owner '+test' }.should raise_error(ArgumentError) - lambda { @securable.owner '~test' }.should raise_error(ArgumentError) - lambda { @securable.owner 'te-st' }.should_not raise_error - lambda { @securable.owner 'te+st' }.should_not raise_error - lambda { @securable.owner 'te~st' }.should_not raise_error + expect { @securable.group '-test' }.to raise_error(ArgumentError) + expect { @securable.group '+test' }.to raise_error(ArgumentError) + expect { @securable.group '~test' }.to raise_error(ArgumentError) + expect { @securable.group 'te-st' }.not_to raise_error + expect { @securable.group 'te+st' }.not_to raise_error + expect { @securable.group 'te~st' }.not_to raise_error + expect { @securable.owner '-test' }.to raise_error(ArgumentError) + expect { @securable.owner '+test' }.to raise_error(ArgumentError) + expect { @securable.owner '~test' }.to raise_error(ArgumentError) + expect { @securable.owner 'te-st' }.not_to raise_error + expect { @securable.owner 'te+st' }.not_to raise_error + expect { @securable.owner 'te~st' }.not_to raise_error end it "should not accept group/owner names containing ':', ',' or non-space whitespace" do - lambda { @securable.group ':test' }.should raise_error(ArgumentError) - lambda { @securable.group 'te:st' }.should raise_error(ArgumentError) - lambda { @securable.group ',test' }.should raise_error(ArgumentError) - lambda { @securable.group 'te,st' }.should raise_error(ArgumentError) - lambda { @securable.group "\ttest" }.should raise_error(ArgumentError) - lambda { @securable.group "te\tst" }.should raise_error(ArgumentError) - lambda { @securable.group "\rtest" }.should raise_error(ArgumentError) - lambda { @securable.group "te\rst" }.should raise_error(ArgumentError) - lambda { @securable.group "\ftest" }.should raise_error(ArgumentError) - lambda { @securable.group "te\fst" }.should raise_error(ArgumentError) - lambda { @securable.group "\0test" }.should raise_error(ArgumentError) - lambda { @securable.group "te\0st" }.should raise_error(ArgumentError) - lambda { @securable.owner ':test' }.should raise_error(ArgumentError) - lambda { @securable.owner 'te:st' }.should raise_error(ArgumentError) - lambda { @securable.owner ',test' }.should raise_error(ArgumentError) - lambda { @securable.owner 'te,st' }.should raise_error(ArgumentError) - lambda { @securable.owner "\ttest" }.should raise_error(ArgumentError) - lambda { @securable.owner "te\tst" }.should raise_error(ArgumentError) - lambda { @securable.owner "\rtest" }.should raise_error(ArgumentError) - lambda { @securable.owner "te\rst" }.should raise_error(ArgumentError) - lambda { @securable.owner "\ftest" }.should raise_error(ArgumentError) - lambda { @securable.owner "te\fst" }.should raise_error(ArgumentError) - lambda { @securable.owner "\0test" }.should raise_error(ArgumentError) - lambda { @securable.owner "te\0st" }.should raise_error(ArgumentError) + expect { @securable.group ':test' }.to raise_error(ArgumentError) + expect { @securable.group 'te:st' }.to raise_error(ArgumentError) + expect { @securable.group ',test' }.to raise_error(ArgumentError) + expect { @securable.group 'te,st' }.to raise_error(ArgumentError) + expect { @securable.group "\ttest" }.to raise_error(ArgumentError) + expect { @securable.group "te\tst" }.to raise_error(ArgumentError) + expect { @securable.group "\rtest" }.to raise_error(ArgumentError) + expect { @securable.group "te\rst" }.to raise_error(ArgumentError) + expect { @securable.group "\ftest" }.to raise_error(ArgumentError) + expect { @securable.group "te\fst" }.to raise_error(ArgumentError) + expect { @securable.group "\0test" }.to raise_error(ArgumentError) + expect { @securable.group "te\0st" }.to raise_error(ArgumentError) + expect { @securable.owner ':test' }.to raise_error(ArgumentError) + expect { @securable.owner 'te:st' }.to raise_error(ArgumentError) + expect { @securable.owner ',test' }.to raise_error(ArgumentError) + expect { @securable.owner 'te,st' }.to raise_error(ArgumentError) + expect { @securable.owner "\ttest" }.to raise_error(ArgumentError) + expect { @securable.owner "te\tst" }.to raise_error(ArgumentError) + expect { @securable.owner "\rtest" }.to raise_error(ArgumentError) + expect { @securable.owner "te\rst" }.to raise_error(ArgumentError) + expect { @securable.owner "\ftest" }.to raise_error(ArgumentError) + expect { @securable.owner "te\fst" }.to raise_error(ArgumentError) + expect { @securable.owner "\0test" }.to raise_error(ArgumentError) + expect { @securable.owner "te\0st" }.to raise_error(ArgumentError) end it "should accept Active Directory-style domain names pulled in via LDAP (on unix hosts)" do - lambda { @securable.owner "domain\@user" }.should_not raise_error - lambda { @securable.owner "domain\\user" }.should_not raise_error - lambda { @securable.group "domain\@group" }.should_not raise_error - lambda { @securable.group "domain\\group" }.should_not raise_error - lambda { @securable.group "domain\\group^name" }.should_not raise_error + expect { @securable.owner "domain\@user" }.not_to raise_error + expect { @securable.owner "domain\\user" }.not_to raise_error + expect { @securable.group "domain\@group" }.not_to raise_error + expect { @securable.group "domain\\group" }.not_to raise_error + expect { @securable.group "domain\\group^name" }.not_to raise_error end it "should not accept group/owner names containing embedded carriage returns" do - pending "XXX: params_validate needs to be extended to support multi-line regex" + skip "XXX: params_validate needs to be extended to support multi-line regex" #lambda { @securable.group "\ntest" }.should raise_error(ArgumentError) #lambda { @securable.group "te\nst" }.should raise_error(ArgumentError) #lambda { @securable.owner "\ntest" }.should raise_error(ArgumentError) @@ -124,53 +124,53 @@ describe Chef::Mixin::Securable do end it "should accept group/owner names in UTF-8" do - lambda { @securable.group 'tëst' }.should_not raise_error - lambda { @securable.group 'ë' }.should_not raise_error - lambda { @securable.owner 'tëst' }.should_not raise_error - lambda { @securable.owner 'ë' }.should_not raise_error + expect { @securable.group 'tëst' }.not_to raise_error + expect { @securable.group 'ë' }.not_to raise_error + expect { @securable.owner 'tëst' }.not_to raise_error + expect { @securable.owner 'ë' }.not_to raise_error end it "should accept a unix file mode in string form as an octal number" do - lambda { @securable.mode "0" }.should_not raise_error - lambda { @securable.mode "0000" }.should_not raise_error - lambda { @securable.mode "0111" }.should_not raise_error - lambda { @securable.mode "0444" }.should_not raise_error - - lambda { @securable.mode "111" }.should_not raise_error - lambda { @securable.mode "444" }.should_not raise_error - lambda { @securable.mode "7777" }.should_not raise_error - lambda { @securable.mode "07777" }.should_not raise_error - - lambda { @securable.mode "-01" }.should raise_error(ArgumentError) - lambda { @securable.mode "010000" }.should raise_error(ArgumentError) - lambda { @securable.mode "-1" }.should raise_error(ArgumentError) - lambda { @securable.mode "10000" }.should raise_error(ArgumentError) - - lambda { @securable.mode "07778" }.should raise_error(ArgumentError) - lambda { @securable.mode "7778" }.should raise_error(ArgumentError) - lambda { @securable.mode "4095" }.should raise_error(ArgumentError) - - lambda { @securable.mode "0foo1234" }.should raise_error(ArgumentError) - lambda { @securable.mode "foo1234" }.should raise_error(ArgumentError) + expect { @securable.mode "0" }.not_to raise_error + expect { @securable.mode "0000" }.not_to raise_error + expect { @securable.mode "0111" }.not_to raise_error + expect { @securable.mode "0444" }.not_to raise_error + + expect { @securable.mode "111" }.not_to raise_error + expect { @securable.mode "444" }.not_to raise_error + expect { @securable.mode "7777" }.not_to raise_error + expect { @securable.mode "07777" }.not_to raise_error + + expect { @securable.mode "-01" }.to raise_error(ArgumentError) + expect { @securable.mode "010000" }.to raise_error(ArgumentError) + expect { @securable.mode "-1" }.to raise_error(ArgumentError) + expect { @securable.mode "10000" }.to raise_error(ArgumentError) + + expect { @securable.mode "07778" }.to raise_error(ArgumentError) + expect { @securable.mode "7778" }.to raise_error(ArgumentError) + expect { @securable.mode "4095" }.to raise_error(ArgumentError) + + expect { @securable.mode "0foo1234" }.to raise_error(ArgumentError) + expect { @securable.mode "foo1234" }.to raise_error(ArgumentError) end it "should accept a unix file mode in numeric form as a ruby-interpreted integer" do - lambda { @securable.mode(0) }.should_not raise_error - lambda { @securable.mode(0000) }.should_not raise_error - lambda { @securable.mode(444) }.should_not raise_error - lambda { @securable.mode(0444) }.should_not raise_error - lambda { @securable.mode(07777) }.should_not raise_error - - lambda { @securable.mode(292) }.should_not raise_error - lambda { @securable.mode(4095) }.should_not raise_error - - lambda { @securable.mode(0111) }.should_not raise_error - lambda { @securable.mode(73) }.should_not raise_error - - lambda { @securable.mode(-01) }.should raise_error(ArgumentError) - lambda { @securable.mode(010000) }.should raise_error(ArgumentError) - lambda { @securable.mode(-1) }.should raise_error(ArgumentError) - lambda { @securable.mode(4096) }.should raise_error(ArgumentError) + expect { @securable.mode(0) }.not_to raise_error + expect { @securable.mode(0000) }.not_to raise_error + expect { @securable.mode(444) }.not_to raise_error + expect { @securable.mode(0444) }.not_to raise_error + expect { @securable.mode(07777) }.not_to raise_error + + expect { @securable.mode(292) }.not_to raise_error + expect { @securable.mode(4095) }.not_to raise_error + + expect { @securable.mode(0111) }.not_to raise_error + expect { @securable.mode(73) }.not_to raise_error + + expect { @securable.mode(-01) }.to raise_error(ArgumentError) + expect { @securable.mode(010000) }.to raise_error(ArgumentError) + expect { @securable.mode(-1) }.to raise_error(ArgumentError) + expect { @securable.mode(4096) }.to raise_error(ArgumentError) end end @@ -187,94 +187,94 @@ describe Chef::Mixin::Securable do end it "should not accept a group name or id for group with spaces and multiple backslashes" do - lambda { @securable.group 'test\ \group' }.should raise_error(ArgumentError) + expect { @securable.group 'test\ \group' }.to raise_error(ArgumentError) end it "should accept a unix file mode in string form as an octal number" do - lambda { @securable.mode "0" }.should_not raise_error - lambda { @securable.mode "0000" }.should_not raise_error - lambda { @securable.mode "0111" }.should_not raise_error - lambda { @securable.mode "0444" }.should_not raise_error - - lambda { @securable.mode "111" }.should_not raise_error - lambda { @securable.mode "444" }.should_not raise_error - lambda { @securable.mode "7777" }.should raise_error(ArgumentError) - lambda { @securable.mode "07777" }.should raise_error(ArgumentError) - - lambda { @securable.mode "-01" }.should raise_error(ArgumentError) - lambda { @securable.mode "010000" }.should raise_error(ArgumentError) - lambda { @securable.mode "-1" }.should raise_error(ArgumentError) - lambda { @securable.mode "10000" }.should raise_error(ArgumentError) - - lambda { @securable.mode "07778" }.should raise_error(ArgumentError) - lambda { @securable.mode "7778" }.should raise_error(ArgumentError) - lambda { @securable.mode "4095" }.should raise_error(ArgumentError) - - lambda { @securable.mode "0foo1234" }.should raise_error(ArgumentError) - lambda { @securable.mode "foo1234" }.should raise_error(ArgumentError) + expect { @securable.mode "0" }.not_to raise_error + expect { @securable.mode "0000" }.not_to raise_error + expect { @securable.mode "0111" }.not_to raise_error + expect { @securable.mode "0444" }.not_to raise_error + + expect { @securable.mode "111" }.not_to raise_error + expect { @securable.mode "444" }.not_to raise_error + expect { @securable.mode "7777" }.to raise_error(ArgumentError) + expect { @securable.mode "07777" }.to raise_error(ArgumentError) + + expect { @securable.mode "-01" }.to raise_error(ArgumentError) + expect { @securable.mode "010000" }.to raise_error(ArgumentError) + expect { @securable.mode "-1" }.to raise_error(ArgumentError) + expect { @securable.mode "10000" }.to raise_error(ArgumentError) + + expect { @securable.mode "07778" }.to raise_error(ArgumentError) + expect { @securable.mode "7778" }.to raise_error(ArgumentError) + expect { @securable.mode "4095" }.to raise_error(ArgumentError) + + expect { @securable.mode "0foo1234" }.to raise_error(ArgumentError) + expect { @securable.mode "foo1234" }.to raise_error(ArgumentError) end it "should accept a unix file mode in numeric form as a ruby-interpreted integer" do - lambda { @securable.mode 0 }.should_not raise_error - lambda { @securable.mode 0000 }.should_not raise_error - lambda { @securable.mode 444 }.should_not raise_error - lambda { @securable.mode 0444 }.should_not raise_error - lambda { @securable.mode 07777 }.should raise_error(ArgumentError) - - lambda { @securable.mode 292 }.should_not raise_error - lambda { @securable.mode 4095 }.should raise_error(ArgumentError) - - lambda { @securable.mode 0111 }.should_not raise_error - lambda { @securable.mode 73 }.should_not raise_error - - lambda { @securable.mode -01 }.should raise_error(ArgumentError) - lambda { @securable.mode 010000 }.should raise_error(ArgumentError) - lambda { @securable.mode -1 }.should raise_error(ArgumentError) - lambda { @securable.mode 4096 }.should raise_error(ArgumentError) + expect { @securable.mode 0 }.not_to raise_error + expect { @securable.mode 0000 }.not_to raise_error + expect { @securable.mode 444 }.not_to raise_error + expect { @securable.mode 0444 }.not_to raise_error + expect { @securable.mode 07777 }.to raise_error(ArgumentError) + + expect { @securable.mode 292 }.not_to raise_error + expect { @securable.mode 4095 }.to raise_error(ArgumentError) + + expect { @securable.mode 0111 }.not_to raise_error + expect { @securable.mode 73 }.not_to raise_error + + expect { @securable.mode -01 }.to raise_error(ArgumentError) + expect { @securable.mode 010000 }.to raise_error(ArgumentError) + expect { @securable.mode -1 }.to raise_error(ArgumentError) + expect { @securable.mode 4096 }.to raise_error(ArgumentError) end it "should allow you to specify :full_control, :modify, :read_execute, :read, and :write rights" do - lambda { @securable.rights :full_control, "The Dude" }.should_not raise_error - lambda { @securable.rights :modify, "The Dude" }.should_not raise_error - lambda { @securable.rights :read_execute, "The Dude" }.should_not raise_error - lambda { @securable.rights :read, "The Dude" }.should_not raise_error - lambda { @securable.rights :write, "The Dude" }.should_not raise_error - lambda { @securable.rights :to_party, "The Dude" }.should raise_error(ArgumentError) + expect { @securable.rights :full_control, "The Dude" }.not_to raise_error + expect { @securable.rights :modify, "The Dude" }.not_to raise_error + expect { @securable.rights :read_execute, "The Dude" }.not_to raise_error + expect { @securable.rights :read, "The Dude" }.not_to raise_error + expect { @securable.rights :write, "The Dude" }.not_to raise_error + expect { @securable.rights :to_party, "The Dude" }.to raise_error(ArgumentError) end it "should allow you to specify :full_control, :modify, :read_execute, :read, and :write deny_rights" do - lambda { @securable.deny_rights :full_control, "The Dude" }.should_not raise_error - lambda { @securable.deny_rights :modify, "The Dude" }.should_not raise_error - lambda { @securable.deny_rights :read_execute, "The Dude" }.should_not raise_error - lambda { @securable.deny_rights :read, "The Dude" }.should_not raise_error - lambda { @securable.deny_rights :write, "The Dude" }.should_not raise_error - lambda { @securable.deny_rights :to_party, "The Dude" }.should raise_error(ArgumentError) + expect { @securable.deny_rights :full_control, "The Dude" }.not_to raise_error + expect { @securable.deny_rights :modify, "The Dude" }.not_to raise_error + expect { @securable.deny_rights :read_execute, "The Dude" }.not_to raise_error + expect { @securable.deny_rights :read, "The Dude" }.not_to raise_error + expect { @securable.deny_rights :write, "The Dude" }.not_to raise_error + expect { @securable.deny_rights :to_party, "The Dude" }.to raise_error(ArgumentError) end it "should accept a principal as a string or an array" do - lambda { @securable.rights :read, "The Dude" }.should_not raise_error - lambda { @securable.rights :read, ["The Dude","Donny"] }.should_not raise_error - lambda { @securable.rights :read, 3 }.should raise_error(ArgumentError) + expect { @securable.rights :read, "The Dude" }.not_to raise_error + expect { @securable.rights :read, ["The Dude","Donny"] }.not_to raise_error + expect { @securable.rights :read, 3 }.to raise_error(ArgumentError) end it "should allow you to specify whether the permissions applies_to_children with true/false/:containers_only/:objects_only" do - lambda { @securable.rights :read, "The Dude", :applies_to_children => false }.should_not raise_error - lambda { @securable.rights :read, "The Dude", :applies_to_children => true }.should_not raise_error - lambda { @securable.rights :read, "The Dude", :applies_to_children => :containers_only }.should_not raise_error - lambda { @securable.rights :read, "The Dude", :applies_to_children => :objects_only }.should_not raise_error - lambda { @securable.rights :read, "The Dude", :applies_to_children => 'poop' }.should raise_error(ArgumentError) + expect { @securable.rights :read, "The Dude", :applies_to_children => false }.not_to raise_error + expect { @securable.rights :read, "The Dude", :applies_to_children => true }.not_to raise_error + expect { @securable.rights :read, "The Dude", :applies_to_children => :containers_only }.not_to raise_error + expect { @securable.rights :read, "The Dude", :applies_to_children => :objects_only }.not_to raise_error + expect { @securable.rights :read, "The Dude", :applies_to_children => 'poop' }.to raise_error(ArgumentError) end it "should allow you to specify whether the permissions applies_to_self with true/false" do - lambda { @securable.rights :read, "The Dude", :applies_to_children => true, :applies_to_self => false }.should_not raise_error - lambda { @securable.rights :read, "The Dude", :applies_to_self => true }.should_not raise_error - lambda { @securable.rights :read, "The Dude", :applies_to_self => 'poop' }.should raise_error(ArgumentError) + expect { @securable.rights :read, "The Dude", :applies_to_children => true, :applies_to_self => false }.not_to raise_error + expect { @securable.rights :read, "The Dude", :applies_to_self => true }.not_to raise_error + expect { @securable.rights :read, "The Dude", :applies_to_self => 'poop' }.to raise_error(ArgumentError) end it "should allow you to specify whether the permissions applies one_level_deep with true/false" do - lambda { @securable.rights :read, "The Dude", :applies_to_children => true, :one_level_deep => false }.should_not raise_error - lambda { @securable.rights :read, "The Dude", :applies_to_children => true, :one_level_deep => true }.should_not raise_error - lambda { @securable.rights :read, "The Dude", :applies_to_children => true, :one_level_deep => 'poop' }.should raise_error(ArgumentError) + expect { @securable.rights :read, "The Dude", :applies_to_children => true, :one_level_deep => false }.not_to raise_error + expect { @securable.rights :read, "The Dude", :applies_to_children => true, :one_level_deep => true }.not_to raise_error + expect { @securable.rights :read, "The Dude", :applies_to_children => true, :one_level_deep => 'poop' }.to raise_error(ArgumentError) end it "should allow multiple rights and deny_rights declarations" do @@ -283,32 +283,32 @@ describe Chef::Mixin::Securable do @securable.rights :full_control, "The Dude" @securable.rights :write, "The Dude" @securable.deny_rights :read, "The Dude" - @securable.rights.size.should == 3 - @securable.deny_rights.size.should == 2 + expect(@securable.rights.size).to eq(3) + expect(@securable.deny_rights.size).to eq(2) end it "should allow you to specify whether the permission applies_to_self only if you specified applies_to_children" do - lambda { @securable.rights :read, "The Dude", :applies_to_children => true, :applies_to_self => true }.should_not raise_error - lambda { @securable.rights :read, "The Dude", :applies_to_children => true, :applies_to_self => false }.should_not raise_error - lambda { @securable.rights :read, "The Dude", :applies_to_children => false, :applies_to_self => true }.should_not raise_error - lambda { @securable.rights :read, "The Dude", :applies_to_children => false, :applies_to_self => false }.should raise_error(ArgumentError) - lambda { @securable.rights :read, "The Dude", :applies_to_self => true }.should_not raise_error - lambda { @securable.rights :read, "The Dude", :applies_to_self => false }.should_not raise_error + expect { @securable.rights :read, "The Dude", :applies_to_children => true, :applies_to_self => true }.not_to raise_error + expect { @securable.rights :read, "The Dude", :applies_to_children => true, :applies_to_self => false }.not_to raise_error + expect { @securable.rights :read, "The Dude", :applies_to_children => false, :applies_to_self => true }.not_to raise_error + expect { @securable.rights :read, "The Dude", :applies_to_children => false, :applies_to_self => false }.to raise_error(ArgumentError) + expect { @securable.rights :read, "The Dude", :applies_to_self => true }.not_to raise_error + expect { @securable.rights :read, "The Dude", :applies_to_self => false }.not_to raise_error end it "should allow you to specify whether the permission applies one_level_deep only if you specified applies_to_children" do - lambda { @securable.rights :read, "The Dude", :applies_to_children => true, :one_level_deep => true }.should_not raise_error - lambda { @securable.rights :read, "The Dude", :applies_to_children => true, :one_level_deep => false }.should_not raise_error - lambda { @securable.rights :read, "The Dude", :applies_to_children => false, :one_level_deep => true }.should raise_error(ArgumentError) - lambda { @securable.rights :read, "The Dude", :applies_to_children => false, :one_level_deep => false }.should_not raise_error - lambda { @securable.rights :read, "The Dude", :one_level_deep => true }.should_not raise_error - lambda { @securable.rights :read, "The Dude", :one_level_deep => false }.should_not raise_error + expect { @securable.rights :read, "The Dude", :applies_to_children => true, :one_level_deep => true }.not_to raise_error + expect { @securable.rights :read, "The Dude", :applies_to_children => true, :one_level_deep => false }.not_to raise_error + expect { @securable.rights :read, "The Dude", :applies_to_children => false, :one_level_deep => true }.to raise_error(ArgumentError) + expect { @securable.rights :read, "The Dude", :applies_to_children => false, :one_level_deep => false }.not_to raise_error + expect { @securable.rights :read, "The Dude", :one_level_deep => true }.not_to raise_error + expect { @securable.rights :read, "The Dude", :one_level_deep => false }.not_to raise_error end it "should allow you to specify whether the permissions inherit with true/false" do - lambda { @securable.inherits true }.should_not raise_error - lambda { @securable.inherits false }.should_not raise_error - lambda { @securable.inherits "monkey" }.should raise_error(ArgumentError) + expect { @securable.inherits true }.not_to raise_error + expect { @securable.inherits false }.not_to raise_error + expect { @securable.inherits "monkey" }.to raise_error(ArgumentError) end end end diff --git a/spec/unit/mixin/shell_out_spec.rb b/spec/unit/mixin/shell_out_spec.rb index 38a63a32ee..afce4dc826 100644 --- a/spec/unit/mixin/shell_out_spec.rb +++ b/spec/unit/mixin/shell_out_spec.rb @@ -38,7 +38,7 @@ describe Chef::Mixin::ShellOut do let(:command_args) { [ cmd ] } it 'should not edit command args' do - should eql(command_args) + is_expected.to eql(command_args) end end @@ -47,7 +47,7 @@ describe Chef::Mixin::ShellOut do let(:environment) { { 'LC_ALL' => 'C' } } it 'should not edit command args' do - should eql(command_args) + is_expected.to eql(command_args) end end @@ -66,7 +66,7 @@ describe Chef::Mixin::ShellOut do let(:command_log_level) { :warn } it 'should convert :command_log_level to :log_level' do - should eql [ cmd, { :log_level => command_log_level } ] + is_expected.to eql [ cmd, { :log_level => command_log_level } ] end should_emit_deprecation_warning_about :command_log_level, :log_level @@ -77,7 +77,7 @@ describe Chef::Mixin::ShellOut do let(:command_log_prepend) { 'PROVIDER:' } it 'should convert :command_log_prepend to :log_tag' do - should eql [ cmd, { :log_tag => command_log_prepend } ] + is_expected.to eql [ cmd, { :log_tag => command_log_prepend } ] end should_emit_deprecation_warning_about :command_log_prepend, :log_tag @@ -88,7 +88,7 @@ describe Chef::Mixin::ShellOut do let(:command_log_level) { :warn } it "should convert 'command_log_level' to :log_level" do - should eql [ cmd, { :log_level => command_log_level } ] + is_expected.to eql [ cmd, { :log_level => command_log_level } ] end should_emit_deprecation_warning_about :command_log_level, :log_level @@ -99,7 +99,7 @@ describe Chef::Mixin::ShellOut do let(:command_log_prepend) { 'PROVIDER:' } it "should convert 'command_log_prepend' to :log_tag" do - should eql [ cmd, { :log_tag => command_log_prepend } ] + is_expected.to eql [ cmd, { :log_tag => command_log_prepend } ] end should_emit_deprecation_warning_about :command_log_prepend, :log_tag diff --git a/spec/unit/mixin/template_spec.rb b/spec/unit/mixin/template_spec.rb index 63fa81782e..f02bd34b8f 100644 --- a/spec/unit/mixin/template_spec.rb +++ b/spec/unit/mixin/template_spec.rb @@ -30,7 +30,7 @@ describe Chef::Mixin::Template, "render_template" do it "should render the template evaluated in the given context" do @context[:foo] = "bar" output = @context.render_template_from_string("<%= @foo %>") - output.should == "bar" + expect(output).to eq("bar") end template_contents = [ "Fancy\r\nTemplate\r\n\r\n", @@ -39,14 +39,14 @@ describe Chef::Mixin::Template, "render_template" do describe "when running on windows" do before do - Chef::Platform.stub(:windows?).and_return(true) + allow(Chef::Platform).to receive(:windows?).and_return(true) end it "should render the templates with windows line endings" do template_contents.each do |template_content| output = @context.render_template_from_string(template_content) output.each_line do |line| - line.should end_with("\r\n") + expect(line).to end_with("\r\n") end end end @@ -54,14 +54,14 @@ describe Chef::Mixin::Template, "render_template" do describe "when running on unix" do before do - Chef::Platform.stub(:windows?).and_return(false) + allow(Chef::Platform).to receive(:windows?).and_return(false) end it "should render the templates with unix line endings" do template_contents.each do |template_content| output = @context.render_template_from_string(template_content) output.each_line do |line| - line.should end_with("\n") + expect(line).to end_with("\n") end end end @@ -70,7 +70,7 @@ describe Chef::Mixin::Template, "render_template" do it "should provide a node method to access @node" do @context[:node] = "tehShizzle" output = @context.render_template_from_string("<%= @node %>") - output.should == "tehShizzle" + expect(output).to eq("tehShizzle") end describe "with a template resource" do @@ -100,7 +100,7 @@ describe Chef::Mixin::Template, "render_template" do it "should provide a render method" do output = @template_context.render_template_from_string("before {<%= render('test.erb').strip -%>} after") - output.should == "before {We could be diving for pearls!} after" + expect(output).to eq("before {We could be diving for pearls!} after") end it "should render local files" do @@ -110,7 +110,7 @@ describe Chef::Mixin::Template, "render_template" do tf.rewind output = @template_context.render_template_from_string("before {<%= render '#{tf.path}', :local => true %>} after") - output.should == "before {test} after" + expect(output).to eq("before {test} after") ensure tf.close end @@ -120,7 +120,7 @@ describe Chef::Mixin::Template, "render_template" do @template_context[:template_finder] = Chef::Provider::TemplateFinder.new(@run_context, 'apache2', @node) output = @template_context.render_template_from_string("before {<%= render('test.erb', :cookbook => 'openldap').strip %>} after") - output.should == "before {We could be diving for pearls!} after" + expect(output).to eq("before {We could be diving for pearls!} after") end it "should render using the source argument if provided" do @@ -130,7 +130,7 @@ describe Chef::Mixin::Template, "render_template" do tf.rewind output = @template_context.render_template_from_string("before {<%= render 'something', :local => true, :source => '#{tf.path}' %>} after") - output.should == "before {test} after" + expect(output).to eq("before {test} after") ensure tf.close end @@ -140,7 +140,7 @@ describe Chef::Mixin::Template, "render_template" do @node.normal[:slappiness] = "happiness" output = @template_context.render_template_from_string("before {<%= render 'openldap_stuff.conf.erb' %>} after") - output.should == "before {slappiness is happiness} after" + expect(output).to eq("before {slappiness is happiness} after") end it "should pass the original variables to partials" do @@ -152,29 +152,29 @@ describe Chef::Mixin::Template, "render_template" do it "should pass variables to partials" do output = @template_context.render_template_from_string("before {<%= render 'openldap_variable_stuff.conf.erb', :variables => {:secret => 'whatever' } %>} after") - output.should == "before {super secret is whatever} after" + expect(output).to eq("before {super secret is whatever} after") end it "should pass variables to partials even if they are named the same" do @template_context[:secret] = 'one' output = @template_context.render_template_from_string("before {<%= render 'openldap_variable_stuff.conf.erb', :variables => {:secret => 'two' } %>} after <%= @secret %>") - output.should == "before {super secret is two} after one" + expect(output).to eq("before {super secret is two} after one") end it "should pass nil for missing variables in partials" do output = @template_context.render_template_from_string("before {<%= render 'openldap_variable_stuff.conf.erb', :variables => {} %>} after") - output.should == "before {super secret is } after" + expect(output).to eq("before {super secret is } after") output = @template_context.render_template_from_string("before {<%= render 'openldap_variable_stuff.conf.erb' %>} after") - output.should == "before {super secret is } after" + expect(output).to eq("before {super secret is } after") end it "should render nested partials" do path = File.expand_path(File.join(CHEF_SPEC_DATA, "partial_one.erb")) output = @template_context.render_template_from_string("before {<%= render('#{path}', :local => true).strip %>} after") - output.should == "before {partial one We could be diving for pearls! calling home} after" + expect(output).to eq("before {partial one We could be diving for pearls! calling home} after") end describe "when customizing the template context" do @@ -187,7 +187,7 @@ describe Chef::Mixin::Template, "render_template" do end @template_context._extend_modules([mod]) output = @template_context.render_template_from_string("<%=hello%>") - output.should == "ohai" + expect(output).to eq("ohai") end it "emits a warning when overriding 'core' methods" do @@ -202,7 +202,7 @@ describe Chef::Mixin::Template, "render_template" do end end ['node', 'render', 'render_template', 'render_template_from_string'].each do |method_name| - Chef::Log.should_receive(:warn).with(/^Core template method `#{method_name}' overridden by extension module/) + expect(Chef::Log).to receive(:warn).with(/^Core template method `#{method_name}' overridden by extension module/) end @template_context._extend_modules([mod]) end @@ -216,11 +216,11 @@ describe Chef::Mixin::Template, "render_template" do end it "should catch and re-raise the exception as a TemplateError" do - lambda { do_raise }.should raise_error(Chef::Mixin::Template::TemplateError) + expect { do_raise }.to raise_error(Chef::Mixin::Template::TemplateError) end it "should raise an error if an attempt is made to access node but it is nil" do - lambda {@context.render_template_from_string("<%= node %>") {|r| r}}.should raise_error(Chef::Mixin::Template::TemplateError) + expect {@context.render_template_from_string("<%= node %>") {|r| r}}.to raise_error(Chef::Mixin::Template::TemplateError) end describe "the raised TemplateError" do @@ -233,35 +233,35 @@ describe Chef::Mixin::Template, "render_template" do end it "should have the original exception" do - @exception.original_exception.should be - @exception.original_exception.message.should =~ /undefined local variable or method `this_is_not_defined'/ + expect(@exception.original_exception).to be + expect(@exception.original_exception.message).to match(/undefined local variable or method `this_is_not_defined'/) end it "should determine the line number of the exception" do - @exception.line_number.should == 4 + expect(@exception.line_number).to eq(4) end it "should provide a source listing of the template around the exception" do - @exception.source_listing.should == " 2: bar\n 3: baz\n 4: <%= this_is_not_defined %>\n 5: quin\n 6: qunx" + expect(@exception.source_listing).to eq(" 2: bar\n 3: baz\n 4: <%= this_is_not_defined %>\n 5: quin\n 6: qunx") end it "should provide the evaluation context of the template" do - @exception.context.should == @context + expect(@exception.context).to eq(@context) end it "should defer the message to the original exception" do - @exception.message.should =~ /undefined local variable or method `this_is_not_defined'/ + expect(@exception.message).to match(/undefined local variable or method `this_is_not_defined'/) end it "should provide a nice source location" do - @exception.source_location.should == "on line #4" + expect(@exception.source_location).to eq("on line #4") end it "should create a pretty output for the terminal" do - @exception.to_s.should =~ /Chef::Mixin::Template::TemplateError/ - @exception.to_s.should =~ /undefined local variable or method `this_is_not_defined'/ - @exception.to_s.should include(" 2: bar\n 3: baz\n 4: <%= this_is_not_defined %>\n 5: quin\n 6: qunx") - @exception.to_s.should include(@exception.original_exception.backtrace.first) + expect(@exception.to_s).to match(/Chef::Mixin::Template::TemplateError/) + expect(@exception.to_s).to match(/undefined local variable or method `this_is_not_defined'/) + expect(@exception.to_s).to include(" 2: bar\n 3: baz\n 4: <%= this_is_not_defined %>\n 5: quin\n 6: qunx") + expect(@exception.to_s).to include(@exception.original_exception.backtrace.first) end end end diff --git a/spec/unit/mixin/windows_architecture_helper_spec.rb b/spec/unit/mixin/windows_architecture_helper_spec.rb index f59602d716..3803d69371 100644 --- a/spec/unit/mixin/windows_architecture_helper_spec.rb +++ b/spec/unit/mixin/windows_architecture_helper_spec.rb @@ -35,13 +35,13 @@ describe Chef::Mixin::WindowsArchitectureHelper do it "returns true when valid architectures are passed to valid_windows_architecture?" do @valid_architectures.each do | architecture | - valid_windows_architecture?(architecture).should == true + expect(valid_windows_architecture?(architecture)).to eq(true) end end it "returns false when invalid architectures are passed to valid_windows_architecture?" do @invalid_architectures.each do | architecture | - valid_windows_architecture?(architecture).should == false + expect(valid_windows_architecture?(architecture)).to eq(false) end end @@ -54,7 +54,7 @@ describe Chef::Mixin::WindowsArchitectureHelper do it "raises an error if an invalid architecture is passed to assert_valid_windows_architecture!" do @invalid_architectures.each do | architecture | begin - assert_valid_windows_architecture!(architecture).should raise_error Chef::Exceptions::Win32ArchitectureIncorrect + expect(assert_valid_windows_architecture!(architecture)).to raise_error Chef::Exceptions::Win32ArchitectureIncorrect rescue Chef::Exceptions::Win32ArchitectureIncorrect end end @@ -75,8 +75,8 @@ describe Chef::Mixin::WindowsArchitectureHelper do new_node.default["kernel"][:machine] = node_architecture.to_s @valid_architectures.each do | supported_architecture | - node_supports_windows_architecture?(new_node, supported_architecture).should == true if only_valid_combinations && (supported_architecture != :x86_64 && node_architecture != :i386 ) - node_supports_windows_architecture?(new_node, supported_architecture).should == false if ! only_valid_combinations && (supported_architecture == :x86_64 && node_architecture == :i386 ) + expect(node_supports_windows_architecture?(new_node, supported_architecture)).to eq(true) if only_valid_combinations && (supported_architecture != :x86_64 && node_architecture != :i386 ) + expect(node_supports_windows_architecture?(new_node, supported_architecture)).to eq(false) if ! only_valid_combinations && (supported_architecture == :x86_64 && node_architecture == :i386 ) end end end diff --git a/spec/unit/mixin/xml_escape_spec.rb b/spec/unit/mixin/xml_escape_spec.rb index 83debb5907..c5156cfb7b 100644 --- a/spec/unit/mixin/xml_escape_spec.rb +++ b/spec/unit/mixin/xml_escape_spec.rb @@ -28,27 +28,27 @@ describe Chef::Mixin::XMLEscape do end it "escapes ampersands to '&'" do - @escaper.xml_escape("&").should == "&" + expect(@escaper.xml_escape("&")).to eq("&") end it "escapes angle brackets to < or >" do - @escaper.xml_escape("<").should == "<" - @escaper.xml_escape(">").should == ">" + expect(@escaper.xml_escape("<")).to eq("<") + expect(@escaper.xml_escape(">")).to eq(">") end it "does not modify ASCII strings" do - @escaper.xml_escape('foobarbaz!@#$%^*()').should == 'foobarbaz!@#$%^*()' + expect(@escaper.xml_escape('foobarbaz!@#$%^*()')).to eq('foobarbaz!@#$%^*()') end it "converts invalid bytes to asterisks" do - @escaper.xml_escape("\x00").should == "*" + expect(@escaper.xml_escape("\x00")).to eq("*") end it "converts UTF-8 correctly" do - @escaper.xml_escape("\xC2\xA9").should == '©' + expect(@escaper.xml_escape("\xC2\xA9")).to eq('©') end it "converts win 1252 characters correctly" do - @escaper.xml_escape("\x80").should == '€' + expect(@escaper.xml_escape("\x80")).to eq('€') end end -- cgit v1.2.1