Class: SimpleCov::SourceFile::Line
- Inherits:
-
Object
- Object
- SimpleCov::SourceFile::Line
- Defined in:
- lib/simplecov/source_file/line.rb,
sig/simplecov.rbs
Overview
A single source line with its coverage: nil (not relevant, e.g. a comment), 0 (missed), or >= 1 (times executed).
Instance Attribute Summary collapse
-
#coverage ⇒ Integer?
readonly
The coverage data for this line: either nil (never), 0 (missed) or >=1 (times covered).
-
#line_number ⇒ Integer
(also: #line, #number)
readonly
The line number in the source file.
-
#skipped ⇒ Boolean
readonly
Whether this line was skipped.
-
#src ⇒ String
(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
Raises ArgumentError unless src is a String, line_number an Integer, and coverage an Integer or nil.
-
#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! ⇒ void
Flags this line as skipped.
-
#skipped? ⇒ Boolean
Returns true if this line was skipped, false otherwise.
-
#status ⇒ String?
"covered", "missed", "skipped", or "never" — useful e.g.
Constructor Details
#initialize(src, line_number, coverage) ⇒ Line
Raises ArgumentError unless src is a String, line_number an Integer, and coverage an Integer or nil.
966 967 968 969 970 971 972 973 974 975 976 977 |
# File 'sig/simplecov.rbs', line 966 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) unless coverage.is_a?(Integer) || coverage.nil? raise ArgumentError, "Only Integer and nil accepted for coverage" end @src = src @line_number = line_number @coverage = coverage @skipped = false end |
Instance Attribute Details
#coverage ⇒ Integer? (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_number ⇒ Integer (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 |
#skipped ⇒ Boolean (readonly)
Whether this line was skipped
18 19 20 |
# File 'lib/simplecov/source_file/line.rb', line 18 def skipped @skipped end |
#src ⇒ String (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
44 45 46 |
# File 'lib/simplecov/source_file/line.rb', line 44 def covered? !never? && !skipped? && coverage.to_i.positive? end |
#missed? ⇒ Boolean
Returns true if this is a line that should have been covered, but was not
39 40 41 |
# File 'lib/simplecov/source_file/line.rb', line 39 def missed? !never? && !skipped? && coverage.to_i.zero? end |
#never? ⇒ Boolean
Returns true if this line is not relevant for coverage
49 50 51 |
# File 'lib/simplecov/source_file/line.rb', line 49 def never? !skipped? && coverage.nil? end |
#skipped! ⇒ void
This method returns an undefined value.
Flags this line as skipped
54 55 56 |
# File 'lib/simplecov/source_file/line.rb', line 54 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.
60 61 62 |
# File 'lib/simplecov/source_file/line.rb', line 60 def skipped? skipped end |
#status ⇒ String?
"covered", "missed", "skipped", or "never" — useful e.g. as a css class.
66 67 68 69 70 71 72 73 74 |
# File 'lib/simplecov/source_file/line.rb', line 66 def status return "skipped" if skipped? return "never" if never? return "missed" if missed? # simplecov:disable — defensive: covered? is the only state left after the three above "covered" if covered? # simplecov:enable end |