Discussion: my way of testing rescue_from in Rails

29 views
Skip to first unread message

Michel Pigassou

unread,
Jul 31, 2012, 12:37:08 PM7/31/12
to rubyonra...@googlegroups.com
I used to rescue an Exception like this:

  unless Rails.application.config.consider_all_requests_local
    rescue_from Exception, :with => :render_error
  end

But this is hard to test.

So I removed the condition in the controller and added it in the render_error method itself: raise e if request.local?

And in my test I overwrite ActionDispatch::Request

class ::ActionDispatch::Request
  def local? ; false end
end

What do you think?
Reply all
Reply to author
Forward
0 new messages