Rspec控制器规范包含自定义参数的路由

时间:2015-08-21 19:50:37

标签: rspec routes controllers

路由 得到'/ foo / bar'=> foo / bar #index {:custom_auth => [:管理员]}

我有在config / routes.rb文件中指定custom_auth的路由。

在从控制器规范中调用索引方法时,它会抱怨未找到路由,如果没有从路由配置中删除custom_auth参数,该路由效果很好。

有没有办法在从控制器规范中调用控制器/操作时传递custom_auth?

   describe Foo::BarsController do
     describe 'GET index' do
        get :index
        expect(response).to eq {}
      end
   end

配置/ routes.rb中

get '/foo/bar', :to => 'foo/bar#index', :custom_auth => [:admin]

1 个答案:

答案 0 :(得分:0)

您可以在调用get :index请求时传递params哈希中的所有必需参数。

因此,构建一个params哈希,然后将其传递给get :index这样的调用:

let(:admin) { double('admin') }
let(:custom_auth_params) { { :custom_auth => [:admin] } }
get :index, custom_auth_params
相关问题