Function exactly(_:)
public func exactly(_ times: Int) -> CountMatcher
Matches an exact count.
The exactly
count matcher can be used to verify that the actual number of invocations received
by a mock equals the expected number of invocations.
// Given two invocations (n = 2)
bird.fly()
bird.fly()
verify(bird.fly()).wasCalled(exactly(1)) // Fails (n ≠ 1)
verify(bird.fly()).wasCalled(exactly(2)) // Passes
You can combine count matchers with adverbial counts for improved readability.
verify(bird.fly()).wasCalled(exactly(once))
Parameters
Name | Type | Description |
---|---|---|
times | Int |
An exact integer count. |
Returns
A count matcher.