Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7629587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:52:21+00:00 2026-05-31T05:52:21+00:00

I was put in charge of testing a non-rails web application using cucumber. I

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T05:52:23+00:00Added an answer on May 31, 2026 at 5:52 am

    From your first example it looks like you’re using rspec, so you could use it’s assertions to verify the error:

    When /^I try to visit a fake page$/ do
        lambda { 
            Mechanize.new.get('http://example.org/fake_page.html')
        }.should raise_error(Mechanize::ResponseCodeError, /404/)
    end
    

    Edit: even better, you can use the block syntax of raise_error to verify the response code directly:

    .should raise_error{|e| e.response_code.should == '404'}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have recently been put in charge of debugging two different programs which will
We're trying to put together kiosk solution where we can charge people by hour
I have some doubts regarding In-Application-Billing in android: Can i test it with different
I have a web application. It does a TON of data reads on small
I am running rails 3.1.3 with postgresql 9.1 and testing with Rspec. This is
Hellu, I want to put a password protection on my entire web application for
I have been developing and testing with inline jQuery. I am using CodeIgniter and
I have a question about testing the queries in a transaction. I've been using
I really have a strange situation. I'm making a Linux multi-threaded C application using
I was recently put in charge of the wiki for the development team. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.