mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Allow stubbing/overriding anonymous double methods
This commit is contained in:
parent
b9fe1b6a60
commit
e44f0229d6
2 changed files with 17 additions and 3 deletions
|
@ -8,9 +8,16 @@ module Spectator::Mocks
|
|||
end
|
||||
|
||||
macro method_missing(call)
|
||||
args = ::Spectator::Mocks::GenericArguments.create({{call.args.splat}})
|
||||
call = ::Spectator::Mocks::GenericMethodCall.new({{call.name.symbolize}}, args)
|
||||
::Spectator::Harness.current.mocks.record_call(self, call)
|
||||
if (stub = ::Spectator::Harness.current.mocks.find_stub(self, call))
|
||||
stub.call!(args, typeof(@values.fetch({{call.name.symbolize}}) { raise }))
|
||||
else
|
||||
@values.fetch({{call.name.symbolize}}) do
|
||||
raise ::Spectator::Mocks::UnexpectedMessageError.new("#{self} received unexpected message {{call.name}}")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,7 +4,14 @@ module Spectator::Mocks
|
|||
end
|
||||
|
||||
macro method_missing(call)
|
||||
args = ::Spectator::Mocks::GenericArguments.create({{call.args.splat}})
|
||||
call = ::Spectator::Mocks::GenericMethodCall.new({{call.name.symbolize}}, args)
|
||||
::Spectator::Harness.current.mocks.record_call(self, call)
|
||||
if (stub = ::Spectator::Harness.current.mocks.find_stub(self, call))
|
||||
stub.call!(args, typeof(@values.fetch({{call.name.symbolize}}) { self }))
|
||||
else
|
||||
@values.fetch({{call.name.symbolize}}) { self }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue