diff options
-rw-r--r-- | chef/lib/chef/node/attribute.rb | 6 | ||||
-rw-r--r-- | chef/spec/unit/node/attribute_spec.rb | 37 |
2 files changed, 43 insertions, 0 deletions
diff --git a/chef/lib/chef/node/attribute.rb b/chef/lib/chef/node/attribute.rb index 6e01a6961c..a0c21aed5e 100644 --- a/chef/lib/chef/node/attribute.rb +++ b/chef/lib/chef/node/attribute.rb @@ -175,6 +175,12 @@ class Chef::Node self.collect { |h| h[1] } end + def size + self.collect{}.length + end + + alias :length :size + def get_keys keys end diff --git a/chef/spec/unit/node/attribute_spec.rb b/chef/spec/unit/node/attribute_spec.rb index cbc0bd7e38..134a55f81a 100644 --- a/chef/spec/unit/node/attribute_spec.rb +++ b/chef/spec/unit/node/attribute_spec.rb @@ -901,4 +901,41 @@ describe Chef::Node::Attribute do ) end end + + describe "size" do + before do + @attributes = Chef::Node::Attribute.new( + { + "one" => "two", + "hut" => "three", + }, + { + "one" => "four", + "snakes" => "on a plane" + }, + { + "one" => "six", + "snack" => "cookies" + } + ) + + @empty = Chef::Node::Attribute.new({},{},{}) + end + + it "should respond to size" do + @attributes.should respond_to(:size) + end + + it "should alias length to size" do + @attributes.should respond_to(:length) + end + + it "should return 0 for an empty attribute" do + @empty.size.should == 0 + end + + it "should return the number of pairs" do + @attributes.size.should == 4 + end + end end |