From c0b107ff6975b3f181dd9e3d8dbcb1e900c3336d Mon Sep 17 00:00:00 2001 From: Seth Vargo Date: Thu, 23 Oct 2014 11:24:13 -0400 Subject: [PATCH] Add Registry#empty? to check if a registry has any items --- lib/vagrant/registry.rb | 7 +++++++ test/unit/vagrant/registry_test.rb | 11 +++++++++++ 2 files changed, 18 insertions(+) diff --git a/lib/vagrant/registry.rb b/lib/vagrant/registry.rb index 4e401777b..bb8521f74 100644 --- a/lib/vagrant/registry.rb +++ b/lib/vagrant/registry.rb @@ -59,6 +59,13 @@ module Vagrant end alias_method :size, :length + # Checks if this registry has any items. + # + # @return [Boolean] + def empty? + @items.keys.empty? + end + # 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 94364404c..12ccbec5c 100644 --- a/test/unit/vagrant/registry_test.rb +++ b/test/unit/vagrant/registry_test.rb @@ -116,6 +116,17 @@ describe Vagrant::Registry do end end + describe "#empty" do + it "should return true when the registry is empty" do + expect(instance.empty?).to be(true) + end + + it "should return false when there is at least one element" do + instance.register("foo") { } + expect(instance.empty?).to be(false) + end + end + describe "merging" do it "should merge in another registry" do one = described_class.new