【问题标题】:Chapter 5 - Ruby on Rails Tutorial - undefined method `has_title?' when running RSpec tests第 5 章 - Ruby on Rails 教程 - 未定义的方法 `has_title?'运行 RSpec 测试时
【发布时间】:2013-05-23 02:36:59
【问题描述】:

只是试图通过 Michael Hartl 的 Ruby on Rails 教程中第 5 章的最后一点,并在运行 RSpec 测试时遇到另一个错误。

输出是:

静态页面应该在布局上有正确的链接 失败/错误:expect(page).to have_title('About Us') 无方法错误: '

中未定义的方法has_title?' for #<Capybara::Session> # ./spec/requests/static_pages_spec.rb:59:inblock(2 级)

以及 static_pages_spec.rb 中以下代码中以 expect(page) 开头的行的结果:

it "should have the right links on the layout" do
    visit root_path
    click_link "About"
   expect(page).to have_title(full_title('About Us'))
end   

注意:无论是否使用 Spork,都会发生这种情况

谁能指出我正确的方向吗?

谢谢, 巴扎

【问题讨论】:

    标签: ruby-on-rails-3 rspec


    【解决方案1】:

    Capybara 2.1 支持 have_title 函数。我想你的 G​​emfile 中有一个旧版本的 Capybara。所以,用

    更新你的 Gemfile
    gem 'capybara', '2.1.0'
    

    然后像这样更新Capybara

    bundle update capybara
    

    并使用 rspec 重新运行规范。它现在应该可以工作了

    请参阅此post 了解其他选项

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-02-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多