【发布时间】:2014-12-01 19:41:42
【问题描述】:
当我运行控制器(或功能)测试时,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'
帐户控制器定义:
class AccountController < ApplicationController
before_filter :login_required, :except => [
应用控制器:
class ApplicationController < ActionController::Base
【问题讨论】:
-
AccountController是如何定义的? -
AccountController 定义在:github.com/JoeCohen/mushroom-observer/blob/ror4-joe/app/…
-
定义在哪里?
-
应用程序/控制器/account_controller.rb
-
我明白了,但我没有在帖子中看到这里的定义。
标签: ruby-on-rails ruby-on-rails-4 minitest testunit