控制器规范使用带有get方法的ActionController :: RoutingError失败

时间:2013-11-26 17:34:47

标签: ruby-on-rails rspec2 rspec-rails

我正在构建一个Rails 3应用程序,我对控制器规范有点困惑。这里是我在申请中的内容:

的routes.rb

get "/:user_name/library", :to => 'users#library', :as => :user_library

users_controller.rb

class UsersController < ApplicationController
    def library
    end
end

users_controller_spec.rb

describe "UsersController" do
    describe "#library" do
        let(:user){FactoryGirl.create(:user)}
        it "renders the users/library.html.erb view" do
            get :library, :parameters => {:user_name => user.user_name}
        end
    end
end

此示例未运行且显示以下错误

Failure/Error: get :library,:parameters => {:user_name => user.user_name}
ActionController::RoutingError:
    No route matches {:parameters=>{:user_name=>"UserName"}, :controller=>"users", :action=>"library"}

1 个答案:

答案 0 :(得分:1)

删除:parameters中的get密钥:

get :library, :user_name => user.user_name