lib/covered/summary.rb in covered-0.9.0 vs lib/covered/summary.rb in covered-0.10.0
- old
+ new
@@ -22,21 +22,19 @@
require_relative 'wrapper'
require 'rainbow'
module Covered
- class Summary < Wrapper
- def initialize(output, threshold: 1.0)
- super(output)
-
+ class Summary
+ def initialize(threshold: 1.0)
@threshold = threshold
end
- def each
+ def each(wrapper)
statistics = Statistics.new
- super do |coverage|
+ wrapper.each do |coverage|
statistics << coverage
if @threshold.nil? or coverage.ratio < @threshold
yield coverage
end
@@ -56,18 +54,20 @@
output.puts Rainbow(annotations.join(", ")).bright
end
end
# A coverage array gives, for each line, the number of line execution by the interpreter. A nil value means coverage is disabled for this line (lines like else and end).
- def print_summary(output = $stdout)
- statistics = self.each do |coverage|
+ def call(wrapper, output = $stdout)
+ statistics = self.each(wrapper) do |coverage|
line_offset = 1
- output.puts "", Rainbow(coverage.path).bold.underline
+ path = wrapper.relative_path(coverage.path)
+ output.puts "", Rainbow(path).bold.underline
+
counts = coverage.counts
- File.open(coverage.path, "r") do |file|
+ coverage.read do |file|
file.each_line do |line|
count = counts[line_offset]
print_annotations(output, coverage, line, line_offset)
@@ -89,51 +89,55 @@
line_offset += 1
end
end
- coverage.print_summary(output)
+ coverage.print(output)
end
- statistics.print_summary(output)
+ statistics.print(output)
end
end
class BriefSummary < Summary
- def print_summary(output = $stdout, before: 4, after: 4)
+ def call(wrapper, output = $stdout, before: 4, after: 4)
ordered = []
- statistics = self.each do |coverage|
+ statistics = self.each(wrapper) do |coverage|
ordered << coverage unless coverage.complete?
end
output.puts
- statistics.print_summary(output)
+ statistics.print(output)
if ordered.any?
output.puts "", "Least Coverage:"
ordered.sort_by!(&:missing_count).reverse!
ordered.first(5).each do |coverage|
- output.write Rainbow(coverage.path).orange
+ path = wrapper.relative_path(coverage.path)
+
+ output.write Rainbow(path).orange
output.puts ": #{coverage.missing_count} lines not executed!"
end
end
end
end
class PartialSummary < Summary
- def print_summary(output = $stdout, before: 4, after: 4)
- statistics = self.each do |coverage|
+ def call(wrapper, output = $stdout, before: 4, after: 4)
+ statistics = self.each(wrapper) do |coverage|
line_offset = 1
- output.puts "", Rainbow(coverage.path).bold.underline
+ path = wrapper.relative_path(coverage.path)
+ output.puts "", Rainbow(path).bold.underline
+
counts = coverage.counts
last_line = nil
unless coverage.zero?
- File.open(coverage.path, "r") do |file|
+ coverage.read do |file|
file.each_line do |line|
range = Range.new([line_offset - before, 0].max, line_offset+after)
if counts[range]&.include?(0)
count = counts[line_offset]
@@ -168,13 +172,13 @@
line_offset += 1
end
end
end
- coverage.print_summary(output)
+ coverage.print(output)
end
output.puts
- statistics.print_summary(output)
+ statistics.print(output)
end
end
end