diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 72df165de21..805a4561c42 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -678,6 +678,33 @@ RSpec.configure do |config| BlockRequestsMiddleware.current_example_location = example.location end + config.after :each do |example| + if example.exception && RspecErrorTracker.exceptions.present? + lines = (RSpec.current_example.metadata[:extra_failure_lines] ||= +"") + + lines << "~~~~~~~ SERVER EXCEPTIONS ~~~~~~~" + + RspecErrorTracker.exceptions.each_with_index do |(path, ex), index| + lines << "\n" + lines << "Error encountered while proccessing #{path}" + lines << " #{ex.class}: #{ex.message}" + ex.backtrace.each_with_index do |line, backtrace_index| + if ENV["RSPEC_EXCLUDE_GEMS_IN_BACKTRACE"] + next if line.match?(%r{/gems/}) + end + lines << " #{line}\n" + end + end + + lines << "~~~~~~~ END SERVER EXCEPTIONS ~~~~~~~" + lines << "\n" + end + + unfreeze_time + ActionMailer::Base.deliveries.clear + Discourse.redis.flushdb + end + config.after(:each, type: :system) do |example| lines = RSpec.current_example.metadata[:extra_failure_lines] @@ -738,33 +765,6 @@ RSpec.configure do |config| MessageBus.backend_instance.reset! # Clears all existing backlog from memory backend end - config.after :each do |example| - if example.exception && RspecErrorTracker.exceptions.present? - lines = (RSpec.current_example.metadata[:extra_failure_lines] ||= +"") - - lines << "~~~~~~~ SERVER EXCEPTIONS ~~~~~~~" - - RspecErrorTracker.exceptions.each_with_index do |(path, ex), index| - lines << "\n" - lines << "Error encountered while proccessing #{path}" - lines << " #{ex.class}: #{ex.message}" - ex.backtrace.each_with_index do |line, backtrace_index| - if ENV["RSPEC_EXCLUDE_GEMS_IN_BACKTRACE"] - next if line.match?(%r{/gems/}) - end - lines << " #{line}\n" - end - end - - lines << "~~~~~~~ END SERVER EXCEPTIONS ~~~~~~~" - lines << "\n" - end - - unfreeze_time - ActionMailer::Base.deliveries.clear - Discourse.redis.flushdb - end - config.before(:each, type: :multisite) do Rails.configuration.multisite = true # rubocop:disable Discourse/NoDirectMultisiteManipulation