From 7ebf44d1e4c91d1bd4e3907f14591c5cbbe85d02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ana=20Mar=C3=ADa=20Mart=C3=ADnez=20G=C3=B3mez?= Date: Tue, 10 Jan 2017 18:29:25 +0100 Subject: [PATCH 1/2] 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. --- spec/spec_helper.rb | 7 ------- spec/support/database_cleaner.rb | 11 +++++++---- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 3b387199..fc56e829 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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 diff --git a/spec/support/database_cleaner.rb b/spec/support/database_cleaner.rb index 2d47903d..fc2fcea3 100644 --- a/spec/support/database_cleaner.rb +++ b/spec/support/database_cleaner.rb @@ -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 From e4104ba2cdb84699ee2e83ee18b75a587b4c92ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ana=20Mar=C3=ADa=20Mart=C3=ADnez=20G=C3=B3mez?= Date: Wed, 11 Jan 2017 10:01:09 +0100 Subject: [PATCH 2/2] Fix the Travis failures in rspec --- spec/support/database_cleaner.rb | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/spec/support/database_cleaner.rb b/spec/support/database_cleaner.rb index fc2fcea3..3e6c8404 100644 --- a/spec/support/database_cleaner.rb +++ b/spec/support/database_cleaner.rb @@ -1,16 +1,6 @@ RSpec.configure do |config| - config.before(:suite) do + config.before(:each) do DatabaseCleaner.clean_with(:truncation) Rails.application.load_seed end - - config.before(:each) do |example| - DatabaseCleaner.strategy = (example.metadata[:js] == true) ? :truncation : :transaction - DatabaseCleaner.start - end - - config.after(:each) do |example| - DatabaseCleaner.clean - Rails.application.load_seed if example.metadata[:js] == true - end end