From a47bcfc2f37470dc9055bca7072189e4348b684e Mon Sep 17 00:00:00 2001 From: Martin Brennan Date: Wed, 31 Jul 2024 14:08:37 +1000 Subject: [PATCH] DEV: Add RSPEC_EXCLUDE_NOISE_IN_BACKTRACE for rspec (#28160) Sometimes the backtrace is quite big for failing specs, this env var (RSPEC_EXCLUDE_NOISE_IN_BACKTRACE) can be set to 1 to remove backtrace from anything but spec or application code in rspec. This makes it easier to see where the actual failure is coming from, most of the time all the gem paths are noise. --- spec/rails_helper.rb | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 943732be66e..058efde2fe9 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -239,7 +239,22 @@ RSpec.configure do |config| # rspec-rails. config.infer_base_class_for_anonymous_controllers = true - config.full_cause_backtrace = true + # Shows more than one line of backtrace in case of an error or spec failure. + config.full_cause_backtrace = false + + # Sometimes the backtrace is quite big for failing specs, this will + # remove rspec/gem paths from the backtrace so it's easier to see the + # actual application code that caused the failure. + if ENV["RSPEC_EXCLUDE_NOISE_IN_BACKTRACE"] + config.backtrace_exclusion_patterns = [ + %r{/lib\d*/ruby/}, + %r{bin/}, + /gems/, + %r{spec/spec_helper\.rb}, + %r{spec/rails_helper\.rb}, + %r{lib/rspec/(core|expectations|matchers|mocks)}, + ] + end config.before(:suite) do CachedCounting.disable