diff options
author | Rafael França <rafaelmfranca@gmail.com> | 2018-02-16 22:37:23 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-16 22:37:23 -0500 |
commit | 7340596de45dc4c0f62a287b6acc4e71d8ee6c60 (patch) | |
tree | 0a9a46ac944a47ad6aae724eabea43f697d206bf /railties | |
parent | 65b370fe7d11d19dcec202967f9a70a4c040e96c (diff) | |
parent | 40a5ba30fb41eba633106509c5b362761b18d497 (diff) | |
download | rails-7340596de45dc4c0f62a287b6acc4e71d8ee6c60.tar.gz rails-7340596de45dc4c0f62a287b6acc4e71d8ee6c60.tar.bz2 rails-7340596de45dc4c0f62a287b6acc4e71d8ee6c60.zip |
Merge pull request #31901 from Kevinrob/patch-1
Use SuppressedSummaryReporter and Rails::TestUnitReporter only if needed
Diffstat (limited to 'railties')
-rw-r--r-- | railties/CHANGELOG.md | 2 | ||||
-rw-r--r-- | railties/lib/minitest/rails_plugin.rb | 15 | ||||
-rw-r--r-- | railties/test/minitest/rails_plugin_test.rb | 38 |
3 files changed, 51 insertions, 4 deletions
diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index b3b35307e3..450022a638 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -1,3 +1,3 @@ - +* Fix minitest rails plugin. The custom reporters are added only if needed. This will fix conflicts with others plugins. *Kevin Robatel* Please check [5-2-stable](https://github.com/rails/rails/blob/5-2-stable/railties/CHANGELOG.md) for previous changes. diff --git a/railties/lib/minitest/rails_plugin.rb b/railties/lib/minitest/rails_plugin.rb index 6901b0bbc8..8b2f15a842 100644 --- a/railties/lib/minitest/rails_plugin.rb +++ b/railties/lib/minitest/rails_plugin.rb @@ -43,10 +43,19 @@ 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) + # Replace progress reporter for colors. - reporter.reporters.delete_if { |reporter| reporter.kind_of?(SummaryReporter) || reporter.kind_of?(ProgressReporter) } - reporter << SuppressedSummaryReporter.new(options[:io], options) - reporter << ::Rails::TestUnitReporter.new(options[:io], options) + 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) + end end # Backwardscompatibility with Rails 5.0 generated plugin test scripts diff --git a/railties/test/minitest/rails_plugin_test.rb b/railties/test/minitest/rails_plugin_test.rb new file mode 100644 index 0000000000..423e74fc66 --- /dev/null +++ b/railties/test/minitest/rails_plugin_test.rb @@ -0,0 +1,38 @@ +# frozen_string_literal: true + +require "abstract_unit" + +class Minitest::RailsPluginTest < ActiveSupport::TestCase + setup do + @options = Minitest.process_args [] + @output = StringIO.new("".encode("UTF-8")) + 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) } + end + + test "no custom reporters are added if nothing to replace" do + reporter = Minitest::CompositeReporter.new + + Minitest::plugin_rails_replace_reporters(reporter, {}) + + assert_equal 0, reporter.reporters.count + end + + test "handle the case when reporter is not CompositeReporter" do + reporter = Minitest::Reporter.new + + Minitest::plugin_rails_replace_reporters(reporter, {}) + end +end |