小编Las*_*ert的帖子

使用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
查看次数

选择递归:last-child.可能?

在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)

但显然这不是一个好方法.

css css-selectors css3

8
推荐指数
1
解决办法
2046
查看次数

标签 统计

capybara ×1

css ×1

css-selectors ×1

css3 ×1

rspec ×1

ruby ×1

ruby-on-rails ×1