Class: SimpleCov::FileList

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/simplecov/file_list.rb

Overview

An array of SimpleCov SourceFile instances with additional collection helper methods for calculating coverage across them etc.

Instance Method Summary collapse

Constructor Details

#initialize(files) ⇒ FileList

Returns a new instance of FileList.



22
23
24
# File 'lib/simplecov/file_list.rb', line 22

def initialize(files)
  @files = files
end

Instance Method Details

#branch_covered_percentObject



107
108
109
# File 'lib/simplecov/file_list.rb', line 107

def branch_covered_percent
  coverage_statistics[:branch]&.percent
end

#coverage_statistics(criterion = nil) ⇒ Object

The per-criterion coverage statistics across all files. With no argument returns the ‘branch:, method:` Hash; pass a criterion symbol (`:line` / `:branch` / `:method`) to get that one CoverageStatistics.



29
30
31
32
# File 'lib/simplecov/file_list.rb', line 29

def coverage_statistics(criterion = nil)
  @coverage_statistics ||= compute_coverage_statistics
  criterion ? @coverage_statistics[criterion] : @coverage_statistics
end

#coverage_statistics_by_fileObject



34
35
36
# File 'lib/simplecov/file_list.rb', line 34

def coverage_statistics_by_file
  @coverage_statistics_by_file ||= compute_coverage_statistics_by_file
end

#covered_branchesObject

Return total count of covered branches



98
99
100
# File 'lib/simplecov/file_list.rb', line 98

def covered_branches
  coverage_statistics[:branch]&.covered
end

#covered_linesObject

Returns the count of lines that have coverage



39
40
41
# File 'lib/simplecov/file_list.rb', line 39

def covered_lines
  coverage_statistics[:line]&.covered
end

#covered_methodsObject

Return total count of covered methods



117
118
119
# File 'lib/simplecov/file_list.rb', line 117

def covered_methods
  coverage_statistics[:method]&.covered
end

#covered_percent(criterion = :line) ⇒ Float?

The coverage across all files in percent, for the given criterion (line by default). Returns nil if the criterion was not measured.

Returns:

  • (Float, nil)


81
82
83
# File 'lib/simplecov/file_list.rb', line 81

def covered_percent(criterion = :line)
  coverage_statistics(criterion)&.percent
end

#covered_percentagesObject

Computes the coverage based upon lines covered and lines missed for each file Returns an array with all coverage percentages



64
65
66
# File 'lib/simplecov/file_list.rb', line 64

def covered_percentages
  map(&:covered_percent)
end

#covered_strength(criterion = :line) ⇒ Float?

The strength (average hits per relevant unit) for the given criterion (line by default).

Returns:

  • (Float, nil)


88
89
90
# File 'lib/simplecov/file_list.rb', line 88

def covered_strength(criterion = :line)
  coverage_statistics(criterion)&.strength
end

#least_covered_fileObject

Finds the least covered file and returns that file’s name



69
70
71
# File 'lib/simplecov/file_list.rb', line 69

def least_covered_file
  min_by(&:covered_percent).filename
end

#lines_of_codeObject

Returns the overall amount of relevant lines of code across all files in this list



74
75
76
# File 'lib/simplecov/file_list.rb', line 74

def lines_of_code
  coverage_statistics[:line]&.total
end

#method_covered_percentObject



126
127
128
# File 'lib/simplecov/file_list.rb', line 126

def method_covered_percent
  coverage_statistics[:method]&.percent
end

#missed_branchesObject

Return total count of covered branches



103
104
105
# File 'lib/simplecov/file_list.rb', line 103

def missed_branches
  coverage_statistics[:branch]&.missed
end

#missed_linesObject

Returns the count of lines that have been missed



44
45
46
# File 'lib/simplecov/file_list.rb', line 44

def missed_lines
  coverage_statistics[:line]&.missed
end

#missed_methodsObject

Return total count of missed methods



122
123
124
# File 'lib/simplecov/file_list.rb', line 122

def missed_methods
  coverage_statistics[:method]&.missed
end

#never_linesObject

Returns the count of lines that are not relevant for coverage



49
50
51
52
53
# File 'lib/simplecov/file_list.rb', line 49

def never_lines
  return 0.0 if empty?

  sum { |f| f.never_lines.size }
end

#skipped_linesObject

Returns the count of skipped lines



56
57
58
59
60
# File 'lib/simplecov/file_list.rb', line 56

def skipped_lines
  return 0.0 if empty?

  sum { |f| f.skipped_lines.size }
end

#total_branchesObject

Return total count of branches in all files



93
94
95
# File 'lib/simplecov/file_list.rb', line 93

def total_branches
  coverage_statistics[:branch]&.total
end

#total_methodsObject

Return total count of methods in all files



112
113
114
# File 'lib/simplecov/file_list.rb', line 112

def total_methods
  coverage_statistics[:method]&.total
end