Some initial work on examples and groups

This commit is contained in:
Michael Miller 2024-06-06 20:13:55 -06:00
parent 10a0ccc8bd
commit 19ff4669ac
No known key found for this signature in database
GPG key ID: 32B47AE8F388A1FF
2 changed files with 55 additions and 0 deletions

29
src/core/example.cr Normal file
View 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
View 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