Handle sample count

This commit is contained in:
Michael Miller 2021-07-17 12:49:11 -06:00
parent 76a23131cb
commit 9d72d26630
No known key found for this signature in database
GPG key ID: FB9F12F7C646A4AD
2 changed files with 11 additions and 1 deletions

View file

@ -125,8 +125,11 @@ module Spectator::DSL
# Key-value pairs can also be specified.
# Any falsey items will remove a previously defined tag.
#
# The number of items iterated can be restricted by specifying a *count* argument.
# The first *count* items will be used if specified, otherwise all items will be used.
#
# TODO: Handle string interpolation in example and group names.
macro sample(collection, *tags, **metadata, &block)
macro sample(collection, *tags, count = nil, **metadata, &block)
{% raise "Cannot use 'sample' inside of a test block" if @def %}
class Group%group < {{@type.id}}
@ -136,6 +139,12 @@ module Spectator::DSL
{{collection}}
end
{% if count %}
def self.%collection
previous_def.first({{count}})
end
{% end %}
::Spectator::DSL::Builder.start_iterative_group(
%collection,
{{collection.stringify}},