Reputation: 4595
I'm using capybara to run my rspec features. The issue is that when an error occurs in the rails stack while running the spec, the error doesn't "pass through" to rspec and cause the test to fail. The error page is generated and checked by rspec.
So, I don't get an immediate failure with an error on my specs. I only get an error when I look for content, or try to fill in a field, that doesn't appear on the error page.
This is not what I want. I want errors encountered in the rails stack (controller, views, etc.) to cause rspec to fail immediately.
How can I resolve this?
Upvotes: 3
Views: 1687
Reputation: 7522
Capybara is capable of raising server errors as failures on your tests, provided it's hooking into Rails correctly (see: the last bullet point on the "Gotchas" section of the README).
Make sure that you:
require 'capybara/rails'
in your spec_helper.rb
or rails_helper.rb
filevisit 'http://localhost:3000/mypage
is wrong, visit '/mypage'
is right).If the above are all true, and you're still seeing the behavior, something else is likely wrong with your setup. Try changing your driver back to the default (Rack::Test) and see if the issue persists.
Edit: as explained in the comments below, the issue here was that the better_errors
gem was loading in the test environment, which rescued the error and displayed the pretty error page before Capybara and Rspec got a chance to see the error. Moving it to the development
-only group in the Gemfile fixed the issue. This thread held the answer.
Upvotes: 3
Reputation: 7067
You can use following capybara
method to force the scenario to fail.
fail(msg = "Error. Check log for details.")
Upvotes: 0
Reputation: 12700
Create a test case for your controller / view and test it before doing any integration tests.
That's the right way to do it :
Upvotes: 1