相关疑难解决方法(0)

使用Rspec + Capybara在Rails中测试错误页面

在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.rbnot_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 = falsetest.rb

ruby rspec ruby-on-rails capybara

24
推荐指数
1
解决办法
8667
查看次数

Rails 3.1错误捕获

我认为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"但我无法在任何地方确认这一点.

谢谢!

ruby ruby-on-rails

10
推荐指数
2
解决办法
5220
查看次数

标签 统计

ruby ×2

ruby-on-rails ×2

capybara ×1

rspec ×1