为什么我的RSpec没有加载Devise :: Test :: ControllerHelpers? [英] Why is my RSpec not loading Devise::Test::ControllerHelpers?

查看:237
本文介绍了为什么我的RSpec没有加载Devise :: Test :: ControllerHelpers?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Rails 5和Devise 3.5.1。

I'm using Rails 5, and Devise 3.5.1.

浏览一本关于创建/测试API的漂亮(较旧的)书籍,它使用Devise认证。它是在Rails 5之前写的,所以我选择不使用新的api-only版本。

Going through a nice (older) book about creating/testing an API, which uses Devise authentication. It was written before Rails 5, so I chose not to use the new api-only version.

这是我的测试...

#/spec/controllers/api/v1/users_controller_spec.rb    

require 'rails_helper'

describe Api::V1::UsersController, :type => :controller do
    before(:each) { request.headers['Accept'] = "application/vnd.marketplace.v1" }
    describe "GET #show" do
        before(:each) do
            @user = FactoryGirl.create :user
            get :show, params: {id: @user.id}, format: :json
        end
        it "returns the information about a reporter on a hash" do
            user_response = JSON.parse(response.body, symbolize_names: true)
            expect(user_response[:email]).to eql @user.email
        end
        it { should respond_with 200 }
    end
end

这是一个完全意外的RSpec错误

And here's a completely unexpected RSpec error

Devise::MissingWarden:
       Devise could not find the `Warden::Proxy` instance on your request environment.
       Make sure that your application is loading Devise and Warden as expected and that the `Warden::Manager` middleware is present in your middleware stack.
       If you are seeing this on one of your tests, ensure that your tests are either executing the Rails middleware stack or that your tests are using the `Devise::Test::ControllerHelpers` module to inject the `request.env['warden']` object for you.

所以我去这里 - http://www.rubydoc.info/gems/devise/Devise/Test/ControllerHelpers

So I go here - http://www.rubydoc.info/gems/devise/Devise/Test/ControllerHelpers

并尝试这个 - > 包括Devise :: Test :: ControllerHelpers

and tried this -> include Devise::Test::ControllerHelpers

哪些没有帮助,因为文件 controller_helpers.rb 在我的项目中没有任何地方

which didn't help because the file controller_helpers.rb is nowhere in my project

我错过了什么?

谢谢

推荐答案

您可以将以下内容添加到 rails_helper 中:

You could add the following to your rails_helper:

RSpec.configure do |config|
  config.include Devise::Test::ControllerHelpers, type: :controller
end

这将包括所有:controller 规范中的 Devise :: Test :: ControllerHelpers 模块。

This will include Devise::Test::ControllerHelpers module in all :controller specs.

这篇关于为什么我的RSpec没有加载Devise :: Test :: ControllerHelpers?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