mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Add ability to remove specific stubs
This commit is contained in:
parent
422b0efa59
commit
25b9931002
7 changed files with 36 additions and 0 deletions
|
@ -103,6 +103,11 @@ module Spectator
|
||||||
@stubs.unshift(stub)
|
@stubs.unshift(stub)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
protected def _spectator_remove_stub(stub : Stub) : Nil
|
||||||
|
Log.debug { "Removing stub #{stub} from #{_spectator_stubbed_name}" }
|
||||||
|
@stubs.delete(stub)
|
||||||
|
end
|
||||||
|
|
||||||
protected def _spectator_clear_stubs : Nil
|
protected def _spectator_clear_stubs : Nil
|
||||||
Log.debug { "Clearing stubs for #{_spectator_stubbed_name}" }
|
Log.debug { "Clearing stubs for #{_spectator_stubbed_name}" }
|
||||||
@stubs.clear
|
@stubs.clear
|
||||||
|
|
|
@ -50,6 +50,10 @@ module Spectator
|
||||||
end
|
end
|
||||||
{% end %}
|
{% end %}
|
||||||
|
|
||||||
|
def _spectator_remove_stub(stub : ::Spectator::Stub) : Nil
|
||||||
|
@_spectator_stubs.try &.delete(stub)
|
||||||
|
end
|
||||||
|
|
||||||
def _spectator_clear_stubs : Nil
|
def _spectator_clear_stubs : Nil
|
||||||
@_spectator_stubs = nil
|
@_spectator_stubs = nil
|
||||||
end
|
end
|
||||||
|
@ -139,6 +143,10 @@ module Spectator
|
||||||
entry.stubs
|
entry.stubs
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def _spectator_remove_stub(stub : ::Spectator::Stub) : Nil
|
||||||
|
@@_spectator_mock_registry[self]?.try &.stubs.delete(stub)
|
||||||
|
end
|
||||||
|
|
||||||
def _spectator_clear_stubs : Nil
|
def _spectator_clear_stubs : Nil
|
||||||
@@_spectator_mock_registry.delete(self)
|
@@_spectator_mock_registry.delete(self)
|
||||||
end
|
end
|
||||||
|
|
|
@ -26,6 +26,10 @@ module Spectator
|
||||||
_spectator_stubs.unshift(stub)
|
_spectator_stubs.unshift(stub)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def _spectator_remove_stub(stub : Stub) : Nil
|
||||||
|
_spectator_stubs.delete(stub)
|
||||||
|
end
|
||||||
|
|
||||||
def _spectator_clear_stubs : Nil
|
def _spectator_clear_stubs : Nil
|
||||||
_spectator_stubs.clear
|
_spectator_stubs.clear
|
||||||
end
|
end
|
||||||
|
|
|
@ -25,6 +25,12 @@ module Spectator
|
||||||
@entries[key]
|
@entries[key]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Retrieves all stubs defined for a mocked object or nil if the object isn't mocked yet.
|
||||||
|
def []?(object : Reference)
|
||||||
|
key = Box.box(object)
|
||||||
|
@entries[key]?
|
||||||
|
end
|
||||||
|
|
||||||
# Retrieves all stubs defined for a mocked object.
|
# Retrieves all stubs defined for a mocked object.
|
||||||
#
|
#
|
||||||
# Yields to the block on the first retrieval.
|
# Yields to the block on the first retrieval.
|
||||||
|
|
|
@ -28,6 +28,9 @@ module Spectator
|
||||||
# Defines a stub to change the behavior of a method.
|
# Defines a stub to change the behavior of a method.
|
||||||
abstract def _spectator_define_stub(stub : Stub) : Nil
|
abstract def _spectator_define_stub(stub : Stub) : Nil
|
||||||
|
|
||||||
|
# Removes a specific, previously defined stub.
|
||||||
|
abstract def _spectator_remove_stub(stub : Stub) : Nil
|
||||||
|
|
||||||
# Clears all previously defined stubs.
|
# Clears all previously defined stubs.
|
||||||
abstract def _spectator_clear_stubs : Nil
|
abstract def _spectator_clear_stubs : Nil
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,10 @@ module Spectator
|
||||||
_spectator_stubs.unshift(stub)
|
_spectator_stubs.unshift(stub)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def _spectator_remove_stub(stub : Stub) : Nil
|
||||||
|
_spectator_stubs.delete(stub)
|
||||||
|
end
|
||||||
|
|
||||||
def _spectator_clear_stubs : Nil
|
def _spectator_clear_stubs : Nil
|
||||||
_spectator_stubs.clear
|
_spectator_stubs.clear
|
||||||
end
|
end
|
||||||
|
|
|
@ -29,6 +29,12 @@ module Spectator
|
||||||
@entries[key]
|
@entries[key]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Retrieves all stubs defined for a mocked object or nil if the object isn't mocked yet.
|
||||||
|
def []?(object : T)
|
||||||
|
key = value_bytes(object)
|
||||||
|
@entries[key]?
|
||||||
|
end
|
||||||
|
|
||||||
# Retrieves all stubs defined for a mocked object.
|
# Retrieves all stubs defined for a mocked object.
|
||||||
#
|
#
|
||||||
# Yields to the block on the first retrieval.
|
# Yields to the block on the first retrieval.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue