Mockingbird Documentation 0.15.0

Function finite​Sequence(of:​)

public func finiteSequence<DeclarationType: Declaration, InvocationType, ReturnType>(of implementations: InvocationType) -> ImplementationProvider<DeclarationType, InvocationType, ReturnType>

Stub a finite sequence of implementations.

Provide one or more implementations which will be returned sequentially for each invocation. The stub will be invalidated if the number of invocations is greater than the number of implementations provided.

given(bird.getName()).willReturn(finiteSequence(of: {
  return Bool.random() ? "Ryan" : "Meisters"
}, {
  return Bool.random() ? "Sterling" : "Hackley"
}))

print(bird.name)  // Prints "Ryan"
print(bird.name)  // Prints "Sterling"
print(bird.name)  // Error: Missing stubbed implementation

Parameters

implementations Invocation​Type

A sequence of implementations to stub.