spec/lib/flapjack/jabber_spec.rb in flapjack-0.6.39 vs spec/lib/flapjack/jabber_spec.rb in flapjack-0.6.40
- old
+ new
@@ -13,21 +13,16 @@
}
}
let(:stanza) { mock('stanza') }
- it "is initialized" do
- fj = Flapjack::Jabber.new
- fj.should_not be_nil
- end
-
it "hooks up event handlers to the appropriate methods" do
Socket.should_receive(:gethostname).and_return('thismachine')
fj = Flapjack::Jabber.new
+ Flapjack::RedisPool.should_receive(:new)
fj.bootstrap(:config => config)
- fj.should_receive(:build_redis_connection_pool)
EventMachine::Synchrony.should_receive(:next_tick).exactly(4).times.and_yield
fj.should_receive(:register_handler).with(:ready).and_yield(stanza)
fj.should_receive(:on_ready).with(stanza)
@@ -44,14 +39,13 @@
fj.setup
end
it "joins a chat room after connecting" do
fj = Flapjack::Jabber.new
+ Flapjack::RedisPool.should_receive(:new).twice
fj.bootstrap(:config => config)
- fj.should_receive(:build_redis_connection_pool)
-
fj.should_receive(:connected?).and_return(true)
fj.should_receive(:write).with(an_instance_of(Blather::Stanza::Presence))
fj.should_receive(:write).with(an_instance_of(Blather::Stanza::Message))
fj.on_ready(stanza)
@@ -77,10 +71,11 @@
Flapjack::Data::EntityCheck.should_receive(:for_event_id).
with('main-example.com:ping', :redis => redis).
and_return(entity_check)
fj = Flapjack::Jabber.new
+ Flapjack::RedisPool.should_receive(:new)
fj.bootstrap(:config => config)
fj.instance_variable_set('@redis_handler', redis)
fj.should_receive(:connected?).and_return(true)
fj.should_receive(:write).with(an_instance_of(Blather::Stanza::Message))
@@ -93,20 +88,22 @@
from = mock('from')
from.should_receive(:stripped).and_return('sender')
stanza.should_receive(:from).and_return(from)
fj = Flapjack::Jabber.new
+ Flapjack::RedisPool.should_receive(:new)
fj.bootstrap(:config => config)
fj.should_receive(:connected?).and_return(true)
fj.should_receive(:write).with(an_instance_of(Blather::Stanza::Message))
fj.on_groupchat(stanza)
end
it "reconnects when disconnected (if not quitting)" do
fj = Flapjack::Jabber.new
+ Flapjack::RedisPool.should_receive(:new)
fj.bootstrap(:config => config)
EventMachine::Timer.should_receive(:new).with(1).and_yield
fj.should_receive(:connect)
@@ -117,10 +114,11 @@
it "prompts the blocking redis connection to quit" do
redis = mock('redis')
redis.should_receive(:rpush).with('jabber_notifications', %q{{"notification_type":"shutdown"}})
fj = Flapjack::Jabber.new
+ Flapjack::RedisPool.should_receive(:new)
fj.bootstrap(:config => config)
fj.add_shutdown_event(:redis => redis)
end
@@ -134,12 +132,12 @@
redis = mock('redis')
redis.should_receive(:empty!)
fj = Flapjack::Jabber.new
+ Flapjack::RedisPool.should_receive(:new).and_return(redis)
fj.bootstrap(:config => config)
- fj.should_receive(:build_redis_connection_pool).and_return(redis)
fj.should_receive(:register_handler).exactly(4).times
fj.should_receive(:connect)
fj.should_receive(:connected?).exactly(3).times.and_return(true)
fj.should_receive(:should_quit?).exactly(4).times.and_return(false, false, true)
@@ -151,8 +149,9 @@
EventMachine::Synchrony.should_receive(:next_tick).twice.and_yield
fj.should_receive(:write).with(an_instance_of(Blather::Stanza::Message))
fj.should_receive(:close)
fj.main
+ fj.cleanup
end
end