Pass along tags

This commit is contained in:
Michael Miller 2021-01-30 11:34:01 -07:00
parent e77d6f0a4f
commit 467f0d3ad4
No known key found for this signature in database
GPG key ID: FB9F12F7C646A4AD
2 changed files with 13 additions and 6 deletions

View file

@ -37,7 +37,8 @@ module Spectator::DSL
::Spectator::DSL::Builder.start_group( ::Spectator::DSL::Builder.start_group(
_spectator_group_name(\{{what}}), _spectator_group_name(\{{what}}),
::Spectator::Source.new(\{{block.filename}}, \{{block.line_number}}) ::Spectator::Source.new(\{{block.filename}}, \{{block.line_number}}),
_spectator_tags
) )
\{{block.body}} \{{block.body}}

View file

@ -53,11 +53,14 @@ module Spectator
# #
# The *source* optionally defined where the group originates in source code. # The *source* optionally defined where the group originates in source code.
# #
# A set of *tags* can be used for filtering and modifying example behavior.
# For instance, adding a "pending" tag will mark tests as pending and skip execution.
#
# The newly created group is returned. # The newly created group is returned.
# It shouldn't be used outside of this class until a matching `#end_group` is called. # It shouldn't be used outside of this class until a matching `#end_group` is called.
def start_group(name, source = nil) : ExampleGroup def start_group(name, source = nil, tags = Spec::Node::Tags.new) : ExampleGroup
Log.trace { "Start group: #{name.inspect} @ #{source}" } Log.trace { "Start group: #{name.inspect} @ #{source}; tags: #{tags}" }
ExampleGroup.new(name, source, current_group).tap do |group| ExampleGroup.new(name, source, current_group, tags).tap do |group|
@group_stack << group @group_stack << group
end end
end end
@ -87,15 +90,18 @@ module Spectator
# The *context* is an instance of the context the test code should run in. # The *context* is an instance of the context the test code should run in.
# See `Context` for more information. # See `Context` for more information.
# #
# A set of *tags* can be used for filtering and modifying example behavior.
# For instance, adding a "pending" tag will mark the test as pending and skip execution.
#
# A block must be provided. # A block must be provided.
# It will be yielded two arguments - the example created by this method, and the *context* argument. # It will be yielded two arguments - the example created by this method, and the *context* argument.
# The return value of the block is ignored. # The return value of the block is ignored.
# It is expected that the test code runs when the block is called. # It is expected that the test code runs when the block is called.
# #
# The newly created example is returned. # The newly created example is returned.
def add_example(name, source, context, tags, &block : Example -> _) : Example def add_example(name, source, context, tags = Spec::Node::Tags.new, &block : Example -> _) : Example
Log.trace { "Add example: #{name} @ #{source}; tags: #{tags}" } Log.trace { "Add example: #{name} @ #{source}; tags: #{tags}" }
Example.new(context, block, name, source, current_group) Example.new(context, block, name, source, current_group, tags)
# The example is added to the current group by `Example` initializer. # The example is added to the current group by `Example` initializer.
end end