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

  • Home
  • SEARCH
  • 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 554373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:42:10+00:00 2026-05-13T11:42:10+00:00

I have a block of code like this: def some_method begin do_some_stuff rescue WWW::Mechanize::ResponseCodeError

  • 0

I have a block of code like this:

def some_method
  begin
    do_some_stuff
  rescue WWW::Mechanize::ResponseCodeError => e
    if e.response_code.to_i == 503
      handle_the_situation
    end
  end
end

I want to test what’s going on in that if e.response_code.to_i == 503 section. I can mock do_some_stuff to throw the right type of exception:

whatever.should_receive(:do_some_stuff).and_raise(WWW::Mechanize::ResponseCodeError)

but how do I mock the error object itself to return 503 when it receives “response_code”?

  • 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-13T11:42:10+00:00Added an answer on May 13, 2026 at 11:42 am
    require 'mechanize'
    
    class Foo
    
      def some_method
        begin
          do_some_stuff
        rescue WWW::Mechanize::ResponseCodeError => e
          if e.response_code.to_i == 503
            handle_the_situation
          end
        end
      end
    
    end
    
    describe "Foo" do
    
      it "should handle a 503 response" do
        page = stub(:code=>503)
        foo = Foo.new
        foo.should_receive(:do_some_stuff).with(no_args)\
        .and_raise(WWW::Mechanize::ResponseCodeError.new(page))
        foo.should_receive(:handle_the_situation).with(no_args)
        foo.some_method
      end
    
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 343k
  • Answers 344k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer It refers to the size of the "wires" in a… May 14, 2026 at 5:32 am
  • Editorial Team
    Editorial Team added an answer etags is short for "Emacs tags", not "exuberant ctags". It… May 14, 2026 at 5:32 am
  • Editorial Team
    Editorial Team added an answer Try setting the scrollHeight option. I would suggest using the… May 14, 2026 at 5:32 am

Related Questions

I have an app where I need to prevent users from editing data while
I have a class with some methods. It's supersekret but I've reproduced what I
I have a class that contains some private attributes. What I would like to
Let's say I have some code (using CherryPy) that looks like this: import cherrypy
I am making an activeresource call to a service, and I'd like some custom

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.