當我試圖運行下面的代碼:未初始化的常量的ActiveSupport :: TestCase的
測試/模型/ 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)
如果*只*需要'test_helper'會怎麼樣?並且是你的測試文件在'/ test'文件夾內? – zwippie 2014-11-24 20:14:06
同樣的事情。是的,這是在test/models/tweet_test.rb裏面 – 2014-11-24 20:54:10
是否存在文件'/ test/test_helper.rb'並且它包含了一些看起來像在運行'rails new my_project'之後從未搞混過的東西?如果沒有,則創建一個新的空Rails項目,並將新生成的'test_helper'文件複製到當前項目中。 – zwippie 2014-11-24 20:59:53