Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion for custom reporter #69

Open
Paxa opened this issue Jun 28, 2017 · 1 comment
Open

Suggestion for custom reporter #69

Paxa opened this issue Jun 28, 2017 · 1 comment

Comments

@Paxa
Copy link

Paxa commented Jun 28, 2017

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)
)

screen shot 2017-06-28 at 20 12 16

@zamith
Copy link
Collaborator

zamith commented Dec 14, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants