1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Decorate Rails' backtrace cleaner before passing to minitest

The minitest database cleaner never returns empty traces so we need to
make sure ours also have the same behavior before passing to minitest.
This commit is contained in:
Rafael Mendonça França 2020-10-06 23:18:16 +00:00
parent d98d749222
commit 0c8df42b50
No known key found for this signature in database
GPG key ID: FC23B6D0F1EEE948
2 changed files with 14 additions and 2 deletions

View file

@ -35,12 +35,24 @@ module Minitest
options[:output_inline] = true
end
class RailsBacktraceCleanerDecorator
def initialize(backtrace_cleaner)
@backtrace_cleaner = backtrace_cleaner
end
def filter(backtrace)
filtered = @backtrace_cleaner.filter(backtrace)
filtered = backtrace.dup if filtered.empty?
filtered
end
end
# Owes great inspiration to test runner trailblazers like RSpec,
# minitest-reporters, maxitest and others.
def self.plugin_rails_init(options)
unless options[:full_backtrace] || ENV["BACKTRACE"]
# Plugin can run without Rails loaded, check before filtering.
Minitest.backtrace_filter = ::Rails.backtrace_cleaner if ::Rails.respond_to?(:backtrace_cleaner)
Minitest.backtrace_filter = RailsBacktraceCleanerDecorator.new(::Rails.backtrace_cleaner) if ::Rails.respond_to?(:backtrace_cleaner)
end
# Suppress summary reports when outputting inline rerun snippets.

View file

@ -514,7 +514,7 @@ module ApplicationTests
def test_shows_filtered_backtrace_by_default
create_backtrace_test
assert_match "Rails::BacktraceCleaner", run_test_command("test/unit/backtrace_test.rb")
assert_match "Minitest::RailsBacktraceCleanerDecorator", run_test_command("test/unit/backtrace_test.rb")
end
def test_backtrace_option