Initial work to pass along pre-set tags

Define pending examples and groups using this method.
This commit is contained in:
Michael Miller 2021-01-30 12:32:13 -07:00
parent de779fdf61
commit 803a09464d
No known key found for this signature in database
GPG key ID: FB9F12F7C646A4AD
2 changed files with 58 additions and 22 deletions

View file

@ -8,7 +8,7 @@ module Spectator::DSL
# Defines a macro to generate code for an example.
# The *name* is the name given to the macro.
# TODO: Mark example as pending if block is omitted.
macro define_example(name)
macro define_example(name, *tags, **metadata)
# Defines an example.
#
# If a block is given, it is treated as the code to test.
@ -28,6 +28,19 @@ module Spectator::DSL
def self.\%tags
tags = _spectator_tags
{% if !tags.empty? %}
tags.concat({ {{tags.map(&.id.symbolize).splat}} })
{% end %}
{% for k, v in metadata %}
cond = begin
{{v}}
end
if cond
tags.add({{k.id.symbolize}})
else
tags.delete({{k.id.symbolize}})
end
{% end %}
\{% if !tags.empty? %}
tags.concat({ \{{tags.map(&.id.symbolize).splat}} })
\{% end %}
@ -85,6 +98,12 @@ module Spectator::DSL
define_example :specify
# TODO: pending, skip, and xit
define_example :xexample, :pending
define_example :xspecify, :pending
define_example :xit, :pending
define_example :skip, :pending
end
end

View file

@ -5,7 +5,7 @@ module Spectator::DSL
# DSL methods and macros for creating example groups.
# This module should be included as a mix-in.
module Groups
macro define_example_group(name)
macro define_example_group(name, *tags, **metadata)
# Defines a new example group.
# The *what* argument is a name or description of the group.
#
@ -16,25 +16,36 @@ module Spectator::DSL
class Group\%group < \{{@type.id}}
_spectator_group_subject(\{{what}})
\{% if !tags.empty? || !metadata.empty? %}
def self._spectator_tags
tags = super
\{% if !tags.empty? %}
tags.concat({ \{{tags.map(&.id.symbolize).splat}} })
\{% end %}
\{% for k, v in metadata %}
cond = begin
\{{v}}
end
if cond
tags.add(\{{k.id.symbolize}})
else
tags.delete(\{{k.id.symbolize}})
end
\{% end %}
tags
end
\{% end %}
def self._spectator_tags
tags = super
{% if !tags.empty? %}
tags.concat({ {{tags.map(&.id.symbolize).splat}} })
{% end %}
{% for k, v in metadata %}
cond = begin
{{v}}
end
if cond
tags.add({{k.id.symbolize}})
else
tags.delete({{k.id.symbolize}})
end
{% end %}
\{% if !tags.empty? %}
tags.concat({ \{{tags.map(&.id.symbolize).splat}} })
\{% end %}
\{% for k, v in metadata %}
cond = begin
\{{v}}
end
if cond
tags.add(\{{k.id.symbolize}})
else
tags.delete(\{{k.id.symbolize}})
end
\{% end %}
tags
end
::Spectator::DSL::Builder.start_group(
_spectator_group_name(\{{what}}),
@ -107,6 +118,12 @@ module Spectator::DSL
define_example_group :context
define_example_group :xexample_group, :pending
define_example_group :xdescribe, :pending
define_example_group :xcontext, :pending
# TODO: sample, random_sample, and given
end
end