Class: Covered::PartialSummary
- Defined in:
- lib/covered/partial_summary.rb
Overview
Generates a report containing only lines near missing coverage.
Instance Method Summary collapse
-
#call(wrapper, output = $stdout, **options) ⇒ Object
Print the partial coverage report.
-
#print_coverage(terminal, coverage, before: 4, after: 4) ⇒ Object
Print coverage snippets around uncovered lines.
Methods inherited from Summary
#each, #initialize, #print_annotations, #print_error, #print_line, #print_line_header, #terminal
Constructor Details
This class inherits a constructor from Covered::Summary
Instance Method Details
#call(wrapper, output = $stdout, **options) ⇒ Object
Print the partial coverage report.
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 |
# File 'lib/covered/partial_summary.rb', line 51 def call(wrapper, output = $stdout, **) terminal = self.terminal(output) complete_files = [] partial_files_count = 0 statistics = self.each(wrapper) do |coverage| partial_files_count += 1 path = wrapper.relative_path(coverage.path) terminal.puts "" terminal.puts path, style: :path begin print_coverage(terminal, coverage, **) rescue => error print_error(terminal, error) end coverage.print(output) end # Collect files with 100% coverage that were not shown: wrapper.each do |coverage| if coverage.ratio >= 1.0 complete_files << wrapper.relative_path(coverage.path) end end terminal.puts statistics.print(output) # Only show information about files with 100% coverage if there were files with partial coverage shown above: if complete_files.any? && partial_files_count > 0 terminal.puts "" if complete_files.size == 1 terminal.puts "1 file has 100% coverage and is not shown above:" else terminal.puts "#{complete_files.size} files have 100% coverage and are not shown above:" end complete_files.sort.each do |path| terminal.write " - ", style: :covered_prefix terminal.puts path, style: :brief_path end end end |
#print_coverage(terminal, coverage, before: 4, after: 4) ⇒ Object
Print coverage snippets around uncovered lines.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/covered/partial_summary.rb', line 16 def print_coverage(terminal, coverage, before: 4, after: 4) return if coverage.zero? line_offset = 1 counts = coverage.counts last_line = nil coverage.read do |file| print_line_header(terminal) 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] if last_line and last_line != line_offset-1 terminal.puts ":".rjust(16) end print_annotations(terminal, coverage, line, line_offset) print_line(terminal, line, line_offset, count) last_line = line_offset end line_offset += 1 end end end |