Add functionality to clear stubs

This commit is contained in:
Michael Miller 2022-05-15 15:56:32 -06:00
parent fdac99d122
commit c98442e0ed
No known key found for this signature in database
GPG key ID: 32B47AE8F388A1FF
7 changed files with 99 additions and 12 deletions

View file

@ -95,6 +95,11 @@ module Spectator
@stubs.unshift(stub)
end
protected def _spectator_clear_stubs : Nil
Log.debug { "Clearing stubs for #{_spectator_stubbed_name}" }
@stubs.clear
end
private def _spectator_find_stub(call : MethodCall) : Stub?
Log.debug { "Finding stub for #{call}" }
stub = @stubs.find &.===(call)

View file

@ -12,6 +12,10 @@ module Spectator
_spectator_stubs.unshift(stub)
end
def _spectator_clear_stubs : Nil
_spectator_stubs.clear
end
private def _spectator_find_stub(call : ::Spectator::MethodCall) : ::Spectator::Stub?
_spectator_stubs.find &.===(call)
end

View file

@ -28,6 +28,9 @@ module Spectator
# Defines a stub to change the behavior of a method.
abstract def _spectator_define_stub(stub : Stub) : Nil
# Clears all previously defined stubs.
abstract def _spectator_clear_stubs : Nil
# Method called when a stub isn't found.
#
# The received message is captured in *call*.