Function atMost(_:)
public func atMost(_ times: Int) -> CountMatcher
Matches less than or equal to some count.
The atMost
count matcher can be used to verify that the actual number of invocations received
by a mock is less than or equal to the expected number of invocations.
// Given two invocations (n = 2)
bird.fly()
bird.fly()
verify(bird.fly()).wasCalled(atMost(1)) // Fails (n > 1)
verify(bird.fly()).wasCalled(atMost(2)) // Passes
verify(bird.fly()).wasCalled(atMost(3)) // Passes
You can combine count matchers with adverbial counts for improved readability.
verify(bird.fly()).wasCalled(atMost(once))
Parameters
Name | Type | Description |
---|---|---|
times | Int |
An inclusive upper bound. |
Returns
A count matcher.