diff --git a/lib/vagrant/registry.rb b/lib/vagrant/registry.rb index 5095f2097..f26e17d4f 100644 --- a/lib/vagrant/registry.rb +++ b/lib/vagrant/registry.rb @@ -34,7 +34,7 @@ module Vagrant def has_key?(key) @items.has_key?(key) end - + # Returns an array populated with the keys of this object. # # @return [Array] @@ -49,6 +49,14 @@ module Vagrant end end + # Return the number of elements in this registry. + # + # @return [Fixnum] + def length + @items.keys.length + end + alias_method :size, :length + # Merge one registry with another and return a completely new # registry. Note that the result cache is completely busted, so # any gets on the new registry will result in a cache miss. diff --git a/test/unit/vagrant/registry_test.rb b/test/unit/vagrant/registry_test.rb index d12f46ffe..3a33e9634 100644 --- a/test/unit/vagrant/registry_test.rb +++ b/test/unit/vagrant/registry_test.rb @@ -90,6 +90,28 @@ describe Vagrant::Registry do expect(result["bar"]).to eq("barvalue") end + describe "#length" do + it "should return 0 when the registry is empty" do + expect(instance.length).to eq(0) + end + + it "should return the number of items in the registry" do + instance.register("foo") { } + instance.register("bar") { } + + expect(instance.length).to eq(2) + end + end + + describe "#size" do + it "should be an alias to #length" do + size = described_class.instance_method(:size) + length = described_class.instance_method(:length) + + expect(size).to eq(length) + end + end + describe "merging" do it "should merge in another registry" do one = described_class.new