无法测试自定义500错误页面的内容

时间:2013-06-13 15:32:27

标签: ruby-on-rails ruby-on-rails-3 capybara

我已经看过this question了,我仍然没有运气测试我的自定义错误页面。在开发中,一切正常,我只想知道我的测试为什么会这样做。我的路线文件设置如下:

# rest of routes file
match '/500', to: 'errors#server_error'
match '/:anything', :to => "errors#not_found", :constraints => { :anything => /(?!500).+/ }
#end of routes file

My ErrorsController:

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页面。任何人都可以向我解释为什么会在测试环境中发生这种情况,而不是开发环境(我已将其修改为像Production一样,将consider_all_requests_local设置为false)?或者也许我只是以错误的方式去做?

0 个答案:

没有答案