Function inOrder(with:file:line:_:)
public func inOrder(with options: OrderedVerificationOptions = [],
file: StaticString = #file, line: UInt = #line,
_ block: () -> Void)
Enforce the relative order of invocations.
Calls to verify
within the scope of an inOrder
verification block are checked relative to
each other.
// Verify that `fly` was called before `chirp`
inOrder {
verify(bird.fly()).wasCalled()
verify(bird.chirp()).wasCalled()
}
Pass options to inOrder
verification blocks for stricter checks with additional invariants.
inOrder(with: .noInvocationsAfter) {
verify(bird.fly()).wasCalled()
verify(bird.chirp()).wasCalled()
}
An inOrder
block is resolved greedily, such that each verification must happen from the oldest
remaining unsatisfied invocations.
// Given these unsatisfied invocations
bird.fly()
bird.fly()
bird.chirp()
// Greedy strategy _must_ start from the first `fly`
inOrder {
verify(bird.fly()).wasCalled(twice)
verify(bird.chirp()).wasCalled()
}
// Non-greedy strategy can start from the second `fly`
inOrder {
verify(bird.fly()).wasCalled()
verify(bird.chirp()).wasCalled()
}
Parameters
Name | Type | Description |
---|---|---|
options | OrderedVerificationOptions |
Options to use when verifying invocations. |
block | () -> Void |
A block containing ordered verification calls. |