mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Move Node out of Spec namespace
This commit is contained in:
parent
f24d634ccb
commit
6bea36d8b6
7 changed files with 96 additions and 98 deletions
|
@ -65,7 +65,7 @@ module Spectator::DSL
|
|||
# Inserts the correct representation of a example's name.
|
||||
# If *what* is a string, then it is dropped in as-is.
|
||||
# For anything else, it is stringified.
|
||||
# This is intended to be used to convert a description from the spec DSL to `Spec::Node#name`.
|
||||
# This is intended to be used to convert a description from the spec DSL to `Node#name`.
|
||||
private macro _spectator_example_name(what)
|
||||
{% if what.is_a?(StringLiteral) ||
|
||||
what.is_a?(StringInterpolation) ||
|
||||
|
|
|
@ -56,7 +56,7 @@ module Spectator::DSL
|
|||
# If *what* appears to be a type name, it will be symbolized.
|
||||
# If it's a string, then it is dropped in as-is.
|
||||
# For anything else, it is stringified.
|
||||
# This is intended to be used to convert a description from the spec DSL to `Spec::Node#name`.
|
||||
# This is intended to be used to convert a description from the spec DSL to `Node#name`.
|
||||
private macro _spectator_group_name(what)
|
||||
{% if (what.is_a?(Generic) ||
|
||||
what.is_a?(Path) ||
|
||||
|
|
|
@ -2,14 +2,14 @@ require "./example_context_delegate"
|
|||
require "./example_group"
|
||||
require "./harness"
|
||||
require "./location"
|
||||
require "./node"
|
||||
require "./pending_result"
|
||||
require "./result"
|
||||
require "./spec/node"
|
||||
require "./tags"
|
||||
|
||||
module Spectator
|
||||
# Standard example that runs a test case.
|
||||
class Example < Spec::Node
|
||||
class Example < Node
|
||||
# Currently running example.
|
||||
class_getter! current : Example
|
||||
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
require "./events"
|
||||
require "./example_procsy_hook"
|
||||
require "./spec/node"
|
||||
require "./node"
|
||||
|
||||
module Spectator
|
||||
# Collection of examples and sub-groups.
|
||||
class ExampleGroup < Spec::Node
|
||||
include Enumerable(Spec::Node)
|
||||
class ExampleGroup < Node
|
||||
include Enumerable(Node)
|
||||
include Events
|
||||
include Iterable(Spec::Node)
|
||||
include Iterable(Node)
|
||||
|
||||
@nodes = [] of Spec::Node
|
||||
@nodes = [] of Node
|
||||
|
||||
group_event before_all do |hooks|
|
||||
Log.trace { "Processing before_all hooks for #{self}" }
|
||||
|
@ -65,7 +65,7 @@ module Spectator
|
|||
|
||||
# Removes the specified *node* from the group.
|
||||
# The node will be unassigned from this group.
|
||||
def delete(node : Spec::Node)
|
||||
def delete(node : Node)
|
||||
# Only remove from the group if it is associated with this group.
|
||||
return unless node.group == self
|
||||
|
||||
|
@ -92,7 +92,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 : Spec::Node)
|
||||
def <<(node : Node)
|
||||
# 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 "./spec/node"
|
||||
require "./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(Spec::Node))
|
||||
@stack : Array(Iterator(Node))
|
||||
|
||||
# Creates a new iterator.
|
||||
# The *group* is the example group to iterate through.
|
||||
def initialize(@group : ExampleGroup)
|
||||
iter = @group.each.as(Iterator(Spec::Node))
|
||||
iter = @group.each.as(Iterator(Node))
|
||||
@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(Spec::Node))
|
||||
iter = @group.each.as(Iterator(Node))
|
||||
@stack = [iter]
|
||||
self
|
||||
end
|
||||
|
|
81
src/spectator/node.cr
Normal file
81
src/spectator/node.cr
Normal file
|
@ -0,0 +1,81 @@
|
|||
require "./label"
|
||||
require "./location"
|
||||
require "./tags"
|
||||
|
||||
module Spectator
|
||||
# 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 Node
|
||||
# Location of the node in source code.
|
||||
getter! location : Location
|
||||
|
||||
# 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.
|
||||
#
|
||||
# This value will be nil if no name was provided.
|
||||
# In this case, and the node is a runnable example,
|
||||
# the name should be set to the description
|
||||
# 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 : Label
|
||||
|
||||
# Updates the name of the node.
|
||||
protected def name=(@name : String)
|
||||
end
|
||||
|
||||
# Group the node belongs to.
|
||||
getter! group : ExampleGroup
|
||||
|
||||
# User-defined keywords used for filtering and behavior modification.
|
||||
getter tags : Tags
|
||||
|
||||
# Assigns the node to the specified *group*.
|
||||
# This is an internal method and should only be called from `ExampleGroup`.
|
||||
# `ExampleGroup` manages the association of nodes to groups.
|
||||
protected setter group : ExampleGroup?
|
||||
|
||||
# Creates the node.
|
||||
# The *name* describes the purpose of the node.
|
||||
# It can be a `Symbol` to describe a type.
|
||||
# The *location* tracks where the node exists in source code.
|
||||
# The node will be assigned to *group* if it is provided.
|
||||
# A set of *tags* can be used for filtering and modifying example behavior.
|
||||
def initialize(@name : Label = nil, @location : Location? = nil,
|
||||
group : ExampleGroup? = nil, @tags : Tags = Tags.new)
|
||||
# Ensure group is linked.
|
||||
group << self if group
|
||||
end
|
||||
|
||||
# Indicates whether the node has completed.
|
||||
abstract def finished? : Bool
|
||||
|
||||
# Checks if the node has been marked as pending.
|
||||
# Pending items should be skipped during execution.
|
||||
def pending?
|
||||
tags.includes?(:pending)
|
||||
end
|
||||
|
||||
# Constructs the full name or description of the node.
|
||||
# This prepends names of groups this node is part of.
|
||||
def to_s(io)
|
||||
name = @name
|
||||
|
||||
# Prefix with group's full name if the node belongs to a group.
|
||||
if (group = @group)
|
||||
group.to_s(io)
|
||||
|
||||
# Add padding between the node names
|
||||
# only if the names don't appear to be symbolic.
|
||||
# Skip blank group names (like the root group).
|
||||
io << ' ' unless !group.name? || # ameba:disable Style/NegatedConditionsInUnless
|
||||
(group.name?.is_a?(Symbol) && name.is_a?(String) &&
|
||||
(name.starts_with?('#') || name.starts_with?('.')))
|
||||
end
|
||||
|
||||
name.to_s(io)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,83 +0,0 @@
|
|||
require "../label"
|
||||
require "../location"
|
||||
require "../tags"
|
||||
|
||||
module Spectator
|
||||
class Spec
|
||||
# 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 Node
|
||||
# Location of the node in source code.
|
||||
getter! location : Location
|
||||
|
||||
# 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.
|
||||
#
|
||||
# This value will be nil if no name was provided.
|
||||
# In this case, and the node is a runnable example,
|
||||
# the name should be set to the description
|
||||
# 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 : Label
|
||||
|
||||
# Updates the name of the node.
|
||||
protected def name=(@name : String)
|
||||
end
|
||||
|
||||
# Group the node belongs to.
|
||||
getter! group : ExampleGroup
|
||||
|
||||
# User-defined keywords used for filtering and behavior modification.
|
||||
getter tags : Tags
|
||||
|
||||
# Assigns the node to the specified *group*.
|
||||
# This is an internal method and should only be called from `ExampleGroup`.
|
||||
# `ExampleGroup` manages the association of nodes to groups.
|
||||
protected setter group : ExampleGroup?
|
||||
|
||||
# Creates the node.
|
||||
# The *name* describes the purpose of the node.
|
||||
# It can be a `Symbol` to describe a type.
|
||||
# The *location* tracks where the node exists in source code.
|
||||
# The node will be assigned to *group* if it is provided.
|
||||
# A set of *tags* can be used for filtering and modifying example behavior.
|
||||
def initialize(@name : Label = nil, @location : Location? = nil,
|
||||
group : ExampleGroup? = nil, @tags : Tags = Tags.new)
|
||||
# Ensure group is linked.
|
||||
group << self if group
|
||||
end
|
||||
|
||||
# Indicates whether the node has completed.
|
||||
abstract def finished? : Bool
|
||||
|
||||
# Checks if the node has been marked as pending.
|
||||
# Pending items should be skipped during execution.
|
||||
def pending?
|
||||
tags.includes?(:pending)
|
||||
end
|
||||
|
||||
# Constructs the full name or description of the node.
|
||||
# This prepends names of groups this node is part of.
|
||||
def to_s(io)
|
||||
name = @name
|
||||
|
||||
# Prefix with group's full name if the node belongs to a group.
|
||||
if (group = @group)
|
||||
group.to_s(io)
|
||||
|
||||
# Add padding between the node names
|
||||
# only if the names don't appear to be symbolic.
|
||||
# Skip blank group names (like the root group).
|
||||
io << ' ' unless !group.name? || # ameba:disable Style/NegatedConditionsInUnless
|
||||
(group.name?.is_a?(Symbol) && name.is_a?(String) &&
|
||||
(name.starts_with?('#') || name.starts_with?('.')))
|
||||
end
|
||||
|
||||
name.to_s(io)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue