Sha256: d30f719770a3580ce2d0444e588a26fd89dd0344babd5116446d565dcb0beb1a

Contents?: true

Size: 1.67 KB

Versions: 12

Compression:

Stored size: 1.67 KB

Contents

require 'tempfile'
require 'stringio'
require 'minitest/autorun'

class Minitest::Test
  def clean s
    s.gsub(/^ {6}/, '')
  end
end

class MetaMetaMetaTestCase < Minitest::Test
  attr_accessor :reporter, :output, :tu

  def run_tu_with_fresh_reporter flags = %w[--seed 42]
    options = Minitest.process_args flags

    @output = StringIO.new("")

    self.reporter = Minitest::CompositeReporter.new
    reporter << Minitest::SummaryReporter.new(@output, options)
    reporter << Minitest::ProgressReporter.new(@output, options)

    reporter.start

    @tus ||= [@tu]
    @tus.each do |tu|
      Minitest::Runnable.runnables.delete tu

      tu.run reporter, options
    end

    reporter.report
  end

  def first_reporter
    reporter.reporters.first
  end

  def assert_report expected, flags = %w[--seed 42]
    header = clean <<-EOM
      Run options: #{flags.map { |s| s =~ /\|/ ? s.inspect : s }.join " "}

      # Running:

    EOM

    run_tu_with_fresh_reporter flags

    output = normalize_output @output.string.dup

    assert_equal header + expected, output
  end

  def normalize_output output
    output.sub!(/Finished in .*/, "Finished in 0.00")
    output.sub!(/Loaded suite .*/, 'Loaded suite blah')

    output.gsub!(/ = \d+.\d\d s = /, ' = 0.00 s = ')
    output.gsub!(/0x[A-Fa-f0-9]+/, '0xXXX')

    if windows? then
      output.gsub!(/\[(?:[A-Za-z]:)?[^\]:]+:\d+\]/, '[FILE:LINE]')
      output.gsub!(/^(\s+)(?:[A-Za-z]:)?[^:]+:\d+:in/, '\1FILE:LINE:in')
    else
      output.gsub!(/\[[^\]:]+:\d+\]/, '[FILE:LINE]')
      output.gsub!(/^(\s+)[^:]+:\d+:in/, '\1FILE:LINE:in')
    end

    output
  end

  def setup
    super
    srand 42
    Minitest::Test.reset
    @tu = nil
  end
end

Version data entries

12 entries across 12 versions & 3 rubygems

Version Path
minitest-5.0.8 test/minitest/metametameta.rb
minitest-5.0.7 test/minitest/metametameta.rb
spec-5.0.19 test/minitest/metametameta.rb
spec-5.0.18 test/minitest/metametameta.rb
spec-5.0.17 test/minitest/metametameta.rb
spec-5.0.16 test/minitest/metametameta.rb
spec-5.0.15 test/minitest/metametameta.rb
spec-5.0.14 test/minitest/metametameta.rb
minitest-5.0.6 test/minitest/metametameta.rb
minitest-5.0.5 test/minitest/metametameta.rb
swipe-rails-0.0.5 vendor/bundle/gems/minitest-5.0.4/test/minitest/metametameta.rb
minitest-5.0.4 test/minitest/metametameta.rb