Class: Covered::Statistics
- Inherits:
-
Object
- Object
- Covered::Statistics
- Includes:
- Ratio
- Defined in:
- lib/covered/statistics.rb
Overview
Aggregates coverage statistics across files.
Defined Under Namespace
Classes: Aggregate
Constant Summary collapse
- COMPLETE =
[ "Enter the code dojo: 100% coverage attained, bugs defeated with one swift strike.", "Nirvana reached: 100% code coverage, where bugs meditate and vanish like a passing cloud.", "With 100% coverage, your code has unlocked the path to enlightenment – bugs have no place to hide.", "In the realm of code serenity, 100% coverage is your ticket to coding enlightenment.", "100% coverage, where code and bugs coexist in perfect harmony, like Yin and Yang.", "Achieving the Zen of code coverage, your code is a peaceful garden where bugs find no shelter.", "Congratulations on coding enlightenment! 100% coverage means your code is one with the universe.", "With 100% coverage, your code is a tranquil pond where bugs cause no ripples.", "At the peak of code mastery: 100% coverage, where bugs bow down before the wisdom of your code.", "100% code coverage: Zen achieved! Bugs in harmony, code at peace.", ]
Instance Attribute Summary collapse
- #Coverage statistics indexed by path.(statisticsindexedbypath.) ⇒ Object readonly
-
#paths ⇒ Object
readonly
Returns the value of attribute paths.
- #The total aggregate statistics.(totalaggregatestatistics.) ⇒ Object readonly
-
#total ⇒ Object
readonly
Returns the value of attribute total.
Class Method Summary collapse
-
.for(coverage) ⇒ Object
Build statistics for a single coverage object.
Instance Method Summary collapse
-
#<<(coverage) ⇒ Object
Add coverage to these statistics.
-
#[](path) ⇒ Object
Get coverage for the given path.
-
#as_json ⇒ Object
A JSON-compatible representation of these statistics.
-
#count ⇒ Object
The number of unique paths with coverage data.
-
#executable_count ⇒ Object
The total number of executable lines.
-
#executed_count ⇒ Object
The total number of executed lines.
-
#initialize ⇒ Statistics
constructor
Initialize empty coverage statistics.
-
#print(output) ⇒ Object
Print a human-readable coverage summary.
-
#to_json(options) ⇒ Object
Convert these statistics to JSON.
-
#validate!(minimum = 1.0) ⇒ Object
Validate that coverage meets the given minimum ratio.
Methods included from Ratio
#complete?, #percentage, #ratio
Constructor Details
#initialize ⇒ Statistics
Initialize empty coverage statistics.
79 80 81 82 |
# File 'lib/covered/statistics.rb', line 79 def initialize @total = Aggregate.new @paths = Hash.new end |
Instance Attribute Details
#Coverage statistics indexed by path.(statisticsindexedbypath.) ⇒ Object (readonly)
88 |
# File 'lib/covered/statistics.rb', line 88 attr :paths |
#paths ⇒ Object (readonly)
Returns the value of attribute paths.
88 89 90 |
# File 'lib/covered/statistics.rb', line 88 def paths @paths end |
#The total aggregate statistics.(totalaggregatestatistics.) ⇒ Object (readonly)
85 |
# File 'lib/covered/statistics.rb', line 85 attr :total |
#total ⇒ Object (readonly)
Returns the value of attribute total.
85 86 87 |
# File 'lib/covered/statistics.rb', line 85 def total @total end |
Class Method Details
.for(coverage) ⇒ Object
Build statistics for a single coverage object.
21 22 23 24 25 |
# File 'lib/covered/statistics.rb', line 21 def self.for(coverage) self.new.tap do |statistics| statistics << coverage end end |
Instance Method Details
#<<(coverage) ⇒ Object
Add coverage to these statistics.
110 111 112 113 |
# File 'lib/covered/statistics.rb', line 110 def << coverage @total << coverage (@paths[coverage.path] ||= coverage.empty).merge!(coverage) end |
#[](path) ⇒ Object
Get coverage for the given path.
118 119 120 |
# File 'lib/covered/statistics.rb', line 118 def [](path) @paths[path] end |
#as_json ⇒ Object
A JSON-compatible representation of these statistics.
124 125 126 127 128 129 |
# File 'lib/covered/statistics.rb', line 124 def as_json { total: total.as_json, paths: @paths.map{|path, coverage| [path, coverage.as_json]}.to_h, } end |
#count ⇒ Object
The number of unique paths with coverage data.
92 93 94 |
# File 'lib/covered/statistics.rb', line 92 def count @paths.size end |
#executable_count ⇒ Object
The total number of executable lines.
98 99 100 |
# File 'lib/covered/statistics.rb', line 98 def executable_count @total.executable_count end |
#executed_count ⇒ Object
The total number of executed lines.
104 105 106 |
# File 'lib/covered/statistics.rb', line 104 def executed_count @total.executed_count end |
#print(output) ⇒ Object
Print a human-readable coverage summary.
153 154 155 156 157 158 159 |
# File 'lib/covered/statistics.rb', line 153 def print(output) output.puts "#{count} files checked; #{@total.executed_count}/#{@total.executable_count} lines executed; #{@total.percentage.to_f.round(2)}% covered." if self.complete? output.puts "🧘 #{COMPLETE.sample}" end end |
#to_json(options) ⇒ Object
Convert these statistics to JSON.
134 135 136 |
# File 'lib/covered/statistics.rb', line 134 def to_json() as_json.to_json() end |
#validate!(minimum = 1.0) ⇒ Object
Validate that coverage meets the given minimum ratio.
164 165 166 167 168 |
# File 'lib/covered/statistics.rb', line 164 def validate!(minimum = 1.0) if total.ratio < minimum raise CoverageError, "Coverage of #{self.percentage.to_f.round(2)}% is less than required minimum of #{(minimum * 100.0).round(2)}%!" end end |