mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Generate context one or more times
This is necessary for iterative (sample) groups so they don't share a context.
This commit is contained in:
parent
4b8d28c916
commit
44ade24fb7
2 changed files with 4 additions and 3 deletions
|
@ -52,7 +52,7 @@ module Spectator::DSL
|
|||
::Spectator::DSL::Builder.add_example(
|
||||
_spectator_example_name(\{{what}}),
|
||||
::Spectator::Location.new(\{{block.filename}}, \{{block.line_number}}, \{{block.end_line_number}}),
|
||||
new.as(::Spectator::Context),
|
||||
-> { new.as(::Spectator::Context) },
|
||||
\%metadata
|
||||
) do |example|
|
||||
example.with_context(\{{@type.name}}) do
|
||||
|
|
|
@ -109,7 +109,7 @@ module Spectator
|
|||
#
|
||||
# The *location* optionally defined where the example originates in source code.
|
||||
#
|
||||
# The *context* is an instance of the context the test code should run in.
|
||||
# The *context_builder* is a proc that creates a context the test code should run in.
|
||||
# See `Context` for more information.
|
||||
#
|
||||
# A set of *metadata* can be used for filtering and modifying example behavior.
|
||||
|
@ -119,9 +119,10 @@ module Spectator
|
|||
# It will be yielded two arguments - the example created by this method, and the *context* argument.
|
||||
# The return value of the block is ignored.
|
||||
# It is expected that the test code runs when the block is called.
|
||||
def add_example(name, location, context, metadata = Metadata.new, &block : Example -> _)
|
||||
def add_example(name, location, context_builder, metadata = Metadata.new, &block : Example -> _)
|
||||
Log.trace { "Add example: #{name} @ #{location}; metadata: #{metadata}" }
|
||||
current_group.create_child do |group|
|
||||
context = context_builder.call
|
||||
Example.new(context, block, name, location, group, metadata)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue