# Gemfile
group :development, :test do
...
gem 'parallel_tests'
gem 'database_cleaner'
end
# config/database.yml
test:
<<: *default
database: db/test<%= ENV['TEST_ENV_NUMBER'] %>.sqlite3
# spec/support/database_cleaner.rb
# Don't forget to add the below comment to your rails_helper.rb
# require 'support/database_cleaner' or
# Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
RSpec.configure do |config|
config.before(:suite) do
DatabaseCleaner.clean_with(:truncation)
end
config.before(:each) do
DatabaseCleaner.strategy = :transaction
end
config.before(:each, type: :feature) do
DatabaseCleaner.strategy = :truncation
end
config.before(:each) do
DatabaseCleaner.start
end
config.after(:each) do
DatabaseCleaner.clean
end
end