[rspec-users] should raise_error

Nick Hoffman nick at deadorange.com
Thu Sep 25 12:33:18 EDT 2008


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')

Results in this:
1)
RuntimeError in 'RentalMap#make_marker should raise an exception for a  
non-Property argument'
The 1st argument (property) should be a Property
/Users/nick/src/myapp.podoboo.com/app/models/rental_map.rb:127:in  
`make_marker'
./spec/models/rental_map_spec.rb:218:
script/spec:4:

Whereas this succeeds:
begin
   RentalMap.make_marker('asdf').should raise_error(RuntimeError, 'The  
1st argument (property) should be a Property')
rescue; end

Is this how #raise_error is supposed to work, or am I doing something  
wrong?

Thanks,
Nick


More information about the rspec-users mailing list