Handle changing test scope

This matches the current pattern, where a nested scope can override 
values from a parent scope.
I think this solution is quite clever :)
This commit is contained in:
Michael Miller 2019-10-06 11:12:06 -06:00
parent 6e50e54e05
commit 4b57ddab80

View file

@ -3,14 +3,18 @@ require "../double"
module Spectator::DSL
macro double(name, &block)
{% if block.is_a?(Nop) %}
Double{{name.id}}.new(@spectator_test_values)
Double{{name.id}}.new(self)
{% else %}
class Double{{name.id}} < ::Spectator::Double
private class Internal < {{@type.id}}
private class Internal
def initialize(@test : {{@type.id}})
end
def initialize(test_values : ::Spectator::TestValues)
@internal = Internal.new(test_values)
forward_missing_to @test
end
def initialize(test : {{@type.id}})
@internal = Internal.new(test)
end
{{block.body}}