当我尝试运行以下代码时:
测试/模型/tweet_test.rb
require 'minitest/spec'
require 'minitest/autorun'
class TweetTest < ActiveSupport::TestCase
test "Tweet should not be null" do
tweet = true
assert tweet
end
end
我收到此错误:
tweet_test.rb:4:in `<main>': uninitialized constant ActiveSupport (NameError)
我正在完美地遵循教程。为什么会发生这种情况? ActiveSuport::TestCase 是否已被弃用?
更新:
我试图require 'test_helper'
:
require 'minitest/spec'
require 'minitest/autorun'
require 'test_helper'
class TweetTest < ActiveSupport::TestCase
test "Tweet should not be null" do
tweet = true
assert tweet
end
end
但收到以下错误:
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- test_helper (LoadError)
最佳答案
您不需要正确的 Rails minitest 文件来设置 ActiveSupport::TestCase
。这是 Rails 特定的类,无法单独在 minitest 中找到。您确定您正在 Rails 项目中工作吗?
在大多数情况下,您可以通过在测试类中要求 test_helper
来在 Rails 中设置测试,以便可以从 ActiveSupport::TestCase
继承。文件 test_helper
包含在 Rails 项目中运行测试的所有要求和设置。
快速修复:只需继承Minitest::Test
。
关于ruby-on-rails - 未初始化常量 ActiveSupport::TestCase,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27112713/