[rspec-users] [rspec-rails] Exception catching in controller

Avdi Grimm groups at inbox.avdi.org
Thu Feb 17 09:36:22 EST 2011

On Wed, Feb 16, 2011 at 7:24 AM, Yuriy Naidyon <yurokle at gmail.com> wrote:
> def some_action
>   raise Exception if some_falsy_value
> rescue
>   @message = 'Error'
> end

Don't raise Exception. Raise some descendant of StandardError, like
RuntimeError (the default if you don't specify a class) or (even
better) your own StandardError-derived exception class.

A straight-up exception will bypass all default "rescue" clauses and
in general indicates that something has gone badly wrong and the
program should end.

Avdi Grimm

More information about the rspec-users mailing list