Add method to clear recorded calls

This commit is contained in:
Michael Miller 2022-07-04 15:35:12 -06:00
parent 056d5892fa
commit 989086c4fc
No known key found for this signature in database
GPG key ID: 32B47AE8F388A1FF
4 changed files with 15 additions and 2 deletions

View file

@ -121,6 +121,10 @@ module Spectator
@calls
end
def _spectator_clear_calls : Nil
@calls.clear
end
# Returns the double's name formatted for user output.
private def _spectator_stubbed_name : String
{% if anno = @type.annotation(StubbedName) %}

View file

@ -46,6 +46,10 @@ module Spectator
_spectator_calls.select { |call| call.method == method }
end
def _spectator_clear_calls : Nil
_spectator_calls.clear
end
# Method called when a stub isn't found.
#
# The received message is captured in *call*.

View file

@ -38,6 +38,9 @@ module Spectator
# Retrieves all previously saved calls.
abstract def _spectator_calls
# Clears all previously saved calls.
abstract def _spectator_clear_calls : Nil
# Method called when a stub isn't found.
#
# The received message is captured in *call*.
@ -387,6 +390,8 @@ module Spectator
extend StubbedType
private class_getter _spectator_stubs : Array(::Spectator::Stub) = [] of ::Spectator::Stub
class_getter _spectator_calls : Array(::Spectator::MethodCall) = [] of ::Spectator::MethodCall
end
end
end

View file

@ -28,8 +28,8 @@ module Spectator
_spectator_calls << call
end
def _spectator_calls
[] of MethodCall
def _spectator_clear_calls : Nil
_spectator_calls.clear
end
def _spectator_stub_fallback(call : MethodCall, &)