class SimpleCov::SourceFile::Branch
Representing single branch that has been detected in coverage report. Give us support methods that handle needed calculations.
Attributes
Public Class Methods
rubocop:disable Metrics/ParameterLists
# 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
Public Instance Methods
Return true if there is relevant count defined > 0
@return [Boolean]
# File lib/simplecov/source_file/branch.rb, line 30 def covered? !skipped? && coverage.positive? end
rubocop:enable Metrics/ParameterLists
# File lib/simplecov/source_file/branch.rb, line 21 def inline? @inline end
Check if branche missed or not
@return [Boolean]
# File lib/simplecov/source_file/branch.rb, line 39 def missed? !skipped? && coverage.zero? end
# File lib/simplecov/source_file/branch.rb, line 69 def overlaps_with?(line_range) start_line <= line_range.end && end_line >= line_range.begin end
Return array with coverage count and badge
@return [Array]
# File lib/simplecov/source_file/branch.rb, line 78 def report [type, coverage] end
The line on which we want to report the coverage
Usually we choose the line above the start of the branch (so that it shows up at if/else) because that
-
highlights the condition
-
makes it distinguishable if the first line of the branch is an inline branch (see the nested_branches fixture)
# File lib/simplecov/source_file/branch.rb, line 51 def report_line if inline? start_line else start_line - 1 end end
Flags the branch as skipped
# File lib/simplecov/source_file/branch.rb, line 60 def skipped! @skipped = true end
Returns true if the branch was marked skipped by virtue of nocov comments.
# File lib/simplecov/source_file/branch.rb, line 65 def skipped? @skipped end