使用新的 Rails/MongoID 应用程序配置 RSpec
我正在启动一个新应用程序,并注意到上次从头开始构建 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
I'm starting a new app and notice some missing documentation from the last time I built a MongoID app from scratch. Namely they used to suggest on a page that no longer exists (http://mongoid.org/docs/integration/) to include some code to drop MongoID's collections (after tests).
It's not mentioned on site anymore...is this (**** below) no longer considered necessary or good practice?!?
#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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这似乎也适用于 Rails3 并且更加简洁
它不需要额外的 GEM。
This also seems to be working on Rails3 and is more neat
It does not need an additional GEM.
修改文件 spec/spec_helper.rb 添加以下内容:
Modify the file spec/spec_helper.rb to add this:
您可以继续这样做(尽管可能切换到之前的套件)——DatabaseCleaner gem 很好。
You can do keep doing (although maybe switch to before suite) that -- the DatabaseCleaner gem is nice though.
mongo(id) 数据库清理器的要点
The gist of database cleaner for mongo(id)