When running the following script:
require "capybara"
Capybara.server do |app, port|
require 'rack/handler/thin'
Rack::Handler::Thin.run(app, :Port => port)
end
html = DATA.read
app = proc { |env| [200, { "Content-Type" => "text/html" }, [html] ] }
sess = Capybara::Session.new(:selenium, app)
sess.visit("/")
__END__
<!doctype html>
<html>
<body>
</body>
</html>
I can see from the command line that the thin server has booted. I can also manually visit the URL and it works.
Error:
Thin web server (v1.7.0 codename Dunder Mifflin)
Maximum connections set to 1024
Listening on localhost:58347, CTRL+C to stop
/Users/stevebooks/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/capybara-2.7.1/lib/capybara/server.rb:112:in `rescue in boot': Rack application timed out during boot (RuntimeError)
Gem version: 2.7.1
Ruby version: 2.3.1
Thin Version: 1.7.0
From what I can tell, inside Capybara::Server, the @server_thread.join(0) always returns false. This is used to determine if the server is responsive?
More info:
Capybara.server_host = "localhost" fixes it. 馃槥
This took a while to debug. Anything we can do here so that others don't run into the same issue?
You should be using the 3 parameter version of the server block which also provides the expected host
Capybara.register_server :thin do |app, port, host|
require 'rack/handler/thin'
Rack::Handler::Thin.run(app, :Port => port, :Host => host)
end
Capybara.server = :thin
@stevebooks I'm facing a similar problem. Can you show me your full configuration and versions please?
@twalpole I've tried your config, but get this error:
undefined method 'register_server' for Capybara:Module
Not sure if your solution does not work for me since I have "poltergeist" instead of "selenium".
@PirunSeng switching to the 3 parameter version worked for me as @twalpole suggested. What version of capybara are you running? Mine is 2.7.1
@stevebooks my capybara is 2.5.
When I have Capybara.register_server ... I get an error "undefined register_server for Capybara module..."
Try upgrading, they might have changed the API
I have tried upgrading to 2.7 too, but I got bundle error that said my Capybara is locked with 2.5.
Unlock it. It is probably set to an exact version number in your Gemfile
@PirunSeng register_server was added in 2.7. That version was released in early 2016 so is pretty old now, and 2.5 is over two years old, so pretty much obsolete. The current release is 2.15.4, and you should upgrade. If bundler is telling you you're locked to 2.5 then specify higher than that in your Gemfile and see what package is locking to 2.5 and upgrade that too (or just search through your Gemfile.lock for capybara and see what package is locking to 2.5).
@stevebooks @twalpole thank guys! My problem solved as your suggestions.
I unlocked the Capybara version and installed Capybara 2.15.4. So my environments are as the following:
Ruby 2.3.3
Capybara 2.15.4
Thin 1.7
And in my spec_helper.rb I have this:
Capybara.register_server :thin do |app, port, host|
require 'rack/handler/thin'
Rack::Handler::Thin.run(app, :Port => port, :Host => host)
end
Capybara.server = :thin
Most helpful comment
You should be using the 3 parameter version of the server block which also provides the expected host