mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Handle sample count
This commit is contained in:
parent
76a23131cb
commit
9d72d26630
2 changed files with 11 additions and 1 deletions
|
@ -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}},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue