Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

tests would fail when run in a certain order because the way Slanger:…

…:Redis was set up to listen for messages. if the file was first loaded when EM::Hiredis.connect was stubbed the object would not receive messages for the rest of the test suite causing the integration tests to hang forever. the opposite case was that EM::Hiredis.connext was never mocked if the tests were green in particular order. fixed by explicitly deleting connections from Slanger::Redis before and after they are mocked and making pubsub subscription lazy instead of eager.
  • Loading branch information...
commit 80c1b17220dd7e15429331b739b3c472a17bba1e 1 parent 0758ca6
@stevegraham authored
View
3  .travis.yml
@@ -10,6 +10,3 @@ env:
services:
- redis-server
-script:
- - bundle exec rspec spec --tag ~@defer --order random
- - bundle exec rspec spec --tag @defer --order random
View
17 lib/slanger/redis.rb
@@ -8,7 +8,7 @@ module Redis
extend Forwardable
def_delegator :publisher, :publish
- def_delegators :subscriber, :on, :subscribe
+ def_delegators :subscriber, :subscribe
def_delegators :regular_connection, :hgetall, :hdel, :hset, :hincrby
private
@@ -22,7 +22,13 @@ def publisher
end
def subscriber
- @subscriber ||= new_connection
+ @subscriber ||= new_connection.tap do |c|
+ c.on(:message) do |channel, message|
+ message = JSON.parse message
+ c = Channel.from message['channel']
+ c.dispatch message, channel
+ end
+ end
end
def new_connection
@@ -30,12 +36,5 @@ def new_connection
end
extend self
-
- # Dispatch messages received from Redis to their destination channel.
- on(:message) do |channel, message|
- message = JSON.parse message
- c = Channel.from message['channel']
- c.dispatch message, channel
- end
end
end
View
1  spec/spec_helper.rb
@@ -26,6 +26,7 @@ def errback
config.formatter = 'documentation'
config.color = true
config.mock_framework = :mocha
+ config.order = 'random'
config.include SlangerHelperMethods
config.fail_fast = true
config.after(:each) { stop_slanger if @server_pid }
View
14 spec/unit/channel_spec.rb
@@ -1,14 +1,22 @@
require 'spec_helper'
require 'slanger'
-describe 'Slanger::Webhook', defer: true do
+def clear_redis_connections
+ Slanger::Redis.instance_variables.each do |ivar|
+ Slanger::Redis.send :remove_instance_variable, ivar
+ end
+end
+
+describe 'Slanger::Channel' do
let(:channel) { Slanger::Channel.create channel_id: 'test' }
- before(:all) do
+ before(:each) do
EM::Hiredis.stubs(:connect).returns stub_everything('redis')
+ clear_redis_connections
end
- after(:all) do
+ after(:each) do
+ clear_redis_connections
EM::Hiredis.unstub(:connect)
end
Please sign in to comment.
Something went wrong with that request. Please try again.