试图通过Michael Hartl的Ruby on Rails教程完成第5章的最后一部分,并获得运行RSpec测试的另一个错误。
输出结果为:
静态页面应该在布局上有正确的链接 失败/错误:期待(页面).to have_title('关于我们') NoMethodError: '
中的未定义方法has_title?' for #<Capybara::Session> # ./spec/requests/static_pages_spec.rb:59:in
块(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的情况下运行
有人能指出我正确的方向吗?
谢谢, 巴扎
答案 0 :(得分:7)
Capybara 2.1支持have_title
功能。我想你的Gemfile中有一个旧版本的Capybara。所以,用
gem 'capybara', '2.1.0'
然后像这样更新Capybara
bundle update capybara
使用rspec重新运行规范。它现在应该工作
有关其他选项,请参阅此post