mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Change contexts from modules to classes
This commit is contained in:
parent
bfd298c0f2
commit
64045171c2
2 changed files with 14 additions and 37 deletions
|
@ -36,8 +36,8 @@ module Spectator
|
||||||
#
|
#
|
||||||
# For more information on how the DSL works, see the `DSL` module.
|
# For more information on how the DSL works, see the `DSL` module.
|
||||||
|
|
||||||
# Root-level module that contains all examples and example groups.
|
# Root-level class that contains all examples and example groups.
|
||||||
module SpectatorExamples
|
class SpectatorExamples
|
||||||
# Include the DSL for creating groups, example, and more.
|
# Include the DSL for creating groups, example, and more.
|
||||||
include ::Spectator::DSL::StructureDSL
|
include ::Spectator::DSL::StructureDSL
|
||||||
|
|
||||||
|
|
|
@ -238,13 +238,9 @@ module Spectator::DSL
|
||||||
# it demonstrates how contexts can reuse code.
|
# it demonstrates how contexts can reuse code.
|
||||||
# Contexts also make it clearer how a scenario is setup.
|
# Contexts also make it clearer how a scenario is setup.
|
||||||
macro context(what, &block)
|
macro context(what, &block)
|
||||||
# Module for the context.
|
# Class for the context.
|
||||||
# The module uses a generated unique name.
|
# The class uses a generated unique name.
|
||||||
module Context%context
|
class Context%context < {{@type.id}}
|
||||||
# Include the parent module.
|
|
||||||
# Since `@type` resolves immediately,
|
|
||||||
# this will reference the parent type.
|
|
||||||
include {{@type.id}}
|
|
||||||
|
|
||||||
# Check if `what` looks like a type.
|
# Check if `what` looks like a type.
|
||||||
# If it is, add the `#described_class` and `subject` methods.
|
# If it is, add the `#described_class` and `subject` methods.
|
||||||
|
@ -507,10 +503,7 @@ module Spectator::DSL
|
||||||
# This has to be a class that includes the parent module.
|
# This has to be a class that includes the parent module.
|
||||||
# The collection could reference a helper method
|
# The collection could reference a helper method
|
||||||
# or anything else in the parent scope.
|
# or anything else in the parent scope.
|
||||||
class Sample%sample
|
class Sample%sample < {{@type.id}}
|
||||||
# Include the parent module.
|
|
||||||
include {{@type.id}}
|
|
||||||
|
|
||||||
# Placeholder initializer.
|
# Placeholder initializer.
|
||||||
# This is needed because examples and groups call super in their initializer.
|
# This is needed because examples and groups call super in their initializer.
|
||||||
# Those initializers pass the sample values upward through their hierarchy.
|
# Those initializers pass the sample values upward through their hierarchy.
|
||||||
|
@ -536,14 +529,9 @@ module Spectator::DSL
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Module for the context.
|
# Class for the context.
|
||||||
# The module uses a generated unique name.
|
# The class uses a generated unique name.
|
||||||
module Context%sample
|
class Context%sample < {{@type.id}}
|
||||||
# Include the parent module.
|
|
||||||
# Since @type resolves immediately,
|
|
||||||
# this will reference the parent type.
|
|
||||||
include {{@type.id}}
|
|
||||||
|
|
||||||
# Value wrapper for the current element.
|
# Value wrapper for the current element.
|
||||||
@%wrapper : ::Spectator::Internals::ValueWrapper
|
@%wrapper : ::Spectator::Internals::ValueWrapper
|
||||||
|
|
||||||
|
@ -642,10 +630,7 @@ module Spectator::DSL
|
||||||
# This has to be a class that includes the parent module.
|
# This has to be a class that includes the parent module.
|
||||||
# The collection could reference a helper method
|
# The collection could reference a helper method
|
||||||
# or anything else in the parent scope.
|
# or anything else in the parent scope.
|
||||||
class Sample%sample
|
class Sample%sample < {{@type.id}}
|
||||||
# Include the parent module.
|
|
||||||
include {{@type.id}}
|
|
||||||
|
|
||||||
# Method that returns an array containing the collection.
|
# Method that returns an array containing the collection.
|
||||||
# This method should be called only once.
|
# This method should be called only once.
|
||||||
# The framework stores the collection as an array for a couple of reasons.
|
# The framework stores the collection as an array for a couple of reasons.
|
||||||
|
@ -657,14 +642,9 @@ module Spectator::DSL
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Module for the context.
|
# Class for the context.
|
||||||
# The module uses a generated unique name.
|
# The class uses a generated unique name.
|
||||||
module Context%sample
|
class Context%sample < {{@type.id}}
|
||||||
# Include the parent module.
|
|
||||||
# Since @type resolves immediately,
|
|
||||||
# this will reference the parent type.
|
|
||||||
include {{@type.id}}
|
|
||||||
|
|
||||||
# Value wrapper for the current element.
|
# Value wrapper for the current element.
|
||||||
@%wrapper : ::Spectator::Internals::ValueWrapper
|
@%wrapper : ::Spectator::Internals::ValueWrapper
|
||||||
|
|
||||||
|
@ -1596,13 +1576,10 @@ module Spectator::DSL
|
||||||
# The block passed to this macro is the actual test code.
|
# The block passed to this macro is the actual test code.
|
||||||
private macro _spectator_test(class_name, run_method_name)
|
private macro _spectator_test(class_name, run_method_name)
|
||||||
# Wrapper class for isolating the test code.
|
# Wrapper class for isolating the test code.
|
||||||
class {{class_name.id}}
|
class {{class_name.id}} < {{@type.id}}
|
||||||
# Mix in methods and macros specifically for example DSL.
|
# Mix in methods and macros specifically for example DSL.
|
||||||
include ::Spectator::DSL::ExampleDSL
|
include ::Spectator::DSL::ExampleDSL
|
||||||
|
|
||||||
# Include the parent (example group) context.
|
|
||||||
include {{@type.id}}
|
|
||||||
|
|
||||||
# Initializer that accepts sample values.
|
# Initializer that accepts sample values.
|
||||||
# The sample values are passed upward to the group modules.
|
# The sample values are passed upward to the group modules.
|
||||||
# Any module that adds sample values can pull their values from this instance.
|
# Any module that adds sample values can pull their values from this instance.
|
||||||
|
|
Loading…
Reference in a new issue