mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Use TestWrapper in Example classes
This commit is contained in:
parent
de8f298676
commit
a178db05ac
4 changed files with 15 additions and 13 deletions
|
@ -2,7 +2,7 @@ require "./example_component"
|
|||
|
||||
module Spectator
|
||||
# Base class for all types of examples.
|
||||
# Concrete types must implement the `#run_impl, `#what`, `#instance`, and `#source` methods.
|
||||
# Concrete types must implement the `#run_impl` method.
|
||||
abstract class Example < ExampleComponent
|
||||
# Indicates whether the example has already been run.
|
||||
getter? finished = false
|
||||
|
@ -11,10 +11,16 @@ module Spectator
|
|||
getter group : ExampleGroup
|
||||
|
||||
# Retrieves the internal wrapped instance.
|
||||
abstract def instance
|
||||
private getter @test_wrapper : TestWrapper
|
||||
|
||||
# Source where the example originated from.
|
||||
abstract def source : Source
|
||||
def source
|
||||
@test_wrapper.source
|
||||
end
|
||||
|
||||
def what
|
||||
@test_wrapper.description
|
||||
end
|
||||
|
||||
# Runs the example code.
|
||||
# A result is returned, which represents the outcome of the test.
|
||||
|
@ -31,7 +37,7 @@ module Spectator
|
|||
|
||||
# Creates the base of the example.
|
||||
# The group should be the example group the example belongs to.
|
||||
def initialize(@group)
|
||||
def initialize(@group, @test_wrapper)
|
||||
end
|
||||
|
||||
# Indicates there is only one example to run.
|
||||
|
|
|
@ -3,6 +3,7 @@ module Spectator
|
|||
# This is used as the base node type for the composite design pattern.
|
||||
abstract class ExampleComponent
|
||||
# Text that describes the context or test.
|
||||
# TODO: Rename to description.
|
||||
abstract def what : String
|
||||
|
||||
# Indicates whether the example (or group) has been completely run.
|
||||
|
|
|
@ -3,7 +3,7 @@ require "./example"
|
|||
module Spectator
|
||||
# Common class for all examples marked as pending.
|
||||
# This class will not run example code.
|
||||
abstract class PendingExample < Example
|
||||
class PendingExample < Example
|
||||
# Returns a pending result.
|
||||
private def run_impl
|
||||
PendingResult.new(self)
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
require "./example"
|
||||
|
||||
module Spectator
|
||||
# Common base for all examples that can be run.
|
||||
# This class includes all the logic for running example hooks,
|
||||
# Includes all the logic for running example hooks,
|
||||
# the example code, and capturing a result.
|
||||
# Sub-classes need to implement the `#what` and `#run_instance` methods.
|
||||
abstract class RunnableExample < Example
|
||||
class RunnableExample < Example
|
||||
# Runs the example, hooks, and captures the result
|
||||
# and translates to a usable result.
|
||||
def run_impl
|
||||
|
@ -14,9 +12,6 @@ module Spectator
|
|||
translate_result(result, expectations)
|
||||
end
|
||||
|
||||
# Runs the actual test code.
|
||||
private abstract def run_instance
|
||||
|
||||
# Runs all hooks and the example code.
|
||||
# A captured result is returned.
|
||||
private def capture_result
|
||||
|
@ -52,7 +47,7 @@ module Spectator
|
|||
# Capture how long it takes to run the test code.
|
||||
result.elapsed = Time.measure do
|
||||
begin
|
||||
run_instance # Actually run the example code.
|
||||
test_wrapper.run {} # Actually run the example code.
|
||||
rescue ex # Catch all errors and handle them later.
|
||||
result.error = ex
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue