Sha256: 924980a07b1faeb1364c02921f046fdffb491d3f79efd09d8273a96160e610b0

Contents?: true

Size: 1.73 KB

Versions: 18

Compression:

Stored size: 1.73 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

    yield(reporter) if block_given?

    @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], &block
    header = clean <<-EOM
      Run options: #{flags.map { |s| s =~ /\|/ ? s.inspect : s }.join " "}

      # Running:

    EOM

    run_tu_with_fresh_reporter flags, &block

    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

18 entries across 18 versions & 5 rubygems

Version Path
arcabouco-0.2.13 vendor/bundle/gems/minitest-5.2.0/test/minitest/metametameta.rb
minitest-5.4.0 test/minitest/metametameta.rb
whos_dated_who-0.1.0 vendor/bundle/gems/minitest-5.3.4/test/minitest/metametameta.rb
minitest-5.3.5 test/minitest/metametameta.rb
whos_dated_who-0.0.1 vendor/bundle/gems/minitest-5.3.4/test/minitest/metametameta.rb
minitest-5.3.4 test/minitest/metametameta.rb
spec-5.3.4 test/minitest/metametameta.rb
spec-5.3.3 test/minitest/metametameta.rb
minitest-5.3.3 test/minitest/metametameta.rb
minitest-5.3.2 test/minitest/metametameta.rb
minitest-5.3.1 test/minitest/metametameta.rb
minitest-5.3.0 test/minitest/metametameta.rb
minitest-5.2.3 test/minitest/metametameta.rb
minitest-5.2.2 test/minitest/metametameta.rb
minitest-5.2.1 test/minitest/metametameta.rb
social_url_stats-0.0.1 vendor/ruby/1.9.1/gems/minitest-5.2.0/test/minitest/metametameta.rb
minitest-5.2.0 test/minitest/metametameta.rb
minitest-5.1.0 test/minitest/metametameta.rb