Class: Minitest::LineReporter

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

Instance Method Summary collapse

Constructor Details

#initializeLineReporter

Returns a new instance of LineReporter.



87
88
89
90
# File 'lib/maxitest/vendor/line.rb', line 87

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

Instance Method Details

#record(result) ⇒ Object



92
93
94
95
96
# File 'lib/maxitest/vendor/line.rb', line 92

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

#reportObject



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/maxitest/vendor/line.rb', line 98

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

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