I'm trying to implement shoulda unit tests on a rails 2.3.5 app using mongomapper.
So far I've:
rake gems:install
config.frameworks -= [ :active_record, :active_resource
] to config/environment.rb
so ActiveRecord
isn't used.My models look like this:
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
My test for that model is this one:
class AccountTest < Test::Unit::TestCase
should_belong_to :company
should_have_many :operations
should_validate_presence_of :name
end
It fails on the first should_belong_to
:
./test/unit/account_test.rb:3: undefined method `should_belong_to' for AccountTest:Class (NoMethodError)
Any ideas why this doesn't work? Should I try something different from shoulda?
I must point out that this is the first time I try to use shoulda, and I'm pretty new to testing itself.
After studying shoulda more profoundly, I realized what was wrong.
Shoulda's macros (should_belong_to
, should_have_many
, should_validate_presence_of
) are only available for ActiveRecord - after all they are defined on Shoulda::ActiveRecord::Macros.
If I were to use those, I would have to implement macros for Shoulda::MongoMapper::Macros. I'm not sure it is worth it.
I hope this helps anyone finding this post.