提交 caa76956 编写于 作者: R Rafael França 提交者: Rafael Mendonça França

Merge pull request #31901 from Kevinrob/patch-1

Use SuppressedSummaryReporter and Rails::TestUnitReporter only if needed
上级 eb92dd7c
* Fix minitest rails plugin.
The custom reporters are added only if needed.
This will fix conflicts with others plugins.
*Kevin Robatel*
## Rails 5.1.5 (February 14, 2018) ##
* Gemfile for new apps: upgrade redis-rb from ~> 3.0 to 4.0.
......
......@@ -38,10 +38,19 @@ def self.plugin_rails_init(options)
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
......
# 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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册