Rails 5.1 / Devise 4.4 - 测试:未定义的方法`setup' for Object:Class(NoMethodError)

时间:2018-03-25 12:09:39

标签: ruby-on-rails testing devise

我正在遇到一个"未定义的方法`setup' for Object:Class(NoMethodError)"用Rails测试时。我在运行任何测试时都会收到此错误。

我正在使用Ruby on Rails Tutorial中的测试设置,另外还在我的测试文件中包含了Devise :: Test :: IntegrationHelpers(用于集成测试)和Devise :: Test :: ControllerHelpers(用于控制器测试)。

这是我得到的错误: .rbenv / versions / 2.4.2 / lib / ruby​​ / gems / 2.4.0 / gems / devise4.4.3 / lib / devise / test / controller_helpers.rb:30:in block in <module:ControllerHelpers>': undefined method setup&#39; for Object:Class(NoMethodError)

这是来自controller_helpers文件的错误引用的行:

module Devise
   module Test

      module ControllerHelpers
        extend ActiveSupport::Concern

        included do
           setup :setup_controller_for_warden, :warden
        end
         .
         .
         .

这些是我的测试宝石:

group :test do
   gem 'rails-controller-testing', '1.0.2'
   gem 'minitest-reporters',       '1.1.14'
   gem 'guard',                    '2.13.0'
   gem 'guard-minitest',           '2.4.4'
end

这是我的test_helper.rb文件:

ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
require "minitest/reporters"
Minitest::Reporters.use!

class ActiveSupport::TestCase
    fixtures :all 
end

这是我的一项测试:

require 'test_helper'

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

 setup do
    @user = users(:one)
 end

 test "should get index" do
    get users_url
    assert_response :success
 end

 test "should get new" do
   get new_user_url
   assert_response :success
 end
  .
  .
  .
end

对此问题的任何帮助将不胜感激。谢谢。

0 个答案:

没有答案