Promote Tags to the Spectator namespace

This commit is contained in:
Michael Miller 2021-01-30 12:07:23 -07:00
parent db877da984
commit c5246e1cd3
No known key found for this signature in database
GPG key ID: FB9F12F7C646A4AD
5 changed files with 14 additions and 8 deletions

View file

@ -5,6 +5,7 @@ require "./pending_result"
require "./result"
require "./source"
require "./spec/node"
require "./tags"
module Spectator
# Standard example that runs a test case.
@ -28,7 +29,7 @@ module Spectator
# 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 = Spec::Node::Tags.new)
group : ExampleGroup? = nil, tags = Tags.new)
super(name, source, group, tags)
end
@ -41,7 +42,7 @@ module Spectator
# 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 = Spec::Node::Tags.new, &block : self ->)
tags = Tags.new, &block : self ->)
super(name, source, group, tags)
@context = NullContext.new
@entrypoint = block

View file

@ -4,6 +4,7 @@ require "../example"
require "../example_context_method"
require "../example_group"
require "../spec"
require "../tags"
module Spectator
class Spec
@ -58,7 +59,7 @@ module Spectator
#
# The newly created group is returned.
# It shouldn't be used outside of this class until a matching `#end_group` is called.
def start_group(name, source = nil, tags = Spec::Node::Tags.new) : ExampleGroup
def start_group(name, source = nil, tags = Tags.new) : ExampleGroup
Log.trace { "Start group: #{name.inspect} @ #{source}; tags: #{tags}" }
ExampleGroup.new(name, source, current_group, tags).tap do |group|
@group_stack << group
@ -99,7 +100,7 @@ module Spectator
# It is expected that the test code runs when the block is called.
#
# The newly created example is returned.
def add_example(name, source, context, tags = Spec::Node::Tags.new, &block : Example -> _) : Example
def add_example(name, source, context, tags = Tags.new, &block : Example -> _) : Example
Log.trace { "Add example: #{name} @ #{source}; tags: #{tags}" }
Example.new(context, block, name, source, current_group, tags)
# The example is added to the current group by `Example` initializer.

View file

@ -1,5 +1,6 @@
require "../label"
require "../source"
require "../tags"
module Spectator
class Spec
@ -7,9 +8,6 @@ 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(Symbol)
# Location of the node in source code.
getter! source : Source

4
src/spectator/tags.cr Normal file
View file

@ -0,0 +1,4 @@
module Spectator
# User-defined keywords used for filtering and behavior modification.
alias Tags = Set(Symbol)
end

View file

@ -1,5 +1,7 @@
require "./context"
require "./dsl"
require "./lazy_wrapper"
require "./tags"
# Class used as the base for all specs using the DSL.
# It adds methods and macros necessary to use the DSL from the spec.
@ -31,6 +33,6 @@ class SpectatorTestContext < SpectatorContext
# Initial tags for tests.
# This method should be overridden by example groups and examples.
def self._spectator_tags
::Spectator::Example::Tags.new
::Spectator::Tags.new
end
end