and_raise should support intentionally raising an ArgumentError #121

merged 1 commit into from Mar 28, 2012


None yet

2 participants


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

it "should raise an ArgumentError" do
  error ="error message")
  lambda {
  }.should raise_error(ArgumentError, "error message")

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
RSpec member

Thanks for the fix!

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