spec/lib/flapjack/gateways/oobetet_spec.rb in flapjack-0.6.53 vs spec/lib/flapjack/gateways/oobetet_spec.rb in flapjack-0.6.54

- old
+ new

@@ -1,9 +1,9 @@ require 'spec_helper' require 'flapjack/gateways/oobetet' -describe Flapjack::Gateways::Oobetet do +describe Flapjack::Gateways::Oobetet, :logger => true do let(:config) { {'server' => 'example.com', 'port' => '5222', 'jabberid' => 'flapjack@example.com', 'password' => 'password', @@ -17,21 +17,19 @@ let(:stanza) { mock('stanza') } it "raises an error if a required config setting is not set" do Socket.should_receive(:gethostname).and_return('thismachine') - fo = Flapjack::Gateways::Oobetet.new - fo.bootstrap(:config => config.delete('watched_check')) + fo = Flapjack::Gateways::Oobetet.new(:config => config.delete('watched_check'), :logger => @logger) lambda { fo.setup }.should raise_error end it "hooks up event handlers to the appropriate methods" do - fo = Flapjack::Gateways::Oobetet.new - fo.bootstrap(:config => config) + fo = Flapjack::Gateways::Oobetet.new(:config => config, :logger => @logger) EventMachine::Synchrony.should_receive(:next_tick).exactly(3).times.and_yield fo.should_receive(:register_handler).with(:ready).and_yield(stanza) fo.should_receive(:on_ready).with(stanza) @@ -44,34 +42,30 @@ fo.register_handlers end it "joins a chat room after connecting" do - fo = Flapjack::Gateways::Oobetet.new - fo.bootstrap(:config => config) + fo = Flapjack::Gateways::Oobetet.new(:config => config, :logger => @logger) fo.should_receive(:write).with(an_instance_of(Blather::Stanza::Presence)) fo.should_receive(:write).with(an_instance_of(Blather::Stanza::Message)) fo.on_ready(stanza) end it "reconnects when disconnected (if not quitting)" do - fo = Flapjack::Gateways::Oobetet.new - fo.bootstrap(:config => config) + fo = Flapjack::Gateways::Oobetet.new(:config => config, :logger => @logger) EventMachine::Timer.should_receive(:new).with(1).and_yield fo.should_receive(:connect) ret = fo.on_disconnect(stanza) ret.should be_true end it "records times of a problem status messages" do - fo = Flapjack::Gateways::Oobetet.new - fo.bootstrap(:config => config) - + fo = Flapjack::Gateways::Oobetet.new(:config => config, :logger => @logger) fo.setup t = Time.now stanza.should_receive(:body).and_return( %q{PROBLEM: "PING" on foo.bar.net} ) @@ -83,13 +77,11 @@ fo_times.should have_key(:last_problem) fo_times[:last_problem].should == t.to_i end it "records times of a recovery status messages" do - fo = Flapjack::Gateways::Oobetet.new - fo.bootstrap(:config => config) - + fo = Flapjack::Gateways::Oobetet.new(:config => config, :logger => @logger) fo.setup t = Time.now stanza.should_receive(:body).and_return( %q{RECOVERY: "PING" on foo.bar.net} ) @@ -101,13 +93,11 @@ fo_times.should have_key(:last_recovery) fo_times[:last_recovery].should == t.to_i end it "records times of an acknowledgement status messages" do - fo = Flapjack::Gateways::Oobetet.new - fo.bootstrap(:config => config) - + fo = Flapjack::Gateways::Oobetet.new(:config => config, :logger => @logger) fo.setup t = Time.now stanza.should_receive(:body).and_return( %q{ACKNOWLEDGEMENT: "PING" on foo.bar.net} ) @@ -123,18 +113,18 @@ it "runs a loop checking for recorded problems" do timer = mock('timer') timer.should_receive(:cancel) EM::Synchrony.should_receive(:add_periodic_timer).with(60).and_return(timer) - fo = Flapjack::Gateways::Oobetet.new - fo.bootstrap(:config => config) + fo = Flapjack::Gateways::Oobetet.new(:config => config, :logger => @logger) fo.should_receive(:register_handler).exactly(3).times - fo.should_receive(:connect) - fo.should_receive(:should_quit?).twice.and_return(false, true) - EM::Synchrony.should_receive(:sleep).with(10) + EM::Synchrony.should_receive(:sleep).with(10) { + fo.instance_variable_set('@should_quit', true) + nil + } - fo.main + fo.start end end