From 4b57ddab806cfded9cfd778099c810a3d8f54e57 Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Sun, 6 Oct 2019 11:12:06 -0600 Subject: [PATCH] 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 :) --- src/spectator/dsl/mocks.cr | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/spectator/dsl/mocks.cr b/src/spectator/dsl/mocks.cr index 18ff002..0e9ea36 100644 --- a/src/spectator/dsl/mocks.cr +++ b/src/spectator/dsl/mocks.cr @@ -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 + + forward_missing_to @test end - def initialize(test_values : ::Spectator::TestValues) - @internal = Internal.new(test_values) + def initialize(test : {{@type.id}}) + @internal = Internal.new(test) end {{block.body}}