我正在启动一个新应用程序,并注意到上次从头构建MongoID应用程序时缺少一些文档。也就是说,他们曾经建议在不再存在的页面上(http://mongoid.org/docs/integration/)包含一些代码来删除MongoID的集合(经过测试)。
不再在网站上提及... ,这个(下面的****)不再被认为是必要的或好的惯例吗?!
#spec/spec_helper.rb:
...
RSpec.configure do |config|
config.mock_with :rspec
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
#config.fixture_path = "#{::Rails.root}/spec/fixtures"
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# instead of true.
#config.use_transactional_fixtures = true
# Below from <http://mongoid.org/docs/integration/> ****
config.after :suite do
Mongoid.master.collections.select do |collection|
collection.name !~ /system/
end.each(&:drop)
end
end
最佳答案
修改文件 spec/spec_helper.rb 来添加以下内容:
RSpec.configure做| config |
# 其他事情
#清理数据库
需要'database_cleaner'
config.before(:suite)做
DatabaseCleaner.strategy =:截断
DatabaseCleaner.orm =“蒙古包”
结尾
config.before(:each)做
DatabaseCleaner.clean
结尾
结尾
关于ruby-on-rails - 使用新的Rails/MongoID应用程序配置RSpec,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5825645/