Playing around with contexts and examples

This commit is contained in:
Michael Miller 2018-08-24 14:53:14 -06:00
parent ed40e995d2
commit b90cc39638
3 changed files with 25 additions and 17 deletions

View File

@ -15,6 +15,10 @@ module Spectator
{% debug %}
end
macro _spec_add_example(example)
{{example.id}}.run
end
at_exit do
# TODO
end

View File

@ -11,6 +11,10 @@ module Spectator
{% module_name = (type.id + safe_name.camelcase).id %}
module {{module_name.id}}
include ::Spectator::DSL
module Context
end
{{block.body}}
end
end
@ -27,32 +31,39 @@ module Spectator
{% safe_name = description.id.stringify.gsub(/\W+/, "_") %}
{% class_name = (safe_name.camelcase + "Example").id %}
class {{class_name.id}} < ::Spectator::Example
include Context
def run
{{block.body}}
end
end
::Spectator._spec_add_example({{class_name.id}}.new)
end
def it_behaves_like
raise NotImplementedError.new("Spectator::DSL#it_behaves_like")
end
def subject
raise NotImplementedError.new("Spectator::DSL#subject")
macro subject(&block)
let(:subject) {{block}}
end
def subject!
raise NotImplementedError.new("Spectator::DSL#subject!")
end
def let
raise NotImplementedError.new("Spectator::DSL#let")
macro let(name, &block)
module Context
def {{name.id}}
{{block.body}}
end
end
end
def let!
raise NotImplementedError.new("Spectator::DSL#let!")
end
macro is_expected
expect(subject)
end
def before_all
raise NotImplementedError.new("Spectator::DSL#before_all")
end

View File

@ -1,12 +1,5 @@
module Spectator
class Example
def initialize(@description : String, @block : ->)
end
def run
@block.call
rescue ex : ExpectationFailedError
puts ex
end
abstract class Example
abstract def run
end
end