abstract class Spectator::AbstractExpression
- Spectator::AbstractExpression
- Reference
- Object
Overview
Represents an expression from a test.
This is typically captured by an expect
macro.
It consists of a label and the value of the expression.
The label should be a string recognizable by the user,
or nil if one isn't available.
This base class is provided so that all generic sub-classes can be stored as this one type.
The value of the expression can be retrieved by down-casting to the expected type with #cast
.
NOTE This is intentionally a class and not a struct. If it were a struct, changes made to the value held by an instance may not be kept when passing it around. See commit ca564619ad2ae45f832a058d514298c868fdf699.
Direct Known Subclasses
Defined in:
spectator/abstract_expression.crConstructors
-
.new(label : Label)
Creates the expression.
Instance Method Summary
-
#cast(type : T.class) : T forall T
Attempts to cast
#raw_value
to the type T and return it. -
#inspect(io : IO) : Nil
Produces a detailed string representation of the expression.
-
#label : Label
User recognizable string for the expression.
-
#raw_value
Retrieves the evaluated value of the expression.
-
#to_s(io : IO) : Nil
Produces a string representation of the expression.
Instance methods inherited from class Object
should(matcher : Spectator::Matchers::TypeMatcher(U), message = nil, *, _file = __FILE__, _line = __LINE__) forall Ushould(matcher, message = nil, *, _file = __FILE__, _line = __LINE__) should, should_eventually(matcher, message = nil, *, _file = __FILE__, _line = __LINE__) should_eventually, should_never(matcher, message = nil, *, _file = __FILE__, _line = __LINE__) should_never, should_not(matcher : Spectator::Matchers::TypeMatcher(U), message = nil, *, _file = __FILE__, _line = __LINE__) forall U
should_not(matcher : Spectator::Matchers::NilMatcher, message = nil, *, _file = __FILE__, _line = __LINE__)
should_not(matcher, message = nil, *, _file = __FILE__, _line = __LINE__) should_not
Constructor Detail
Creates the expression.
The label is usually the Crystal code evaluating to the #raw_value
.
It can be nil if it isn't available.
Instance Method Detail
Attempts to cast #raw_value
to the type T and return it.
Produces a detailed string representation of the expression. This consists of the label (if one is available) and the value.
User recognizable string for the expression. This can be something like a variable name or a snippet of Crystal code.
Produces a string representation of the expression. This consists of the label (if one is available) and the value.