Conditionally insert top-level namespace (double colon)

This commit is contained in:
Michael Miller 2024-08-13 18:42:22 -06:00
parent 12f3f35958
commit a634046a86
No known key found for this signature in database
GPG key ID: AC78B32D30CE34A2
2 changed files with 3 additions and 3 deletions

View file

@ -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 %}

View file

@ -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