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.
This commit is contained in:
Martin Brennan 2024-07-31 14:08:37 +10:00 committed by GitHub
parent 46b296527b
commit a47bcfc2f3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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