aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authorKasper Timm Hansen <kaspth@gmail.com>2018-02-18 21:35:30 +0100
committerKasper Timm Hansen <kaspth@gmail.com>2018-02-18 21:35:30 +0100
commit6cc000c34cc6ecea9262033c46ad795f9bc56f07 (patch)
tree4696e3f12e647ed129be09d66ae994d9fb9f4aa7 /railties
parent86f7c269073a3a9e6ddec9b957deaa2716f2627d (diff)
downloadrails-6cc000c34cc6ecea9262033c46ad795f9bc56f07.tar.gz
rails-6cc000c34cc6ecea9262033c46ad795f9bc56f07.tar.bz2
rails-6cc000c34cc6ecea9262033c46ad795f9bc56f07.zip
Clean up reporter replacement a bit.
* Don't use :: for class methods, we don't do that elsewhere. * Don't install a needless method on minitest. Prefer assigning the reporter anyway as that's what minitest does internally. * Don't bother opting out when the reporter ain't a Minitest::CompositeReporter. It's hardcoded: https://github.com/seattlerb/minitest/blob/005a3ba42c07d04797e2d00ac2c53e3be127c12f/lib/minitest.rb#L125 And overrides have to create delegate reporters: https://github.com/kern/minitest-reporters/blob/1018b1b42f34b01d4de179c8aad2fa06771fe9b0/lib/minitest/minitest_reporter_plugin.rb#L72
Diffstat (limited to 'railties')
-rw-r--r--railties/lib/minitest/rails_plugin.rb16
-rw-r--r--railties/test/minitest/rails_plugin_test.rb42
2 files changed, 29 insertions, 29 deletions
diff --git a/railties/lib/minitest/rails_plugin.rb b/railties/lib/minitest/rails_plugin.rb
index 8b2f15a842..7193abbc33 100644
--- a/railties/lib/minitest/rails_plugin.rb
+++ b/railties/lib/minitest/rails_plugin.rb
@@ -43,18 +43,14 @@ module Minitest
Minitest.backtrace_filter = ::Rails.backtrace_cleaner if ::Rails.respond_to?(:backtrace_cleaner)
end
- self.plugin_rails_replace_reporters(reporter, options)
- end
-
- def self.plugin_rails_replace_reporters(minitest_reporter, options)
- return unless minitest_reporter.kind_of?(Minitest::CompositeReporter)
+ # Suppress summary reports when outputting inline rerun snippets.
+ if reporter.reporters.reject! { |reporter| reporter.kind_of?(SummaryReporter) }
+ reporter << SuppressedSummaryReporter.new(options[:io], options)
+ end
# Replace progress reporter for colors.
- if minitest_reporter.reporters.reject! { |reporter| reporter.kind_of?(SummaryReporter) } != nil
- minitest_reporter << SuppressedSummaryReporter.new(options[:io], options)
- end
- if minitest_reporter.reporters.reject! { |reporter| reporter.kind_of?(ProgressReporter) } != nil
- minitest_reporter << ::Rails::TestUnitReporter.new(options[:io], options)
+ if reporter.reporters.reject! { |reporter| reporter.kind_of?(ProgressReporter) }
+ reporter << ::Rails::TestUnitReporter.new(options[:io], options)
end
end
diff --git a/railties/test/minitest/rails_plugin_test.rb b/railties/test/minitest/rails_plugin_test.rb
index 423e74fc66..1620bc312f 100644
--- a/railties/test/minitest/rails_plugin_test.rb
+++ b/railties/test/minitest/rails_plugin_test.rb
@@ -9,30 +9,34 @@ class Minitest::RailsPluginTest < ActiveSupport::TestCase
end
test "default reporters are replaced" do
- reporter = Minitest::CompositeReporter.new
- reporter << Minitest::SummaryReporter.new(@output, @options)
- reporter << Minitest::ProgressReporter.new(@output, @options)
- reporter << Minitest::Reporter.new(@output, @options)
-
- Minitest::plugin_rails_replace_reporters(reporter, {})
-
- assert_equal 3, reporter.reporters.count
- assert reporter.reporters.any? { |candidate| candidate.kind_of?(Minitest::SuppressedSummaryReporter) }
- assert reporter.reporters.any? { |candidate| candidate.kind_of?(::Rails::TestUnitReporter) }
- assert reporter.reporters.any? { |candidate| candidate.kind_of?(Minitest::Reporter) }
+ with_reporter Minitest::CompositeReporter.new do |reporter|
+ reporter << Minitest::SummaryReporter.new(@output, @options)
+ reporter << Minitest::ProgressReporter.new(@output, @options)
+ reporter << Minitest::Reporter.new(@output, @options)
+
+ Minitest.plugin_rails_init({})
+
+ assert_equal 3, reporter.reporters.count
+ assert reporter.reporters.any? { |candidate| candidate.kind_of?(Minitest::SuppressedSummaryReporter) }
+ assert reporter.reporters.any? { |candidate| candidate.kind_of?(::Rails::TestUnitReporter) }
+ assert reporter.reporters.any? { |candidate| candidate.kind_of?(Minitest::Reporter) }
+ end
end
test "no custom reporters are added if nothing to replace" do
- reporter = Minitest::CompositeReporter.new
+ with_reporter Minitest::CompositeReporter.new do |reporter|
+ Minitest.plugin_rails_init({})
- Minitest::plugin_rails_replace_reporters(reporter, {})
-
- assert_equal 0, reporter.reporters.count
+ assert_empty reporter.reporters
+ end
end
- test "handle the case when reporter is not CompositeReporter" do
- reporter = Minitest::Reporter.new
+ private
+ def with_reporter(reporter)
+ old_reporter, Minitest.reporter = Minitest.reporter, reporter
- Minitest::plugin_rails_replace_reporters(reporter, {})
- end
+ yield reporter
+ ensure
+ Minitest.reporter = old_reporter
+ end
end