Implement defer logic in harness

This commit is contained in:
Michael Miller 2019-11-14 18:30:48 -07:00
parent 173f7bfa13
commit 2128184659

View file

@ -51,10 +51,22 @@ module Spectator
@reporter.expectations
end
# Marks a block of code to run later.
def defer(&block : ->) : Nil
@deferred << block
end
# Runs all deferred blocks.
def run_deferred : Nil
@deferred.each(&.call)
@deferred.clear
end
# Creates a new harness.
# The example the harness is for should be passed in.
private def initialize(@example)
@reporter = Expectations::ExpectationReporter.new
@deferred = Deque(->).new
end
end
end