mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Add test wrapper
This commit is contained in:
parent
00a2495027
commit
b8e125e38f
1 changed files with 30 additions and 0 deletions
30
src/spectator/test_wrapper.cr
Normal file
30
src/spectator/test_wrapper.cr
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
require "../spectator_test"
|
||||||
|
require "./source"
|
||||||
|
|
||||||
|
module Spectator
|
||||||
|
# Stores information about a end-user test.
|
||||||
|
# Used to instantiate tests and run them.
|
||||||
|
struct TestWrapper
|
||||||
|
# Location of the test in source code.
|
||||||
|
getter source : Source
|
||||||
|
|
||||||
|
# Description the user provided for the test.
|
||||||
|
getter description : String
|
||||||
|
|
||||||
|
# Creates a wrapper for the test.
|
||||||
|
# The *builder* creates an instance of the test.
|
||||||
|
# The *runner* takes the test created by *builder* and runs it.
|
||||||
|
def initialize(@description, @source, @builder : -> SpectatorTest, @runner : SpectatorTest ->)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Instantiates and runs the test.
|
||||||
|
# This method yields twice - before and after the test.
|
||||||
|
# The test instance is yielded.
|
||||||
|
def run : Nil
|
||||||
|
test = @builder.call
|
||||||
|
yield test
|
||||||
|
@runner.call(test)
|
||||||
|
yield test
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue