mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Some initial work on examples and groups
This commit is contained in:
parent
10a0ccc8bd
commit
19ff4669ac
2 changed files with 55 additions and 0 deletions
29
src/core/example.cr
Normal file
29
src/core/example.cr
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
module Spectator
|
||||||
|
# Information about a test case and functionality for running it.
|
||||||
|
class Example
|
||||||
|
# Name of the example.
|
||||||
|
# This may be nil if the example does not have a name.
|
||||||
|
# In that case, the description of the first matcher executed in the example should be used.
|
||||||
|
property! name : String
|
||||||
|
|
||||||
|
# Creates a new example.
|
||||||
|
# The *name* may be nil if the example has no name.
|
||||||
|
def initialize(@name = nil, &@block : Example -> Nil)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Runs the example.
|
||||||
|
def run
|
||||||
|
@block.call(self)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Constructs a string representation of the example.
|
||||||
|
# The name will be used if it is set, otherwise the example will be anonymous.
|
||||||
|
def to_s(io : IO) : Nil
|
||||||
|
if (name = @name)
|
||||||
|
io << name
|
||||||
|
else
|
||||||
|
io << "<Anonymous Example>"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
26
src/core/example_group.cr
Normal file
26
src/core/example_group.cr
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
module Spectator
|
||||||
|
# Information about a group of examples and functionality for running them.
|
||||||
|
# The group can be nested.
|
||||||
|
class ExampleGroup
|
||||||
|
# Name of the group.
|
||||||
|
# This may be nil if the group does not have a name.
|
||||||
|
property! name : String
|
||||||
|
|
||||||
|
getter examples = [] of Example
|
||||||
|
|
||||||
|
# Creates a new group.
|
||||||
|
# The *name* may be nil if the group has no name.
|
||||||
|
def initialize(@name = nil)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Constructs a string representation of the group.
|
||||||
|
# The name will be used if it is set, otherwise the group will be anonymous.
|
||||||
|
def to_s(io : IO) : Nil
|
||||||
|
if (name = @name)
|
||||||
|
io << name
|
||||||
|
else
|
||||||
|
io << "<Anonymous Context>"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue