Scratch work on structure

This commit is contained in:
Michael Miller 2018-08-19 01:15:32 -06:00
parent 630e537726
commit 0613344230
4 changed files with 117 additions and 1 deletions

View file

@ -1,6 +1,26 @@
require "./spectator/*"
def expect(actual : T) forall T
pp actual
end
# TODO: Write documentation for `Spectator`
module Spectator
VERSION = "0.1.0"
# TODO: Put your code here
@@top_level_groups = [] of ExampleGroup
def self.describe(type : T.class) : Nil forall T
group = DSL.new(type.to_s)
with group yield
@@top_level_groups << group._spec_build
end
at_exit do
@@top_level_groups.each do |group|
group.examples.each do |example|
example.run
end
end
end
end

76
src/spectator/dsl.cr Normal file
View file

@ -0,0 +1,76 @@
require "./example_group"
private macro _spec_add_example(example)
@examples << example
end
module Spectator
class DSL
@examples = [] of Spectator::Example
protected def initialize(@type : String)
end
def describe
raise NotImplementedError.new("Spectator::DSL::ExampleGroupDSL#describe")
end
def context
raise NotImplementedError.new("Spectator::DSL::ExampleGroupDSL#context")
end
def it(description : String, &block) : Nil
example = Spectator::Example.new(description, block)
_spec_add_example(example)
end
def it_behaves_like
raise NotImplementedError.new("Spectator::DSL::ExampleGroupDSL#it_behaves_like")
end
def subject
raise NotImplementedError.new("Spectator::DSL::ExampleGroupDSL#subject")
end
def subject!
raise NotImplementedError.new("Spectator::DSL::ExampleGroupDSL#subject!")
end
def let
raise NotImplementedError.new("Spectator::DSL::ExampleGroupDSL#let")
end
def let!
raise NotImplementedError.new("Spectator::DSL::ExampleGroupDSL#let!")
end
def before_all
raise NotImplementedError.new("Spectator::DSL::ExampleGroupDSL#before_all")
end
def before_each
raise NotImplementedError.new("Spectator::DSL::ExampleGroupDSL#before_each")
end
def after_all
raise NotImplementedError.new("Spectator::DSL::ExampleGroupDSL#after_all")
end
def after_each
raise NotImplementedError.new("Spectator::DSL::ExampleGroupDSL#after_each")
end
def around_each
raise NotImplementedError.new("Spectator::DSL::ExampleGroupDSL#around_each")
end
def include_examples
raise NotImplementedError.new("Spectator::DSL::ExampleGroupDSL#include_examples")
end
# :nodoc:
protected def _spec_build : Spectator::ExampleGroup
Spectator::ExampleGroup.new(@examples)
end
end
end

10
src/spectator/example.cr Normal file
View file

@ -0,0 +1,10 @@
module Spectator
class Example
def initialize(@description : String, @block : ->)
end
def run
@block.call
end
end
end

View file

@ -0,0 +1,10 @@
require "./example"
module Spectator
class ExampleGroup
protected getter examples : Array(Example)
def initialize(@examples)
end
end
end