summaryrefslogtreecommitdiff
path: root/spec/unit/node
diff options
context:
space:
mode:
authorClaire McQuin <claire@getchef.com>2014-10-29 15:14:22 -0700
committerClaire McQuin <claire@getchef.com>2014-10-29 15:59:04 -0700
commit5fed7a65a2f024d964ecf2de1bcf2911cf8a600c (patch)
tree14cc6968e4fe4fd2485c0211088b25c645a80a4b /spec/unit/node
parentb92c309b0f1aa0837f76ab89d6c81c36076ceca9 (diff)
downloadchef-5fed7a65a2f024d964ecf2de1bcf2911cf8a600c.tar.gz
Update to RSpec 3.
Diffstat (limited to 'spec/unit/node')
-rw-r--r--spec/unit/node/attribute_spec.rb282
-rw-r--r--spec/unit/node/immutable_collections_spec.rb42
2 files changed, 162 insertions, 162 deletions
diff --git a/spec/unit/node/attribute_spec.rb b/spec/unit/node/attribute_spec.rb
index 5325117d6c..c5d0f2398e 100644
--- a/spec/unit/node/attribute_spec.rb
+++ b/spec/unit/node/attribute_spec.rb
@@ -215,22 +215,22 @@ describe Chef::Node::Attribute do
describe "initialize" do
it "should return a Chef::Node::Attribute" do
- @attributes.should be_a_kind_of(Chef::Node::Attribute)
+ expect(@attributes).to be_a_kind_of(Chef::Node::Attribute)
end
it "should take an Automatioc, Normal, Default and Override hash" do
- lambda { Chef::Node::Attribute.new({}, {}, {}, {}) }.should_not raise_error
+ expect { Chef::Node::Attribute.new({}, {}, {}, {}) }.not_to raise_error
end
[ :normal, :default, :override, :automatic ].each do |accessor|
it "should set #{accessor}" do
na = Chef::Node::Attribute.new({ :normal => true }, { :default => true }, { :override => true }, { :automatic => true })
- na.send(accessor).should == { accessor.to_s => true }
+ expect(na.send(accessor)).to eq({ accessor.to_s => true })
end
end
it "should be enumerable" do
- @attributes.should be_is_a(Enumerable)
+ expect(@attributes).to be_is_a(Enumerable)
end
end
@@ -242,7 +242,7 @@ describe Chef::Node::Attribute do
# the "strict" conversion method that should only be implemented by
# things that are truly Array-like, so NoMethodError is the right choice.
# (cf. there is no Hash#to_ary).
- lambda { @attributes.default.to_ary }.should raise_error(NoMethodError)
+ expect { @attributes.default.to_ary }.to raise_error(NoMethodError)
end
end
@@ -274,7 +274,7 @@ describe Chef::Node::Attribute do
["force_override", "force_override"],
["automatic", "automatic"]
]
- @attributes.debug_value(:foo, :bar).should == expected
+ expect(@attributes.debug_value(:foo, :bar)).to eq(expected)
end
end
@@ -288,68 +288,68 @@ describe Chef::Node::Attribute do
@attributes.default!["default"] = "force default"
@attributes.role_default["default"] = "role default"
@attributes.env_default["default"] = "environment default"
- @attributes["default"].should == "force default"
+ expect(@attributes["default"]).to eq("force default")
end
it "prefers role_default over environment or cookbook default" do
@attributes.role_default["default"] = "role default"
@attributes.env_default["default"] = "environment default"
- @attributes["default"].should == "role default"
+ expect(@attributes["default"]).to eq("role default")
end
it "prefers environment default over cookbook default" do
@attributes.env_default["default"] = "environment default"
- @attributes["default"].should == "environment default"
+ expect(@attributes["default"]).to eq("environment default")
end
it "returns the cookbook default when no other default values are present" do
- @attributes["default"].should == "cookbook default"
+ expect(@attributes["default"]).to eq("cookbook default")
end
it "prefers 'forced overrides' over role or cookbook overrides" do
@attributes.override!["override"] = "force override"
@attributes.env_override["override"] = "environment override"
@attributes.role_override["override"] = "role override"
- @attributes["override"].should == "force override"
+ expect(@attributes["override"]).to eq("force override")
end
it "prefers environment overrides over role or cookbook overrides" do
@attributes.env_override["override"] = "environment override"
@attributes.role_override["override"] = "role override"
- @attributes["override"].should == "environment override"
+ expect(@attributes["override"]).to eq("environment override")
end
it "prefers role overrides over cookbook overrides" do
@attributes.role_override["override"] = "role override"
- @attributes["override"].should == "role override"
+ expect(@attributes["override"]).to eq("role override")
end
it "returns cookbook overrides when no other overrides are present" do
- @attributes["override"].should == "cookbook override"
+ expect(@attributes["override"]).to eq("cookbook override")
end
it "merges arrays within the default precedence" do
@attributes.role_default["array"] = %w{role}
@attributes.env_default["array"] = %w{env}
- @attributes["array"].should == %w{env role}
+ expect(@attributes["array"]).to eq(%w{env role})
end
it "merges arrays within the override precedence" do
@attributes.role_override["array"] = %w{role}
@attributes.env_override["array"] = %w{env}
- @attributes["array"].should == %w{role env}
+ expect(@attributes["array"]).to eq(%w{role env})
end
it "does not merge arrays between default and normal" do
@attributes.role_default["array"] = %w{role}
@attributes.normal["array"] = %w{normal}
- @attributes["array"].should == %w{normal}
+ expect(@attributes["array"]).to eq(%w{normal})
end
it "does not merge arrays between normal and override" do
@attributes.normal["array"] = %w{normal}
@attributes.role_override["array"] = %w{role}
- @attributes["array"].should == %w{role}
+ expect(@attributes["array"]).to eq(%w{role})
end
it "merges nested hashes between precedence levels" do
@@ -358,9 +358,9 @@ describe Chef::Node::Attribute do
@attributes.normal = {"a" => {"b" => {"normal" => "normal"}}}
@attributes.override = {"a" => {"override" => "role"}}
@attributes.automatic = {"a" => {"automatic" => "auto"}}
- @attributes["a"].should == {"b"=>{"default"=>"default", "normal"=>"normal"},
+ expect(@attributes["a"]).to eq({"b"=>{"default"=>"default", "normal"=>"normal"},
"override"=>"role",
- "automatic"=>"auto"}
+ "automatic"=>"auto"})
end
end
@@ -377,94 +377,94 @@ describe Chef::Node::Attribute do
end
it "merges all types of overrides into a combined override" do
- @attributes.combined_override["co"].should == "cookbook override"
- @attributes.combined_override["ro"].should == "role override"
- @attributes.combined_override["eo"].should == "env override"
- @attributes.combined_override["fo"].should == "force override"
+ expect(@attributes.combined_override["co"]).to eq("cookbook override")
+ expect(@attributes.combined_override["ro"]).to eq("role override")
+ expect(@attributes.combined_override["eo"]).to eq("env override")
+ expect(@attributes.combined_override["fo"]).to eq("force override")
end
it "merges all types of defaults into a combined default" do
- @attributes.combined_default["cd"].should == "cookbook default"
- @attributes.combined_default["rd"].should == "role default"
- @attributes.combined_default["ed"].should == "env default"
- @attributes.combined_default["fd"].should == "force default"
+ expect(@attributes.combined_default["cd"]).to eq("cookbook default")
+ expect(@attributes.combined_default["rd"]).to eq("role default")
+ expect(@attributes.combined_default["ed"]).to eq("env default")
+ expect(@attributes.combined_default["fd"]).to eq("force default")
end
end
describe "[]" do
it "should return override data if it exists" do
- @attributes["macaddress"].should == "00:00:00:00:00:00"
+ expect(@attributes["macaddress"]).to eq("00:00:00:00:00:00")
end
it "should return attribute data if it is not overridden" do
- @attributes["platform"].should == "mac_os_x"
+ expect(@attributes["platform"]).to eq("mac_os_x")
end
it "should return data that doesn't have corresponding keys in every hash" do
- @attributes["command"]["ps"].should == "ps -ef"
+ expect(@attributes["command"]["ps"]).to eq("ps -ef")
end
it "should return default data if it is not overriden or in attribute data" do
- @attributes["music"]["mastodon"].should == "rocks"
+ expect(@attributes["music"]["mastodon"]).to eq("rocks")
end
it "should prefer the override data over an available default" do
- @attributes["music"]["mars_volta"].should == "cicatriz"
+ expect(@attributes["music"]["mars_volta"]).to eq("cicatriz")
end
it "should prefer the attribute data over an available default" do
- @attributes["music"]["jimmy_eat_world"].should == "nice"
+ expect(@attributes["music"]["jimmy_eat_world"]).to eq("nice")
end
it "should prefer override data over default data if there is no attribute data" do
- @attributes["hot"]["day"].should == "sunday"
+ expect(@attributes["hot"]["day"]).to eq("sunday")
end
it "should return the merged hash if all three have values" do
result = @attributes["music"]
- result["mars_volta"].should == "cicatriz"
- result["jimmy_eat_world"].should == "nice"
- result["mastodon"].should == "rocks"
+ expect(result["mars_volta"]).to eq("cicatriz")
+ expect(result["jimmy_eat_world"]).to eq("nice")
+ expect(result["mastodon"]).to eq("rocks")
end
end
describe "[]=" do
it "should error out when the type of attribute to set has not been specified" do
@attributes.normal["the_ghost"] = { }
- lambda { @attributes["the_ghost"]["exterminate"] = false }.should raise_error(Chef::Exceptions::ImmutableAttributeModification)
+ expect { @attributes["the_ghost"]["exterminate"] = false }.to raise_error(Chef::Exceptions::ImmutableAttributeModification)
end
it "should let you set an attribute value when another hash has an intermediate value" do
@attributes.normal["the_ghost"] = { "exterminate" => "the future" }
- lambda { @attributes.normal["the_ghost"]["eviscerate"]["tomorrow"] = false }.should_not raise_error
+ expect { @attributes.normal["the_ghost"]["eviscerate"]["tomorrow"] = false }.not_to raise_error
end
it "should set the attribute value" do
@attributes.normal["longboard"] = "surfing"
- @attributes.normal["longboard"].should == "surfing"
- @attributes.normal["longboard"].should == "surfing"
+ expect(@attributes.normal["longboard"]).to eq("surfing")
+ expect(@attributes.normal["longboard"]).to eq("surfing")
end
it "should set deeply nested attribute values when a precedence level is specified" do
@attributes.normal["deftones"]["hunters"]["nap"] = "surfing"
- @attributes.normal["deftones"]["hunters"]["nap"].should == "surfing"
+ expect(@attributes.normal["deftones"]["hunters"]["nap"]).to eq("surfing")
end
it "should die if you try and do nested attributes that do not exist without read vivification" do
- lambda { @attributes["foo"]["bar"] = :baz }.should raise_error
+ expect { @attributes["foo"]["bar"] = :baz }.to raise_error
end
it "should let you set attributes manually without vivification" do
@attributes.normal["foo"] = Mash.new
@attributes.normal["foo"]["bar"] = :baz
- @attributes.normal["foo"]["bar"].should == :baz
+ expect(@attributes.normal["foo"]["bar"]).to eq(:baz)
end
it "should optionally skip setting the value if one already exists" do
@attributes.set_unless_value_present = true
@attributes.normal["hostname"] = "bar"
- @attributes["hostname"].should == "latte"
+ expect(@attributes["hostname"]).to eq("latte")
end
it "does not support ||= when setting" do
@@ -472,19 +472,19 @@ describe Chef::Node::Attribute do
# Users who need this behavior can use set_unless and friends
@attributes.normal["foo"] = Mash.new
@attributes.normal["foo"]["bar"] ||= "stop the world"
- @attributes.normal["foo"]["bar"].should == {}
+ expect(@attributes.normal["foo"]["bar"]).to eq({})
end
end
describe "to_hash" do
it "should convert to a hash" do
- @attributes.to_hash.class.should == Hash
+ expect(@attributes.to_hash.class).to eq(Hash)
end
it "should convert to a hash based on current state" do
hash = @attributes["hot"].to_hash
- hash.class.should == Hash
- hash["day"].should == "sunday"
+ expect(hash.class).to eq(Hash)
+ expect(hash["day"]).to eq("sunday")
end
end
@@ -497,65 +497,65 @@ describe Chef::Node::Attribute do
describe "has_key?" do
it "should return true if an attribute exists" do
- @attributes.has_key?("music").should == true
+ expect(@attributes.has_key?("music")).to eq(true)
end
it "should return false if an attribute does not exist" do
- @attributes.has_key?("ninja").should == false
+ expect(@attributes.has_key?("ninja")).to eq(false)
end
it "should return false if an attribute does not exist using dot notation" do
- @attributes.has_key?("does_not_exist_at_all").should == false
+ expect(@attributes.has_key?("does_not_exist_at_all")).to eq(false)
end
it "should return true if an attribute exists but is set to nil using dot notation" do
- @attributes.music.deeper.has_key?("gates_of_ishtar").should == true
+ expect(@attributes.music.deeper.has_key?("gates_of_ishtar")).to eq(true)
end
it "should return true if an attribute exists but is set to false" do
@attributes.has_key?("music")
- @attributes["music"].has_key?("apophis").should == true
+ expect(@attributes["music"].has_key?("apophis")).to eq(true)
end
it "does not find keys above the current nesting level" do
- @attributes["music"]["this"]["apparatus"].should_not have_key("this")
+ expect(@attributes["music"]["this"]["apparatus"]).not_to have_key("this")
end
it "does not find keys below the current nesting level" do
- @attributes["music"]["this"].should_not have_key("must")
+ expect(@attributes["music"]["this"]).not_to have_key("must")
end
[:include?, :key?, :member?].each do |method|
it "should alias the method #{method} to itself" do
- @attributes.should respond_to(method)
+ expect(@attributes).to respond_to(method)
end
it "#{method} should behave like has_key?" do
- @attributes.send(method, "music").should == true
+ expect(@attributes.send(method, "music")).to eq(true)
end
end
end
describe "attribute?" do
it "should return true if an attribute exists" do
- @attributes.attribute?("music").should == true
+ expect(@attributes.attribute?("music")).to eq(true)
end
it "should return false if an attribute does not exist" do
- @attributes.attribute?("ninja").should == false
+ expect(@attributes.attribute?("ninja")).to eq(false)
end
end
describe "method_missing" do
it "should behave like a [] lookup" do
- @attributes.music.mastodon.should == "rocks"
+ expect(@attributes.music.mastodon).to eq("rocks")
end
it "should allow the last method to set a value if it has an = sign on the end" do
@attributes.normal.music.mastodon = [ "dream", "still", "shining" ]
@attributes.reset
- @attributes.normal.music.mastodon.should == [ "dream", "still", "shining" ]
+ expect(@attributes.normal.music.mastodon).to eq([ "dream", "still", "shining" ])
end
end
@@ -584,12 +584,12 @@ describe Chef::Node::Attribute do
@attributes.keys.each do |k|
collect << k
end
- collect.include?("one").should == true
- collect.include?("hut").should == true
- collect.include?("snakes").should == true
- collect.include?("snack").should == true
- collect.include?("place").should == true
- collect.length.should == 5
+ expect(collect.include?("one")).to eq(true)
+ expect(collect.include?("hut")).to eq(true)
+ expect(collect.include?("snakes")).to eq(true)
+ expect(collect.include?("snack")).to eq(true)
+ expect(collect.include?("place")).to eq(true)
+ expect(collect.length).to eq(5)
end
it "should yield lower if we go deeper" do
@@ -597,14 +597,14 @@ describe Chef::Node::Attribute do
@attributes.one.keys.each do |k|
collect << k
end
- collect.include?("two").should == true
- collect.include?("four").should == true
- collect.include?("six").should == true
- collect.length.should == 3
+ expect(collect.include?("two")).to eq(true)
+ expect(collect.include?("four")).to eq(true)
+ expect(collect.include?("six")).to eq(true)
+ expect(collect.length).to eq(3)
end
it "should not raise an exception if one of the hashes has a nil value on a deep lookup" do
- lambda { @attributes.place.keys { |k| } }.should_not raise_error
+ expect { @attributes.place.keys { |k| } }.not_to raise_error
end
end
@@ -633,15 +633,15 @@ describe Chef::Node::Attribute do
collect[k] = v
end
- collect["one"].should == "six"
- collect["hut"].should == "three"
- collect["snakes"].should == "on a plane"
- collect["snack"].should == "cookies"
+ expect(collect["one"]).to eq("six")
+ expect(collect["hut"]).to eq("three")
+ expect(collect["snakes"]).to eq("on a plane")
+ expect(collect["snack"]).to eq("cookies")
end
it "should yield as a two-element array" do
@attributes.each do |a|
- a.should be_an_instance_of(Array)
+ expect(a).to be_an_instance_of(Array)
end
end
end
@@ -666,7 +666,7 @@ describe Chef::Node::Attribute do
end
it "should respond to each_key" do
- @attributes.should respond_to(:each_key)
+ expect(@attributes).to respond_to(:each_key)
end
it "should yield each top level key, post merge rules" do
@@ -675,10 +675,10 @@ describe Chef::Node::Attribute do
collect << k
end
- collect.should include("one")
- collect.should include("snack")
- collect.should include("hut")
- collect.should include("snakes")
+ expect(collect).to include("one")
+ expect(collect).to include("snack")
+ expect(collect).to include("hut")
+ expect(collect).to include("snakes")
end
end
@@ -702,7 +702,7 @@ describe Chef::Node::Attribute do
end
it "should respond to each_pair" do
- @attributes.should respond_to(:each_pair)
+ expect(@attributes).to respond_to(:each_pair)
end
it "should yield each top level key and value pair, post merge rules" do
@@ -711,10 +711,10 @@ describe Chef::Node::Attribute do
collect[k] = v
end
- collect["one"].should == "six"
- collect["hut"].should == "three"
- collect["snakes"].should == "on a plane"
- collect["snack"].should == "cookies"
+ expect(collect["one"]).to eq("six")
+ expect(collect["hut"]).to eq("three")
+ expect(collect["snakes"]).to eq("on a plane")
+ expect(collect["snack"]).to eq("cookies")
end
end
@@ -738,7 +738,7 @@ describe Chef::Node::Attribute do
end
it "should respond to each_value" do
- @attributes.should respond_to(:each_value)
+ expect(@attributes).to respond_to(:each_value)
end
it "should yield each value, post merge rules" do
@@ -747,9 +747,9 @@ describe Chef::Node::Attribute do
collect << v
end
- collect.should include("cookies")
- collect.should include("three")
- collect.should include("on a plane")
+ expect(collect).to include("cookies")
+ expect(collect).to include("three")
+ expect(collect).to include("on a plane")
end
it "should yield four elements" do
@@ -758,7 +758,7 @@ describe Chef::Node::Attribute do
collect << v
end
- collect.length.should == 4
+ expect(collect.length).to eq(4)
end
end
@@ -783,15 +783,15 @@ describe Chef::Node::Attribute do
end
it "should respond to empty?" do
- @attributes.should respond_to(:empty?)
+ expect(@attributes).to respond_to(:empty?)
end
it "should return true when there are no keys" do
- @empty.empty?.should == true
+ expect(@empty.empty?).to eq(true)
end
it "should return false when there are keys" do
- @attributes.empty?.should == false
+ expect(@attributes.empty?).to eq(false)
end
end
@@ -816,7 +816,7 @@ describe Chef::Node::Attribute do
end
it "should respond to fetch" do
- @attributes.should respond_to(:fetch)
+ expect(@attributes).to respond_to(:fetch)
end
describe "when the key exists" do
@@ -827,7 +827,7 @@ describe Chef::Node::Attribute do
"snakes" => "on a plane",
"snack" => "cookies"
}.each do |k,v|
- @attributes.fetch(k).should == v
+ expect(@attributes.fetch(k)).to eq(v)
end
end
end
@@ -835,19 +835,19 @@ describe Chef::Node::Attribute do
describe "when the key does not exist" do
describe "and no args are passed" do
it "should raise an indexerror" do
- lambda { @attributes.fetch("lololol") }.should raise_error(IndexError)
+ expect { @attributes.fetch("lololol") }.to raise_error(IndexError)
end
end
describe "and a default arg is passed" do
it "should return the value of the default arg" do
- @attributes.fetch("lol", "blah").should == "blah"
+ expect(@attributes.fetch("lol", "blah")).to eq("blah")
end
end
describe "and a block is passed" do
it "should run the block and return its value" do
- @attributes.fetch("lol") { |x| "#{x}, blah" }.should == "lol, blah"
+ expect(@attributes.fetch("lol") { |x| "#{x}, blah" }).to eq("lol, blah")
end
end
end
@@ -873,19 +873,19 @@ describe Chef::Node::Attribute do
end
it "should respond to has_value?" do
- @attributes.should respond_to(:has_value?)
+ expect(@attributes).to respond_to(:has_value?)
end
it "should return true if any key has the value supplied" do
- @attributes.has_value?("cookies").should == true
+ expect(@attributes.has_value?("cookies")).to eq(true)
end
it "should return false no key has the value supplied" do
- @attributes.has_value?("lololol").should == false
+ expect(@attributes.has_value?("lololol")).to eq(false)
end
it "should alias value?" do
- @attributes.should respond_to(:value?)
+ expect(@attributes).to respond_to(:value?)
end
end
@@ -918,13 +918,13 @@ describe Chef::Node::Attribute do
end
it "should respond to index" do
- @attributes.should respond_to(:index)
+ expect(@attributes).to respond_to(:index)
end
describe "when the value is indexed" do
it "should return the index" do
silence do
- @attributes.index("six").should == "one"
+ expect(@attributes.index("six")).to eq("one")
end
end
end
@@ -932,7 +932,7 @@ describe Chef::Node::Attribute do
describe "when the value is not indexed" do
it "should return nil" do
silence do
- @attributes.index("lolol").should == nil
+ expect(@attributes.index("lolol")).to eq(nil)
end
end
end
@@ -960,18 +960,18 @@ describe Chef::Node::Attribute do
end
it "should respond to values" do
- @attributes.should respond_to(:values)
+ expect(@attributes).to respond_to(:values)
end
it "should return an array of values" do
- @attributes.values.length.should == 4
+ expect(@attributes.values.length).to eq(4)
end
it "should match the values output from each" do
- @attributes.values.should include("six")
- @attributes.values.should include("cookies")
- @attributes.values.should include("three")
- @attributes.values.should include("on a plane")
+ expect(@attributes.values).to include("six")
+ expect(@attributes.values).to include("cookies")
+ expect(@attributes.values).to include("three")
+ expect(@attributes.values).to include("on a plane")
end
end
@@ -996,26 +996,26 @@ describe Chef::Node::Attribute do
end
it "should respond to select" do
- @attributes.should respond_to(:select)
+ expect(@attributes).to respond_to(:select)
end
if RUBY_VERSION >= "1.8.7"
it "should not raise a LocalJumpError if no block is given" do
- lambda { @attributes.select }.should_not raise_error
+ expect { @attributes.select }.not_to raise_error
end
else
it "should raise a LocalJumpError if no block is given" do
- lambda{ @attributes.select }.should raise_error(LocalJumpError)
+ expect{ @attributes.select }.to raise_error(LocalJumpError)
end
end
it "should return an empty hash/array (ruby-version-dependent) for a block containing nil" do
- @attributes.select { nil }.should == {}.select { nil }
+ expect(@attributes.select { nil }).to eq({}.select { nil })
end
# sorted for spec clarity
it "should return a new array of k,v pairs for which the block returns true" do
- @attributes.select { true }.sort.should == (
+ expect(@attributes.select { true }.sort).to eq(
[
["hut", "three"],
["one", "six"],
@@ -1048,37 +1048,37 @@ describe Chef::Node::Attribute do
end
it "should respond to size" do
- @attributes.should respond_to(:size)
+ expect(@attributes).to respond_to(:size)
end
it "should alias length to size" do
- @attributes.should respond_to(:length)
+ expect(@attributes).to respond_to(:length)
end
it "should return 0 for an empty attribute" do
- @empty.size.should == 0
+ expect(@empty.size).to eq(0)
end
it "should return the number of pairs" do
- @attributes.size.should == 4
+ expect(@attributes.size).to eq(4)
end
end
describe "kind_of?" do
it "should falsely inform you that it is a Hash" do
- @attributes.should be_a_kind_of(Hash)
+ expect(@attributes).to be_a_kind_of(Hash)
end
it "should falsely inform you that it is a Mash" do
- @attributes.should be_a_kind_of(Mash)
+ expect(@attributes).to be_a_kind_of(Mash)
end
it "should inform you that it is a Chef::Node::Attribute" do
- @attributes.should be_a_kind_of(Chef::Node::Attribute)
+ expect(@attributes).to be_a_kind_of(Chef::Node::Attribute)
end
it "should inform you that it is anything else" do
- @attributes.should_not be_a_kind_of(Chef::Node)
+ expect(@attributes).not_to be_a_kind_of(Chef::Node)
end
end
@@ -1087,8 +1087,8 @@ describe Chef::Node::Attribute do
# NOTE: previous implementation hid the values, showing @automatic={...}
# That is nice and compact, but hides a lot of info, which seems counter
# to the point of calling #inspect...
- @attributes.inspect.should =~ /@automatic=\{.*\}/
- @attributes.inspect.should =~ /@normal=\{.*\}/
+ expect(@attributes.inspect).to match(/@automatic=\{.*\}/)
+ expect(@attributes.inspect).to match(/@normal=\{.*\}/)
end
end
@@ -1099,13 +1099,13 @@ describe Chef::Node::Attribute do
:shift
].each do |mutator|
it "resets the cache when the mutator #{mutator} is called" do
- @attributes.should_receive(:reset_cache)
+ expect(@attributes).to receive(:reset_cache)
@attributes.default.send(mutator)
end
end
it "resets the cache when the mutator delete is called" do
- @attributes.should_receive(:reset_cache)
+ expect(@attributes).to receive(:reset_cache)
@attributes.default.delete(:music)
end
@@ -1116,7 +1116,7 @@ describe Chef::Node::Attribute do
].each do |mutator|
it "resets the cache when the mutator #{mutator} is called" do
# Implementation of Mash means that this could get called many times. That's okay.
- @attributes.should_receive(:reset_cache).at_least(1).times
+ expect(@attributes).to receive(:reset_cache).at_least(1).times
@attributes.default.send(mutator, {:foo => :bar})
end
end
@@ -1129,7 +1129,7 @@ describe Chef::Node::Attribute do
].each do |mutator|
it "resets the cache when the mutator #{mutator} is called" do
# Implementation of Mash means that this could get called many times. That's okay.
- @attributes.should_receive(:reset_cache).at_least(1).times
+ expect(@attributes).to receive(:reset_cache).at_least(1).times
block = lambda {|k,v| true }
@attributes.default.send(mutator, &block)
end
@@ -1142,7 +1142,7 @@ describe Chef::Node::Attribute do
@attributes.default[:foo][:bar] = "set on original"
subtree = @attributes[:foo]
@attributes.default[:foo].dup[:bar] = "set on dup"
- subtree[:bar].should == "set on original"
+ expect(subtree[:bar]).to eq("set on original")
end
end
@@ -1151,35 +1151,35 @@ describe Chef::Node::Attribute do
it "converts the input in to a VividMash tree (default)" do
@attributes.default = {}
@attributes.default.foo = "bar"
- @attributes.merged_attributes[:foo].should == "bar"
+ expect(@attributes.merged_attributes[:foo]).to eq("bar")
end
it "converts the input in to a VividMash tree (normal)" do
@attributes.normal = {}
@attributes.normal.foo = "bar"
- @attributes.merged_attributes[:foo].should == "bar"
+ expect(@attributes.merged_attributes[:foo]).to eq("bar")
end
it "converts the input in to a VividMash tree (override)" do
@attributes.override = {}
@attributes.override.foo = "bar"
- @attributes.merged_attributes[:foo].should == "bar"
+ expect(@attributes.merged_attributes[:foo]).to eq("bar")
end
it "converts the input in to a VividMash tree (automatic)" do
@attributes.automatic = {}
@attributes.automatic.foo = "bar"
- @attributes.merged_attributes[:foo].should == "bar"
+ expect(@attributes.merged_attributes[:foo]).to eq("bar")
end
end
describe "when attemping to write without specifying precedence" do
it "raises an error when using []=" do
- lambda { @attributes[:new_key] = "new value" }.should raise_error(Chef::Exceptions::ImmutableAttributeModification)
+ expect { @attributes[:new_key] = "new value" }.to raise_error(Chef::Exceptions::ImmutableAttributeModification)
end
it "raises an error when using `attr=value`" do
- lambda { @attributes.new_key = "new value" }.should raise_error(Chef::Exceptions::ImmutableAttributeModification)
+ expect { @attributes.new_key = "new value" }.to raise_error(Chef::Exceptions::ImmutableAttributeModification)
end
end
diff --git a/spec/unit/node/immutable_collections_spec.rb b/spec/unit/node/immutable_collections_spec.rb
index 1c216e327a..b1e7b9169b 100644
--- a/spec/unit/node/immutable_collections_spec.rb
+++ b/spec/unit/node/immutable_collections_spec.rb
@@ -30,28 +30,28 @@ describe Chef::Node::ImmutableMash do
end
it "element references like regular hash" do
- @immutable_mash[:top][:second_level].should == "some value"
+ expect(@immutable_mash[:top][:second_level]).to eq("some value")
end
it "elelment references like a regular Mash" do
- @immutable_mash[:top_level_2].should == %w[array of values]
+ expect(@immutable_mash[:top_level_2]).to eq(%w[array of values])
end
it "converts Hash-like inputs into ImmutableMash's" do
- @immutable_mash[:top].should be_a(Chef::Node::ImmutableMash)
+ expect(@immutable_mash[:top]).to be_a(Chef::Node::ImmutableMash)
end
it "converts array inputs into ImmutableArray's" do
- @immutable_mash[:top_level_2].should be_a(Chef::Node::ImmutableArray)
+ expect(@immutable_mash[:top_level_2]).to be_a(Chef::Node::ImmutableArray)
end
it "converts arrays of hashes to ImmutableArray's of ImmutableMashes" do
- @immutable_mash[:top_level_3].first.should be_a(Chef::Node::ImmutableMash)
+ expect(@immutable_mash[:top_level_3].first).to be_a(Chef::Node::ImmutableMash)
end
it "converts nested hashes to ImmutableMashes" do
- @immutable_mash[:top_level_4].should be_a(Chef::Node::ImmutableMash)
- @immutable_mash[:top_level_4][:level2].should be_a(Chef::Node::ImmutableMash)
+ expect(@immutable_mash[:top_level_4]).to be_a(Chef::Node::ImmutableMash)
+ expect(@immutable_mash[:top_level_4][:level2]).to be_a(Chef::Node::ImmutableMash)
end
describe "to_hash" do
@@ -60,23 +60,23 @@ describe Chef::Node::ImmutableMash do
end
it "converts an immutable mash to a new mutable hash" do
- @copy.should be_instance_of(Hash)
+ expect(@copy).to be_instance_of(Hash)
end
it "converts an immutable nested mash to a new mutable hash" do
- @copy['top_level_4']['level2'].should be_instance_of(Hash)
+ expect(@copy['top_level_4']['level2']).to be_instance_of(Hash)
end
it "converts an immutable nested array to a new mutable array" do
- @copy['top_level_2'].should be_instance_of(Array)
+ expect(@copy['top_level_2']).to be_instance_of(Array)
end
it "should create a mash with the same content" do
- @copy.should == @immutable_mash
+ expect(@copy).to eq(@immutable_mash)
end
it 'should allow mutation' do
- lambda { @copy['m'] = 'm' }.should_not raise_error
+ expect { @copy['m'] = 'm' }.not_to raise_error
end
end
@@ -97,14 +97,14 @@ describe Chef::Node::ImmutableMash do
:shift
].each do |mutator|
it "doesn't allow mutation via `#{mutator}'" do
- lambda { @immutable_mash.send(mutator) }.should raise_error
+ expect { @immutable_mash.send(mutator) }.to raise_error
end
end
it "returns a mutable version of itself when duped" do
mutable = @immutable_mash.dup
mutable[:new_key] = :value
- mutable[:new_key].should == :value
+ expect(mutable[:new_key]).to eq(:value)
end
end
@@ -154,7 +154,7 @@ describe Chef::Node::ImmutableArray do
:unshift
].each do |mutator|
it "does not allow mutation via `#{mutator}" do
- lambda { @immutable_array.send(mutator)}.should raise_error
+ expect { @immutable_array.send(mutator)}.to raise_error
end
end
@@ -165,7 +165,7 @@ describe Chef::Node::ImmutableArray do
it "returns a mutable version of itself when duped" do
mutable = @immutable_array.dup
mutable[0] = :value
- mutable[0].should == :value
+ expect(mutable[0]).to eq(:value)
end
describe "to_a" do
@@ -174,23 +174,23 @@ describe Chef::Node::ImmutableArray do
end
it "converts an immutable array to a new mutable array" do
- @copy.should be_instance_of(Array)
+ expect(@copy).to be_instance_of(Array)
end
it "converts an immutable nested array to a new mutable array" do
- @copy[1].should be_instance_of(Array)
+ expect(@copy[1]).to be_instance_of(Array)
end
it "converts an immutable nested mash to a new mutable hash" do
- @copy[2].should be_instance_of(Hash)
+ expect(@copy[2]).to be_instance_of(Hash)
end
it "should create an array with the same content" do
- @copy.should == @immutable_nested_array
+ expect(@copy).to eq(@immutable_nested_array)
end
it 'should allow mutation' do
- lambda { @copy << 'm' }.should_not raise_error
+ expect { @copy << 'm' }.not_to raise_error
end
end