marcgg marcgg - 2 years ago 83
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 Source
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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download