ruby-on-rails - 使用新的Rails/MongoID应用程序配置RSpec

标签 ruby-on-rails rspec mongoid

我正在启动一个新应用程序,并注意到上次从头构建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/

相关文章:

css - 使用 Bootstrap CDN 时如何更改 Bootstrap 断点大小

ruby-on-rails-3 - RoutingError 与 RSpec Controller 对作用域路由进行测试

ruby - 使用 Rspec 测试 Goliath + Grape

ruby-on-rails - 为什么 elem_match 返回 0 个元素?

ruby-on-rails - 在MongoDB中使用巨大的 "documents"不好吗?

ruby-on-rails - 在 Ruby 哈希中提取 `Moped::BSON::Document` 属性

ruby-on-rails - 回形针( rails )的动态附件尺寸

ruby-on-rails - 简单的 Rails 文本字段格式

ruby-on-rails - 如何在 Rails 中测试非 ActiveRecord 模型?

ruby-on-rails - 模型属于 2 个 has_many 关联时的机械师蓝图