Module: Rigor::Testing
- Defined in:
- lib/rigor/testing.rb,
sig/rigor/testing.rbs
Overview
Slice 7 phase 19 — PHPStan-style typing helpers.
Rigor::Testing ships two runtime no-op helpers that serve as anchors for
static-analysis diagnostics:
dump_type(value)— returnsvalueunchanged at runtime. The Rigor analyzer surfaces an:info-severity diagnostic at the call site showing the inferred type ofvalueso the user can see what the engine sees at that program point.assert_type(expected, value)— returnsvalueunchanged at runtime. The analyzer comparesvalue's inferred type (rendered throughRigor::Type#describe(:short)) against the literalexpectedString; a mismatch produces an:error-severity diagnostic. This lets a user-written fixture be self-asserting:rigor check fixture.rbexits non-zero exactly when the engine's inference drifts from what the fixture documents.
Three usage shapes are recognised by the static rules:
require "rigor/testing"
include Rigor::Testing
dump_type(x)
assert_type("Constant[1]", x)
... or fully qualified:
Rigor::Testing.dump_type(x)
Rigor::Testing.assert_type("String | nil", x)
... or via the convenience top-level alias Rigor itself:
Rigor.dump_type(x)
Rigor.assert_type("Constant[\"hello\"]", x)
All three resolve to the same no-op runtime body, so a fixture may freely run under MRI without depending on the analyzer being present.
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.assert_type(_expected, value) ⇒ Object
45 46 47 |
# File 'lib/rigor/testing.rb', line 45 def assert_type(_expected, value) value end |
.dump_type(value) ⇒ Object
41 42 43 |
# File 'lib/rigor/testing.rb', line 41 def dump_type(value) value end |
Instance Method Details
#self?.assert_type ⇒ Object
4 |
# File 'sig/rigor/testing.rbs', line 4
def self?.assert_type: (String expected, untyped value) -> untyped
|
#self?.dump_type ⇒ Object
3 |
# File 'sig/rigor/testing.rbs', line 3
def self?.dump_type: (untyped value) -> untyped
|