[rspec-users] [RSpec] #and_raise

Nick Hoffman nick at deadorange.com
Mon Feb 16 14:48:52 EST 2009

I often use #and_raise like so:

@error_message = 'Some error'
@sf.should_receive(:shift_time!).and_raise @error_message

However, after trying to do this:

@argument_error = mock_model ArgumentError,
     :message => @error_message
@sf.should_receive(:shift_time!).and_raise @argument_error

and then reading the docs for #and_raise, I realised that #and_raise  
only accepts a String or exception class.

Is there a way to set the exception class and error message?

More information about the rspec-users mailing list