Ruby on rails注册路径不可用-遵循Ruby on rails教程



我遵循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)>'

测试报错路由注册路径不存在。下面是路由文件:

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

和routes命令:

    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

我的错。我在模型和请求文件夹中定义了相同的测试。所以我猜models文件夹下的测试无法访问路由。

最新更新