Class: SimpleCov::SourceFile::Line

Inherits:
Object
  • Object
show all
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)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(src, line_number, coverage) ⇒ Line

Returns a new instance of Line.

Raises:

  • (ArgumentError)


25
26
27
28
29
30
31
32
33
34
# 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

#coverageObject (readonly)

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



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

def coverage
  @coverage
end

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

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



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

def line_number
  @line_number
end

#skippedObject (readonly)

Whether this line was skipped



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

def skipped
  @skipped
end

#srcObject (readonly) Also known as: source

The source code for this line. Aliased as :source



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

def src
  @src
end

Instance Method Details

#covered?Boolean

Returns true if this is a line that has been covered

Returns:

  • (Boolean)


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

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

#missed?Boolean

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

Returns:

  • (Boolean)


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

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

#never?Boolean

Returns true if this line is not relevant for coverage

Returns:

  • (Boolean)


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

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

#skipped!Object

Flags this line as skipped



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

def skipped!
  @skipped = true
end

#skipped?Boolean

Returns true if this line was skipped, false otherwise. Lines are skipped if they are wrapped with # :nocov: comment lines.

Returns:

  • (Boolean)


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

def skipped?
  skipped
end

#statusObject

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



64
65
66
67
68
69
# File 'lib/simplecov/source_file/line.rb', line 64

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