在我們的Rails應用程序2.3,我已經設置了路由錯誤一rescue_from如下:如何測試rescue_from的路由失敗?
rescue_from ActionController::RoutingError, :with => :redirect_or_render_error
rescue_from ActionController::UnknownController, :with => :redirect_or_render_error
rescue_from ActionController::UnknownAction, :with => :redirect_or_render_error
,然後在我的redirect_or_render_error
方法我重定向某些URL(從DB拉,所以我不能只是使用routes.rb),我想測試這個。我在做這在我的索引頁的功能測試(是正確的地方?)像這樣:
@request.remote_addr = '12.34.56.78' # fake remote request
get '/example'
assert_redirected_to '/example_things/123456'
我得到
ActionController::RoutingError: No route matches {:action=>"/example", :controller=>"home"}
即使它在發展。如何測試rescue_from的路由失敗?
使用集成測試解決了此處所述的問題。但是,我在測試環境文件中將'config.action_controller.consider_all_requests_local'設置爲'true'。 – berto 2011-04-12 00:54:18