rspec - 预期 css "title"与 capybara 文本

标签 rspec capybara

我在 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/

相关文章:

ruby-on-rails - 如何为所有 capybara 功能设置 http header

ruby-on-rails - Rails 3 和 Factory Girl 仅在传入属性时创建用户

ruby - 检查测试是否失败并相应地给出控制台输出

rspec - Rails 4、RSpec、Capybara 和 webkit_server

capybara - 使用 Capybara 从标签中选择单选按钮

html - 如何使用 Capybara 在 lightbox/fancybox 中查找元素

capybara - Selenium::WebDriver::Error::ElementNotVisibleError:元素不可交互

ruby-on-rails - rspec 的集成测试和正常测试有什么区别?

selenium - 如何使用 poltergeist 拖放?

ruby-on-rails - Errno::ENOENT: 功能测试后没有这样的文件或目录@rb_file_s_mtime