mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Dedicated example runner type
This commit is contained in:
parent
b8901d485d
commit
347e1a84e5
1 changed files with 21 additions and 5 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue