From 2fad7a49cf8fad290a22d38d009f9bdffa56946b Mon Sep 17 00:00:00 2001 From: Ryan Souza Date: Wed, 18 Mar 2015 14:40:27 -0700 Subject: [PATCH] Forward output from server pipes ASAP If the webkit server fails to start an error is raised before the output forwarding is set up. Without output forwarding we don't get to see the error from the server making it harder to debug. --- lib/capybara/webkit/connection.rb | 2 +- spec/connection_spec.rb | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/capybara/webkit/connection.rb b/lib/capybara/webkit/connection.rb index 68523018..ac0bd7f7 100644 --- a/lib/capybara/webkit/connection.rb +++ b/lib/capybara/webkit/connection.rb @@ -59,9 +59,9 @@ def read(length) def start_server open_pipe + forward_output_in_background_thread discover_port discover_pid - forward_output_in_background_thread end def open_pipe diff --git a/spec/connection_spec.rb b/spec/connection_spec.rb index 445f284b..1dfad4cf 100644 --- a/spec/connection_spec.rb +++ b/spec/connection_spec.rb @@ -50,6 +50,17 @@ to raise_error(Capybara::Webkit::ConnectionError, error_string) end + it "gets stderr output if the server fails to start", skip_on_windows: true do + server_path = 'echo "A bad thing" >&2' + stub_const("Capybara::Webkit::Connection::SERVER_PATH", server_path) + + read_io, write_io = IO.pipe + expect { Capybara::Webkit::Connection.new(:stderr => write_io) }. + to raise_error(Capybara::Webkit::ConnectionError) + + expect(read_io).to include_response "A bad thing" + end + it "boots a server to talk to" do url = "http://#{@rack_server.host}:#{@rack_server.port}/" connection.puts "Visit"