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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
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
if tu.respond_to? :run_suite then
tu.run_suite reporter, options
else
tu.run reporter, options
end
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
def teardown
super
Object.send :remove_const, :ATestCase if defined? ATestCase
end
end
|