我正在尝试使用 mongomapper 在 rails 2.3.5 应用程序上实现 shoulda 单元测试。
到目前为止,我已经:
- 配置了一个使用 mongomapper 的 rails 应用程序(该应用程序有效)
- 将 shoulda 添加到我的 gems 中,并使用
rake gems:install
- 添加
config.frameworks -= [ :active_record, :active_resource
]config/environment.rb
所以ActiveRecord
不使用。
我的模型如下所示:
class Account
include MongoMapper::Document
key :name, String, :required => true
key :description, String
key :company_id, ObjectId
key :_type, String
belongs_to :company
many :operations
end
我对该模型的测试是这个:
class AccountTest < Test::Unit::TestCase
should_belong_to :company
should_have_many :operations
should_validate_presence_of :name
end
它在第一个失败should_belong_to
:
./test/unit/account_test.rb:3: undefined method `should_belong_to' for AccountTest:Class (NoMethodError)
任何想法为什么这不起作用?我应该尝试与应该不同的东西吗?
我必须指出,这是我第一次尝试使用 shoulda,而且我对测试本身还是很陌生。