and_raise should support intentionally raising an ArgumentError #121

Merged
merged 1 commit into from Mar 28, 2012

Projects

None yet

2 participants

@maeve

Prior to rspec-mocks 2.9.0, a trivial test like this would pass:

it "should raise an ArgumentError" do
  error = ArgumentError.new("error message")
  @mock.should_receive(:something).and_raise(error)
  lambda {
    @mock.something
  }.should raise_error(ArgumentError, "error message")
end

As of 2.9.0, this now fails with the rather cryptic message:

expected ArgumentError with "error message", got #<NoMethodError: undefined method `instance_method' for #<ArgumentError: error message>>

This appears to be a side effect of changes to introduce a friendlier error message when and_raise is called with an Exception class that doesn't have a zero-arg constructor. This fix explicitly checks for that case instead of trying to rescue all ArgumentErrors.

@myronmarston myronmarston merged commit 2478a16 into rspec:master Mar 28, 2012
@myronmarston
RSpec member

Thanks for the fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment