1

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

输出是:

静态页面应该在布局上具有正确的链接失败/错误:expect(page).to have_title('About Us') NoMethodError: undefined method has_title?' for #<Capybara::Session> # ./spec/requests/static_pages_spec.rb:59:inblock (2 levels) in '

并来自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,都会发生这种情况

谁能指出我正确的方向?

谢谢,巴扎

4

1 回答 1

7

have_titleCapybara 2.1 支持该功能。我想你的 G​​emfile 中有一个旧版本的 Capybara。所以,更新你的 Gemfile

gem 'capybara', '2.1.0'

然后像这样更新Capybara

bundle update capybara

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

有关其他选项,请参阅此帖子

于 2013-07-20T03:09:19.367 回答