【发布时间】:2012-12-21 19:44:38
【问题描述】:
在 Rails 3.2.9 中,我有这样的自定义错误页面定义:
# application.rb
config.exceptions_app = self.routes
# routes.rb
match '/404' => 'errors#not_found'
效果符合预期。当我在development.rb 中设置config.consider_all_requests_local = false 时,我在访问/foo 时得到not_found 视图
但是如何使用 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
当我运行这个规范时,我得到:
1) not found page should respond with 404 page
Failure/Error: visit '/foo'
ActionController::RoutingError:
No route matches [GET] "/foo"
我该如何测试这个?
编辑:
忘了说:我在test.rb中设置了config.consider_all_requests_local = false
【问题讨论】:
标签: ruby-on-rails ruby rspec capybara