2015-05-11 38 views
9

Nie można wyczyścić danych za pomocą database_cleaner.rb; rzucanie następującego problemu podczas uruchamiania testów.`autodetect ': nie wykryto ORM

/Users/prashanth_sams/.rvm/gems/ruby-2.0.0-p598/gems/database_cleaner-1.3.0/lib/database_cleaner/base.rb:147:in `wykryje ': Brak doniesień Wykryto ORM! Czy ActiveRecord, DataMapper, Sequel, MongoMapper, Mongoid, Motorower lub CouchPotato, Redis lub Ohm są załadowane? (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

Zamówienie tego bloga do konfiguracji Czyszczenia baz danych http://devblog.avdi.org/2012/08/31/configuring-database_cleaner-with-rails-rspec-capybara-and-selenium/ –

+0

Czy zdefiniowałeś model? – gnerkus

Odpowiedz

0

Użyj mojej konfiguracji, wydaje się działać dobrze dla RDBMS (che cked na MySQL i PostgreSQL), umieścić go w 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 

Jeśli chcesz użyć truncation strategię, wystarczy użyć describe 'something', strategy: :truncation lub it 'something', strategy: truncation.

4

Miałem ten sam problem na control_spec. 'autodetect': No known ORM was detected! Is ActiveRecord, DataMapper, Sequel, MongoMapper, Mongoid, Moped, or CouchPotato, Redis or Ohm loaded? (DatabaseCleaner::NoORMDetected)

Rozwiązałem, wymagając pliku rails_helper na specyfikacji kontrolera.

require 'rails_helper' 

W katalogu rails_helper.rb wymagany jest plik "database_cleaner".

require 'database_cleaner' 
0

miałem ten problem (on Rails 5.1) a powodem było to, że miałem

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 

w moim spec_helper.rb.

Umieszczam również require 'database_cleaner w spec_helper.rb.

Tak więc ostatecznie przeniosłem obie rzeczy do rails_helper.rb i to naprawiło problem dla mnie.