Update naming and fresh variables

This commit is contained in:
Michael Miller 2019-02-10 01:20:30 -07:00
parent fc3a7285a0
commit 55b655e90a

View file

@ -34,7 +34,7 @@ module Spectator::DSL
# def initialize(group, sample_values) # def initialize(group, sample_values)
# # group and sample_values are covered later. # # group and sample_values are covered later.
# super # super
# @wrapper = Wrapper123.new(sample_values) # @instance = Test123.new(sample_values)
# end # end
# #
# # Returns the text provided by the user. # # Returns the text provided by the user.
@ -47,13 +47,13 @@ module Spectator::DSL
# # This method is called by `RunnableExample` # # This method is called by `RunnableExample`
# # when the example code should be ran. # # when the example code should be ran.
# def run_instance # def run_instance
# @wrapper._run123 # @instance._run123
# end # end
# end # end
# #
# # Wrapper class for the example code. # # Wrapper class for the example code.
# # This isolates it from Spectator's internals. # # This isolates it from Spectator's internals.
# class Wrapper123 # class Test123
# include Context123 # More on this in a bit. # include Context123 # More on this in a bit.
# include ExampleDSL # Include DSL for the example code. # include ExampleDSL # Include DSL for the example code.
# #
@ -89,7 +89,7 @@ module Spectator::DSL
# # becomes... # # becomes...
# #
# # describe "#foo" # # describe "#foo"
# module Group123 # module Context123
# # Start a new group. # # Start a new group.
# # More on this in a bit. # # More on this in a bit.
# Builder.start_group("#foo") # Builder.start_group("#foo")
@ -99,8 +99,8 @@ module Spectator::DSL
# end # end
# #
# # context "when given :bar" # # context "when given :bar"
# module Group456 # module Context456
# include Group123 # Inherit parent module. # include Context123 # Inherit parent module.
# #
# # Start a nested group. # # Start a nested group.
# Builder.start_group("when given :bar") # Builder.start_group("when given :bar")
@ -110,10 +110,10 @@ module Spectator::DSL
# end # end
# #
# # Wrapper class for the test case. # # Wrapper class for the test case.
# class Wrapper456 # class Test456
# include Group456 # Include context. # include Context456 # Include context.
# #
# # Rest of example code... # # Rest of test code...
# end # end
# #
# # Example class for the test case. # # Example class for the test case.
@ -242,7 +242,7 @@ module Spectator::DSL
macro context(what, &block) macro context(what, &block)
# 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 Context%context
# Include the parent module. # Include the parent module.
# Since `@type` resolves immediately, # Since `@type` resolves immediately,
# this will reference the parent type. # this will reference the parent type.
@ -493,7 +493,7 @@ module Spectator::DSL
# This simplifies getting the element type. # This simplifies getting the element type.
# The name is uniquely generated to prevent namespace collision. # The name is uniquely generated to prevent namespace collision.
# This method should be called only once. # This method should be called only once.
def %collection def %sample
{{collection}} {{collection}}
end end
@ -501,7 +501,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 Collection%group class Sample%sample
# Include the parent module. # Include the parent module.
include {{@type.id}} include {{@type.id}}
@ -516,16 +516,16 @@ module Spectator::DSL
# only select the first `count` items from the collection. # only select the first `count` items from the collection.
# Otherwise, select all of them. # Otherwise, select all of them.
{% if count %} {% if count %}
%collection.first({{count}}) %sample.first({{count}})
{% else %} {% else %}
%collection.to_a %sample.to_a
{% end %} {% end %}
end end
end end
# 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 Context%sample
# Include the parent module. # Include the parent module.
# Since `@type` resolves immediately, # Since `@type` resolves immediately,
# this will reference the parent type. # this will reference the parent type.
@ -539,22 +539,22 @@ module Spectator::DSL
# Unwrap the value and return it. # Unwrap the value and return it.
# The `#first` method has a return type that matches the element type. # The `#first` method has a return type that matches the element type.
# So it is used on the collection method proxy to resolve the type at compile-time. # So it is used on the collection method proxy to resolve the type at compile-time.
@%wrapper.as(::Spectator::Internals::TypedValueWrapper(typeof(%collection.first))).value @%wrapper.as(::Spectator::Internals::TypedValueWrapper(typeof(%sample.first))).value
end end
# Initializer to extract current element of the collection from sample values. # Initializer to extract current element of the collection from sample values.
def initialize(sample_values : ::Spectator::Internals::SampleValues) def initialize(sample_values : ::Spectator::Internals::SampleValues)
super super
@%wrapper = sample_values.get_wrapper(:%group) @%wrapper = sample_values.get_wrapper(:%sample)
end end
# Start a new example group. # Start a new example group.
# Sample groups require additional configuration. # Sample groups require additional configuration.
::Spectator::DSL::Builder.start_sample_group( ::Spectator::DSL::Builder.start_sample_group(
{{collection.stringify}}, # String representation of the collection. {{collection.stringify}}, # String representation of the collection.
Collection%group.new.%to_a, # All elements in the collection. Sample%sample.new.%to_a, # All elements in the collection.
{{name.stringify}}, # Name for the current element. {{name.stringify}}, # Name for the current element.
:%group # Unique identifier for retrieving elements for the associated collection. :%sample # Unique identifier for retrieving elements for the associated collection.
) )
# Nest the block's content in the module. # Nest the block's content in the module.
@ -620,7 +620,7 @@ module Spectator::DSL
# This simplifies getting the element type. # This simplifies getting the element type.
# The name is uniquely generated to prevent namespace collision. # The name is uniquely generated to prevent namespace collision.
# This method should be called only once. # This method should be called only once.
def %collection def %sample
{{collection}} {{collection}}
end end
@ -628,7 +628,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 Collection%group class Sample%sample
# Include the parent module. # Include the parent module.
include {{@type.id}} include {{@type.id}}
@ -639,13 +639,13 @@ module Spectator::DSL
# 2. The collection might contain randomly generated values. # 2. The collection might contain randomly generated values.
# Iterating multiple times would generate inconsistent values at runtime. # Iterating multiple times would generate inconsistent values at runtime.
def %to_a def %to_a
%collection.to_a.sample({{count}}) %sample.to_a.sample({{count}})
end end
end end
# 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 Context%sample
# Include the parent module. # Include the parent module.
# Since `@type` resolves immediately, # Since `@type` resolves immediately,
# this will reference the parent type. # this will reference the parent type.
@ -659,22 +659,22 @@ module Spectator::DSL
# Unwrap the value and return it. # Unwrap the value and return it.
# The `#first` method has a return type that matches the element type. # The `#first` method has a return type that matches the element type.
# So it is used on the collection method proxy to resolve the type at compile-time. # So it is used on the collection method proxy to resolve the type at compile-time.
@%wrapper.as(::Spectator::Internals::TypedValueWrapper(typeof(%collection.first))).value @%wrapper.as(::Spectator::Internals::TypedValueWrapper(typeof(%sample.first))).value
end end
# Initializer to extract current element of the collection from sample values. # Initializer to extract current element of the collection from sample values.
def initialize(sample_values : ::Spectator::Internals::SampleValues) def initialize(sample_values : ::Spectator::Internals::SampleValues)
super super
@%wrapper = sample_values.get_wrapper(:%group) @%wrapper = sample_values.get_wrapper(:%sample)
end end
# Start a new example group. # Start a new example group.
# Sample groups require additional configuration. # Sample groups require additional configuration.
::Spectator::DSL::Builder.start_sample_group( ::Spectator::DSL::Builder.start_sample_group(
{{collection.stringify}}, # String representation of the collection. {{collection.stringify}}, # String representation of the collection.
Collection%group.new.%to_a, # All elements in the collection. Sample%sample.new.%to_a, # All elements in the collection.
{{name.stringify}}, # Name for the current element. {{name.stringify}}, # Name for the current element.
:%group # Unique identifier for retrieving elements for the associated collection. :%sample # Unique identifier for retrieving elements for the associated collection.
) )
# Nest the block's content in the module. # Nest the block's content in the module.