Class: SpecGuard::RSpec::Finding

Inherits:
Object
  • Object
show all
Defined in:
lib/specguard/rspec/finding.rb

Overview

One @intent: annotation, located and (where possible) parsed.

Exactly one of intent and problem is non-nil:

* `intent`  — the parsed annotation as a Hash with String keys. Says
nothing about whether it is *valid*; schema validation is a later
stage, so a Finding with an `intent` may still be rejected then.
* `problem` — why this annotation could not be turned into a Hash at
all, as a human-readable sentence.

kind names how it failed and is nil when it did not. It is carried here rather than reconstructed by the caller because a failed extraction and an unparseable payload both land in problem, which makes the two indistinguishable downstream once flattened to prose.

line is the 1-based line the annotation sits on — except under KIND_READ, where nothing in the file was ever seen and Scanner.scan_file / Scanner.scan_text construct the Finding with a line of 0. That 0 is a sentinel standing in for "no line", not a position anything can be pointed at.

NOTE: this is a subclass of an anonymous Data.define rather than a Data.define do ... end block, because a constant assigned inside that block binds to the lexically enclosing module (SpecGuard::RSpec) rather than to the value class — so KIND_EXTRACTION below would silently not be Finding::KIND_EXTRACTION.

Constant Summary collapse

KIND_EXTRACTION =

The annotation's payload could not be captured off the line at all (unterminated literal, or no {...} after the token).

:extraction
KIND_PARSE =

The payload was captured but is not JSON even after normalization.

:parse
KIND_READ =

The file itself could not be read (missing, unopenable, or not valid UTF-8), so no annotation in it was ever seen. Distinct from KIND_EXTRACTION — nothing here is a claim about an annotation — and named after the read kind the validator's --json report carries, so the two classifications line up.

:read
KIND_SCHEMA =

The payload parsed but violates the OpenTestIntent schema. Not produced by discovery — Linter stamps it — but it lives here so the full set of ways an annotation can fail is written down in one place.

:schema
KIND_UNREACHABLE =

The annotation is well-formed in isolation but can never be EXTRACTED: it is a comment-form @intent: on a line whose next line is also a comment-form @intent:, so the one-line lookback (SPGD-12 §2 — AnnotationLookup claims only the comment on the line immediately above an example) always skips it in favour of the lower line. The contract is dead metadata: counted by the linter, discarded by extraction. Produced by Scanner's structural pass, not by AnnotationScanner — each annotation is scanned in isolation there, which is exactly why this defect is invisible to it.

:unreachable

Instance Method Summary collapse

Constructor Details

#initialize(file:, line:, intent: nil, problem: nil, kind: nil) ⇒ Finding

Returns a new instance of Finding.



62
63
64
# File 'lib/specguard/rspec/finding.rb', line 62

def initialize(file:, line:, intent: nil, problem: nil, kind: nil)
  super
end

Instance Method Details

#extracted?Boolean

True when the annotation yielded a Hash. Not a claim that it is valid.

Returns:

  • (Boolean)


67
68
69
# File 'lib/specguard/rspec/finding.rb', line 67

def extracted?
  problem.nil?
end

#problem?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/specguard/rspec/finding.rb', line 71

def problem?
  !problem.nil?
end