1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/railties/test/minitest/rails_plugin_test.rb
Kasper Timm Hansen 6cc000c34c
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: 005a3ba42c/lib/minitest.rb (L125)
  And overrides have to create delegate reporters:
  1018b1b42f/lib/minitest/minitest_reporter_plugin.rb (L72)
2018-02-18 21:35:30 +01:00

42 lines
1.3 KiB
Ruby

# 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
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
with_reporter Minitest::CompositeReporter.new do |reporter|
Minitest.plugin_rails_init({})
assert_empty reporter.reporters
end
end
private
def with_reporter(reporter)
old_reporter, Minitest.reporter = Minitest.reporter, reporter
yield reporter
ensure
Minitest.reporter = old_reporter
end
end