mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Don't require registration
This commit is contained in:
parent
fc0b46caca
commit
5a072301af
1 changed files with 11 additions and 16 deletions
|
@ -15,30 +15,25 @@ module Spectator::Mocks
|
||||||
@entries.clear
|
@entries.clear
|
||||||
end
|
end
|
||||||
|
|
||||||
def register(object) : Nil
|
|
||||||
key = unique_key(object)
|
|
||||||
@@entries[key] = Entry.new
|
|
||||||
end
|
|
||||||
|
|
||||||
def add_stub(object, stub : MethodStub) : Nil
|
def add_stub(object, stub : MethodStub) : Nil
|
||||||
key = unique_key(object)
|
fetch(object).stubs << stub
|
||||||
@@entries[key].stubs << stub
|
|
||||||
rescue KeyError
|
|
||||||
raise "Cannot stub unregistered mock"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_stub(object, call : GenericMethodCall(T, NT)) forall T, NT
|
def find_stub(object, call : GenericMethodCall(T, NT)) forall T, NT
|
||||||
key = unique_key(object)
|
fetch(object).stubs.find(&.callable?(call))
|
||||||
@@entries[key].stubs.find(&.callable?(call))
|
|
||||||
rescue KeyError
|
|
||||||
raise "Cannot stub unregistered mock"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def record_call(object, call : MethodCall) : Nil
|
def record_call(object, call : MethodCall) : Nil
|
||||||
|
fetch(object).calls << call
|
||||||
|
end
|
||||||
|
|
||||||
|
private def fetch(object)
|
||||||
key = unique_key(object)
|
key = unique_key(object)
|
||||||
@@entries[key].calls << call
|
if @@entries.has_key?(key)
|
||||||
rescue KeyError
|
@@entries[key]
|
||||||
raise "Cannot record call for unregistered mock"
|
else
|
||||||
|
@@entries[key] = Entry.new
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private def unique_key(reference : Reference)
|
private def unique_key(reference : Reference)
|
||||||
|
|
Loading…
Reference in a new issue