Add #length and #size methods to Registry
This commit is contained in:
parent
60a8472891
commit
bc4bbb9fc0
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue