我正在缓慢地阅读Mike Hartl的Rails教程,in section 4.4似乎让我将rspec请求文件从以下格式更改为:
page.should have_selector('title', :text => "#{base_title}")至
expect(page).to have_title("Ruby on Rails Tutorial Sample App")当我使用".to have_title“和".to_not have_title”时,我得到了两个未定义的方法错误。我关闭并重新启动了Webrick、Spork和Guard以防万一,但它仍然不起作用。
水豚版本1.1.2 Rspec版本2.11.1
如果需要任何其他信息,请让我知道。
发布于 2013-05-27 19:32:10
显然,教程最近发生了变化。
通过google缓存访问页面会显示原始版本(这对我来说很好):
require 'spec_helper'
describe "Static pages" do
describe "Home page" do
it "should have the h1 'Sample App'" do
visit '/static_pages/home'
page.should have_selector('h1', :text => 'Sample App')
end
it "should have the base title" do
visit '/static_pages/home'
page.should have_selector('title',
:text => "Ruby on Rails Tutorial Sample App")
end
it "should not have a custom page title" do
visit '/static_pages/home'
page.should_not have_selector('title', :text => '| Home')
end
end
.
.
.
end发布于 2013-05-27 17:34:14
可能是你的版本有问题。通过https://github.com/jnicklas/capybara/issues/863
expect(first('title').native.text).to eq "my title"发布于 2013-06-30 17:53:03
我遇到了这个问题,我最终意识到我已经切换到遵循rails版本4的代码,而不是3.2版本。
要测试您正在使用的rails版本,请键入以下命令
rails -v然后在教程页面上,使用右侧的导航器选择正确的rails版本。看起来很简单,但希望它能为其他有这个问题的人省去痛苦。
https://stackoverflow.com/questions/16770151
复制相似问题