ruby-on-rails - `autodetect' : No known ORM was detected

标签 ruby-on-rails ruby ruby-on-rails-3 capybara

无法使用database_cleaner.rb 清理数据;在运行测试时抛出以下问题。

/Users/prashanth_sams/.rvm/gems/ruby-2.0.0-p598/gems/database_cleaner-1.3.0/lib/database_cleaner/base.rb:147:in `autodetect': No known ORM was detected! Is ActiveRecord, DataMapper, Sequel, MongoMapper, Mongoid, Moped, or CouchPotato, Redis or Ohm loaded? (DatabaseCleaner::NoORMDetected)

enter image description here

spec_helper.rb

ENV["RAILS_ENV"] ||= 'test'

require File.expand_path("../config/environment", __FILE__)
require 'rspec/rails'

Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}

RSpec.configure do |config|

  config.mock_with :rspec

  config.use_transactional_fixtures = false


  config.expect_with :rspec do |expectations|
    expectations.include_chain_clauses_in_custom_matcher_descriptions = true
  end

  config.expect_with :rspec do |c|
    c.syntax = [:should, :expect]
  end

  config.mock_with :rspec do |mocks|
    mocks.verify_partial_doubles = true
  end

  config.color = true

  Selenium::Application.reload_routes!

end

database_cleaner.rb

require 'database_cleaner'

DatabaseCleaner.strategy = :truncation

RSpec.configure do |config|
  config.use_transactional_fixtures = false
  config.before :each do
    DatabaseCleaner.start
  end
  config.after :each do
    DatabaseCleaner.clean
  end
end

最佳答案

我在 controller_spec 上遇到了同样的问题。 'autodetect':未检测到已知的 ORM!是否加载了 ActiveRecord、DataMapper、Sequel、MongoMapper、Mongoid、Moped 或 CouchPotato、Redis 或 Ohm? (DatabaseCleaner::NoORMDetected)

我通过在 Controller 规范上要求 rails_helper 文件来解决。

require 'rails_helper'

在 rails_helper.rb 中需要文件“database_cleaner”。

require 'database_cleaner'

关于ruby-on-rails - `autodetect' : No known ORM was detected,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30168421/

相关文章:

ruby-on-rails - 无法确定行数 Ruby-On-Rails

ruby-on-rails - rake 数据库 :migrate - how do I know if there is an unrun migration

ruby - 在瓦提尔打开新的一页

ruby-on-rails - 错误 : Failed to build gem native extension on Mavericks

ruby - 使用户输入的 url 成为 rails 中的外部链接

java.net 正在迁移到 Jruby?

ruby-on-rails - 自定义Rails路由的正确方法

ruby-on-rails - 限制 will_paginate 中的页数

ruby-on-rails - 如何在 Heroku 中重命名文件

ruby-on-rails - 按模型的 belongs_to 关系查询和排序