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 %} {% debug %}
end end
macro _spec_add_example(example)
{{example.id}}.run
end
at_exit do at_exit do
# TODO # TODO
end end

View File

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

View File

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