mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Match RSpec behavior
This commit is contained in:
parent
a8e55e32d2
commit
613c969fbb
5 changed files with 59 additions and 56 deletions
|
@ -110,13 +110,8 @@ module Spectator
|
|||
end
|
||||
|
||||
private def _spectator_stub_fallback(call : MethodCall, &)
|
||||
if @stubs.any? { |stub| stub.method == call.method }
|
||||
Log.info { "Stubs are defined for #{call.method.inspect}, but none matched (no argument constraints met)." }
|
||||
raise UnexpectedMessage.new("#{_spectator_stubbed_name} received unexpected message #{call}")
|
||||
else
|
||||
Log.trace { "Fallback for #{call} - call original" }
|
||||
yield
|
||||
end
|
||||
Log.trace { "Fallback for #{call} - call original" }
|
||||
yield
|
||||
end
|
||||
|
||||
private def _spectator_stub_fallback(call : MethodCall, _type, &)
|
||||
|
@ -124,6 +119,12 @@ module Spectator
|
|||
end
|
||||
|
||||
private def _spectator_abstract_stub_fallback(call : MethodCall)
|
||||
Log.info do
|
||||
break unless @stubs.any? { |stub| stub.method == call.method }
|
||||
|
||||
"Stubs are defined for #{call.method.inspect}, but none matched (no argument constraints met)."
|
||||
end
|
||||
|
||||
raise UnexpectedMessage.new("#{_spectator_stubbed_name} received unexpected message #{call}")
|
||||
end
|
||||
|
||||
|
|
|
@ -31,6 +31,16 @@ module Spectator
|
|||
"#<LazyDouble #{@name || "Anonymous"}>"
|
||||
end
|
||||
|
||||
private def _spectator_stub_fallback(call : MethodCall, &)
|
||||
if @stubs.any? { |stub| stub.method == call.method }
|
||||
Log.info { "Stubs are defined for #{call.method.inspect}, but none matched (no argument constraints met)." }
|
||||
raise UnexpectedMessage.new("#{_spectator_stubbed_name} received unexpected message #{call}")
|
||||
else
|
||||
Log.trace { "Fallback for #{call} - call original" }
|
||||
yield
|
||||
end
|
||||
end
|
||||
|
||||
# Handles all messages.
|
||||
macro method_missing(call)
|
||||
Log.trace { "Got undefined method `{{call.name}}({{*call.args}}{% if call.named_args %}{% unless call.args.empty? %}, {% end %}{{*call.named_args}}{% end %}){% if call.block %} { ... }{% end %}`" }
|
||||
|
|
|
@ -23,16 +23,6 @@ module Spectator
|
|||
{% end %}
|
||||
end
|
||||
|
||||
private def _spectator_stub_fallback(call : MethodCall, &)
|
||||
if @stubs.any? { |stub| stub.method == call.method }
|
||||
Log.info { "Stubs are defined for #{call.method.inspect}, but none matched (no argument constraints met)." }
|
||||
raise UnexpectedMessage.new("#{_spectator_stubbed_name} received unexpected message #{call}")
|
||||
else
|
||||
Log.trace { "Fallback for #{call} - return original" }
|
||||
yield
|
||||
end
|
||||
end
|
||||
|
||||
private def _spectator_abstract_stub_fallback(call : MethodCall)
|
||||
if @stubs.any? { |stub| stub.method == call.method }
|
||||
Log.info { "Stubs are defined for #{call.method.inspect}, but none matched (no argument constraints met)." }
|
||||
|
@ -43,10 +33,12 @@ module Spectator
|
|||
end
|
||||
end
|
||||
|
||||
# Specialization that matches when the return type matches self.
|
||||
private def _spectator_abstract_stub_fallback(call : MethodCall, _type : self)
|
||||
_spectator_abstract_stub_fallback(call)
|
||||
end
|
||||
|
||||
# Default implementation that raises a `TypeCastError` since the return type isn't self.
|
||||
private def _spectator_abstract_stub_fallback(call : MethodCall, type)
|
||||
if @stubs.any? { |stub| stub.method == call.method }
|
||||
Log.info { "Stubs are defined for #{call.method.inspect}, but none matched (no argument constraints met)." }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue