diff options
Diffstat (limited to 'spec/unit/node/vivid_mash_spec.rb')
-rw-r--r-- | spec/unit/node/vivid_mash_spec.rb | 37 |
1 files changed, 27 insertions, 10 deletions
diff --git a/spec/unit/node/vivid_mash_spec.rb b/spec/unit/node/vivid_mash_spec.rb index 4898c22380..651cfa0058 100644 --- a/spec/unit/node/vivid_mash_spec.rb +++ b/spec/unit/node/vivid_mash_spec.rb @@ -1,5 +1,5 @@ # -# Copyright:: Copyright 2016, Chef Software Inc. +# Copyright:: Copyright 2016-2017, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -60,7 +60,7 @@ describe Chef::Node::VividMash do end it "deep converts values through arrays" do - expect(root).to receive(:reset_cache).with("foo") + expect(root).to receive(:reset_cache).with(no_args) vivid["foo"] = [ { :bar => true } ] expect(vivid["foo"].class).to eql(Chef::Node::AttrArray) expect(vivid["foo"][0].class).to eql(Chef::Node::VividMash) @@ -68,7 +68,7 @@ describe Chef::Node::VividMash do end it "deep converts values through nested arrays" do - expect(root).to receive(:reset_cache).with("foo") + expect(root).to receive(:reset_cache).with(no_args) vivid["foo"] = [ [ { :bar => true } ] ] expect(vivid["foo"].class).to eql(Chef::Node::AttrArray) expect(vivid["foo"][0].class).to eql(Chef::Node::AttrArray) @@ -77,7 +77,7 @@ describe Chef::Node::VividMash do end it "deep converts values through hashes" do - expect(root).to receive(:reset_cache).with("foo") + expect(root).to receive(:reset_cache).with(no_args) vivid["foo"] = { baz: { :bar => true } } expect(vivid["foo"]).to be_an_instance_of(Chef::Node::VividMash) expect(vivid["foo"]["baz"]).to be_an_instance_of(Chef::Node::VividMash) @@ -184,42 +184,55 @@ describe Chef::Node::VividMash do it "should deeply autovivify" do expect(root).to receive(:reset_cache).at_least(:once).with("one") + expect(root).to receive(:reset_cache).at_least(:once).with("one", "five") + expect(root).to receive(:reset_cache).at_least(:once).with("one", "five", "six") + expect(root).to receive(:reset_cache).at_least(:once).with("one", "five", "six", "seven") + expect(root).to receive(:reset_cache).at_least(:once).with("one", "five", "six", "seven", "eight") vivid.write("one", "five", "six", "seven", "eight", "nine", "ten") expect(vivid["one"]["five"]["six"]["seven"]["eight"]["nine"]).to eql("ten") end it "should raise an exception if you overwrite an array with a hash" do + expect(root).to receive(:reset_cache).at_least(:once).with(no_args) expect(root).to receive(:reset_cache).at_least(:once).with("array") vivid.write("array", "five", "six") expect(vivid).to eql({ "one" => { "two" => { "three" => "four" } }, "array" => { "five" => "six" }, "nil" => nil }) end it "should raise an exception if you traverse through an array with a hash" do + expect(root).to receive(:reset_cache).at_least(:once).with(no_args) expect(root).to receive(:reset_cache).at_least(:once).with("array") + expect(root).to receive(:reset_cache).at_least(:once).with("array", "five") vivid.write("array", "five", "six", "seven") expect(vivid).to eql({ "one" => { "two" => { "three" => "four" } }, "array" => { "five" => { "six" => "seven" } }, "nil" => nil }) end it "should raise an exception if you overwrite a string with a hash" do - expect(root).to receive(:reset_cache).at_least(:once).with("one") + expect(root).to receive(:reset_cache).at_least(:once).with("one", "two") + expect(root).to receive(:reset_cache).at_least(:once).with("one", "two", "three") vivid.write("one", "two", "three", "four", "five") expect(vivid).to eql({ "one" => { "two" => { "three" => { "four" => "five" } } }, "array" => [ 0, 1, 2 ], "nil" => nil }) end it "should raise an exception if you traverse through a string with a hash" do - expect(root).to receive(:reset_cache).at_least(:once).with("one") + expect(root).to receive(:reset_cache).at_least(:once).with("one", "two") + expect(root).to receive(:reset_cache).at_least(:once).with("one", "two", "three") + expect(root).to receive(:reset_cache).at_least(:once).with("one", "two", "three", "four") vivid.write("one", "two", "three", "four", "five", "six") expect(vivid).to eql({ "one" => { "two" => { "three" => { "four" => { "five" => "six" } } } }, "array" => [ 0, 1, 2 ], "nil" => nil }) end it "should raise an exception if you overwrite a nil with a hash" do + expect(root).to receive(:reset_cache).at_least(:once).with(no_args) expect(root).to receive(:reset_cache).at_least(:once).with("nil") vivid.write("nil", "one", "two") expect(vivid).to eql({ "one" => { "two" => { "three" => "four" } }, "array" => [ 0, 1, 2 ], "nil" => { "one" => "two" } }) end it "should raise an exception if you traverse through a nil with a hash" do + expect(root).to receive(:reset_cache).at_least(:once).with(no_args) expect(root).to receive(:reset_cache).at_least(:once).with("nil") + expect(root).to receive(:reset_cache).at_least(:once).with("nil", "one") vivid.write("nil", "one", "two", "three") expect(vivid).to eql({ "one" => { "two" => { "three" => "four" } }, "array" => [ 0, 1, 2 ], "nil" => { "one" => { "two" => "three" } } }) end @@ -240,6 +253,10 @@ describe Chef::Node::VividMash do it "should deeply autovivify" do expect(root).to receive(:reset_cache).at_least(:once).with("one") + expect(root).to receive(:reset_cache).at_least(:once).with("one", "five") + expect(root).to receive(:reset_cache).at_least(:once).with("one", "five", "six") + expect(root).to receive(:reset_cache).at_least(:once).with("one", "five", "six", "seven") + expect(root).to receive(:reset_cache).at_least(:once).with("one", "five", "six", "seven", "eight") vivid.write!("one", "five", "six", "seven", "eight", "nine", "ten") expect(vivid["one"]["five"]["six"]["seven"]["eight"]["nine"]).to eql("ten") end @@ -295,7 +312,7 @@ describe Chef::Node::VividMash do end it "should unlink hashes" do - expect(root).to receive(:reset_cache).at_least(:once).with("one") + expect(root).to receive(:reset_cache).at_least(:once).with(no_args) expect( vivid.unlink("one") ).to eql({ "two" => { "three" => "four" } }) expect(vivid).to eql({ "array" => [ 0, 1, 2 ], "nil" => nil }) end @@ -307,7 +324,7 @@ describe Chef::Node::VividMash do end it "should unlink nil" do - expect(root).to receive(:reset_cache).at_least(:once).with("nil") + expect(root).to receive(:reset_cache).at_least(:once).with(no_args) expect(vivid.unlink("nil")).to eql(nil) expect(vivid).to eql({ "one" => { "two" => { "three" => "four" } }, "array" => [ 0, 1, 2 ] }) end @@ -327,7 +344,7 @@ describe Chef::Node::VividMash do end it "should unlink! hashes" do - expect(root).to receive(:reset_cache).at_least(:once).with("one") + expect(root).to receive(:reset_cache).at_least(:once).with(no_args) expect( vivid.unlink!("one") ).to eql({ "two" => { "three" => "four" } }) expect(vivid).to eql({ "array" => [ 0, 1, 2 ], "nil" => nil }) end @@ -339,7 +356,7 @@ describe Chef::Node::VividMash do end it "should unlink! nil" do - expect(root).to receive(:reset_cache).at_least(:once).with("nil") + expect(root).to receive(:reset_cache).at_least(:once).with(no_args) expect(vivid.unlink!("nil")).to eql(nil) expect(vivid).to eql({ "one" => { "two" => { "three" => "four" } }, "array" => [ 0, 1, 2 ] }) end |