aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test/minitest/rails_plugin_test.rb
blob: 423e74fc663978e9a6f738f91114777a98a028f9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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