marcgg marcgg - 4 months ago 9
Ruby Question

How to use RSpec's should_raise with any kind of exception?

I'd like to do something like this:

some_method.should_raise <any kind of exception, I don't care>


How should I do this?

some_method.should_raise exception


... doesn't work.

Answer
expect { some_method }.to raise_error

RSpec 1 Syntax:

lambda { some_method }.should raise_error

See the documentation (for RSpec 1 syntax) and RSpec 2 documentation for more.