Skip to content

Commit

Permalink
String inspect warnings for bare Celluloid objects
Browse files Browse the repository at this point in the history
  • Loading branch information
tarcieri committed Sep 8, 2012
1 parent 9c1fa92 commit 3af0db8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
8 changes: 6 additions & 2 deletions lib/celluloid.rb
Expand Up @@ -6,7 +6,11 @@
module Celluloid
extend self # expose all instance methods as singleton methods

SHUTDOWN_TIMEOUT = 120 # How long actors have to terminate
# How long actors have to terminate
SHUTDOWN_TIMEOUT = 120

# Warning message added to Celluloid objects accessed outside their actors
BARE_OBJECT_WARNING_MESSAGE = "WARNING: BARE CELLULOID OBJECT "

class << self
attr_accessor :logger # Thread-safe logger class
Expand Down Expand Up @@ -202,7 +206,7 @@ module InstanceMethods
def wrapped_object; self; end

def inspect
str = "#<Celluloid::Actor(#{self.class}:0x#{object_id.to_s(16)})"
str = "#<#{Celluloid::BARE_OBJECT_WARNING_MESSAGE}(#{self.class}:0x#{object_id.to_s(16)})"
ivars = instance_variables.map do |ivar|
"#{ivar}=#{instance_variable_get(ivar).inspect}"
end
Expand Down
2 changes: 1 addition & 1 deletion lib/celluloid/proxies/actor_proxy.rb
Expand Up @@ -20,7 +20,7 @@ def _send_(meth, *args, &block)
end

def inspect
Actor.call @mailbox, :inspect
Actor.call(@mailbox, :inspect).sub(::Celluloid::BARE_OBJECT_WARNING_MESSAGE, "Celluloid::Actor")
rescue DeadActorError
"#<Celluloid::Actor(#{@klass}) dead>"
end
Expand Down
7 changes: 7 additions & 0 deletions spec/support/actor_examples.rb
Expand Up @@ -207,6 +207,13 @@ def to_s
actor.wrapped_object.should be_a actor_class
end

it "warns about leaked wrapped objects via #inspect" do
actor = actor_class.new "Troy McClure"

actor.inspect.should_not include Celluloid::BARE_OBJECT_WARNING_MESSAGE
actor.wrapped_object.inspect.should include Celluloid::BARE_OBJECT_WARNING_MESSAGE
end

describe 'mocking methods' do
let(:actor) { actor_class.new "Troy McClure" }

Expand Down

0 comments on commit 3af0db8

Please sign in to comment.