Rename DSL::Builder to SpecBuilder

Place all builders under SpecBuilder.
This commit is contained in:
Michael Miller 2019-09-13 14:10:25 -06:00
parent 5d86b4f50e
commit fafe5606e6
9 changed files with 27 additions and 26 deletions

View file

@ -101,7 +101,7 @@ module Spectator
# Builds the tests and runs the framework. # Builds the tests and runs the framework.
private def run private def run
# Build the test suite and run it. # Build the test suite and run it.
suite = ::Spectator::DSL::Builder.build(config.example_filter) suite = ::Spectator::SpecBuilder.build(config.example_filter)
Runner.new(suite, config).run Runner.new(suite, config).run
rescue ex rescue ex
# Catch all unhandled exceptions here. # Catch all unhandled exceptions here.

View file

@ -263,7 +263,7 @@ module Spectator::DSL
{% end %} {% end %}
# Start a new group. # Start a new group.
::Spectator::DSL::Builder.start_group( ::Spectator::SpecBuilder.start_group(
{% if what.is_a?(StringLiteral) %} {% if what.is_a?(StringLiteral) %}
{% if what.starts_with?("#") || what.starts_with?(".") %} {% if what.starts_with?("#") || what.starts_with?(".") %}
{{what.id.symbolize}} {{what.id.symbolize}}
@ -279,7 +279,7 @@ module Spectator::DSL
{{block.body}} {{block.body}}
# End the current group. # End the current group.
::Spectator::DSL::Builder.end_group ::Spectator::SpecBuilder.end_group
end end
end end
@ -543,7 +543,7 @@ module Spectator::DSL
# 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::SpecBuilder.start_sample_group(
{{collection.stringify}}, # String representation of the collection. {{collection.stringify}}, # String representation of the collection.
Sample%sample, # Type that can construct the elements. Sample%sample, # Type that can construct the elements.
->(s : Sample%sample) { s.%to_a }, # Proc to build the array of elements in the collection. ->(s : Sample%sample) { s.%to_a }, # Proc to build the array of elements in the collection.
@ -555,7 +555,7 @@ module Spectator::DSL
{{block.body}} {{block.body}}
# End the current group. # End the current group.
::Spectator::DSL::Builder.end_group ::Spectator::SpecBuilder.end_group
end end
end end
@ -656,7 +656,7 @@ module Spectator::DSL
# 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::SpecBuilder.start_sample_group(
{{collection.stringify}}, # String representation of the collection. {{collection.stringify}}, # String representation of the collection.
Sample%sample, # All elements in the collection. Sample%sample, # All elements in the collection.
{{name.stringify}}, # Name for the current element. {{name.stringify}}, # Name for the current element.
@ -667,7 +667,7 @@ module Spectator::DSL
{{block.body}} {{block.body}}
# End the current group. # End the current group.
::Spectator::DSL::Builder.end_group ::Spectator::SpecBuilder.end_group
end end
end end
@ -990,7 +990,7 @@ module Spectator::DSL
# #
# See also: `#before_each`, `#after_all`, `#after_each`, and `#around_each`. # See also: `#before_each`, `#after_all`, `#after_each`, and `#around_each`.
macro before_all(&block) macro before_all(&block)
::Spectator::DSL::Builder.add_before_all_hook {{block}} ::Spectator::SpecBuilder.add_before_all_hook {{block}}
end end
# Creates a hook that will run prior to every example in the group. # Creates a hook that will run prior to every example in the group.
@ -1051,7 +1051,7 @@ module Spectator::DSL
{{yield}} {{yield}}
end end
::Spectator::DSL::Builder.add_before_each_hook do ::Spectator::SpecBuilder.add_before_each_hook do
# Get the wrapper instance and cast to current group type. # Get the wrapper instance and cast to current group type.
example = ::Spectator::Internals::Harness.current.example example = ::Spectator::Internals::Harness.current.example
instance = example.instance.as({{@type.id}}) instance = example.instance.as({{@type.id}})
@ -1110,7 +1110,7 @@ module Spectator::DSL
# #
# See also: `#before_all`, `#before_each`, `#after_each`, and `#around_each`. # See also: `#before_all`, `#before_each`, `#after_each`, and `#around_each`.
macro after_all(&block) macro after_all(&block)
::Spectator::DSL::Builder.add_after_all_hook {{block}} ::Spectator::SpecBuilder.add_after_all_hook {{block}}
end end
# Creates a hook that will run following every example in the group. # Creates a hook that will run following every example in the group.
@ -1170,7 +1170,7 @@ module Spectator::DSL
{{yield}} {{yield}}
end end
::Spectator::DSL::Builder.add_after_each_hook do ::Spectator::SpecBuilder.add_after_each_hook do
# Get the wrapper instance and cast to current group type. # Get the wrapper instance and cast to current group type.
example = ::Spectator::Internals::Harness.current.example example = ::Spectator::Internals::Harness.current.example
instance = example.instance.as({{@type.id}}) instance = example.instance.as({{@type.id}})
@ -1266,7 +1266,7 @@ module Spectator::DSL
{{yield}} {{yield}}
end end
::Spectator::DSL::Builder.add_around_each_hook do |proc| ::Spectator::SpecBuilder.add_around_each_hook do |proc|
# Get the wrapper instance and cast to current group type. # Get the wrapper instance and cast to current group type.
example = ::Spectator::Internals::Harness.current.example example = ::Spectator::Internals::Harness.current.example
instance = example.instance.as({{@type.id}}) instance = example.instance.as({{@type.id}})
@ -1325,7 +1325,7 @@ module Spectator::DSL
{{yield}} {{yield}}
end end
::Spectator::DSL::Builder.add_pre_condition do ::Spectator::SpecBuilder.add_pre_condition do
example = ::Spectator::Internals::Harness.current.example example = ::Spectator::Internals::Harness.current.example
instance = example.instance.as({{@type.id}}) instance = example.instance.as({{@type.id}})
instance.%condition instance.%condition
@ -1384,7 +1384,7 @@ module Spectator::DSL
{{yield}} {{yield}}
end end
::Spectator::DSL::Builder.add_post_condition do ::Spectator::SpecBuilder.add_post_condition do
example = ::Spectator::Internals::Harness.current.example example = ::Spectator::Internals::Harness.current.example
instance = example.instance.as({{@type.id}}) instance = example.instance.as({{@type.id}})
instance.%condition instance.%condition
@ -1429,7 +1429,7 @@ module Spectator::DSL
{% end %} {% end %}
%source = ::Spectator::Source.new({{_source_file}}, {{_source_line}}) %source = ::Spectator::Source.new({{_source_file}}, {{_source_line}})
::Spectator::DSL::Builder.add_example({{what.stringify}}, %source, {{@type.name}}) { |test| test.as({{@type.name}}).%run } ::Spectator::SpecBuilder.add_example({{what.stringify}}, %source, {{@type.name}}) { |test| test.as({{@type.name}}).%run }
end end
# Creates an example, or a test case. # Creates an example, or a test case.

View file

@ -18,6 +18,7 @@ require "./matchers"
require "./formatting" require "./formatting"
# Then all of the top-level types. # Then all of the top-level types.
require "./spec_builder"
require "./example_component" require "./example_component"
require "./example" require "./example"
require "./runnable_example" require "./runnable_example"

View file

@ -1,14 +1,14 @@
require "../builders/example_group_stack" require "./spec_builder/*"
module Spectator::DSL module Spectator
# Global builder used to create the runtime instance of the spec. # Global builder used to create the runtime instance of the spec.
# The DSL methods call into this module to generate parts of the spec. # The DSL methods call into this module to generate parts of the spec.
# Once the DSL is done, the `#build` method can be invoked # Once the DSL is done, the `#build` method can be invoked
# to create the entire spec as a runtime instance. # to create the entire spec as a runtime instance.
module Builder module SpecBuilder
extend self extend self
@@stack = Builders::ExampleGroupStack.new @@stack = ExampleGroupStack.new
# Begins a new nested group in the spec. # Begins a new nested group in the spec.
# A corresponding `#end_group` call must be made # A corresponding `#end_group` call must be made
@ -16,7 +16,7 @@ module Spectator::DSL
# See `NestedExampleGroupBuilder#initialize` for the arguments # See `NestedExampleGroupBuilder#initialize` for the arguments
# as arguments to this method are passed directly to it. # as arguments to this method are passed directly to it.
def start_group(*args) : Nil def start_group(*args) : Nil
group = Builders::NestedExampleGroupBuilder.new(*args) group = NestedExampleGroupBuilder.new(*args)
@@stack.push(group) @@stack.push(group)
end end
@ -46,7 +46,7 @@ module Spectator::DSL
example_type : ::SpectatorTest.class, &runner : ::SpectatorTest ->) : Nil example_type : ::SpectatorTest.class, &runner : ::SpectatorTest ->) : Nil
builder = ->{ example_type.new.as(::SpectatorTest) } builder = ->{ example_type.new.as(::SpectatorTest) }
wrapper = TestWrapper.new(description, source, builder, runner) wrapper = TestWrapper.new(description, source, builder, runner)
factory = Builders::ExampleBuilder.new(wrapper) factory = ExampleBuilder.new(wrapper)
@@stack.current.add_child(factory) @@stack.current.add_child(factory)
end end

