title: Rspec false positive because failure exception is rescued in code being tested
body: <p>I have an rspec test that I expect to fail, but it is passing because the code that it is testing rescues the exception that rspec raises. Here's an example of the situation:</p>
  
  <pre><code>class Thing do
  
    def self.method_being_tested( object )
      # ... do some stuff
  
      begin
        object.save!
      rescue Exception =&gt; e
        # Swallow the exception and log it
      end
    end
  
  end
  </code></pre>
  
  <p>In the rspec file:</p>
  
  <pre><code>describe "method_being_tested" do
    it "should not call 'save!' on the object passed in" do
      # ... set up the test conditions
  
      mock_object.should_not_receive( :save! )
      Thing.method_being_tested( mock_object )
    end
  end
  </code></pre>
  
  <p>I knew that the execution was reaching the "object.save!" line of the method being tested, and the test should therefore be failing, but the test passes. Using the debugger in the rescue block, I find the following:</p>
  
  <pre><code>(rdb:1) p e # print the exception object "e"
  #&lt;RSpec::Mocks::MockExpectationError: (Mock "TestObject_1001").save!
      expected: 0 times
      received: 1 time&gt;
  </code></pre>
  
  <p>So basically the test is failing but, but the failure is being suppressed by the very code it is trying to test. I cannot figure out a viable way to stop this code from swallowing Rspec exceptions without somehow compromising the code. I don't want the code to explicitly check if the exception is an Rspec exception, because that is bad design (tests should be written for code, code should never be written for tests). But I also can't check that the exception is any particular type that I DO want it to catch, because I want it to catch ANYTHING that could be raised in a normal production environment.</p>
  
  <p>Someone must have had this problem before me! Please help me find a solution.</p>