spec/klomp/connection_spec.rb in klomp-1.0.3 vs spec/klomp/connection_spec.rb in klomp-1.0.4

- old
+ new

@@ -7,16 +7,17 @@ Given(:options) { { "login" => "admin", "passcode" => "password", "logger" => logger } } Given(:socket) { double(TCPSocket, gets:data, write:nil, set_encoding:nil, close:nil) } Given(:logger) { double("Logger", error:nil, warn:nil, info:nil, debug:nil).as_null_object } Given(:subscriber) { double "subscriber", call:nil } Given(:thread) { double Thread } + Given(:sentinel) { double Klomp::Sentinel, alive?:true } Given do IO.stub!(:select).and_return([[socket], [socket]]) TCPSocket.stub!(:new).and_return socket Thread.stub!(:new).and_return {|*args,&blk| thread.stub!(:block => blk); thread } - Klomp::Sentinel.stub!(new: double("sentinel")) + Klomp::Sentinel.stub!(new: sentinel) end context "new" do When { Klomp::Connection.new server, options } @@ -271,9 +272,19 @@ context "and starts reconnect sentinel" do Then do expect_publish.to raise_error(SystemCallError) Klomp::Sentinel.should have_received(:new).with(connection) + end + + context "only once" do + + Then do + expect_publish.to raise_error(SystemCallError) + connection.send(:go_offline, begin; raise "error"; rescue; $!; end) + Klomp::Sentinel.should have_received(:new).with(connection).once + end + end end end