lib/undercover/result.rb in undercover-0.5.0 vs lib/undercover/result.rb in undercover-0.6.0
- old
+ new
@@ -11,11 +11,11 @@
def_delegators :node, :first_line, :last_line, :name
def initialize(node, file_cov, file_path)
@node = node
@coverage = file_cov.select do |ln, _|
- first_line == last_line ? ln == first_line : ln > first_line && ln < last_line
+ (node.empty_def? ? ln >= first_line : ln > first_line) && ln < last_line
end
@file_path = file_path
@flagged = false
end
@@ -25,38 +25,39 @@
def flagged?
@flagged
end
- # rubocop:disable Metrics/CyclomaticComplexity
def uncovered?(line_no)
+ return true if coverage.empty?
+
# check branch coverage for line_no
coverage.each do |ln, _block, _branch, cov|
return true if ln == line_no && cov && cov.zero?
end
# check line coverage for line_no
line_cov = coverage.select { |cov| cov.size == 2 }.find { |ln, _cov| ln == line_no }
line_cov && line_cov[1].zero?
end
- # rubocop:enable Metrics/CyclomaticComplexity
# Method `coverage_f` returns the total coverage of this Undercover::Result
# as a % value, taking into account missing branches. Line coverage will be counted
# as 0 if any branch is untested.
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
def coverage_f
+ return 0.0 if coverage.empty?
+
lines = {}
coverage.each do |ln, block_or_line_cov, _, branch_cov|
lines[ln] = 1 unless lines.key?(ln)
if branch_cov
lines[ln] = 0 if branch_cov.zero?
elsif block_or_line_cov.zero?
lines[ln] = 0
end
end
- return 1.0 if lines.keys.empty?
(lines.values.sum.to_f / lines.keys.size).round(4)
end
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
@@ -85,18 +86,18 @@
pretty_print_lines.map do |covered, (num, line)|
formatted_line = "#{num.to_s.rjust(pad)}: #{line}"
if line.strip.empty?
Rainbow(formatted_line).darkgray.dark
elsif covered.nil?
- Rainbow(formatted_line).darkgray.dark + \
+ Rainbow(formatted_line).darkgray.dark +
Rainbow(' hits: n/a').italic.darkgray.dark
elsif covered.positive?
- Rainbow(formatted_line).green + \
+ Rainbow(formatted_line).green +
Rainbow(" hits: #{covered}").italic.darkgray.dark + \
count_covered_branches(num)
elsif covered.zero?
- Rainbow(formatted_line).red + \
+ Rainbow(formatted_line).red +
Rainbow(" hits: #{covered}").italic.darkgray.dark + \
count_covered_branches(num)
end
end.join("\n")
end
@@ -120,10 +121,10 @@
count_covered = branches.count { |cov| cov[3].positive? }
return '' if branches.empty?
if count_covered < branches.size
- Rainbow(' branches: ').italic.darkgray.dark + \
+ Rainbow(' branches: ').italic.darkgray.dark +
Rainbow("#{count_covered}/#{branches.size}").italic.red
else
Rainbow(" branches: #{count_covered}/#{branches.size}").italic.darkgray.dark
end
end