Function any(_:count:)
public func any<T: Collection>(_ type: T.Type = T.self, count countMatcher: CountMatcher) -> T
Matches any collection with a specific number of elements.
Argument matching allows you to stub or verify specific invocations of parameterized methods.
Use the argument matcher any(count:)
to match collections with a specific number of elements.
protocol Bird {
func send(_ messages: [String])
}
given(bird.send(any(count: 2))).will { print($0) }
bird.send(["Hi", "Hello"]) // Prints ["Hi", "Hello"]
bird.send(["Hi"]) // Error: Missing stubbed implementation
Methods overloaded by parameter type can be disambiguated by explicitly specifying the type.
protocol Bird {
func send<T>(_ messages: [T]) // Overloaded generically
func send(_ messages: [String]) // Overloaded explicitly
func send(_ messages: [Data])
}
given(bird.send(any([String].self, count: 2)))
.will { print($0) }
bird.send(["Hi", "Hello"]) // Prints ["Hi", "Hello"]
bird.send([Data([1]), Data([2])]) // Error: Missing stubbed implementation
Parameters
Name | Type | Description |
---|---|---|
type | T.Type |
The parameter type used to disambiguate overloaded methods. |
countMatcher | CountMatcher |
A count matcher defining the number of acceptable elements in the collection. |