[rspec-rails] Exception catching in controller

Hi folks. I’m currently using rspec-2.4.0 and rspec-rails-2.4.1.
In the controller I have the code like this (at least at two different
places):

def some_action
raise Exception if some_falsy_value
rescue
@message = ‘Error’
end

but when I do testing with rspec this exception doesn’t proceeded by
controller, and I’m getting the following:

  1. SignupsController GET confirm_email should proceed unexpected
    errors
    Failure/Error: get :confirm_email, @params
    Exception:
    Exception

    ./app/controllers/signups_controller.rb:251:in `confirm_email’

    ./spec/controllers/signups_controller_spec.rb:168:in `block (3

levels) in <top (required)>’

I saw in examples that we can do exceptions catching by contoller
filters
like (rescue_from ActiveRecord::RecordNotFound, :with =>
:record_not_found)
but I don’t want to use this way, con my exceptions aren’t controller
wide,
they only related to some single action.
Also, it’s my first email to mailing group, if I composed it
incorrectly,
someone please let me know.

Yuriy

On Wed, Feb 16, 2011 at 7:24 AM, Yuriy N. [email protected]
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.

On Thu, Feb 17, 2011 at 11:46 AM, Justin Ko [email protected] wrote:

“A straight-up exception will bypass all default “rescue” clauses” - I
learn something everyday!

If you will forgive a brief moment of self-promotion, I recently
posted an entire talk I did on Ruby exception handling:
http://avdi.org/devblog/exceptional-ruby/

Cheers,

On Feb 17, 7:36am, Avdi G. [email protected] wrote:

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 G.http://avdi.org


rspec-users mailing list
[email protected]://rubyforge.org/mailman/listinfo/rspec-users

“A straight-up exception will bypass all default “rescue” clauses” - I
learn something everyday!

On Feb 17, 7:34pm, Avdi G. [email protected] wrote:


rspec-users mailing list
[email protected]://rubyforge.org/mailman/listinfo/rspec-users

@Avdi - watched the whole video, great stuff!

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs