mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Change ExampleNode to SpecNode
This commit is contained in:
parent
0ee708281f
commit
7d0ba752e9
4 changed files with 21 additions and 18 deletions
|
@ -1,14 +1,14 @@
|
|||
require "./example_context_delegate"
|
||||
require "./example_group"
|
||||
require "./example_node"
|
||||
require "./harness"
|
||||
require "./pending_result"
|
||||
require "./result"
|
||||
require "./source"
|
||||
require "./spec_node"
|
||||
|
||||
module Spectator
|
||||
# Standard example that runs a test case.
|
||||
class Example < ExampleNode
|
||||
class Example < SpecNode
|
||||
# Currently running example.
|
||||
class_getter! current : Example
|
||||
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
require "./events"
|
||||
require "./example_node"
|
||||
require "./spec_node"
|
||||
|
||||
module Spectator
|
||||
# Collection of examples and sub-groups.
|
||||
class ExampleGroup < ExampleNode
|
||||
include Enumerable(ExampleNode)
|
||||
class ExampleGroup < SpecNode
|
||||
include Enumerable(SpecNode)
|
||||
include Events
|
||||
include Iterable(ExampleNode)
|
||||
include Iterable(SpecNode)
|
||||
|
||||
group_event before_all do |hooks|
|
||||
Log.trace { "Processing before_all hooks" }
|
||||
|
@ -48,11 +48,11 @@ module Spectator
|
|||
end
|
||||
end
|
||||
|
||||
@nodes = [] of ExampleNode
|
||||
@nodes = [] of SpecNode
|
||||
|
||||
# Removes the specified *node* from the group.
|
||||
# The node will be unassigned from this group.
|
||||
def delete(node : ExampleNode)
|
||||
def delete(node : SpecNode)
|
||||
# Only remove from the group if it is associated with this group.
|
||||
return unless node.group == self
|
||||
|
||||
|
@ -79,7 +79,7 @@ module Spectator
|
|||
# Assigns the node to this group.
|
||||
# If the node already belongs to a group,
|
||||
# it will be removed from the previous group before adding it to this group.
|
||||
def <<(node : ExampleNode)
|
||||
def <<(node : SpecNode)
|
||||
# Remove from existing group if the node is part of one.
|
||||
if (previous = node.group?)
|
||||
previous.delete(node)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require "./example"
|
||||
require "./example_group"
|
||||
require "./example_node"
|
||||
require "./spec_node"
|
||||
|
||||
module Spectator
|
||||
# Iterates through all examples in a group and its nested groups.
|
||||
|
@ -9,12 +9,12 @@ module Spectator
|
|||
|
||||
# Stack that contains the iterators for each group.
|
||||
# A stack is used to track where in the tree this iterator is.
|
||||
@stack : Array(Iterator(ExampleNode))
|
||||
@stack : Array(Iterator(SpecNode))
|
||||
|
||||
# Creates a new iterator.
|
||||
# The *group* is the example group to iterate through.
|
||||
def initialize(@group : ExampleGroup)
|
||||
iter = @group.each.as(Iterator(ExampleNode))
|
||||
iter = @group.each.as(Iterator(SpecNode))
|
||||
@stack = [iter]
|
||||
end
|
||||
|
||||
|
@ -39,7 +39,7 @@ module Spectator
|
|||
# Restart the iterator at the beginning.
|
||||
def rewind
|
||||
# Same code as `#initialize`, but return self.
|
||||
iter = @group.each.as(Iterator(ExampleNode))
|
||||
iter = @group.each.as(Iterator(SpecNode))
|
||||
@stack = [iter]
|
||||
self
|
||||
end
|
||||
|
|
|
@ -1,12 +1,15 @@
|
|||
require "./label"
|
||||
require "./source"
|
||||
|
||||
module Spectator
|
||||
# A single example or collection (group) of examples in an example tree.
|
||||
abstract class ExampleNode
|
||||
# A single item in a test spec.
|
||||
# This is commonly an `Example` or `ExampleGroup`,
|
||||
# but can be anything that should be iterated over when running the spec.
|
||||
abstract class SpecNode
|
||||
# Location of the node in source code.
|
||||
getter! source : Source
|
||||
|
||||
# User-provided name or description of the test.
|
||||
# User-provided name or description of the node.
|
||||
# This does not include the group name or descriptions.
|
||||
# Use `#to_s` to get the full name.
|
||||
#
|
||||
|
@ -16,7 +19,7 @@ module Spectator
|
|||
# of the first matcher that runs in the test case.
|
||||
#
|
||||
# If this value is a `Symbol`, the user specified a type for the name.
|
||||
getter! name : String | Symbol
|
||||
getter! name : Label
|
||||
|
||||
# Updates the name of the node.
|
||||
protected def name=(@name : String)
|
||||
|
@ -35,7 +38,7 @@ module Spectator
|
|||
# It can be a `Symbol` to describe a type.
|
||||
# The *source* tracks where the node exists in source code.
|
||||
# The node will be assigned to *group* if it is provided.
|
||||
def initialize(@name : String | Symbol? = nil, @source : Source? = nil, group : ExampleGroup? = nil)
|
||||
def initialize(@name : Label = nil, @source : Source? = nil, group : ExampleGroup? = nil)
|
||||
# Ensure group is linked.
|
||||
group << self if group
|
||||
end
|
Loading…
Reference in a new issue