From a634046a86c689835de09f4fb96a488d6657c25a Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Tue, 13 Aug 2024 18:42:22 -0600 Subject: [PATCH] Conditionally insert top-level namespace (double colon) --- src/spectator/dsl/mocks.cr | 4 ++-- src/spectator/mocks/mock.cr | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/spectator/dsl/mocks.cr b/src/spectator/dsl/mocks.cr index 18fe1fa..19645fc 100644 --- a/src/spectator/dsl/mocks.cr +++ b/src/spectator/dsl/mocks.cr @@ -226,7 +226,7 @@ module Spectator::DSL # Store information about how the mock is defined and its context. # This is important for constructing an instance of the mock later. - ::Spectator::DSL::Mocks::TYPES << {type.id.symbolize, @type.name(generic_args: false).symbolize, "::#{resolved.name}::#{mock_type_name}".id.symbolize} + ::Spectator::DSL::Mocks::TYPES << {type.id.symbolize, @type.name(generic_args: false).symbolize, "#{"::".id unless resolved.name.starts_with?("::")}#{resolved.name}::#{mock_type_name}".id.symbolize} base = if resolved.class? :class @@ -237,7 +237,7 @@ module Spectator::DSL end %} {% begin %} - {{base.id}} ::{{resolved.name}} + {{base.id}} {{"::".id unless resolved.name.starts_with?("::")}}{{resolved.name}} ::Spectator::Mock.define_subtype({{base}}, {{type.id}}, {{mock_type_name}}, {{name}}, {{**value_methods}}) {{block}} end {% end %} diff --git a/src/spectator/mocks/mock.cr b/src/spectator/mocks/mock.cr index 87e8e23..d2a1fde 100644 --- a/src/spectator/mocks/mock.cr +++ b/src/spectator/mocks/mock.cr @@ -149,7 +149,7 @@ module Spectator macro inject(base, type_name, name = nil, **value_methods, &block) {% begin %} {% if name %}@[::Spectator::StubbedName({{name}})]{% end %} - {{base.id}} ::{{type_name.id}} + {{base.id}} {{"::".id unless type_name.id.starts_with?("::")}}{{type_name.id}} include ::Spectator::Mocked extend ::Spectator::StubbedType