2013-03-23 41 views
1

爲什麼我得到/我該如何解決它?Rspec錯誤:無路由匹配{:controller =>「user」}

代碼是:

class UserController < ApplicationController 
    def index 
    @users=User.all 
    end 
end 

規格是:

require 'spec_helper' 

describe UserController do 

    describe "GET index" do 
    it "assigns @users" do 
     user = User.create(:email => '[email protected]', :password=>'12', :password_confirmation=> '12') 
     get :index 
     assigns(:users).should eq([user]) 
    end 

    it "renders the index template" do 
     get :index 
     response.should render_template("index") 
    end 
    end 

end 

Failures: 

    1) UserController GET index assigns @users 
    Failure/Error: get :index 
    ActionController::RoutingError: 
     No route matches {:controller=>"user"} 
    # ./spec/controllers/user_controller_spec.rb:8:in `block (3 levels) in <top (required)>' 

    2) UserController GET index renders the index template 
    Failure/Error: get :index 
    ActionController::RoutingError: 
     No route matches {:controller=>"user"} 
    # ./spec/controllers/user_controller_spec.rb:13:in `block (3 levels) in <top (required)>' 

Finished in 0.13146 seconds 
2 examples, 2 failures 

航線有:

TimeTracker::Application.routes.draw do 
    devise_for :users 

    resources :users 

    root :to => 'users#index' 

end 

回答

2

控制器類名是單數(UserController),它應該是UsersController

+0

是的,就是這樣。最初我在嘗試時獲得了未初始化的常量UsersController(NameError)。原來我的控制自己被誤稱了 – 2013-03-23 01:35:13

相關問題