title: Run an RSpec example with exception-raising code without raise_error
body: <p>To test whether code raises an exception using RSpec, you can use a block with <code>raise_error</code>:</p>
  
  <pre><code>it "raises an exception" do
    expect { raise_an_exception }.to raise_error
  end
  </code></pre>
  
  <p>Let's say you want to test whether the code that raises an exception does something else as well. Must you always use the above syntax?</p>
  
  <pre><code># testing whether an error is raised
  it "reraises exceptions" do
    expect { log_exception_and_reraise }.to raise_error(ExceptionClass)
  end
  
  # not testing whether an error is raised
  it "logs errors" do
    expect(Rails.logger).to receive(:error)
    expect { log_exception_and_reraise }.to raise_error
  end
  
  # not testing whether an error is raised
  it "sends errors to error tracker"
    expect(ErrorTracker).to receive(:send_error)
    expect { log_exception_and_reraise }.to raise_error
  end
  </code></pre>
  
  <p>This works, but you're testing two separate things in each example (even though you don't want to). And you have to duplicate the <code>raise_error</code> expectation for each one.</p>
  
  <p>I'd rather do something like </p>
  
  <pre><code>it "sends errors to error tracker"
    expect(ErrorTracker).to receive(:send_error)
    execute { log_exception_and_reraise }
  end
  </code></pre>