我在 Rails 中使用 capybara 代替 webrat。我已经安装了 capybara 并在 Gemfile 中使用 gem 'capybara' 。当我使用
page.should have_selector("title", :text => "anything title")
报错
Failure/Error: page.should have_selector("title", :text => "anything title")
expected css "title" with text "anything title" to return something
测试文件如下:
require 'spec_helper'
describe "Test pages" do
describe "Home page" do
it "should have the content 'Demo App'" do
visit '/test_pages/home'
page.should have_selector("title", :text => "anything title")
end
end
end
最佳答案
不确定您使用的是哪个版本的 gems,但我遇到了类似的实例,其中使用 :text 失败,但当我使用 :content 时它通过了测试。我在 Ubuntu Lucid Lynx 上使用 Rails 3.2.3、rspec-rails 2.9.0、capybara 1.1.2 和 therubyracer gems。
尝试更换
page.should have_selector("title", :text => "anything title")
与
page.should have_selector("title", :content => "anything title")
关于rspec - 预期 css "title"与 capybara 文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10269445/