Indicate class double/mock in stubbed name

This commit is contained in:
Michael Miller 2022-07-04 15:34:38 -06:00
parent cecd2464de
commit 056d5892fa
No known key found for this signature in database
GPG key ID: 32B47AE8F388A1FF
3 changed files with 25 additions and 8 deletions

View file

@ -130,6 +130,14 @@ module Spectator
{% end %}
end
private def self._spectator_stubbed_name : String
{% if anno = @type.annotation(StubbedName) %}
"#<Class Double " + \{{(anno[0] || :Anonymous.id).stringify}} + "\">"
{% else %}
"#<Class Double Anonymous>"
{% end %}
end
private def _spectator_stub_fallback(call : MethodCall, &)
Log.trace { "Fallback for #{call} - call original" }
yield

View file

@ -63,6 +63,14 @@ module Spectator
\{% end %}
end
private def self._spectator_stubbed_name : String
\{% if anno = @type.annotation(::Spectator::StubbedName) %}
"#<Class Mock {{mocked_type.id}} \"" + \{{(anno[0] || :Anonymous.id).stringify}} + "\">"
\{% else %}
"#<Class Mock {{mocked_type.id}}>"
\{% end %}
end
macro finished
stub_type {{mocked_type.id}}
@ -149,6 +157,15 @@ module Spectator
\{% end %}
end
# Returns the mock's name formatted for user output.
private def self._spectator_stubbed_name : String
\{% if anno = @type.annotation(::Spectator::StubbedName) %}
"#<Class Mock {{type_name.id}} \"" + \{{(anno[0] || :Anonymous.id).stringify}} + "\">"
\{% else %}
"#<Class Mock {{type_name.id}}>"
\{% end %}
end
macro finished
stub_type {{type_name.id}}

View file

@ -54,13 +54,5 @@ module Spectator
def _spectator_abstract_stub_fallback(call : MethodCall, type)
_spectator_abstract_stub_fallback(call)
end
def _spectator_stubbed_name : String
{% if anno = @type.annotation(StubbedName) %}
"#<Stubbed " + {{(anno[0] || :Anonymous.id).stringify}} + ">"
{% else %}
"#<Stubbed " + {{@type.name.stringify}} + ">"
{% end %}
end
end
end