Class: SimpleCov::SourceFile::Line
- Inherits:
-
Object
- Object
- SimpleCov::SourceFile::Line
- Defined in:
- lib/simplecov/source_file.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
-
#coverage ⇒ Object
readonly
The coverage data for this line: either nil (never), 0 (missed) or >=1 (times covered).
-
#line_number ⇒ Object
(also: #line, #number)
readonly
The line number in the source file.
-
#skipped ⇒ Object
readonly
Whether this line was skipped.
-
#src ⇒ Object
(also: #source)
readonly
The source code for this line.
Instance Method Summary collapse
-
#covered? ⇒ Boolean
Returns true if this is a line that has been covered.
-
#initialize(src, line_number, coverage) ⇒ Line
constructor
A new instance of Line.
-
#missed? ⇒ Boolean
Returns true if this is a line that should have been covered, but was not.
-
#never? ⇒ Boolean
Returns true if this line is not relevant for coverage.
-
#skipped! ⇒ Object
Flags this line as skipped.
-
#skipped? ⇒ Boolean
Returns true if this line was skipped, false otherwise.
-
#status ⇒ Object
The status of this line - either covered, missed, skipped or never.
Constructor Details
#initialize(src, line_number, coverage) ⇒ Line
Returns a new instance of Line.
27 28 29 30 31 32 33 |
# File 'lib/simplecov/source_file.rb', line 27 def initialize(src, line_number, coverage) raise ArgumentError, "Only String accepted for source" unless src.kind_of?(String) raise ArgumentError, "Only Fixnum accepted for line_number" unless line_number.kind_of?(Fixnum) raise ArgumentError, "Only Fixnum and nil accepted for coverage" unless coverage.kind_of?(Fixnum) or coverage.nil? @src, @line_number, @coverage = src, line_number, coverage @skipped = false end |
Instance Attribute Details
#coverage ⇒ Object (readonly)
The coverage data for this line: either nil (never), 0 (missed) or >=1 (times covered)
18 19 20 |
# File 'lib/simplecov/source_file.rb', line 18 def coverage @coverage end |
#line_number ⇒ Object (readonly) Also known as: line, number
The line number in the source file. Aliased as :line, :number
16 17 18 |
# File 'lib/simplecov/source_file.rb', line 16 def line_number @line_number end |
#skipped ⇒ Object (readonly)
Whether this line was skipped
20 21 22 |
# File 'lib/simplecov/source_file.rb', line 20 def skipped @skipped end |
#src ⇒ Object (readonly) Also known as: source
The source code for this line. Aliased as :source
14 15 16 |
# File 'lib/simplecov/source_file.rb', line 14 def src @src end |
Instance Method Details
#covered? ⇒ Boolean
Returns true if this is a line that has been covered
41 42 43 |
# File 'lib/simplecov/source_file.rb', line 41 def covered? not never? and not skipped? and coverage > 0 end |
#missed? ⇒ Boolean
Returns true if this is a line that should have been covered, but was not
36 37 38 |
# File 'lib/simplecov/source_file.rb', line 36 def missed? not never? and not skipped? and coverage == 0 end |
#never? ⇒ Boolean
Returns true if this line is not relevant for coverage
46 47 48 |
# File 'lib/simplecov/source_file.rb', line 46 def never? not skipped? and coverage.nil? end |
#skipped! ⇒ Object
Flags this line as skipped
51 52 53 |
# File 'lib/simplecov/source_file.rb', line 51 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.
57 58 59 |
# File 'lib/simplecov/source_file.rb', line 57 def skipped? !!skipped end |
#status ⇒ Object
The status of this line - either covered, missed, skipped or never. Useful i.e. for direct use as a css class in report generation
63 64 65 66 67 68 |
# File 'lib/simplecov/source_file.rb', line 63 def status return 'skipped' if skipped? return 'never' if never? return 'missed' if missed? return 'covered' if covered? end |