title: mocking an error/exception in rspec (not just its type)
body: <p>I have a block of code like this:</p>
  
  <pre><code>def some_method
    begin
      do_some_stuff
    rescue WWW::Mechanize::ResponseCodeError =&gt; e
      if e.response_code.to_i == 503
        handle_the_situation
      end
    end
  end
  </code></pre>
  
  <p>I want to test what's going on in that <code>if e.response_code.to_i == 503</code> section.  I can mock do_some_stuff to throw the right type of exception:</p>
  
  <pre><code>whatever.should_receive(:do_some_stuff).and_raise(WWW::Mechanize::ResponseCodeError)
  </code></pre>
  
  <p>but how do I mock the error object itself to return 503 when it receives "response_code"?</p>