Capture reported expectations

This commit is contained in:
Michael Miller 2021-01-30 20:07:45 -07:00
parent bda554739c
commit 9743f37e5c
No known key found for this signature in database
GPG key ID: FB9F12F7C646A4AD

View file

@ -53,6 +53,7 @@ module Spectator
end end
@deferred = Deque(->).new @deferred = Deque(->).new
@expectations = [] of Expectation
# Runs test code and produces a result based on the outcome. # Runs test code and produces a result based on the outcome.
# The test code should be called from within the block given to this method. # The test code should be called from within the block given to this method.
@ -64,6 +65,7 @@ module Spectator
def report(expectation : Expectation) : Nil def report(expectation : Expectation) : Nil
Log.debug { "Reporting expectation #{expectation}" } Log.debug { "Reporting expectation #{expectation}" }
@expectations << expectation
raise ExpectationFailed.new(expectation) if expectation.failed? raise ExpectationFailed.new(expectation) if expectation.failed?
end end
@ -94,11 +96,11 @@ module Spectator
example = Example.current # TODO: Remove this. example = Example.current # TODO: Remove this.
case error case error
when nil when nil
PassResult.new(example, elapsed) PassResult.new(example, elapsed, @expectations)
when ExpectationFailed when ExpectationFailed
FailResult.new(example, elapsed, error) FailResult.new(example, elapsed, error, @expectations)
else else
ErrorResult.new(example, elapsed, error) ErrorResult.new(example, elapsed, error, @expectations)
end end
end end