123456789_123456789_123456789_123456789_123456789_

Class: SimpleCov::SourceFile::Line

Relationships & Source Files
Inherits: Object
Defined in: lib/simplecov/source_file/line.rb

Overview

Representation of a single line in a source file including this specific line’s source code, line_number and code coverage, with the coverage being either nil (coverage not applicable, e.g. comment line), 0 (line not covered) or >1 (the amount of times the line was executed)

Class Method Summary

Instance Attribute Summary

Instance Method Summary

  • #skipped!

    Flags this line as skipped.

  • #status

    The status of this line - either covered, missed, skipped or never.

Constructor Details

.new(src, line_number, coverage) ⇒ Line

Raises:

  • (ArgumentError)
[ GitHub ]

  
# File 'lib/simplecov/source_file/line.rb', line 25

def initialize(src, line_number, coverage)
  raise ArgumentError, "Only String accepted for source" unless src.is_a?(String)
  raise ArgumentError, "Only Integer accepted for line_number" unless line_number.is_a?(Integer)
  raise ArgumentError, "Only Integer and nil accepted for coverage" unless coverage.is_a?(Integer) || coverage.nil?

  @src         = src
  @line_number = line_number
  @coverage    = coverage
  @skipped     = false
end

Instance Attribute Details

#coverage (readonly)

The coverage data for this line: either nil (never), 0 (missed) or >=1 (times covered)

[ GitHub ]

  
# File 'lib/simplecov/source_file/line.rb', line 16

attr_reader :coverage

#covered?Boolean (readonly)

Returns true if this is a line that has been covered

[ GitHub ]

  
# File 'lib/simplecov/source_file/line.rb', line 42

def covered?
  !never? && !skipped? && coverage.positive?
end

#line (readonly)

Alias for #line_number.

[ GitHub ]

  
# File 'lib/simplecov/source_file/line.rb', line 22

alias line line_number

#line_number (readonly) Also known as: #line, #number

The line number in the source file. Aliased as :line, :number

[ GitHub ]

  
# File 'lib/simplecov/source_file/line.rb', line 14

attr_reader :line_number

#missed?Boolean (readonly)

Returns true if this is a line that should have been covered, but was not

[ GitHub ]

  
# File 'lib/simplecov/source_file/line.rb', line 37

def missed?
  !never? && !skipped? && coverage.zero?
end

#never?Boolean (readonly)

Returns true if this line is not relevant for coverage

[ GitHub ]

  
# File 'lib/simplecov/source_file/line.rb', line 47

def never?
  !skipped? && coverage.nil?
end

#number (readonly)

Alias for #line_number.

[ GitHub ]

  
# File 'lib/simplecov/source_file/line.rb', line 23

alias number line_number

#skipped (readonly)

Whether this line was skipped

[ GitHub ]

  
# File 'lib/simplecov/source_file/line.rb', line 18

attr_reader :skipped

#skipped?Boolean (readonly)

Returns true if this line was skipped, false otherwise. Lines are skipped if they are wrapped with

:nocov: comment lines.

[ GitHub ]

  
# File 'lib/simplecov/source_file/line.rb', line 58

def skipped?
  skipped
end

#source (readonly)

Alias for #src.

[ GitHub ]

  
# File 'lib/simplecov/source_file/line.rb', line 21

alias source src

#src (readonly) Also known as: #source

The source code for this line. Aliased as :source

[ GitHub ]

  
# File 'lib/simplecov/source_file/line.rb', line 12

attr_reader :src

Instance Method Details

#skipped!

Flags this line as skipped

[ GitHub ]

  
# File 'lib/simplecov/source_file/line.rb', line 52

def skipped!
  @skipped = true
end

#status

The status of this line - either covered, missed, skipped or never. Useful i.e. for direct use as a css class in report generation

[ GitHub ]

  
# File 'lib/simplecov/source_file/line.rb', line 64

def status
  return "skipped" if skipped?
  return "never" if never?
  return "missed" if missed?

  "covered" if covered?
end