期望css"标题"与水豚文本

vaj*_*vin 8 rspec capybara

我在铁轨中使用水豚代替webrat.我已经安装了水豚并在Gemfile中使用了宝石'capybara'.我用的时候

page.should have_selector("title", :text => "anything title")
Run Code Online (Sandbox Code Playgroud)

它给出了一个错误

Failure/Error: page.should have_selector("title", :text => "anything title")
expected css "title" with text "anything title" to return something
Run Code Online (Sandbox Code Playgroud)

测试文件如下:

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
Run Code Online (Sandbox Code Playgroud)

小智 12

不确定你使用的是哪个版本的宝石,但我遇到了一个使用类似的实例:文本失败但是当我使用时:内容它通过了测试.我在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")
Run Code Online (Sandbox Code Playgroud)

page.should have_selector("title", :content => "anything title")
Run Code Online (Sandbox Code Playgroud)

  • 对我来说,一个测试:内容通过,即使它不应该通过. (6认同)