我一直按照教程中的内容进行操作。到目前为止,一切都顺利进行,直到本节。
我应该将 config/routes.rb 文件中的“GET”语句更改为以下内容:
SampleApp::Application.routes.draw do
root to: 'static_pages#home'
match '/help', to: 'static_pages#help'
match '/about', to: 'static_pages#about'
match '/contact', to: 'static_pages#contact'
这应该使测试通过。他们没有通过。作为 9 个类似错误之一,它们继续失败,并出现以下错误:
Failure/Error: visit about_path
NameError:
undefined local variable or method 'about_path' ....
我不知道如何让这件事通过,这样我才能继续前进。我错过了什么?哈特尔错过了什么?其他问过这个问题的人从来没有得到任何有意义的答案,甚至在尝试时也没有得到任何答案。
在有人问之前:
Rails、Ruby 和其他已安装组件的所有版本与本教程中使用的版本完全相同,与今天 2012-10-05 编写的版本完全相同。一切都与教程完美匹配。
更新:这是当前的 static_pages_spec.rb 文件
require 'spec_helper'
describe "Static pages" do
describe "Home page" do
it "should have the h1 'Sample App'" do
visit root_path
page.should have_selector('h1', text: 'Sample App')
end
it "should have the base title" do
visit root_path
page.should have_selector('title',
text: "Ruby on Rails Tutorial Sample App")
end
it "should not have a custom page title" do
visit root_path
page.should_not have_selector('title', text: '| Home')
end
end
describe "Help page" do
it "should have the h1 'Help'" do
visit help_path
page.should have_selector('h1', text: 'Help')
end
it "should have the title 'Help'" do
visit help_path
page.should have_selector('title',
text: "Ruby on Rails Tutorial Sample App | Help")
end
end
describe "About page" do
it "should have the h1 'About'" do
visit about_path
page.should have_selector('h1', text: 'About Us')
end
it "should have the title 'About Us'" do
visit about_path
page.should have_selector('title',
text: "Ruby on Rails Tutorial Sample App | About Us")
end
end
describe "Contact page" do
it "should have the h1 'Contact'" do
visit contact_path
page.should have_selector('h1', text: 'Contact')
end
it "should have the title 'Contact'" do
visit contact_path
page.should have_selector('title',
text: "Ruby on Rails Tutorial Sample App | Contact")
end
end
end
耙路线结果:
root / static_pages#home
help /help(.:format) static_pages#help
about /about(.:format) static_pages#about
contact /contact(.:format) static_pages#contact