Yuriy Naidyon
2011-Feb-16 12:24 UTC
[rspec-users] [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 -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20110216/4558d658/attachment-0001.html>
Avdi Grimm
2011-Feb-17 14:36 UTC
[rspec-users] [rspec-rails] Exception catching in controller
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'' > endDon''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 http://avdi.org
Justin Ko
2011-Feb-17 16:46 UTC
[rspec-users] [rspec-rails] Exception catching in controller
On Feb 17, 7:36?am, Avdi Grimm <gro... at inbox.avdi.org> wrote:> On Wed, Feb 16, 2011 at 7:24 AM, Yuriy Naidyon <yuro... 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 Grimmhttp://avdi.org > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users"A straight-up exception will bypass all default "rescue" clauses" - I learn something everyday!
Avdi Grimm
2011-Feb-18 02:34 UTC
[rspec-users] [rspec-rails] Exception catching in controller
On Thu, Feb 17, 2011 at 11:46 AM, Justin Ko <jko170 at gmail.com> 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, -- Avdi Grimm http://avdi.org
Justin Ko
2011-Feb-19 06:49 UTC
[rspec-users] [rspec-rails] Exception catching in controller
On Feb 17, 7:34?pm, Avdi Grimm <gro... at inbox.avdi.org> wrote:> On Thu, Feb 17, 2011 at 11:46 AM, Justin Ko <jko... at gmail.com> 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, > -- > Avdi Grimmhttp://avdi.org > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users@Avdi - watched the whole video, great stuff!