Don't cache the block return value

Let the matcher handle this if it needs to.
This commit is contained in:
Michael Miller 2021-01-15 23:15:07 -07:00
parent a74957204b
commit 50d1f69230
No known key found for this signature in database
GPG key ID: F9A0C5C65B162436

View file

@ -1,6 +1,5 @@
require "./expression"
require "./label"
require "./lazy"
module Spectator
# Represents a block from a test.
@ -9,9 +8,6 @@ module Spectator
# The label should be a string recognizable by the user,
# or nil if one isn't available.
class Block(T) < Expression(T)
# Cached value returned from the block.
@value = Lazy(T).new
# Creates the block expression from a proc.
# The *proc* will be called to evaluate the value of the expression.
# The *label* is usually the Crystal code for the *proc*.
@ -28,18 +24,10 @@ module Spectator
super(label)
end
# Retrieves the value of the block expression.
# This will be the return value of the block.
# The block is lazily evaluated and the value retrieved only once.
# Afterwards, the value is cached and returned by successive calls to this method.
def value
@value.get { call }
end
# Evaluates the block and returns the value from it.
# This method _does not_ cache the resulting value like `#value` does.
# Successive calls to this method may return different values.
def call : T
def value : T
@block.call
end
end