From 3ed396c34ba5ebd804cde9ed7a9c6cdd1dd3d640 Mon Sep 17 00:00:00 2001 From: slyphon Date: Tue, 22 May 2012 18:14:12 +0000 Subject: [PATCH 1/2] add a method to clear the registry (for use in tests) --- lib/celluloid/registry.rb | 11 +++++++++++ spec/celluloid/registry_spec.rb | 10 ++++++++++ 2 files changed, 21 insertions(+) diff --git a/lib/celluloid/registry.rb b/lib/celluloid/registry.rb index 9e0e5a92..0caf0a6e 100644 --- a/lib/celluloid/registry.rb +++ b/lib/celluloid/registry.rb @@ -31,5 +31,16 @@ def [](name) def registered @@registry_lock.synchronize { @@registry.keys } end + + # removes and returns all registered actors as a hash of `name => actor` + # can be used in testing to clear the registry + def clear_registry + hash = nil + @@registry_lock.synchronize do + hash = @@registry.dup + @@registry.clear + end + hash + end end end diff --git a/spec/celluloid/registry_spec.rb b/spec/celluloid/registry_spec.rb index dcf91b12..f2431489 100644 --- a/spec/celluloid/registry_spec.rb +++ b/spec/celluloid/registry_spec.rb @@ -29,4 +29,14 @@ def sing_for(person) Celluloid::Actor[:marilyn] = Marilyn.new Celluloid::Actor[:marilyn].name.should == :marilyn end + + describe :clear do + it "should return a hash of registered actors and remove them from the registry" do + Celluloid::Actor[:marilyn] ||= Marliyn.new + rval = Celluloid::Actor.clear_registry + rval.should be_kind_of(Hash) + rval.should have_key(:marilyn) + rval[:marilyn].wrapped_object.should be_instance_of(Marilyn) + end + end end From 51b86c9dec23fdf9a8b3c64d69e71b1cbc62e264 Mon Sep 17 00:00:00 2001 From: slyphon Date: Wed, 13 Jun 2012 13:44:53 +0000 Subject: [PATCH 2/2] actually assert the registry is empty --- spec/celluloid/registry_spec.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/celluloid/registry_spec.rb b/spec/celluloid/registry_spec.rb index 2f4353e3..165e73bc 100644 --- a/spec/celluloid/registry_spec.rb +++ b/spec/celluloid/registry_spec.rb @@ -37,6 +37,7 @@ def sing_for(person) rval.should be_kind_of(Hash) rval.should have_key(:marilyn) rval[:marilyn].wrapped_object.should be_instance_of(Marilyn) + Celluloid::Actor.registered.should be_empty end end end