我升级到 Rails 3.2 和 Capybara 2.1,我的 700 个测试中有大约 30% 失败了。一堆失败的测试是这样的:
require 'spec_helper'
describe BooksController do
render_views
let(:page) { Capybara::Node::Simple.new(@response.body) }
describe "new" do
it "should get new" do
get :new, :author_id => author_token, :publish_action => "Publish"
response.should be_success
page.should have_selector "h1", text:"Transition"
end
end
end
失败的测试输出是:
BooksController should get new content
Failure/Error: page.should have_selector 'h1', text:'Preview'
Capybara::ExpectationNotMet:
expected to find css "h1" with text "Preview" but there were no matches
# ./spec/controllers/books_controller_spec.rb:46:in `block (5 levels) in <top (required)>'
当我使用 print page.html、save_and_open_page 等时,我得到一个空白或没有输出。但是很多其他的测试都通过了。这似乎与检查 h1 标签有关。