mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Implement returning multiple values
This commit is contained in:
parent
1a3f663b70
commit
6e287f864b
2 changed files with 27 additions and 0 deletions
19
src/spectator/mocks/multi_value_method_stub.cr
Normal file
19
src/spectator/mocks/multi_value_method_stub.cr
Normal file
|
@ -0,0 +1,19 @@
|
|||
require "./generic_arguments"
|
||||
require "./generic_method_stub"
|
||||
|
||||
module Spectator::Mocks
|
||||
class MultiValueMethodStub(ReturnType) < GenericMethodStub(ReturnType)
|
||||
@index = 0
|
||||
|
||||
def initialize(name, source, @values : ReturnType, args = nil)
|
||||
super(name, source, args)
|
||||
raise ArgumentError.new("Values must have at least one item") if @values.size < 1
|
||||
end
|
||||
|
||||
def call(_args : GenericArguments(T2, NT2), rt : RT.class) forall T2, NT2, RT
|
||||
value = @values[@index]
|
||||
@index += 1 if @index < @values.size - 1
|
||||
value
|
||||
end
|
||||
end
|
||||
end
|
|
@ -8,10 +8,18 @@ module Spectator::Mocks
|
|||
nil
|
||||
end
|
||||
|
||||
def and_return
|
||||
self
|
||||
end
|
||||
|
||||
def and_return(value)
|
||||
ValueMethodStub.new(@name, @source, value, @args)
|
||||
end
|
||||
|
||||
def and_return(*values)
|
||||
MultiValueMethodStub.new(@name, @source, values.to_a, @args)
|
||||
end
|
||||
|
||||
def with(*args : *T, **opts : **NT) forall T, NT
|
||||
args = GenericArguments.new(args, opts)
|
||||
NilMethodStub.new(@name, @source, args)
|
||||
|
|
Loading…
Reference in a new issue