我正在关注 ruby on rails 教程。坚持获得注册页面集成测试通过。这是错误:
Failures:
1) User signup with valid information should create a user
Failure/Error: before { visit signup_path }
NameError:
undefined local variable or method `signup_path' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_14::Nested_2:0x007fb7a99749e8>
# ./spec/models/user_spec.rb:127:in `block (3 levels) in <top (required)>'
2) User signup with invalid information should not create a user
Failure/Error: before { visit signup_path }
NameError:
undefined local variable or method `signup_path' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_14::Nested_1:0x007fb7a9bf84d0>
# ./spec/models/user_spec.rb:127:in `block (3 levels) in <top (required)>'
测试抱怨路由 signup_path 不存在。这是路由文件:
SampleApp::Application.routes.draw do
# get "users/new"
resources :users
# get "static_pages/home"
root to: 'static_pages#home'
# get "static_pages/help"
match '/help', to: 'static_pages#help'
# get "static_pages/about"
match '/about', to: 'static_pages#about'
# automatically creates:
# about_path => '/about'
# about_url => 'http://localhost:3000/about'
# get "static_pages/contact"
match '/contact', to: 'static_pages#contact'
match '/signup', to: 'users#new'
end
和路线命令:
users GET /users(.:format) users#index
POST /users(.:format) users#create
new_user GET /users/new(.:format) users#new
edit_user GET /users/:id/edit(.:format) users#edit
user GET /users/:id(.:format) users#show
PUT /users/:id(.:format) users#update
DELETE /users/:id(.:format) users#destroy
root / static_pages#home
help /help(.:format) static_pages#help
about /about(.:format) static_pages#about
contact /contact(.:format) static_pages#contact
signup /signup(.:format) users#new