mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Some code for repeating examples in given blocks
This commit is contained in:
parent
830aa7b43a
commit
a28f512ae4
2 changed files with 38 additions and 11 deletions
|
@ -27,24 +27,30 @@ module Spectator
|
||||||
end
|
end
|
||||||
|
|
||||||
macro given(collection, &block)
|
macro given(collection, &block)
|
||||||
context({{collection}}, "Given") do
|
module Given%given
|
||||||
|
include {{@type.id}}
|
||||||
|
|
||||||
def {{block.args.empty? ? "value".id : block.args.first}}
|
def {{block.args.empty? ? "value".id : block.args.first}}
|
||||||
nil # TODO
|
nil # TODO
|
||||||
end
|
end
|
||||||
|
|
||||||
{{block.body}}
|
_given_collection Collection%collection, %to_a do
|
||||||
|
|
||||||
_given_enumerator Collection%collection, %each do
|
|
||||||
{{collection}}
|
{{collection}}
|
||||||
end
|
end
|
||||||
|
%collection = Collection%collection.new.%to_a
|
||||||
|
|
||||||
Collection%collection.new.%each do |%item|
|
::Spectator::Definitions::GROUPS[\{{@type.stringify}}] =
|
||||||
# TODO
|
GivenExampleGroup(typeof(%collection.first)).new(
|
||||||
end
|
{{collection.stringify}},
|
||||||
|
%collection,
|
||||||
|
::Spectator::Definitions::GROUPS[{{@type.stringify}}]
|
||||||
|
)
|
||||||
|
|
||||||
|
{{block.body}}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
macro _given_enumerator(class_name, each_method_name, &block)
|
macro _given_collection(class_name, to_a_method_name, &block)
|
||||||
class {{class_name.id}}
|
class {{class_name.id}}
|
||||||
include {{@type.id}}
|
include {{@type.id}}
|
||||||
|
|
||||||
|
@ -52,9 +58,15 @@ module Spectator
|
||||||
{{block.body}}
|
{{block.body}}
|
||||||
end
|
end
|
||||||
|
|
||||||
def {{each_method_name.id}}
|
def %first
|
||||||
|
%collection.first
|
||||||
|
end
|
||||||
|
|
||||||
|
def {{to_a_method_name.id}}
|
||||||
|
Array(typeof(%first)).new.tap do |%array|
|
||||||
%collection.each do |%item|
|
%collection.each do |%item|
|
||||||
yield %item
|
%array << %item
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
15
src/spectator/given_example_group.cr
Normal file
15
src/spectator/given_example_group.cr
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
require "./example_group"
|
||||||
|
|
||||||
|
module Spectator
|
||||||
|
class GivenExampleGroup(T) < ExampleGroup
|
||||||
|
def initialize(what, @collection : Array(T), parent = nil)
|
||||||
|
super(what, parent)
|
||||||
|
end
|
||||||
|
|
||||||
|
protected def add_examples(array : Array(Example))
|
||||||
|
@collection.each do |item|
|
||||||
|
super(array)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue