1
我正在使用rails 4.2.1 & ruby 2.2.1在我的應用程序中。所以minitest會自動添加,版本號爲5.1。我的應用程序中沒有數據庫。 有了數據庫,我可以測試模型。如何在沒有數據庫的情況下測試模型?如何用Minitest和沒有數據庫測試模型?
我創建了一個用戶模型:
class User
include ActiveModel::Model
end
users.yml裏:
one:
firstName: Avi
email: [email protected]
user_test.rb:
require 'test_helper'
class UserTest < ActiveSupport::TestCase
test "the truth" do
user = users(:one)
assert true
end
end
在這裏,我得到的錯誤:Undefined methods users
。如果daabase存在,我會獲得正確的數據。 我甚至嘗試加入include ActiveModel::Lint::Tests
仍然收到相同的錯誤。 任何人都可以幫助我嗎?
由於
稍微有點棘手,我找到了。您需要手動導入minitest,而不是* test_helper.rb *中的默認* rails/test_help * ...當我將它分類後,會報告更多... – ericpeters0n