无法在rspec中测试控制器操作

时间:2015-09-28 17:43:32

标签: ruby-on-rails ruby ruby-on-rails-3 model-view-controller rspec

我正在尝试在非宁静路线上测试控制器动作。

config/routes.rb

  match '/integration/:provider/callback' => "providers#manual_auth", as: :integration_callback

您也可以通过rake routes

查看
integration_callback /integration/:provider/callback(.:format) providers#manual_auth

在我的spec文件中:

spec/controllers/providers_controller_spec.rb

describe ProvidersController do
  describe '#manual_auth' do
    it 'hits the manual_auth action' do
      get :manual_auth, use_route: :integration_callback
    end
  end
end

这给了我一个错误:

Failures:

  1) ProvidersController#manual_auth hits the manual_auth action
     Failure/Error: get :manual_auth, use_route: :integration_callback
     ActionController::RoutingError:
       No route matches {:controller=>"providers", :action=>"manual_auth"}

但在app/controllers/providers_controller.rb我有

class ProvidersController < ApplicationController
  def manual_auth
    logger.info "Got into manual auth"
  end
end

我应该提到我故意在这里避免使用请求规范,因为我需要能够访问和设置会话对象(存在于此#manual_auth操作中),这显然只能在控制器测试中完成,不要求规格。

1 个答案:

答案 0 :(得分:2)

integration_callback有一个参数,即:provider

试试这个:

get :manual_auth, provider: 'test', use_route: :integration_callback
相关问题