如何使用MongoDB通过Mongoid on Rails编写适当的单元测试(以及相关的集成测试)?
我这样问是因为与使用SQLite3相反,即使在运行测试时,我所做的一切都会持续.所以目前我正在编写创建测试,然后手动删除我所做的一切.但是集成测试越来越烦人,甚至变得复杂.
我所做的示例:
before(:each) do
@user = User.create!(@attr)
end
after(:each) do
# MongoDB is not a transactional DB, so added objects (create) during tests can't be rollbacked
# checking for the existance of a similar object with exact :name and :email (regex make it case insensitive)
cleanup = User.where(:name => "Example User", :email => /^user@example.com/i)
cleanup.destroy unless cleanup.nil?
end
知道如何让MongoDB在测试期间不持久吗?(我甚至无法在Sandbox 模式下运行控制台,因为要使用Mongoid,我必须停用活动记录).