Search code examples
ruby-on-railsrubycucumbercapybaracapybara-webkit

Capybara & Cucumber - feature with expected controller exceptions fails


I recently switched to capybara 2.5.0 & webkit 1.7.1.

I have a cucumber feature in which I want to check my javascript handling of a failed ajax request.

With previous capybara version:

  • I stubbed an API request to respond with 400 thus the controller action raised this exception (RestClient::BadRequest) without rescuing it.
  • My javascript was showing a custom message in case the ajax request failed.
  • The feature didn't fail when the exception was raised by the controller, the flow was continuing normally. The ajax request failed and my js was handling it as expected.

With the new capybara version: The feature fails when the exception takes place at the controller level.

I don't want the feature to stop at that level but to continue with the error response to the browser so I can handle the error with my js.


Solution

  • I would guess this behavior change isn't because of the capybara update, but rather because you moved the web_console gem out of the test group. That meant exceptions were never actually being raised in the server because web_console caught them all. Now that exceptions aren't being caught Capybara is displaying them. Capybara has the Capybara.raise_server_errors setting to enable/disable that behavior.

    Capybara.raise_server_errors = false