mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Pretty up iterative group names
This commit is contained in:
parent
d8e9d3128a
commit
640857bef2
4 changed files with 15 additions and 8 deletions
|
@ -146,6 +146,8 @@ module Spectator::DSL
|
|||
|
||||
::Spectator::DSL::Builder.start_iterative_group(
|
||||
%collection,
|
||||
{{collection.stringify}},
|
||||
{{block.args.empty? ? :nil.id : block.args.first.stringify}},
|
||||
::Spectator::Location.new({{block.filename}}, {{block.line_number}}),
|
||||
metadata
|
||||
)
|
||||
|
|
|
@ -3,7 +3,7 @@ require "./node_builder"
|
|||
module Spectator
|
||||
class ExampleBuilder < NodeBuilder
|
||||
def initialize(@context_builder : -> Context, @entrypoint : Example ->,
|
||||
@name : String? = nil, @location : Location? = nil, @metadata : Metadata = Metadata.new)
|
||||
@name : String? = nil, @location : Location? = nil, @metadata : Metadata = Metadata.new)
|
||||
end
|
||||
|
||||
def build(parent)
|
||||
|
|
|
@ -3,9 +3,9 @@ require "./example_group_iteration"
|
|||
|
||||
module Spectator
|
||||
class IterativeExampleGroupBuilder(T) < ExampleGroupBuilder
|
||||
def initialize(@collection : Enumerable(T),
|
||||
location : Location? = nil, metadata : Metadata = Metadata.new)
|
||||
super(nil, location, metadata)
|
||||
def initialize(@collection : Enumerable(T), name : String? = nil, @iterator : String? = nil,
|
||||
location : Location? = nil, metadata : Metadata = Metadata.new)
|
||||
super(name, location, metadata)
|
||||
end
|
||||
|
||||
def build(parent = nil)
|
||||
|
@ -16,7 +16,12 @@ module Spectator
|
|||
@after_each_hooks.each { |hook| group.add_after_each_hook(hook) }
|
||||
@around_each_hooks.each { |hook| group.add_around_each_hook(hook) }
|
||||
@collection.each do |item|
|
||||
ExampleGroupIteration.new(item, item.inspect, @location, group).tap do |iteration|
|
||||
name = if iterator = @iterator
|
||||
"#{iterator}: #{item.inspect}"
|
||||
else
|
||||
item.inspect
|
||||
end
|
||||
ExampleGroupIteration.new(item, name, @location, group).tap do |iteration|
|
||||
@children.each(&.build(iteration))
|
||||
end
|
||||
end
|
||||
|
|
|
@ -76,9 +76,9 @@ module Spectator
|
|||
#
|
||||
# A set of *metadata* can be used for filtering and modifying example behavior.
|
||||
# For instance, adding a "pending" tag will mark tests as pending and skip execution.
|
||||
def start_iterative_group(collection, location = nil, metadata = Metadata.new) : Nil
|
||||
Log.trace { "Start iterative group: #{typeof(collection)} @ #{location}; metadata: #{metadata}" }
|
||||
builder = IterativeExampleGroupBuilder.new(collection, location, metadata)
|
||||
def start_iterative_group(collection, name, iterator = nil, location = nil, metadata = Metadata.new) : Nil
|
||||
Log.trace { "Start iterative group: #{name} (#{typeof(collection)}) @ #{location}; metadata: #{metadata}" }
|
||||
builder = IterativeExampleGroupBuilder.new(collection, name, iterator, location, metadata)
|
||||
current << builder
|
||||
@stack.push(builder)
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue