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 module Spectator::DSL
macro double(name, &block) macro double(name, &block)
{% if block.is_a?(Nop) %} {% if block.is_a?(Nop) %}
Double{{name.id}}.new(@spectator_test_values) Double{{name.id}}.new(self)
{% else %} {% else %}
class Double{{name.id}} < ::Spectator::Double class Double{{name.id}} < ::Spectator::Double
private class Internal < {{@type.id}} private class Internal
def initialize(@test : {{@type.id}})
end
forward_missing_to @test
end end
def initialize(test_values : ::Spectator::TestValues) def initialize(test : {{@type.id}})
@internal = Internal.new(test_values) @internal = Internal.new(test)
end end
{{block.body}} {{block.body}}