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
extend self
@group_stack = [ExampleGroupBuilder.new]
@group_stack = [::Spectator::DSL::ExampleGroupBuilder.new]
private def current_group
@group_stack.last
@ -15,18 +15,21 @@ module Spectator
end
def start_group(what : String) : Nil
push_group(ExampleGroupBuilder.new(what))
group = ::Spectator::DSL::ExampleGroupBuilder.new(what)
push_group(group)
end
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
def end_group : Nil
@group_stack.pop
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)
end
@ -52,7 +55,7 @@ module Spectator
protected def build : Array(Example)
# TODO
ExampleGroup.new
[] of Example
end
end
end

View file

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

View file

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