Class: SimpleCov::FileList
| Relationships & Source Files | |
| Super Chains via Extension / Inclusion / Inheritance | |
|
Class Chain:
self,
Forwardable
|
|
|
Instance Chain:
self,
Enumerable
|
|
| Inherits: | Object |
| 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.
Class Method Summary
- .new(files) ⇒ FileList constructor
Instance Method Summary
- #branch_covered_percent
-
#coverage_statistics(criterion = nil)
The per-criterion coverage statistics across all files.
- #coverage_statistics_by_file
-
#covered_branches
Return total count of covered branches.
-
#covered_lines
Returns the count of lines that have coverage.
-
#covered_methods
Return total count of covered methods.
-
#covered_percent(criterion = :line) ⇒ Float?
The coverage across all files in percent, for the given criterion (line by default).
-
#covered_percentages
Computes the coverage based upon lines covered and lines missed for each file Returns an array with all coverage percentages.
-
#covered_strength(criterion = :line) ⇒ Float?
The strength (average hits per relevant unit) for the given criterion (line by default).
-
#least_covered_file
Finds the least covered file and returns that file's name.
-
#lines_of_code
Returns the overall amount of relevant lines of code across all files in this list.
- #method_covered_percent
-
#missed_branches
Return total count of covered branches.
-
#missed_lines
Returns the count of lines that have been missed.
-
#missed_methods
Return total count of missed methods.
-
#never_lines
Returns the count of lines that are not relevant for coverage.
-
#skipped_lines
Returns the count of skipped lines.
-
#total_branches
Return total count of branches in all files.
-
#total_methods
Return total count of methods in all files.
- #compute_coverage_statistics private
-
#compute_coverage_statistics_by_file
private
Seed the result hash with one entry per criterion the user enabled — so an empty
FileList(e.g. a group with no files) still yields the right shape — then fold each file's stats into the matching bucket. -
#enabled_criteria_for_reporting
private
:line(or its:oneshot_linesynonym) is reported when either criterion is enabled; the JRuby-gated branch/method criteria are reported when they pass their own engine-support check.
Constructor Details
.new(files) ⇒ FileList
# File 'lib/simplecov/file_list.rb', line 22
def initialize(files) @files = files end
Instance Method Details
#branch_covered_percent
[ GitHub ]# File 'lib/simplecov/file_list.rb', line 107
def branch_covered_percent coverage_statistics[:branch]&.percent end
#compute_coverage_statistics (private)
[ GitHub ]# File 'lib/simplecov/file_list.rb', line 148
def compute_coverage_statistics coverage_statistics_by_file.transform_values { |stats| CoverageStatistics.from(stats) } end
#compute_coverage_statistics_by_file (private)
Seed the result hash with one entry per criterion the user
enabled — so an empty FileList (e.g. a group with no files) still
yields the right shape — then fold each file's stats into the
matching bucket. SourceFile#coverage_statistics always reports
all three criteria; FileList is the layer that filters to the
enabled set so disabled criteria don't surface in totals, JSON,
or the HTML report.
# File 'lib/simplecov/file_list.rb', line 139
def compute_coverage_statistics_by_file seed = enabled_criteria_for_reporting.to_h { |criterion| [criterion, []] } @files.each_with_object(seed) do |file, together| file.coverage_statistics.each do |criterion, stats| together[criterion] << stats if together.key?(criterion) end end end
#coverage_statistics(criterion = nil)
The per-criterion coverage statistics across all files. With no argument
returns the {line:, branch:, method:} Hash; pass a criterion symbol
(:line / :branch / :method) to get that one CoverageStatistics.
# 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_file
[ GitHub ]# File 'lib/simplecov/file_list.rb', line 34
def coverage_statistics_by_file @coverage_statistics_by_file ||= compute_coverage_statistics_by_file end
#covered_branches
Return total count of covered branches
# File 'lib/simplecov/file_list.rb', line 98
def covered_branches coverage_statistics[:branch]&.covered end
#covered_lines
Returns the count of lines that have coverage
# File 'lib/simplecov/file_list.rb', line 39
def covered_lines coverage_statistics[:line]&.covered end
#covered_methods
Return total count of covered methods
# 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.
# File 'lib/simplecov/file_list.rb', line 81
def covered_percent(criterion = :line) coverage_statistics(criterion)&.percent end
#covered_percentages
Computes the coverage based upon lines covered and lines missed for each file Returns an array with all coverage percentages
# 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).
# File 'lib/simplecov/file_list.rb', line 88
def covered_strength(criterion = :line) coverage_statistics(criterion)&.strength end
#enabled_criteria_for_reporting (private)
:line (or its :oneshot_line synonym) is reported when either
criterion is enabled; the JRuby-gated branch/method criteria are
reported when they pass their own engine-support check.
# File 'lib/simplecov/file_list.rb', line 155
def enabled_criteria_for_reporting criteria = [] criteria << :line if SimpleCov.coverage_criterion_enabled?(:line) || SimpleCov.coverage_criterion_enabled?(:oneshot_line) criteria << :branch if SimpleCov.branch_coverage? criteria << :method if SimpleCov.method_coverage? criteria end
#least_covered_file
Finds the least covered file and returns that file's name
# File 'lib/simplecov/file_list.rb', line 69
def least_covered_file min_by(&:covered_percent).filename end
#lines_of_code
Returns the overall amount of relevant lines of code across all files in this list
# File 'lib/simplecov/file_list.rb', line 74
def lines_of_code coverage_statistics[:line]&.total end
#method_covered_percent
[ GitHub ]# File 'lib/simplecov/file_list.rb', line 126
def method_covered_percent coverage_statistics[:method]&.percent end
#missed_branches
Return total count of covered branches
# File 'lib/simplecov/file_list.rb', line 103
def missed_branches coverage_statistics[:branch]&.missed end
#missed_lines
Returns the count of lines that have been missed
# File 'lib/simplecov/file_list.rb', line 44
def missed_lines coverage_statistics[:line]&.missed end
#missed_methods
Return total count of missed methods
# File 'lib/simplecov/file_list.rb', line 122
def missed_methods coverage_statistics[:method]&.missed end
#never_lines
Returns the count of lines that are not relevant for coverage
# File 'lib/simplecov/file_list.rb', line 49
def never_lines return 0.0 if empty? sum { |f| f.never_lines.size } end
#skipped_lines
Returns the count of skipped lines
# File 'lib/simplecov/file_list.rb', line 56
def skipped_lines return 0.0 if empty? sum { |f| f.skipped_lines.size } end
#total_branches
Return total count of branches in all files
# File 'lib/simplecov/file_list.rb', line 93
def total_branches coverage_statistics[:branch]&.total end
#total_methods
Return total count of methods in all files
# File 'lib/simplecov/file_list.rb', line 112
def total_methods coverage_statistics[:method]&.total end