mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Move collection class out of given module
The collection would incorrectly have access to the `given` block's context, instead of just the parent context, like it should.
This commit is contained in:
parent
69905c01f3
commit
06743a181c
1 changed files with 13 additions and 18 deletions
|
@ -312,6 +312,17 @@ module Spectator::DSL
|
||||||
# If a block argument is provided, use it, otherwise use "value".
|
# If a block argument is provided, use it, otherwise use "value".
|
||||||
{% name = block.args.empty? ? "value".id : block.args.first %}
|
{% name = block.args.empty? ? "value".id : block.args.first %}
|
||||||
|
|
||||||
|
# Method for retrieving the entire collection.
|
||||||
|
# This simplifies getting the element type.
|
||||||
|
# The name is uniquely generated to prevent namespace collision.
|
||||||
|
def %collection
|
||||||
|
{{collection}}
|
||||||
|
end
|
||||||
|
|
||||||
|
# Additional logic for setting up the collection.
|
||||||
|
# See the `#_spectator_given_collection` for nitty-gritty details.
|
||||||
|
_spectator_given_collection Collection%collection, %to_a, %collection
|
||||||
|
|
||||||
# Module for the context.
|
# Module for the context.
|
||||||
# The module uses a generated unique name.
|
# The module uses a generated unique name.
|
||||||
module Group%group
|
module Group%group
|
||||||
|
@ -320,13 +331,6 @@ module Spectator::DSL
|
||||||
# this will reference the parent type.
|
# this will reference the parent type.
|
||||||
include {{@type.id}}
|
include {{@type.id}}
|
||||||
|
|
||||||
# Method for retrieving the entire collection.
|
|
||||||
# This simplifies getting the element type.
|
|
||||||
# The name is uniquely generated to prevent namespace collision.
|
|
||||||
def %collection
|
|
||||||
{{collection}}
|
|
||||||
end
|
|
||||||
|
|
||||||
# Value wrapper for the current element.
|
# Value wrapper for the current element.
|
||||||
@%wrapper : ::Spectator::Internals::ValueWrapper
|
@%wrapper : ::Spectator::Internals::ValueWrapper
|
||||||
|
|
||||||
|
@ -344,10 +348,6 @@ module Spectator::DSL
|
||||||
@%wrapper = sample_values.get_wrapper(:%group)
|
@%wrapper = sample_values.get_wrapper(:%group)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Additional logic for setting up the collection.
|
|
||||||
# See the `#_spectator_given_collection` for nitty-gritty details.
|
|
||||||
_spectator_given_collection Collection%collection, %to_a, %collection
|
|
||||||
|
|
||||||
# Start a new example group.
|
# Start a new example group.
|
||||||
# Given groups require additional configuration.
|
# Given groups require additional configuration.
|
||||||
::Spectator::DSL::Builder.start_given_group(
|
::Spectator::DSL::Builder.start_given_group(
|
||||||
|
@ -459,19 +459,14 @@ module Spectator::DSL
|
||||||
# :nodoc:
|
# :nodoc:
|
||||||
# Don't use this outside of Spectator DSL.
|
# Don't use this outside of Spectator DSL.
|
||||||
# This macro creates a class that is used to return the given collection as an array.
|
# This macro creates a class that is used to return the given collection as an array.
|
||||||
# This macro is *required* and cannot be embedded in the `#given` macro.
|
# The collection could reference a helper method or method local to the context.
|
||||||
# There are a couple of reasons for this:
|
# The class that the collection is defined in must have access to the context.
|
||||||
# 1. `@type` is resolved immediately.
|
|
||||||
# The resolution of `@type` in this macro occurs after the `#given` block.
|
|
||||||
# 2. The collection could reference a helper method or method local to the context.
|
|
||||||
# The class that the collection is defined in must have access to the context.
|
|
||||||
# Since the names are generated, and macros can't return information,
|
# Since the names are generated, and macros can't return information,
|
||||||
# the names must be created outside of the macro and passed in.
|
# the names must be created outside of the macro and passed in.
|
||||||
private macro _spectator_given_collection(class_name, to_a_method_name, collection_method_name)
|
private macro _spectator_given_collection(class_name, to_a_method_name, collection_method_name)
|
||||||
# Class for generating an array with the collection's contents.
|
# Class for generating an array with the collection's contents.
|
||||||
class {{class_name.id}}
|
class {{class_name.id}}
|
||||||
# Include the parent module.
|
# Include the parent module.
|
||||||
# This should be the module created for the `#given` block.
|
|
||||||
include {{@type.id}}
|
include {{@type.id}}
|
||||||
|
|
||||||
# Method that returns an array from the collection.
|
# Method that returns an array from the collection.
|
||||||
|
|
Loading…
Reference in a new issue