Rspec-rails: Wrong error message when System Tests cannot run

Created on 18 Dec 2017  路  16Comments  路  Source: rspec/rspec-rails

I struggled quite long with this error message:

System test integration requires Rails >= 5.1 and has a hard dependency on a webserver and capybara, please add capybara to your Gemfile and configure a webserver (e.g. Capybara.server = :webrick) before attempting to use system tests.

which is very detailed but was actually pointing me in the wrong direction. After manually checking what was going on here I found out that the original exception was the following:

irb(main):002:0> require 'action_dispatch/system_test_case'
LoadError: cannot load such file -- rack/handler/puma

and therefore the fact that I did not have puma in by test group of Gemfile.

I would suggest to not suppress the original error and print also the original stacktrace to give proper information about what is going on. If you agree I'll open a PR.

Most helpful comment

It would be nice if the original error message was re-raised. The error in my case that was swallowed is:

Gem::LoadError:
  can't activate capybara (~> 2.13), already activated capybara-3.0.2. Make sure all dependencies are added to Gemfile.

Rspec's suggestion to install capybara is misleading because I do have

gem "capybara"

in my Gemfile, it's just that capybara's recent release of version 3.0 conflicts with Rails's runtime requirement of ~> 2.13.

It looks like Rails has since loosened the requirement, but people will still run into this on certain released versions of Rails.

All 16 comments

The warning is correct, you had not configured your web server, in your case puma, simply raising the original error was naturally the original behaviour but it caused bug reports, but it's not a bug, it's a configuration problem.

If you have a sensible suggestion on how to improve the warning we'd welcome the feedback

I just tried removing puma from my app and change it to :webrick and run into this same issue. rspec-rails would keep telling me to add Capybara.server = :webrick even though I had already added it.

Turns out this has been fixed in rails' master, after manually removing that require everything went fine.

On a similar note:

require 'action_dispatch/system_test_case'

(from here) raises

LoadError: cannot load such file -- capybara/minitest

which is causing me to get this error. So I'd support the OP in his suggestion to print the original stacktrace alongside this message.

The problem is the stack trace is misleading in the majority of cases, as the problem is improper configuration, in your case it looks like you hadn't added Capybara to the Gemfile as the message warns about.

Thinking about it I think I'd support adding a message about trying to require 'action_dispatch/system_test_case' manually to diagnose the issue.

We could warn separately about capybara, but the require 'action_dispatch/system_test_case' line also depends on a specific version of Capybara, so the message would probably stay the same.

Anyways, my issue ended up being a bug in Rails. This rescue made it difficult to find the culprit (since I already had webrick on my Gemfile and Capybara.server = :webrick properly configured).

Maybe the message should be kept for rails 5.2, but say that puma as a webserver is actually required for rails 5.1.

Puma isn't required for Rails 5.1, its just the default, the webserver trick normally works if done at the right time.

Really? How can avoid this require to fail without having puma in my Gemfile?

I guess I could rescue it, but you're rescuing it for me and aborting...

Hmm, I was under the impression that Rails depended on puma, but maybe it just puts it in the Gemfile for you. This abort is basically "hey Rails system testing isn't working and you're trying to use it".

Remember we are just a thin wrapper around Rails.

Yeah, I was just suggesting a friendlier message, since the webserver is not really switchable in rails 5.1 (unintentionally, due to Rails bugs). It works properly in rails 5.2 though.

Maybe I should request the fixes in railsto be backported to 5.1, but it's not really that much of a big deal now for me.

It would be nice if the original error message was re-raised. The error in my case that was swallowed is:

Gem::LoadError:
  can't activate capybara (~> 2.13), already activated capybara-3.0.2. Make sure all dependencies are added to Gemfile.

Rspec's suggestion to install capybara is misleading because I do have

gem "capybara"

in my Gemfile, it's just that capybara's recent release of version 3.0 conflicts with Rails's runtime requirement of ~> 2.13.

It looks like Rails has since loosened the requirement, but people will still run into this on certain released versions of Rails.

@JonRowe my suggestion on how to improve the message is to also print the original exception.
I wrote that in the first comment; if you think that could be useful I'll open a PR.
Due to the amount of messages in this thread seems like something that could save some pain/time to people.

The original error is printed now via #1959

@abevoelker I have the same issue as you did. Were you able to upgrade to capybara to v3 while remaining on Rails 5.1.x? Or you remained on capybara v2 for now?

Was this page helpful?
0 / 5 - 0 ratings