Function notEmpty(_:)
public func notEmpty<T: Collection>(_ type: T.Type = T.self) -> T
Matches any collection with at least one element.
Argument matching allows you to stub or verify specific invocations of parameterized methods.
Use the argument matcher notEmpty
to match collections with one or more elements.
protocol Bird {
func send(_ messages: [String])
}
given(bird.send(any(count: 2))).will { print($0) }
bird.send(["Hi"]) // Prints ["Hi"]
bird.send([]) // 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(notEmpty([String].self)))
.will { print($0) }
bird.send(["Hi"]) // Prints ["Hi"]
bird.send([Data([1])]) // Error: Missing stubbed implementation
Parameters
Name | Type | Description |
---|---|---|
type | T.Type |
The parameter type used to disambiguate overloaded methods. |