2013-01-06 66 views
2

我在轨道上跟随ruby教程。停留在获得注册页面集成测试通行证。这是错误:轨道上的红宝石signup_path不可用 - 在轨道上的红宝石教程

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 

回答

3

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

+1

请标记为已解决 – Fa11enAngel

+0

它说“你明天可以接受你的答案”。明天会做。 –