26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
# File 'lib/simplecov-console.rb', line 26
def format(result)
root = nil
if Module.const_defined? :ROOT then
root = ROOT
elsif Module.const_defined?(:Rails) && Rails.respond_to?(:root) then
root = Rails.root.to_s
elsif ENV["BUNDLE_GEMFILE"] then
root = File.dirname(ENV["BUNDLE_GEMFILE"])
else
root = Dir.pwd
end
puts
puts "COVERAGE: #{colorize(pct(result))} -- #{result.covered_lines}/#{result.total_lines} lines in #{result.files.size} files"
puts
if root.nil? then
return
end
if SimpleCov::Formatter::Console.sort == 'coverage'
files = result.files.sort{ |a,b| a.covered_percent <=> b.covered_percent }
else
files = result.files
end
covered_files = 0
unless SimpleCov::Formatter::Console.show_covered
files.select!{ |file|
if file.covered_percent == 100 then
covered_files += 1
false
else
true
end
}
if files.nil? or files.empty? then
return
end
end
table = files.map do |f|
[
colorize(pct(f)),
f.filename.gsub(root + "/", ''),
f.lines_of_code,
f.missed_lines.count,
missed(f.missed_lines).join(", ")
]
end
max_rows = SimpleCov::Formatter::Console.max_rows
if ![-1, nil].include?(max_rows) && table.size > max_rows then
puts "showing bottom (worst) #{max_rows} of #{table.size} files"
table = table.slice(0, max_rows)
end
table_options = SimpleCov::Formatter::Console.table_options || {}
if !table_options.kind_of?(Hash) then
raise ArgumentError.new("SimpleCov::Formatter::Console.table_options must be a Hash")
end
headings = %w{ coverage file lines missed missing }
opts = table_options.merge({:headings => headings, :rows => table})
t = Terminal::Table.new(opts)
puts t
if covered_files > 0 then
puts "#{covered_files} file(s) with 100% coverage not shown"
end
end
|