Class: Maxitest::Line::LineReporter

Inherits:
Minitest::Reporter
  • Object
show all
Defined in:
lib/maxitest/line.rb

Instance Method Summary collapse

Constructor Details

#initializeLineReporter

Returns a new instance of LineReporter.



37
38
39
40
# File 'lib/maxitest/line.rb', line 37

def initialize(*)
  super
  @failures = []
end

Instance Method Details

#record(result) ⇒ Object



42
43
44
45
46
# File 'lib/maxitest/line.rb', line 42

def record(result)
  if !result.skipped? && !result.passed?
    @failures << result
  end
end

#reportObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/maxitest/line.rb', line 48

def report
  return unless @failures.any?
  io.puts
  io.puts "Focus on failing tests:"
  pwd = Pathname.new(Dir.pwd)
  bin_rails = File.exist?("bin/rails")
  @failures.each do |res|
    result = (res.respond_to?(:source_location) ? res : res.method(res.name))
    file, line = result.source_location
    next unless file

    file = Pathname.new(file)
    file = file.relative_path_from(pwd) if file.absolute?
    output = "#{bin_rails ? "bin/rails test" : "minitest"} #{file}:#{line}"
    output = "\e[31m#{output}\e[0m" if $stdout.tty?
    io.puts output
  end
end