Mockingbird Documentation 0.18.0

Function in​Order(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 `canFly` was called before `fly`
inOrder {
  verify(bird.canFly).wasCalled()
  verify(bird.fly()).wasCalled()
}

Pass options to inOrder verification blocks for stricter checks with additional invariants.

inOrder(with: .noInvocationsAfter) {
  verify(bird.canFly).wasCalled()
  verify(bird.fly()).wasCalled()
}

An inOrder block is resolved greedily, such that each verification must happen from the oldest remaining unsatisfied invocations.

// Given these unsatisfied invocations
bird.canFly
bird.canFly
bird.fly()

// Greedy strategy _must_ start from the first `canFly`
inOrder {
  verify(bird.canFly).wasCalled(twice)
  verify(bird.fly()).wasCalled()
}

// Non-greedy strategy can start from the second `canFly`
inOrder {
  verify(bird.canFly).wasCalled()
  verify(bird.fly()).wasCalled()
}

Parameters

options Ordered​Verification​Options

Options to use when verifying invocations.

block () -> Void

A block containing ordered verification calls.