diff --git a/lib/celluloid_pubsub/reactor.rb b/lib/celluloid_pubsub/reactor.rb index a0c3f3b..0b73a79 100644 --- a/lib/celluloid_pubsub/reactor.rb +++ b/lib/celluloid_pubsub/reactor.rb @@ -329,10 +329,23 @@ def unsubscribe_clients(channel, _json_data) def shutdown @shutting_down = true log_debug "#{self.class} tries to 'shutdown'" - @websocket.close if ENV['RACK_ENV'] != 'test' && @websocket.present? && !@websocket.closed? + @websocket.close if close_websocket? && @websocket.present? && !@websocket.closed? terminate end + # In tests we sometimes mock the websocket to b e a double + # in which case we can't call close on the double + # because it's outside of the test + # @see Celluloid.shutdown in spec_helper + # + # @return [void] + # + # @api public + def close_websocket? + return true if ENV['RACK_ENV'] != 'test' + defined?(Rspec::Mocks::Double) && !websocket.is_a?(Rspec::Mocks::Double) + end + # this method will add the current actor to the list of the subscribers {#add_subscriber_to_channel} # and will write to the socket a message for succesful subscription #