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(
|
::Spectator::DSL::Builder.start_iterative_group(
|
||||||
%collection,
|
%collection,
|
||||||
|
{{collection.stringify}},
|
||||||
|
{{block.args.empty? ? :nil.id : block.args.first.stringify}},
|
||||||
::Spectator::Location.new({{block.filename}}, {{block.line_number}}),
|
::Spectator::Location.new({{block.filename}}, {{block.line_number}}),
|
||||||
metadata
|
metadata
|
||||||
)
|
)
|
||||||
|
|
|
@ -3,7 +3,7 @@ require "./node_builder"
|
||||||
module Spectator
|
module Spectator
|
||||||
class ExampleBuilder < NodeBuilder
|
class ExampleBuilder < NodeBuilder
|
||||||
def initialize(@context_builder : -> Context, @entrypoint : Example ->,
|
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
|
end
|
||||||
|
|
||||||
def build(parent)
|
def build(parent)
|
||||||
|
|
|
@ -3,9 +3,9 @@ require "./example_group_iteration"
|
||||||
|
|
||||||
module Spectator
|
module Spectator
|
||||||
class IterativeExampleGroupBuilder(T) < ExampleGroupBuilder
|
class IterativeExampleGroupBuilder(T) < ExampleGroupBuilder
|
||||||
def initialize(@collection : Enumerable(T),
|
def initialize(@collection : Enumerable(T), name : String? = nil, @iterator : String? = nil,
|
||||||
location : Location? = nil, metadata : Metadata = Metadata.new)
|
location : Location? = nil, metadata : Metadata = Metadata.new)
|
||||||
super(nil, location, metadata)
|
super(name, location, metadata)
|
||||||
end
|
end
|
||||||
|
|
||||||
def build(parent = nil)
|
def build(parent = nil)
|
||||||
|
@ -16,7 +16,12 @@ module Spectator
|
||||||
@after_each_hooks.each { |hook| group.add_after_each_hook(hook) }
|
@after_each_hooks.each { |hook| group.add_after_each_hook(hook) }
|
||||||
@around_each_hooks.each { |hook| group.add_around_each_hook(hook) }
|
@around_each_hooks.each { |hook| group.add_around_each_hook(hook) }
|
||||||
@collection.each do |item|
|
@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))
|
@children.each(&.build(iteration))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -76,9 +76,9 @@ module Spectator
|
||||||
#
|
#
|
||||||
# A set of *metadata* can be used for filtering and modifying example behavior.
|
# 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.
|
# 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
|
def start_iterative_group(collection, name, iterator = nil, location = nil, metadata = Metadata.new) : Nil
|
||||||
Log.trace { "Start iterative group: #{typeof(collection)} @ #{location}; metadata: #{metadata}" }
|
Log.trace { "Start iterative group: #{name} (#{typeof(collection)}) @ #{location}; metadata: #{metadata}" }
|
||||||
builder = IterativeExampleGroupBuilder.new(collection, location, metadata)
|
builder = IterativeExampleGroupBuilder.new(collection, name, iterator, location, metadata)
|
||||||
current << builder
|
current << builder
|
||||||
@stack.push(builder)
|
@stack.push(builder)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue