diff --git a/src/spectator/dsl/examples.cr b/src/spectator/dsl/examples.cr index 8063b61..d789a44 100644 --- a/src/spectator/dsl/examples.cr +++ b/src/spectator/dsl/examples.cr @@ -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 diff --git a/src/spectator/dsl/groups.cr b/src/spectator/dsl/groups.cr index ad35a30..d6dd9c2 100644 --- a/src/spectator/dsl/groups.cr +++ b/src/spectator/dsl/groups.cr @@ -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