From 8b49a83ea8b65f1a5a9cbef50d0d73a7dd4717c6 Mon Sep 17 00:00:00 2001 From: Rich Dammkoehler Date: Mon, 10 Dec 2012 20:56:39 -0600 Subject: [PATCH] raises exception when remote socket end disconnects --- lib/cucumber/wire_support/connection.rb | 1 + spec/cucumber/wire_support/connection_spec.rb | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/lib/cucumber/wire_support/connection.rb b/lib/cucumber/wire_support/connection.rb index 8356df47bf..018b7841f7 100644 --- a/lib/cucumber/wire_support/connection.rb +++ b/lib/cucumber/wire_support/connection.rb @@ -42,6 +42,7 @@ def fetch_data_from_socket(timeout) else Timeout.timeout(timeout) { socket.gets } end + raise exception({'message' => "Remote Socket with #{@config.host}:#{@config.port} closed."}) if raw_response.nil? WirePacket.parse(raw_response) end diff --git a/spec/cucumber/wire_support/connection_spec.rb b/spec/cucumber/wire_support/connection_spec.rb index 2d582c64f8..81b42edbe0 100644 --- a/spec/cucumber/wire_support/connection_spec.rb +++ b/spec/cucumber/wire_support/connection_spec.rb @@ -19,6 +19,14 @@ def timeout(message = nil) return :default_timeout if message.nil? @custom_timeout[message] || Configuration::DEFAULT_TIMEOUTS.fetch(message) end + + def host + 'localhost' + end + + def port + '3902' + end end before(:each) do @@ -39,6 +47,14 @@ def timeout(message = nil) handler = mock(:handle_response => :response) @connection.call_remote(handler, :foo, []).should == :response end + + it "raises an exception on remote connection closed" do + @config.custom_timeout[:foo] = :never + @socket.stub(:gets => nil) + lambda { + @connection.call_remote(nil, :foo, []) + }.should raise_error(WireException, 'Remote Socket with localhost:3902 closed.') + end end end end