Class: Test::Unit::Coverage::DefaultPrinter

Inherits:
Object
  • Object
show all
Defined in:
lib/test/unit/coverage.rb

Instance Method Summary collapse

Constructor Details

#initialize(out = $stdout) ⇒ DefaultPrinter

Returns a new instance of DefaultPrinter.



81
82
83
# File 'lib/test/unit/coverage.rb', line 81

def initialize(out=$stdout)
  @out = out
end

Instance Method Details



85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/test/unit/coverage.rb', line 85

def print(result)
  result.each do |path, counts|
    next if /test-unit/ =~ path
    source = Pathname(path)
    @out.puts "### %s ###" % source.basename
    source.each_line.with_index.zip(counts) do |(line, index), count|
      line_num = index + 1
      @out.puts "%8s:%4s:%s" % [count, line_num, line]
    end
  end
ensure
  @out.close unless @out.closed?
end