Rspec错误:没有路由匹配{:controller =>“user”}

时间:2013-03-23 01:26:49

标签: ruby testing rspec

为什么我会这样做/我该如何解决它?

代码是:

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 => 'bob@test.com', :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

1 个答案:

答案 0 :(得分:2)

您的控制器类名称是单数(UserController),它应该是UsersController