我已经查看了这个问题,但仍然无法测试我的自定义错误页面。在开发中,一切正常,我只想知道为什么我的测试正在做他们的事情。我的路线文件设置如下:
# rest of routes file
match '/500', to: 'errors#server_error'
match '/:anything', :to => "errors#not_found", :constraints => { :anything => /(?!500).+/ }
#end of routes file
我的错误控制器:
def not_found
render '404', status: :not_found
end
def server_error
render '500', status: :internal_server_error
end
我的 500.html.haml 视图:
.well.offset3.span6
%h2 Something went wrong...
%p We've been notified of this issue, and will get to work right away!
=link_to "Home", root_path, class: "btn btn-primary"
我的测试:
scenario "An exception is raised in the application", js: true, focus: true do
CallQueue.should_receive(:find_by_queue_code).and_raise("problem")
visit "/"
page.should have_content "Something went wrong..."
page.should have_content "We've been notified of this issue"
page.should have_link "Home"
end
每次测试都会失败,因为呈现的页面是 WEBrick Internal Server Error 页面。谁能向我解释为什么这会发生在测试环境而不是开发环境(我已经修改为像生产环境一样,设置consider_all_requests_local
为假)?或者,也许我只是以错误的方式去做?