Resolve let! not working on uninferable types

Resolves https://github.com/icy-arctic-fox/spectator/issues/4
Use ValueWrapper trick again and initialize immediately with before_each 
hook.
This commit is contained in:
Michael Miller 2020-01-14 20:07:56 -07:00
parent 7868755eee
commit c48b9ed9e1

View file

@ -19,11 +19,18 @@ module Spectator
end
macro let!(name, &block)
# TODO: Doesn't work with late-defined values (let).
@%value = {{yield}}
@%wrapper : ::Spectator::ValueWrapper?
def %wrapper
{{block.body}}
end
before_each do
@%wrapper = ::Spectator::TypedValueWrapper.new(%wrapper)
end
def {{name.id}}
@%value
@%wrapper.as(::Spectator::TypedValueWrapper(typeof(%wrapper))).value
end
end