More refatoring

This commit is contained in:
Michael Miller 2018-09-22 19:41:56 -06:00
parent a1b5533504
commit 9ba3fc898b
8 changed files with 31 additions and 70 deletions

View file

@ -4,10 +4,8 @@ require "./spectator/*"
module Spectator
VERSION = "0.1.0"
macro describe(what, source_file = __FILE__, source_line = __LINE__, &block)
module SpectatorExamples
::Spectator::DSL::StructureDSL.describe({{what}}) {{block}}
end
macro describe(what, &block)
DSL.root({{what}}) {{block}}
end
at_exit do

View file

@ -1,39 +0,0 @@
module Spectator
module Definitions
ALL = {} of Path => Object
GROUPS = {} of Symbol => ExampleGroup
SPECIAL_CHARS = {
'~' => "Tilde",
'`' => "Tick",
'!' => "Bang",
'@' => "At",
'#' => "Hash",
'$' => "Dollar",
'%' => "Percent",
'^' => "Carret",
'&' => "And",
'*' => "Star",
'(' => "LParen",
')' => "RParen",
'+' => "Plus",
'=' => "Eq",
'{' => "LBrace",
'}' => "RBrace",
'[' => "LBracket",
']' => "RBracket",
':' => "Colon",
';' => "SColon",
'<' => "Lt",
'>' => "Gt",
',' => "Comma",
'.' => "Dot",
'?' => "Question",
'/' => "Slash",
'"' => "DQuote",
'|' => "Or",
'\\' => "BSlash",
'\'' => "SQuote"
}
end
end

View file

@ -2,5 +2,12 @@ require "./dsl/*"
module Spectator
module DSL
macro root(what, &block)
module SpectatorExamples
include StructureDSL
describe({{what}}) {{block}}
end
end
end
end

View file

@ -0,0 +1,7 @@
module Spectator
module DSL
abstract class AbstractExampleFactory
abstract def build(locals : Hash(Symbol, ValueWrapper)) : Example
end
end
end

View file

@ -26,7 +26,7 @@ module Spectator
@group_stack.pop
end
def add_example(factory : ExampleFactory) : Nil
def add_example(factory : AbstractExampleFactory) : Nil
current_group.add_child(factory)
end

View file

@ -0,0 +1,11 @@
require "./abstract_example_factory"
module Spectator
module DSL
class ExampleFactory(T) < AbstractExampleFactory
def build(locals : Hash(Symbol, ValueWrapper)) : Example
T.new(locals)
end
end
end
end

View file

@ -165,13 +165,9 @@ module Spectator
end
end
class Factory%example < ::Spectator::ExampleFactory
def build(locals : Hash(Symbol, ValueWrapper))
Example%example.new(locals)
end
end
::Spectator::Definitions::GROUPS[\{{@type.symbolize}}].children << Factory%example.new
::Spectator::DSL::Builder.add_example_factory(
::Spectator::DSL::ExampleFactory(Example%example).new
)
end
macro pending(description, &block)

View file

@ -1,19 +0,0 @@
require "./dsl"
require "./definitions"
module Spectator
module Examples
include ::Spectator::DSL::StructureDSL
{% ::Spectator::Definitions::ALL[@type.id] = {
name: "ROOT",
parent: nil,
given: [] of Object,
children: [] of Object
} %}
::Spectator::Definitions::GROUPS[{{@type.symbolize}}] = ::Spectator::ExampleGroup::ROOT
def initialize(locals = {} of Symbol => ValueWrapper)
end
end
end