I was put in charge of testing a non-rails web application using cucumber. I have basic testing up and running, I.E. I can do things like
Then /^the page should have a header$/ do
response_body.should have_xpath(%\//header\)
end
The next thing I wanted to test is that non-existent pages, in addition to presenting a friendly error page, are returning the correct http response code (404).
When I visit
the 404 page during the cucumber test, the following happens.
Scenario: Visit a url which does not lead to a page # features\404.feature:6
Given I try to visit a fake page # features/step_definitions/404_steps.rb:1
404 => Net::HTTPNotFound (Mechanize::ResponseCodeError)
./features/step_definitions/404_steps.rb:2:in `/^I try to visit a fake page$/'
features\404.feature:7:in `Given I try to visit a fake page'
When the page loads # features/step_definitions/home_steps.rb:5
This makes sense for testing pages that you expect to exist, but I really would like to be able to test my errors as well.
My question is, how can I rescue the Mechanize::ResponseCodeError so that I may verify the correctness of the 404 error page?
Thanks.