Class: SimpleCov::SourceFile::Branch
- Inherits:
-
Object
- Object
- SimpleCov::SourceFile::Branch
- Defined in:
- lib/simplecov/source_file/branch.rb,
sig/simplecov.rbs
Overview
A single branch detected in the coverage data.
Instance Attribute Summary collapse
-
#coverage ⇒ Integer
readonly
Returns the value of attribute coverage.
-
#end_line ⇒ Integer
readonly
Returns the value of attribute end_line.
-
#start_line ⇒ Integer
readonly
Returns the value of attribute start_line.
-
#type ⇒ Symbol
readonly
Branch arm type as reported by Coverage (:then, :else, :when, ...).
Instance Method Summary collapse
-
#covered? ⇒ Boolean
Return true if there is relevant count defined > 0.
-
#initialize(start_line:, end_line:, coverage:, inline:, type:) ⇒ Branch
constructor
A new instance of Branch.
- #inline? ⇒ Boolean
-
#missed? ⇒ Boolean
Check if branch missed or not.
- #overlaps_with?(line_range) ⇒ Boolean
-
#report ⇒ [ Symbol, Integer ]
[branch type, hit count].
-
#report_line ⇒ Integer
The line the branch is reported on: its own start line when inline, otherwise the line above (the if/else itself).
-
#skipped! ⇒ void
Flags the branch as skipped.
-
#skipped? ⇒ Boolean
Returns true if the branch was marked skipped by virtue of nocov comments.
Constructor Details
#initialize(start_line:, end_line:, coverage:, inline:, type:) ⇒ Branch
Returns a new instance of Branch.
11 12 13 14 15 16 17 18 |
# File 'lib/simplecov/source_file/branch.rb', line 11 def initialize(start_line:, end_line:, coverage:, inline:, type:) @start_line = start_line @end_line = end_line @coverage = coverage @inline = inline @type = type @skipped = false end |
Instance Attribute Details
#coverage ⇒ Integer (readonly)
Returns the value of attribute coverage.
9 10 11 |
# File 'lib/simplecov/source_file/branch.rb', line 9 def coverage @coverage end |
#end_line ⇒ Integer (readonly)
Returns the value of attribute end_line.
9 10 11 |
# File 'lib/simplecov/source_file/branch.rb', line 9 def end_line @end_line end |
#start_line ⇒ Integer (readonly)
Returns the value of attribute start_line.
9 10 11 |
# File 'lib/simplecov/source_file/branch.rb', line 9 def start_line @start_line end |
#type ⇒ Symbol (readonly)
Branch arm type as reported by Coverage (:then, :else, :when, ...).
989 990 991 |
# File 'sig/simplecov.rbs', line 989 def type @type end |
Instance Method Details
#covered? ⇒ Boolean
Return true if there is relevant count defined > 0
29 30 31 |
# File 'lib/simplecov/source_file/branch.rb', line 29 def covered? !skipped? && coverage.positive? end |
#inline? ⇒ Boolean
20 21 22 |
# File 'lib/simplecov/source_file/branch.rb', line 20 def inline? @inline end |
#missed? ⇒ Boolean
Check if branch missed or not
38 39 40 |
# File 'lib/simplecov/source_file/branch.rb', line 38 def missed? !skipped? && coverage.zero? end |
#overlaps_with?(line_range) ⇒ Boolean
68 69 70 |
# File 'lib/simplecov/source_file/branch.rb', line 68 def overlaps_with?(line_range) start_line <= line_range.end && end_line >= line_range.begin end |
#report ⇒ [ Symbol, Integer ]
[branch type, hit count]
77 78 79 |
# File 'lib/simplecov/source_file/branch.rb', line 77 def report [type, coverage] end |
#report_line ⇒ Integer
The line the branch is reported on: its own start line when inline, otherwise the line above (the if/else itself).
50 51 52 53 54 55 56 |
# File 'lib/simplecov/source_file/branch.rb', line 50 def report_line if inline? start_line else start_line - 1 end end |
#skipped! ⇒ void
This method returns an undefined value.
Flags the branch as skipped
59 60 61 |
# File 'lib/simplecov/source_file/branch.rb', line 59 def skipped! @skipped = true end |
#skipped? ⇒ Boolean
Returns true if the branch was marked skipped by virtue of nocov comments.
64 65 66 |
# File 'lib/simplecov/source_file/branch.rb', line 64 def skipped? @skipped end |