[rspec-users] should raise_error

Nick Hoffman nick at deadorange.com
Thu Sep 25 13:33:11 EDT 2008

> On Thu, Sep 25, 2008 at 9:33 AM, Nick Hoffman <nick at deadorange.com>  
> wrote:
> I noticed in the RSpec documentation that "object.should  
> raise_error" isn't enclosed in a begin..rescue..end :
> http://rspec.info/rdoc/classes/Spec/Matchers.html#M000420
> However, when I use #raise_error , I have to rescue it, otherwise an  
> actual exception is raised and the script bails.
> This:
> RentalMap.make_marker('asdf').should raise_error(RuntimeError, 'The  
> 1st argument (property) should be a Property')

On 2008-09-25, at 12:56, Mark Wilden wrote:
> You need to send :should to a Proc:
>  lambda { RentalMap.make_marker('asdf') }.should raise_error(blah,  
> blah)
> I'll be every RSpec user has made this mistake at least once (in my  
> case, numerous times). I wonder if it would be possible for the  
> matcher to call this out?
> ///ark

Thanks for that tip, Mark. When you have a minute, would you mind  
explaining why #should needs to be sent to a Proc?

More information about the rspec-users mailing list