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?
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?
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?
Thanks for that tip, Mark. When you have a minute, would you mind explaining
why #should needs to be sent to a Proc?
Precisely because of the problem you’re experiencing. If you look at
the code for Spec::Matchers::RaiseError, you’ll see that it accepts a
proc and calls it in the context of a begin/rescue structure - saving
you from having to do that in your example.
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?
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.