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
|
@ -31,6 +31,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
- Cleanup and simplify DSL implementation.
|
||||
- Better error messages and detection when DSL methods are used when they shouldn't (i.e. `describe` inside `it`).
|
||||
- Prevent usage of reserved keywords in DSL (such as `initialize`).
|
||||
- The count argument for `sample` and `random_sample` groups must be named (use `count: 5` instead of just `5`).
|
||||
- Other minor internal improvements and cleanup.
|
||||
|
||||
### Deprecated
|
||||
|
|
|
@ -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…
Reference in a new issue