Installazione DatabaseCleaner
Crea il file spec/plugins/database-cleaner.rb e aggiungilo al file rails_helper.rb
require 'plugins/database-cleaner'Nello stesso file aggiungere il codice sottostante
# frozen_string_literal: true
require 'database_cleaner/active_record'
RSpec.configure do |config|
config.before(:suite) do
DatabaseCleaner.clean_with(:truncation)
DatabaseCleaner.strategy = :transaction
DatabaseCleaner.start
end
config.around do |example|
DatabaseCleaner.cleaning do
example.run
end
end
endLast updated
Was this helpful?