m
m copied to clipboard
Suggestion for custom reporter
I like rspec's feature that print commands to re-run failed tests. I tried to implement same for m
(minitest).
Do you think it will be nice to make it as part of m
(only module to extend minitest's reporter)?
module MRerun
def m_rerun
out = StringIO.new
failed = tests.reject {|t| t.passed? || t.skipped? }
if failed.size > 0
out.puts "\nRe-run with m:"
failed.each do |test|
file = nil
test.failure.backtrace.each do |line|
path = line.split(':in').first
if path =~ /_(test|spec).rb:\d+$/
file = path
break
end
end
file ||= test.failure.location
out.puts "m #{file.sub(Dir.pwd, '').sub(/^\//, '')}"
end
end
out.string
end
def on_report
super
puts yellow(m_rerun)
end
end
class Minitest::Reporters::DefaultReporterWithM < Minitest::Reporters::DefaultReporter
include MRerun
end
Minitest::Reporters.use!(
Minitest::Reporters::DefaultReporterWithM.new(color: true)
)
Thanks for the suggestion, I do like that feature of RSpec, but the rspec retry feature goes even further and saves the tests that failed in a file and you can then run only those with one command.
If you want to try to do that for M
in a way that works for all the runners we support I'd be willing to merge it in.