Skip to content

Commit

Permalink
Merge pull request celluloid#47 from motionbox/clear_registry
Browse files Browse the repository at this point in the history
add a method to clear the registry (for use in tests)
  • Loading branch information
tarcieri committed Jun 13, 2012
2 parents d7d1c77 + 51b86c9 commit 011db4a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/celluloid/registry.rb
Expand Up @@ -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
11 changes: 11 additions & 0 deletions spec/celluloid/registry_spec.rb
Expand Up @@ -29,4 +29,15 @@ 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)
Celluloid::Actor.registered.should be_empty
end
end
end

0 comments on commit 011db4a

Please sign in to comment.