From 7e702fc7ed6fe67b0cda814fe511c8524310fdaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Mon, 20 Apr 2020 16:33:33 +0200 Subject: [PATCH] Fix DB corruption in system tests after exceptions This is a known bug in Rails, fixed in the Rails 5.2 and Rails 6.x branches: https://github.com/rails/rails/pull/32293/commits/5c4e1338 --- spec/rails_helper.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index c4756dd02..3de8fd85d 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -19,6 +19,18 @@ Warden.test_mode! ActiveRecord::Migration.maintain_test_schema! +# Monkey patch from https://github.com/rails/rails/pull/32293 +# Remove when we upgrade to Rails 5.2 +require "action_dispatch/system_testing/test_helpers/setup_and_teardown" +module ActionDispatch::SystemTesting::TestHelpers::SetupAndTeardown + def after_teardown + take_failed_screenshot + Capybara.reset_sessions! + ensure + super + end +end + RSpec.configure do |config| config.infer_spec_type_from_file_location! config.after do