2019-08-01 21:44:04 +00:00
|
|
|
module Spectator
|
2019-08-01 21:38:20 +00:00
|
|
|
# Base type for capturing an expression from a test.
|
2019-08-09 17:12:15 +00:00
|
|
|
abstract struct TestExpression(T)
|
2019-08-01 02:01:39 +00:00
|
|
|
# User-friendly string displayed for the actual expression being tested.
|
|
|
|
# For instance, in the expectation:
|
|
|
|
# ```
|
|
|
|
# expect(foo).to eq(bar)
|
|
|
|
# ```
|
|
|
|
# This property will be "foo".
|
|
|
|
# It will be the literal string "foo",
|
|
|
|
# and not the actual value of the foo.
|
|
|
|
getter label : String
|
|
|
|
|
2019-08-01 21:38:20 +00:00
|
|
|
# Creates the common base of the expression.
|
2019-08-01 02:01:39 +00:00
|
|
|
def initialize(@label)
|
|
|
|
end
|
|
|
|
|
2019-08-09 17:12:15 +00:00
|
|
|
abstract def value : T
|
|
|
|
|
2019-08-01 21:38:20 +00:00
|
|
|
# String representation of the expression.
|
2019-08-01 02:01:39 +00:00
|
|
|
def to_s(io)
|
|
|
|
io << label
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|