From dd48bf6f2548395845794cb71c7335870d1cbf91 Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Sun, 16 Feb 2020 19:34:48 -0700 Subject: [PATCH] Fix subject not being memoized when using described_class --- src/spectator/dsl/groups.cr | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/spectator/dsl/groups.cr b/src/spectator/dsl/groups.cr index 33c12a1..937e052 100644 --- a/src/spectator/dsl/groups.cr +++ b/src/spectator/dsl/groups.cr @@ -24,8 +24,16 @@ module Spectator {{what}} end + @%wrapper : ::Spectator::TypedValueWrapper({{what}})? + def subject(*args) - described_class.new(*args) + if (wrapper = @%wrapper) + wrapper.value + else + described_class.new(*args).tap do |value| + @%wrapper = ::Spectator::TypedValueWrapper.new(value) + end + end end {% else %} def _spectator_implicit_subject(*args)