我正在尝试使用MongoMapper在Rails2.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的方法吗?
我必须指出,这是我第一次尝试使用shoulda,我对测试本身还很陌生。