在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
在CSS中,是否可以递归选择all:last-child from body?
鉴于此标记:
<body>
<div id="_1">
<div id="_2"></div>
</div>
<div id="_3">
<div id="_4">
<div id="_5"></div>
<div id="_6"></div>
</div>
</div>
</body>
Run Code Online (Sandbox Code Playgroud)
我正在寻找div no.3,4和6
另一种说法是:
body > :last-child,
body > :last-child > :last-child,
body > :last-child > :last-child > :last-child,
body > :last-child > :last-child > :last-child > :last-child {
/* My stuff here */
}
Run Code Online (Sandbox Code Playgroud)
但显然这不是一个好方法.