diff options
author | sersut <serdar@opscode.com> | 2014-03-30 13:45:00 -0700 |
---|---|---|
committer | sersut <serdar@opscode.com> | 2014-03-30 13:45:00 -0700 |
commit | 7a1778fb309423114462d578e01ba0e00108010f (patch) | |
tree | 792e1fbafdca12725edf923cdad22536f3124fc3 /spec/unit/node | |
parent | 0d097217dda26ac5551d1ad24132d9e53a62e0fb (diff) | |
parent | cacf2a53a3b789829dd6b5b2956e07cc1aa42931 (diff) | |
download | chef-7a1778fb309423114462d578e01ba0e00108010f.tar.gz |
Merge branch 'master' into 11-stable11.12.0.rc.0
Merging mater branch for RC version.
Diffstat (limited to 'spec/unit/node')
-rw-r--r-- | spec/unit/node/attribute_spec.rb | 7 | ||||
-rw-r--r-- | spec/unit/node/immutable_collections_spec.rb | 61 |
2 files changed, 67 insertions, 1 deletions
diff --git a/spec/unit/node/attribute_spec.rb b/spec/unit/node/attribute_spec.rb index ef3fc60cc6..bab2e33aa9 100644 --- a/spec/unit/node/attribute_spec.rb +++ b/spec/unit/node/attribute_spec.rb @@ -488,6 +488,13 @@ describe Chef::Node::Attribute do end end + describe "dup" do + it "array can be duped even if some elements can't" do + @attributes.default[:foo] = %w[foo bar baz] + Array(1..3) + [nil, true, false, [ "el", 0, nil ] ] + @attributes.default[:foo].dup + end + end + describe "has_key?" do it "should return true if an attribute exists" do @attributes.has_key?("music").should == true diff --git a/spec/unit/node/immutable_collections_spec.rb b/spec/unit/node/immutable_collections_spec.rb index 0c2b878cd2..d7abfa26e6 100644 --- a/spec/unit/node/immutable_collections_spec.rb +++ b/spec/unit/node/immutable_collections_spec.rb @@ -54,6 +54,32 @@ describe Chef::Node::ImmutableMash do @immutable_mash[:top_level_4][:level2].should be_a(Chef::Node::ImmutableMash) end + describe "to_hash" do + before do + @copy = @immutable_mash.to_hash + end + + it "converts an immutable mash to a new mutable hash" do + @copy.should 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) + end + + it "converts an immutable nested array to a new mutable array" do + @copy['top_level_2'].should be_instance_of(Array) + end + + it "should create a mash with the same content" do + @copy.should == @immutable_mash + end + + it 'should allow mutation' do + lambda { @copy['m'] = 'm' }.should_not raise_error(Chef::Exceptions::ImmutableAttributeModification) + end + + end [ :[]=, @@ -86,7 +112,9 @@ end describe Chef::Node::ImmutableArray do before do - @immutable_array = Chef::Node::ImmutableArray.new(%w[foo bar baz]) + @immutable_array = Chef::Node::ImmutableArray.new(%w[foo bar baz] + Array(1..3) + [nil, true, false, [ "el", 0, nil ] ]) + immutable_mash = Chef::Node::ImmutableMash.new({:m => 'm'}) + @immutable_nested_array = Chef::Node::ImmutableArray.new(["level1",@immutable_array, immutable_mash]) end ## @@ -130,10 +158,41 @@ describe Chef::Node::ImmutableArray do end end + it "can be duped even if some elements can't" do + @immutable_array.dup + end + it "returns a mutable version of itself when duped" do mutable = @immutable_array.dup mutable[0] = :value mutable[0].should == :value end + + describe "to_a" do + before do + @copy = @immutable_nested_array.to_a + end + + it "converts an immutable array to a new mutable array" do + @copy.should be_instance_of(Array) + end + + it "converts an immutable nested array to a new mutable array" do + @copy[1].should be_instance_of(Array) + end + + it "converts an immutable nested mash to a new mutable hash" do + @copy[2].should be_instance_of(Hash) + end + + it "should create an array with the same content" do + @copy.should == @immutable_nested_array + end + + it 'should allow mutation' do + lambda { @copy << 'm' }.should_not raise_error(Chef::Exceptions::ImmutableAttributeModification) + end + end + end |