mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Add MultiValueStub
This commit is contained in:
parent
813983de4b
commit
9c705bf888
2 changed files with 126 additions and 0 deletions
30
src/spectator/mocks/multi_value_stub.cr
Normal file
30
src/spectator/mocks/multi_value_stub.cr
Normal file
|
@ -0,0 +1,30 @@
|
|||
require "../location"
|
||||
require "./arguments"
|
||||
require "./stub_modifiers"
|
||||
require "./typed_stub"
|
||||
|
||||
module Spectator
|
||||
# Stub that responds with a multiple values in succession.
|
||||
class MultiValueStub(T) < TypedStub(T)
|
||||
# Invokes the stubbed implementation.
|
||||
def call(call : MethodCall) : T
|
||||
if @values.size == 1
|
||||
@values.first
|
||||
else
|
||||
@values.shift
|
||||
end
|
||||
end
|
||||
|
||||
# Creates the stub.
|
||||
def initialize(method : Symbol, @values : Array(T), constraint : AbstractArguments? = nil, location : Location? = nil)
|
||||
super(method, constraint, location)
|
||||
end
|
||||
end
|
||||
|
||||
module StubModifiers
|
||||
# Returns a new stub that returns multiple values in succession.
|
||||
def and_return(value, *values)
|
||||
MultiValueStub.new(method, [value, *values], constraint, location)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue