Jonathan del Strother
2007-Jan-10 16:03 UTC
Functional tests : rescue_action-rewrite causing problems (autotest)
Functional tests all come with a handy line that gives more sensible exception reporting, looking something like : class FooController; def rescue_action(e) raise e end; end This can cause a few problems. For example, assert_response :missing isn''t going to work : the 404 status is no longer set on getting an ActiveRecord::RecordNotFound. Within functional tests, this isn''t too bad : you''d probably be content with something like assert_raises(ActiveRecord::RecordNotFound){get ''show'', :id => 40000} However, I''m struggling to deal with this and autotest. AFAICT, autotest doesn''t reload the controllers when moving between functional tests and integration tests, so controllers still have the rewritten rescue_action method in integration. So the exception gets caught at dispatcher.rb:42, which always returns a status of 500. The end result is that in autotest''s integration testing, you might get 404 or you might get 500, depending on whether or not your functional tests got loaded first on that particular run. Has anyone found a workaround for this? At the moment I''m having to remove the "def rescue_action(e) raise e end" line from functional tests, and it''s making functional test debugging a bit painful... Jon --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Jon
2007-Jan-11 21:40 UTC
Re: Functional tests : rescue_action-rewrite causing problems (autotest)
No takers? Jonathan del Strother wrote:> Functional tests all come with a handy line that gives more sensible > exception reporting, looking something like : > > class FooController; def rescue_action(e) raise e end; end > > This can cause a few problems. For example, > assert_response :missing isn''t going to work : the 404 status is no > longer set on getting an ActiveRecord::RecordNotFound. Within > functional tests, this isn''t too bad : you''d probably be content with > something like assert_raises(ActiveRecord::RecordNotFound){get > ''show'', :id => 40000} > > > However, I''m struggling to deal with this and autotest. AFAICT, > autotest doesn''t reload the controllers when moving between > functional tests and integration tests, so controllers still have the > rewritten rescue_action method in integration. So the exception gets > caught at dispatcher.rb:42, which always returns a status of 500. > The end result is that in autotest''s integration testing, you might > get 404 or you might get 500, depending on whether or not your > functional tests got loaded first on that particular run. > > > Has anyone found a workaround for this? At the moment I''m having to > remove the "def rescue_action(e) raise e end" line from functional > tests, and it''s making functional test debugging a bit painful...--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Francois Beausoleil
2007-Jan-12 04:15 UTC
Re: Functional tests : rescue_action-rewrite causing problems (autotest)
2007/1/10, Jonathan del Strother <maillist@steelskies.com>:> However, I'm struggling to deal with this and autotest. AFAICT, > autotest doesn't reload the controllers when moving between > functional tests and integration tests, so controllers still have the > rewritten rescue_action method in integration. So the exception gets > caught at dispatcher.rb:42, which always returns a status of 500. > The end result is that in autotest's integration testing, you might > get 404 or you might get 500, depending on whether or not your > functional tests got loaded first on that particular run.This is causing problems even outside autotest. rake test will run functionals, and in the same Ruby process, run the integration tests. Most if not all controllers will have the redefined rescue_action method... The thing that should be done is to do it in setup, and replace that in teardown. A bit like the mocks do. They replace a method, and on teardown, put the method back into place. Bye ! -- François Beausoleil http://blog.teksol.info/ http://piston.rubyforge.org/ --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com 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 -~----------~----~----~----~------~----~------~--~---
Jon
2007-Jan-18 16:05 UTC
Re: Functional tests : rescue_action-rewrite causing problems (autotest)
Francois Beausoleil wrote:> 2007/1/10, Jonathan del Strother <maillist-3GLpx8vVthx0ubjbjo6WXg@public.gmane.org>: > > However, I''m struggling to deal with this and autotest. AFAICT, > > autotest doesn''t reload the controllers when moving between > > functional tests and integration tests, so controllers still have the > > rewritten rescue_action method in integration. So the exception gets > > caught at dispatcher.rb:42, which always returns a status of 500. > > The end result is that in autotest''s integration testing, you might > > get 404 or you might get 500, depending on whether or not your > > functional tests got loaded first on that particular run. > > This is causing problems even outside autotest. > > rake test > > will run functionals, and in the same Ruby process, run the > integration tests. Most if not all controllers will have the > redefined rescue_action method... > > The thing that should be done is to do it in setup, and replace that > in teardown.Just to see if anyone can find a cleaner way, this is what I''m using at the moment in my test_helper : unless ActionController::Base.method_defined? :rescue_action_without_optional_raise class ActionController::Base attr_accessor :reraise_exceptions def rescue_action_with_optional_raise(e) if reraise_exceptions raise e else rescue_action_without_optional_raise(e) end end alias_method_chain :rescue_action, :optional_raise def initialize(opts={}) self.reraise_exceptions = opts[:reraise_exceptions] end end end Then, in the functional tests'' setup method, I can do @controller PostsController.new(:reraise_exceptions => true), which will give me a controller that gives a nice stack trace, without polluting rescue_action''s behaviour for integration testing. Anyone spot a better way? Jon --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---