class SimpleCov::SourceFile::Branch

Give us support methods that handle needed calculations.
Representing single branch that has been detected in coverage report.

def badge

Returns:
  • (String) -
def badge
  positive? ? "+" : "-"
end

def covered?

Returns:
  • (Boolean) -
def covered?
  !skipped? && coverage.positive?
end

def initialize(start_line:, end_line:, coverage:, inline:, positive:)

rubocop:disable Metrics/ParameterLists
def initialize(start_line:, end_line:, coverage:, inline:, positive:)
  @start_line = start_line
  @end_line   = end_line
  @coverage   = coverage
  @inline     = inline
  @positive   = positive
  @skipped    = false
end

def inline?

def inline?
  @inline
end

def missed?

Returns:
  • (Boolean) -
def missed?
  !skipped? && coverage.zero?
end

def negative?

Returns:
  • (Boolean) -
def negative?
  !positive?
end

def overlaps_with?(line_range)

def overlaps_with?(line_range)
  start_line <= line_range.end && end_line >= line_range.begin
end

def positive?

def positive?
  @positive
end

def report

Returns:
  • (Array) -
def report
  [coverage, badge]
end

def report_line


(see the nested_branches fixture)
* makes it distinguishable if the first line of the branch is an inline branch
* highlights the condition
at if/else) because that
Usually we choose the line above the start of the branch (so that it shows up

The line on which we want to report the coverage
def report_line
  if inline?
    start_line
  else
    start_line - 1
  end
end

def skipped!

Flags the branch as skipped
def skipped!
  @skipped = true
end

def skipped?

Returns true if the branch was marked skipped by virtue of nocov comments.
def skipped?
  @skipped
end