2015-05-11 7 views
9

Impossibile pulire i dati utilizzando database_cleaner.rb; lanciando il seguente problema sui test di corsa.`autodetect ': non è stato rilevato alcun ORM noto

/Users/prashanth_sams/.rvm/gems/ruby-2.0.0-p598/gems/database_cleaner-1.3.0/lib/database_cleaner/base.rb:147:in `rilevare automaticamente ': Non sono noti È stato rilevato ORM! ActiveRecord, DataMapper, Sequel, MongoMapper, Mongoide, Ciclomotore o CouchPotato, Redis o Ohm caricato? (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 
+0

checkout questo blog per configurare Database Cleaner http://devblog.avdi.org/2012/08/31/configuring-database_cleaner-with-rails-rspec-capybara-and-selenium/ –

+0

Hai definito un modello? – gnerkus

risposta

0

Usa mio setup, sembra funzionare bene per RDBMS (che cked su MySQL e Postgres), alla tua database_cleaner.rb:

RSpec.configure do |config| 
    config.use_transactional_fixtures = false 

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

    config.before(:each) do 
    DatabaseCleaner.strategy = :transaction 
    end 

    # this may be needed for Capybara tests and for testing after_commit hooks 
    config.before(:each, strategy: :truncation) do 
    DatabaseCleaner.strategy = :truncation 
    end 

    config.before(:each) do 
    DatabaseCleaner.start 
    end 

    config.after(:each) do 
    DatabaseCleaner.clean 
    end 
end 

Se si desidera utilizzare truncation strategia, basta usare describe 'something', strategy: :truncation o it 'something', strategy: truncation.

4

Ho avuto lo stesso problema su controller_spec. 'autodetect': No known ORM was detected! Is ActiveRecord, DataMapper, Sequel, MongoMapper, Mongoid, Moped, or CouchPotato, Redis or Ohm loaded? (DatabaseCleaner::NoORMDetected)

Ho risolto richiedendo il file rails_helper sulle specifiche del controller.

require 'rails_helper' 

In rails_helper.rb richiede il file 'database_cleaner'.

require 'database_cleaner' 
0

ho avuto questo problema (on Rails 5.1) e la ragione era che avevo

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

config.before(:each) do 
    DatabaseCleaner.strategy = :transaction 
end 

config.before(:each) do 
    DatabaseCleaner.start 
end 

config.after(:each) do 
    DatabaseCleaner.clean 
end 

nel mio spec_helper.rb.

Ho inserito require 'database_cleaner in spec_helper.rb.

Quindi alla fine ho spostato entrambe le cose su rails_helper.rb e questo ha risolto il problema per me.