Improvements in the DatabaseCleaner

Move all what is related to the DatabaseCleaner to the
database_cleaner.rb file. Load the seeds only when they have been
deleted and not before every test.
This commit is contained in:
Ana María Martínez Gómez 2017-01-10 18:29:25 +01:00
parent 052cfebf4e
commit 7ebf44d1e4
2 changed files with 7 additions and 11 deletions

View file

@ -55,13 +55,6 @@ RSpec.configure do |config|
# --seed 1234
config.order = 'random'
config.around(:each) do |example|
DatabaseCleaner.cleaning do
Rails.application.load_seed
example.run
end
end
# poltergeist as a underlying mech for Capybara
Capybara.javascript_driver = :poltergeist

View file

@ -1,13 +1,16 @@
RSpec.configure do |config|
config.before(:suite) do
DatabaseCleaner.clean_with(:truncation)
Rails.application.load_seed
end
config.before(:each) do
DatabaseCleaner.strategy = :transaction
config.before(:each) do |example|
DatabaseCleaner.strategy = (example.metadata[:js] == true) ? :truncation : :transaction
DatabaseCleaner.start
end
config.before(:each, js: true) do
DatabaseCleaner.strategy = :truncation
config.after(:each) do |example|
DatabaseCleaner.clean
Rails.application.load_seed if example.metadata[:js] == true
end
end