Pretty up iterative group names

This commit is contained in:
Michael Miller 2021-07-17 12:15:41 -06:00
parent d8e9d3128a
commit 640857bef2
No known key found for this signature in database
GPG key ID: FB9F12F7C646A4AD
4 changed files with 15 additions and 8 deletions

View file

@ -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
)

View file

@ -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)

View file

@ -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

View file

@ -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