在Rails 3.2.9中我有自定义错误页面定义如下:
# application.rb
config.exceptions_app = self.routes
# routes.rb
match '/404' => 'errors#not_found'
Run Code Online (Sandbox Code Playgroud)
哪个效果如预期.当我进入时config.consider_all_requests_local = false,development.rb我not_found在访问时获得了视图/foo
但是我如何用Rspec + Capybara测试呢?
我试过这个:
# /spec/features/not_found_spec.rb
require 'spec_helper'
describe 'not found page' do
it 'should respond with 404 page' do
visit '/foo'
page.should have_content('not found')
end
end
Run Code Online (Sandbox Code Playgroud)
当我运行此规范时,我得到:
1) not found page should respond with 404 page
Failure/Error: visit '/foo'
ActionController::RoutingError:
No route matches [GET] "/foo"
Run Code Online (Sandbox Code Playgroud)
我该怎么测试呢?
编辑:
忘了提一下:我已经开始config.consider_all_requests_local = false了test.rb
我认为Rails 3.1正在改变引发错误的方式.任何人都可以协助或确认吗?我正在尝试使用Rails 3.1.0.rc1创建自定义错误页面
unless config.consider_all_requests_local
rescue_from Exception, :with => :render_error
rescue_from ActiveRecord::RecordNotFound, :with => :render_not_found
rescue_from ActionController::RoutingError, :with => :render_not_found
rescue_from ActionController::UnknownController, :with => :render_not_found
rescue_from ActionController::UnknownAction, :with => :render_not_found
end
Run Code Online (Sandbox Code Playgroud)
^^这不起作用.
config.consider_all_requests_local = true
Run Code Online (Sandbox Code Playgroud)
默认情况下,这是在我的开发环境中.我假设Rails 3.1删除了"action_controller"但我无法在任何地方确认这一点.
谢谢!