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

marcgg picture marcgg · Nov 12, 2009 · Viewed 87.9k times · Source

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

Avdi picture Avdi · Nov 12, 2009
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.