Move tags to node level

This commit is contained in:
Michael Miller 2021-01-30 11:20:20 -07:00
parent 8cf498c9e9
commit 71a497b148
No known key found for this signature in database
GPG key ID: FB9F12F7C646A4AD
2 changed files with 16 additions and 11 deletions

View file

@ -9,9 +9,6 @@ require "./spec/node"
module Spectator
# Standard example that runs a test case.
class Example < Spec::Node
# User-defined keywords used for filtering and behavior modification.
alias Tags = Set(String)
# Currently running example.
class_getter! current : Example
@ -21,9 +18,6 @@ module Spectator
# Retrieves the result of the last time the example ran.
getter result : Result = PendingResult.new
# User-defined keywords used for filtering and behavior modification.
getter tags : Set(String)
# Creates the example.
# An instance to run the test code in is given by *context*.
# The *entrypoint* defines the test code (typically inside *context*).
@ -31,9 +25,11 @@ module Spectator
# It can be a `Symbol` to describe a type.
# The *source* tracks where the example exists in source code.
# The example will be assigned to *group* if it is provided.
# A set of *tags* can be used for filtering and modifying example behavior.
def initialize(@context : Context, @entrypoint : self ->,
name : String? = nil, source : Source? = nil, group : ExampleGroup? = nil, @tags = Tags.new)
super(name, source, group)
name : String? = nil, source : Source? = nil,
group : ExampleGroup? = nil, tags = Spec::Node::Tags.new)
super(name, source, group, tags)
end
# Creates a dynamic example.
@ -43,9 +39,10 @@ module Spectator
# It can be a `Symbol` to describe a type.
# The *source* tracks where the example exists in source code.
# The example 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 : String? = nil, source : Source? = nil, group : ExampleGroup? = nil,
@tags = Tags.new, &block : self ->)
super(name, source, group)
tags = Spec::Node::Tags.new, &block : self ->)
super(name, source, group, tags)
@context = NullContext.new
@entrypoint = block
end

View file

@ -7,6 +7,9 @@ module Spectator
# This is commonly an `Example` or `ExampleGroup`,
# but can be anything that should be iterated over when running the spec.
abstract class Node
# User-defined keywords used for filtering and behavior modification.
alias Tags = Set(String)
# Location of the node in source code.
getter! source : Source
@ -29,6 +32,9 @@ module Spectator
# 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.
@ -39,7 +45,9 @@ 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 : Label = nil, @source : Source? = nil, group : ExampleGroup? = nil)
# A set of *tags* can be used for filtering and modifying example behavior.
def initialize(@name : Label = nil, @source : Source? = nil,
group : ExampleGroup? = nil, @tags : Tags = Tags.new)
# Ensure group is linked.
group << self if group
end