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
|
||||
end
|
||||
|
||||
def register(object) : Nil
|
||||
key = unique_key(object)
|
||||
@@entries[key] = Entry.new
|
||||
end
|
||||
|
||||
def add_stub(object, stub : MethodStub) : Nil
|
||||
key = unique_key(object)
|
||||
@@entries[key].stubs << stub
|
||||
rescue KeyError
|
||||
raise "Cannot stub unregistered mock"
|
||||
fetch(object).stubs << stub
|
||||
end
|
||||
|
||||
def find_stub(object, call : GenericMethodCall(T, NT)) forall T, NT
|
||||
key = unique_key(object)
|
||||
@@entries[key].stubs.find(&.callable?(call))
|
||||
rescue KeyError
|
||||
raise "Cannot stub unregistered mock"
|
||||
fetch(object).stubs.find(&.callable?(call))
|
||||
end
|
||||
|
||||
def record_call(object, call : MethodCall) : Nil
|
||||
fetch(object).calls << call
|
||||
end
|
||||
|
||||
private def fetch(object)
|
||||
key = unique_key(object)
|
||||
@@entries[key].calls << call
|
||||
rescue KeyError
|
||||
raise "Cannot record call for unregistered mock"
|
||||
if @@entries.has_key?(key)
|
||||
@@entries[key]
|
||||
else
|
||||
@@entries[key] = Entry.new
|
||||
end
|
||||
end
|
||||
|
||||
private def unique_key(reference : Reference)
|
||||
|
|
Loading…
Reference in a new issue