[rspec-users] should raise_error

Mark Wilden mark at mwilden.com
Thu Sep 25 12:56:01 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')
>

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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20080925/827f5f5c/attachment.html>


More information about the rspec-users mailing list