Don't try to read empty responses (fixes issues on jruby)

This commit is contained in:
Joe Ferris 2012-05-04 16:00:21 -04:00
parent 665e0fc729
commit 99c3c9ae73
2 changed files with 19 additions and 3 deletions

View File

@ -143,9 +143,13 @@ class Capybara::Driver::Webkit
def read_response
response_length = @connection.gets.to_i
response = @connection.read(response_length)
response.force_encoding("UTF-8") if response.respond_to?(:force_encoding)
response
if response_length > 0
response = @connection.read(response_length)
response.force_encoding("UTF-8") if response.respond_to?(:force_encoding)
response
else
""
end
end
def default_proxy_options

View File

@ -158,4 +158,16 @@ describe Capybara::Driver::Webkit::Browser do
@proxy_requests.size.should == 0
end
end
it "doesn't try to read an empty response" do
connection = stub("connection")
connection.stub(:puts)
connection.stub(:print)
connection.stub(:gets).and_return("ok\n", "0\n")
connection.stub(:read).and_raise(StandardError.new("tried to read empty response"))
browser = Capybara::Driver::Webkit::Browser.new(connection)
expect { browser.visit("/") }.not_to raise_error(/empty response/)
end
end