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".
|
||||
{% 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.
|
||||
# The module uses a generated unique name.
|
||||
module Group%group
|
||||
|
@ -320,13 +331,6 @@ module Spectator::DSL
|
|||
# this will reference the parent type.
|
||||
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.
|
||||
@%wrapper : ::Spectator::Internals::ValueWrapper
|
||||
|
||||
|
@ -344,10 +348,6 @@ module Spectator::DSL
|
|||
@%wrapper = sample_values.get_wrapper(:%group)
|
||||
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.
|
||||
# Given groups require additional configuration.
|
||||
::Spectator::DSL::Builder.start_given_group(
|
||||
|
@ -459,11 +459,7 @@ module Spectator::DSL
|
|||
# :nodoc:
|
||||
# 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 is *required* and cannot be embedded in the `#given` macro.
|
||||
# There are a couple of reasons for this:
|
||||
# 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 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,
|
||||
# the names must be created outside of the macro and passed in.
|
||||
|
@ -471,7 +467,6 @@ module Spectator::DSL
|
|||
# Class for generating an array with the collection's contents.
|
||||
class {{class_name.id}}
|
||||
# Include the parent module.
|
||||
# This should be the module created for the `#given` block.
|
||||
include {{@type.id}}
|
||||
|
||||
# Method that returns an array from the collection.
|
||||
|
|
Loading…
Reference in a new issue