Dedicated example runner type

This commit is contained in:
Michael Miller 2020-11-07 13:47:31 -07:00
parent b8901d485d
commit 347e1a84e5
No known key found for this signature in database
GPG key ID: FB9F12F7C646A4AD

View file

@ -30,12 +30,10 @@ module Spectator
# Returns the result of the execution.
# The result will also be stored in `#result`.
def run : Result
Log.debug { "Running example #{self}" }
elapsed = Time.measure do
@delegate.call(self)
end
runner = Runner.new(self, @delegate)
@result = runner.run
ensure
@finished = true
@result = PassResult.new(elapsed)
end
# Exposes information about the example useful for debugging.
@ -53,5 +51,23 @@ module Spectator
io << result
end
# Responsible for executing example code and reporting results.
private struct Runner
# Creates the runner.
# *example* is the example being tested.
# The *delegate* is the entrypoint of the example's test code.
def initialize(@example : Example, @delegate : ExampleContextDelegate)
end
# Executes the example's test code and produces a result.
def run : Result
Log.debug { "Running example #{@example}" }
elapsed = Time.measure do
@delegate.call(@example)
end
PassResult.new(elapsed)
end
end
end
end