Fix clearing stubs for mocks

Prevent reverting initial defaults set by mock macro.
This commit is contained in:
Michael Miller 2022-05-15 16:21:05 -06:00
parent a39b27387c
commit 4f0e2f6e46
No known key found for this signature in database
GPG key ID: 32B47AE8F388A1FF

View file

@ -14,13 +14,19 @@ module Spectator
include ::Spectator::Mocked
{% begin %}
private getter _spectator_stubs = [
{% for key, value in value_methods %}
::Spectator::ValueStub.new({{key.id.symbolize}}, {{value}}),
{% end %}
] of ::Spectator::Stub
private getter(_spectator_stubs) do
[
{% for key, value in value_methods %}
::Spectator::ValueStub.new({{key.id.symbolize}}, {{value}}),
{% end %}
] of ::Spectator::Stub
end
{% end %}
def _spectator_clear_stubs : Nil
@_spectator_stubs = nil
end
# Returns the mock's name formatted for user output.
private def _spectator_stubbed_name : String
\{% if anno = @type.annotation(::Spectator::StubbedName) %}
@ -73,6 +79,10 @@ module Spectator
end
end
def _spectator_clear_stubs : Nil
@@_spectator_mock_registry.delete(self)
end
# Returns the mock's name formatted for user output.
private def _spectator_stubbed_name : String
\{% if anno = @type.annotation(::Spectator::StubbedName) %}