Ruby on Rails / raise_error matcher

Use the raise_error matcher to specify that a block of code raises an error.
The most basic form passes if any error is thrown:
expect { raise StandardError }.to raise_error 

You can use raise_exception instead if you prefer that wording
:expect { 3 / 0 }.to raise_exception

raise_error and raise_exception are functionally interchangeable, so use the one that makes the most sense to you in any given context.

No comments:

Post a Comment