Search code examples
ruby-on-railsrspeccapybarapoltergeist

Capybara: First test times out with 'failed to reach server, check DNS and/or server status', all other tests work fine


I maintain several extension for the Spree/Solidus Rails platform(s), and for some reason on one extension in particular I’m having a Capybara issue I can’t seem to track down.

Once I build a test environment, the first test of the first run through the specs always fails, with the following:

Capybara::Poltergeist::StatusFailError:
   Request to 'http://127.0.0.1:52234/products' failed to reach server,
   check DNS and/or server status - Timed out with no open resource requests

All subsequent specs pass. If I run bundle exec rspec spec again, then all specs pass.

I have tried increasing the Capybara timeout values to super high numbers:

RSpec.configure do |config|
  config.include Spree::TestingSupport::CapybaraHelpers, type: :feature
  Capybara.register_driver(:poltergeist) do |app|
    Capybara::Poltergeist::Driver.new app, timeout: 90
  end
  Capybara.javascript_driver = :poltergeist
  Capybara.default_max_wait_time = 90
end

But it seems to have no effect.

All my Travis builds fail on the first spec of the first run (and pass on everything else), which is making it hard to maintain the project, as all PRs look red.

Any ideas what might be going on here?


Solution

  • Most likely this is failing when Rails processes the asset pipeline at the first request. Try precompiling the test mode assets before running the test or increase the timeout in the driver registration even more. The Capybara.default_max_wait_time shouldn't affect this at all.