mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Implement basic and_return
This commit is contained in:
parent
27bc976ae3
commit
aecdb514b3
2 changed files with 11 additions and 1 deletions
|
@ -51,7 +51,7 @@ module Spectator
|
||||||
call = ::Spectator::MethodCall.new({{name.symbolize}}, args, options)
|
call = ::Spectator::MethodCall.new({{name.symbolize}}, args, options)
|
||||||
stub = @stubs.find(&.callable?(call))
|
stub = @stubs.find(&.callable?(call))
|
||||||
if stub
|
if stub
|
||||||
stub.as(::Spectator::GenericMethodStub(typeof(%method(*args, **options)))).call(call)
|
stub.as(::Spectator::GenericMethodStub(typeof(%method(*args, **options) { |*yield_args| yield *yield_args }))).call(call)
|
||||||
else
|
else
|
||||||
%method(*args, **options) do |*yield_args|
|
%method(*args, **options) do |*yield_args|
|
||||||
yield *yield_args
|
yield *yield_args
|
||||||
|
@ -66,6 +66,12 @@ module Spectator
|
||||||
{{body.body}}
|
{{body.body}}
|
||||||
{% else %}
|
{% else %}
|
||||||
raise "Stubbed method called without being allowed"
|
raise "Stubbed method called without being allowed"
|
||||||
|
# This code shouldn't be reached, but makes the compiler happy to have a matching type.
|
||||||
|
{% if definition.is_a?(TypeDeclaration) %}
|
||||||
|
%x = uninitialized {{definition.type}}
|
||||||
|
{% else %}
|
||||||
|
nil
|
||||||
|
{% end %}
|
||||||
{% end %}
|
{% end %}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -15,5 +15,9 @@ module Spectator
|
||||||
def call(call : MethodCall) : ReturnType
|
def call(call : MethodCall) : ReturnType
|
||||||
@proc.call
|
@proc.call
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def and_return(value : T) forall T
|
||||||
|
GenericMethodStub(T).new(@name, @source, -> { value })
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue