Why is my RSpec not loading Devise::Test::ControllerHelpers?

▼魔方 西西 提交于 2019-11-28 19:06:49

You could add the following to your rails_helper:

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

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

In the spec_helper.rb add:

config.include Devise::Test::ControllerHelpers, :type => :controller

MiniTest, Rails 4

This works for vanilla Rails 4 MiniTest

test\controllers\users_controller_test.rb
require 'test_helper'

class UsersControllerTest < ActionController::TestCase
  include Warden::Test::Helpers
  include Devise::Test::ControllerHelpers

  setup do
    # https://github.com/plataformatec/devise/wiki/How-To:-Test-with-Capybara
    # @user = users(:admin)
    # sign_in @user
  end

  teardown do
    Warden.test_reset!
  end

  test "login as admin" do
    @user = users :admin
    sign_in @user
    get :dashboard
    assert_redirected_to admin_dashboard_path
  end

end
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!