Bob Mundane
2009-Feb-16 11:20 UTC
What happen when a controller raises a custom exception ?
Hello, some controllers of mine raises security exception. environments/test.rb defines config.action_controller.consider_all_requests_local = true 1) I want to raise from a controller, and have the exception visible in test, inside assert_raise blocks but I don''t. 2) I defined rescue_action_in_public() which (I''m sure) is not called during tests. 3) But during tests, when my controller raises AppException::SecurityError it is not caught by the assert_raise block. So I added this, to see what happens : def rescue_action_locally(exception) p exception raise exception end The exception is well printed on console but re-raising lead to Class: <NoMethodError> Message: <"You have a nil object when you didn''t expect it!\nYou might have expected an instance of ActiveRecord::Base.\nThe error occurred while evaluating nil.[]="> I really don''t understand what happen because after re-raising no code of mine is running, it leave my scope ... So I wonder how to have these exceptions visible in test ? Thanks -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
jemminger
2009-Feb-17 00:16 UTC
Re: What happen when a controller raises a custom exception ?
Try rescue_from: http://api.rubyonrails.org/classes/ActiveSupport/Rescuable/ClassMethods.html#M000978 On Feb 16, 6:20 am, Bob Mundane <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Hello, some controllers of mine raises security exception. > > environments/test.rb defines > config.action_controller.consider_all_requests_local = true > > 1) I want to raise from a controller, and have the exception visible in > test, inside assert_raise blocks but I don''t. > > 2) I defined rescue_action_in_public() which (I''m sure) is not called > during tests. > > 3) But during tests, when my controller raises > AppException::SecurityError it is not caught by the assert_raise block. > > So I added this, to see what happens : > > def rescue_action_locally(exception) > p exception > raise exception > end > > The exception is well printed on console but re-raising lead to Class: > <NoMethodError> > Message: <"You have a nil object when you didn''t expect it!\nYou might > have expected an instance of ActiveRecord::Base.\nThe error occurred > while evaluating nil.[]="> > > I really don''t understand what happen because after re-raising no code > of mine is running, it leave my scope ... > > So I wonder how to have these exceptions visible in test ? > > Thanks > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---