Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

patch the JRuby TCPSocket#read(0) (originated by @duelinmarkers) #220

Closed
wants to merge 3 commits into from

2 participants

@dnagir

See #197

@halogenandtoast

Any chance you can add a test for this. With a test case I'd have no problem merging this in.

@dnagir

@halogenandtoast I've added "blind" specs (couldn't run those due to some local installation issues). Please double check those before merging. Sorry for that, hope that's not a big hassle.

@halogenandtoast

@dnagir Sorry for taking so long to get back to you. The blind specs you wrote fail because they're calling a private method for subject { browser.read_response }. I tried very briefly to fix this, but wasn't successful. I want to come back to this, but if you can get your tests working before I do, that would help greatly.

@derekprior derekprior referenced this pull request from a commit in derekprior/capybara-webkit
@derekprior derekprior Read from socket only when there's content
This works around an issue with the TCPSocket class in jruby that causes
it to block indefinitely while trying to read a non-existent response.
MRI will immediately return an empty string.

The fix was to a private method and required stubbing an instance
variable not publically accessible so the specs have to get kind of cute
to work around this.

This pull request closes issue #197 and supersedes pull request #220
(which had broken specs). Credit @duelinmarkers.
e5d0a78
@halogenandtoast

@jferris and I refactored the code a bit to make testing this easier and added the fix for this and merged it into master. Closing this pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 29, 2011
  1. @dnagir
Commits on Feb 19, 2012
  1. @dnagir

    added specs for the issue #220

    dnagir authored
  2. @dnagir

    use ruby 1.8 hashes

    dnagir authored
This page is out of date. Refresh to see the latest.
Showing with 24 additions and 1 deletion.
  1. +1 −1  lib/capybara/driver/webkit/browser.rb
  2. +23 −0 spec/browser_spec.rb
View
2  lib/capybara/driver/webkit/browser.rb
@@ -199,7 +199,7 @@ def check
def read_response
response_length = @socket.gets.to_i
- response = @socket.read(response_length)
+ response = response_length > 0 ? @socket.read(response_length) : ''
response.force_encoding("UTF-8") if response.respond_to?(:force_encoding)
response
end
View
23 spec/browser_spec.rb
@@ -175,4 +175,27 @@
@proxy_requests.size.should == 0
end
end
+
+
+ describe '#read_response' do
+ let(:out) { stub 'OUT', :gets => line }
+ let(:browser) { Capybara::Driver::Webkit::Browser.new(:stdout => out) }
+ subject { browser.read_response }
+
+ context "when there's something to read" do
+ let(:line) { '3' }
+ it "should read from socket" do
+ out.should_receive(:read).with(3).and_return 'abc'
+ subject
+ end
+ end
+ context "when there's nothing to read" do
+ let(:line) { '' }
+ it "should not read from socket" do
+ out.should_not_receive(:read)
+ subject
+ end
+ end
+ end
+
end
Something went wrong with that request. Please try again.