Ruby on rails Rails 4.0运行时错误:@controller为nil:确保在测试中设置它';s设置方法

Ruby on rails Rails 4.0运行时错误:@controller为nil:确保在测试中设置它';s设置方法,ruby-on-rails,ruby-on-rails-4,minitest,testunit,Ruby On Rails,Ruby On Rails 4,Minitest,Testunit,当我运行控制器(或功能)测试时,Rails 4.0无法自动实例化控制器实例(@controller),即使相同的测试在Rails 3.2中运行良好。 关于如何开始解决这个问题有什么建议吗 样本输出: $ ruby -Ilib:test test/controllers/account_controller_test.rb [Coveralls] Set up the SimpleCov formatter. [Coveralls] Using SimpleCov's 'rails' setti

当我运行控制器(或功能)测试时,Rails 4.0无法自动实例化控制器实例(@controller),即使相同的测试在Rails 3.2中运行良好。
关于如何开始解决这个问题有什么建议吗

样本输出:

 $ ruby -Ilib:test test/controllers/account_controller_test.rb
[Coveralls] Set up the SimpleCov formatter.
[Coveralls] Using SimpleCov's 'rails' settings.
warning: parser/current is loading parser/ruby21, which recognizes
warning: 2.1.5-compliant syntax, but you are running 2.1.3.

...

  1) Error:
AccountControllerTest#test_activate_api_key:
NoMethodError: undefined method `before_filter' for AccountController:Class
    app/controllers/account_controller.rb:47:in `<class:AccountController>'
    app/controllers/account_controller.rb:46:in `<top (required)>'

  2) Error:
AccountControllerTest#test_add_mugshot:
RuntimeError: @controller is nil: make sure you set it in your test's setup method.
    test/functional_test_case.rb:26:in `post'
    test/controller_extensions.rb:533:in `assert_request'
    test/controller_extensions.rb:202:in `either_requires_either'
    test/controller_extensions.rb:137:in `post_requires_login'
    test/controllers/account_controller_test.rb:418:in `test_add_mugshot'
$ruby-Ilib:test-test/controllers/account\u controller\u test.rb
[工作服]设置SimpleCov格式化程序。
[工作服]使用SimpleCov的“rails”设置。
警告:parser/current正在加载parser/ruby21,它可以识别
警告:符合2.1.5的语法,但您正在运行2.1.3。
...
1) 错误:
AccountControllerTest#test(测试)激活(api)键:
NoMethodError:AccountController:类的未定义方法“before_filter”
app/controllers/account\u controller.rb:47:in`'
app/controllers/account\u controller.rb:46:in`'
2) 错误:
AccountControllerTest#test _add _mugshot:
RuntimeError:@controller为nil:请确保在测试的设置方法中设置它。
测试/功能测试案例。rb:26:in'post'
test/controller_extensions.rb:533:in'assert_request'
test/controller\u extensions.rb:202:in'other\u requires\u other'
测试/控制器扩展。rb:137:in`post\u需要登录'
test/controllers/account\u controller\u test.rb:418:in'test\u add\u mugshot'
帐户控制器定义:

class AccountController < ApplicationController
  before_filter :login_required, :except => [
class AccountController[
应用程序控制器:

class ApplicationController < ActionController::Base
class ApplicationController
在定义
AccountController
时,似乎
ApplicationController
不是从
ActionController::Base
派生出来的,因此在
AccountController
声明之前添加
require

# file app/controllers/account_controller.rb
require 'app/controllers/application_controller'

class AccountController < ApplicationController
  before_filter :login_required, :except => [
#文件app/controllers/account_controller.rb
需要“应用程序/控制器/应用程序\控制器”
类AccountController<应用程序控制器
在筛选之前:需要登录,:except=>[

如何定义
AccountController
?AccountController在中定义:它在哪里定义?app/controllers/account_controller.rbI请参阅,但我在帖子中看不到定义。谢谢你添加一个require解决了问题。问题似乎来自以不同顺序加载的文件n Rails 4.应用程序的test\u helper文件试图重新打开ApplicationController的定义。这在Rails 3中运行良好。但看起来Rails 4在加载控制器之前加载了test\u helper。因此,test\u helper文件没有重新打开ApplicationController,而是为其提供了一个初始定义,该定义不是从Actio派生的nController::Base。