Read more

Test that an exception or error page is raised in Capybara

Henning Koch
December 10, 2010Software engineer at makandra GmbH

You can use these step definitions:

Then /^I should not see an error$/ do
  (200 .. 399).should include(page.status_code)
end

Then /^I should see an error$/ do
  (400 .. 599).should include(page.status_code)
end
Illustration web development

Do you need DevOps-experts?

Your development team has a full backlog? No time for infrastructure architecture? Our DevOps team is ready to support you!

  • We build reliable cloud solutions with Infrastructure as code
  • We are experts in security, Linux and databases
  • We support your dev team to perform
Read more Show archive.org snapshot

Note that you need to tag the scenario with @allow-rescue to test that an error is shown like this

@allow-rescue
Scenario: Accessing the admin area requires a login
  When I go to the admin area
  Then I should see an error

These step definitions will not work for @javascript scenarios using the selenium web-driver

@allow-rescue @javascript
Scenario: Accessing the admin area requires a login
  When I go to the admin area
  Then I should see an error
  # This throws `Capybara::Driver::Base#status_code (Capybara::NotSupportedByDriverError)`
Posted by Henning Koch to makandra dev (2010-12-10 19:02)