View file

@ -1,4 +1,4 @@
module Spectator::Builders module Spectator::SpecBuilder
class ExampleBuilder class ExampleBuilder
def initialize(@wrapper : TestWrapper) def initialize(@wrapper : TestWrapper)
end end

View file

@ -1,6 +1,6 @@
require "./example_builder" require "./example_builder"
module Spectator::Builders module Spectator::SpecBuilder
abstract class ExampleGroupBuilder abstract class ExampleGroupBuilder
alias Child = NestedExampleGroupBuilder | ExampleBuilder alias Child = NestedExampleGroupBuilder | ExampleBuilder

View file

@ -1,7 +1,7 @@
require "./root_example_group_builder" require "./root_example_group_builder"
require "./nested_example_group_builder" require "./nested_example_group_builder"
module Spectator::Builders module Spectator::SpecBuilder
struct ExampleGroupStack struct ExampleGroupStack
getter root getter root

View file

@ -1,6 +1,6 @@
require "./example_group_builder" require "./example_group_builder"
module Spectator::Builders module Spectator::SpecBuilder
class NestedExampleGroupBuilder < ExampleGroupBuilder class NestedExampleGroupBuilder < ExampleGroupBuilder
def initialize(@what : String | Symbol) def initialize(@what : String | Symbol)
end end

View file

@ -1,6 +1,6 @@
require "./example_group_builder" require "./example_group_builder"
module Spectator::Builders module Spectator::SpecBuilder
class RootExampleGroupBuilder < ExampleGroupBuilder class RootExampleGroupBuilder < ExampleGroupBuilder
def build def build
RootExampleGroup.new.tap do |group| RootExampleGroup.new.tap do |group|