Class: Coco::CoverageResult
- Inherits:
-
Object
- Object
- Coco::CoverageResult
- Defined in:
- lib/coco/cover/coverage_result.rb
Overview
Compute results of interest from the big results information (from Coverage.result)
Instance Attribute Summary collapse
-
#coverable_files ⇒ Object
readonly
Returns a Hash coverage for all the sources that live in the root project folder.
-
#not_covered_enough ⇒ Object
readonly
Returns a Hash coverage for sources that are not sufficiently covered.
Instance Method Summary collapse
-
#average ⇒ Object
Public: Computes the average coverage rate.
-
#count ⇒ Object
Public: Count the number of “coverable” files.
-
#initialize(config, raw_results) ⇒ CoverageResult
constructor
Public: Initialize a CoverageResult.
-
#uncovered_count ⇒ Object
Public: Count the number of uncovered files, that is, files with a coverage rate of 0%.
Constructor Details
#initialize(config, raw_results) ⇒ CoverageResult
Public: Initialize a CoverageResult.
config - Hash raw_results - The Hash from Coverage.result. Keys are filenames
and values are an Array representing each lines of
the file :
+ nil : Unreacheable (comments, etc).
+ 0 : Not hit.
+ 1 or more : Number of hits.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/coco/cover/coverage_result.rb', line 30 def initialize(config, raw_results) raise ArgumentError if config[:threshold] < 0 @exclude_files = config[:exclude] @threshold = config[:threshold] @result = raw_results exclude_external_sources exclude_files_user_dont_want if @exclude_files @not_covered_enough = if config[:exclude_above_threshold] exclude_sources_above_threshold else @coverable_files end end |
Instance Attribute Details
#coverable_files ⇒ Object (readonly)
Returns a Hash coverage for all the sources that live in the root project folder.
11 12 13 |
# File 'lib/coco/cover/coverage_result.rb', line 11 def coverable_files @coverable_files end |
#not_covered_enough ⇒ Object (readonly)
Returns a Hash coverage for sources that are not sufficiently covered. More technically, the sources that live in the root project folder and for which the coverage percentage is under the threshold.
18 19 20 |
# File 'lib/coco/cover/coverage_result.rb', line 18 def not_covered_enough @not_covered_enough end |
Instance Method Details
#average ⇒ Object
Public: Computes the average coverage rate. The formula is simple:
N = number of files f = a file average = sum(f_i%) / N
In words: Take the sum of the coverage’s percentage of all files and divide this sum by the number of files.
Returns the Fixnum rounded average rate of coverage.
78 79 80 |
# File 'lib/coco/cover/coverage_result.rb', line 78 def average files_present? ? (sum / count).round : 0 end |
#count ⇒ Object
Public: Count the number of “coverable” files.
Returns the Fixnum number of files.
51 52 53 |
# File 'lib/coco/cover/coverage_result.rb', line 51 def count coverable_files.size end |
#uncovered_count ⇒ Object
Public: Count the number of uncovered files, that is, files with a coverage rate of 0%.
Returns the Fixnum number of uncovered files.
60 61 62 63 64 |
# File 'lib/coco/cover/coverage_result.rb', line 60 def uncovered_count not_covered_enough.select do |_, hits| CoverageStat.coverage_percent(hits).zero? end.size end |