Search code examples
ruby-on-railsrubyrspecdatabase-cleanerruby-on-rails-5

Database Cleaner unable to detect ORM in Rails application


The error below is displayed when $ rspec is executed:

No known ORM was detected! Is ActiveRecord, DataMapper, Sequel, MongoMapper, Mongoid, Moped, or CouchPotato, Redis or Ohm loaded? (DatabaseCleaner::NoORMDetected)

This is a snippet from the spec_helper.rb file:

config.before(:suite) do
  DatabaseCleaner.strategy = :transaction
  DatabaseCleaner.clean_with(:truncation)
end

The Rails application in question uses ActiveRecord as the ORM and the documentation for Database Cleaner states that it checks for ActiveRecord first.

The Rails version for the application is 5.0.0.beta2.

What is the cause of the error and how can this be fixed?


Solution

  • The cause:

    The error is caused by the absence of a model. Because there is no model, no ORM has been specified by the application. As a result, DatabaseCleaner cannot choose an appropriate strategy.

    Solution

    At least one model should be created. This can be done via the rails generate scaffold or rails generate model commands.