Use fully-qualified names

This commit is contained in:
Michael Miller 2018-09-23 12:05:19 -06:00
parent 9109fc30fd
commit 0999cb2dbc
3 changed files with 18 additions and 17 deletions

View file

@ -3,7 +3,7 @@ module Spectator
module Builder module Builder
extend self extend self
@group_stack = [ExampleGroupBuilder.new] @group_stack = [::Spectator::DSL::ExampleGroupBuilder.new]
private def current_group private def current_group
@group_stack.last @group_stack.last
@ -15,18 +15,21 @@ module Spectator
end end
def start_group(what : String) : Nil def start_group(what : String) : Nil
push_group(ExampleGroupBuilder.new(what)) group = ::Spectator::DSL::ExampleGroupBuilder.new(what)
push_group(group)
end end
def start_given_group(what : String, values : Array(ValueWrapper)) : Nil def start_given_group(what : String, values : Array(ValueWrapper)) : Nil
push_group(GivenExampleGroupBuilder.new(what, values)) group = ::Spectator::DSL::GivenExampleGroupBuilder.new(what, values)
push_group(group)
end end
def end_group : Nil def end_group : Nil
@group_stack.pop @group_stack.pop
end end
def add_example(factory : AbstractExampleFactory) : Nil def add_example(example_type : Example.class) : Nil
factory = ::Spectator::DSL::ExampleGroupBuilder.new(example_type)
current_group.add_child(factory) current_group.add_child(factory)
end end
@ -52,7 +55,7 @@ module Spectator
protected def build : Array(Example) protected def build : Array(Example)
# TODO # TODO
ExampleGroup.new [] of Example
end end
end end
end end

View file

@ -38,13 +38,13 @@ module Spectator
%collection.first %collection.first
end end
@%wrapper : ValueWrapper @%wrapper : ::Spectator::ValueWrapper
def {{block.args.empty? ? "value".id : block.args.first}} def {{block.args.empty? ? "value".id : block.args.first}}
@%wrapper.as(TypedValueWrapper(typeof(%first))).value @%wrapper.as(::Spectator::TypedValueWrapper(typeof(%first))).value
end end
def initialize(locals : Hash(Symbol, ValueWrapper)) def initialize(locals : Hash(Symbol, ::Spectator::ValueWrapper))
super super
@%wrapper = locals[:%group] @%wrapper = locals[:%group]
end end
@ -94,14 +94,14 @@ module Spectator
macro let(name, &block) macro let(name, &block)
let!(%value) {{block}} let!(%value) {{block}}
@%wrapper : ValueWrapper? @%wrapper : ::Spectator::ValueWrapper?
def {{name.id}} def {{name.id}}
if (wrapper = @%wrapper) if (wrapper = @%wrapper)
wrapper.unsafe_as(TypedValueWrapper(typeof(%value))).value wrapper.unsafe_as(::Spectator::TypedValueWrapper(typeof(%value))).value
else else
%value.tap do |value| %value.tap do |value|
@%wrapper = TypedValueWrapper(typeof(%value)).new(value) @%wrapper = ::Spectator::TypedValueWrapper(typeof(%value)).new(value)
end end
end end
end end
@ -142,7 +142,7 @@ module Spectator
include ::Spectator::DSL::ExampleDSL include ::Spectator::DSL::ExampleDSL
include {{@type.id}} include {{@type.id}}
def initialize(locals : Hash(Symbol, ValueWrapper)) def initialize(locals : Hash(Symbol, ::Spectator::ValueWrapper))
super super
end end
@ -161,13 +161,11 @@ module Spectator
end end
def group def group
::Spectator::Definitions::GROUPS[{{@type.symbolize}}] nil # TODO
end end
end end
::Spectator::DSL::Builder.add_example_factory( ::Spectator::DSL::Builder.add_example(Example%example)
::Spectator::DSL::ExampleFactory(Example%example).new
)
end end
macro pending(description, &block) macro pending(description, &block)

View file

@ -2,7 +2,7 @@ module Spectator
# Base class for proxying test values to examples. # Base class for proxying test values to examples.
# This abstraction is required for inferring types. # This abstraction is required for inferring types.
# The `DSL#let` macro makes heavy use of this. # The `DSL#let` macro makes heavy use of this.
private abstract class ValueWrapper abstract class ValueWrapper
# Retrieves the underlying value. # Retrieves the underlying value.
abstract def value abstract def value
end end