Function any(_:of:)
public func any<T: Equatable>(_ type: T.Type = T.self, of objects: T...) -> T
Matches argument values equal to any of the provided values.
Argument matching allows you to stub or verify specific invocations of parameterized methods.
Use the argument matcher any(of:)
to match Equatable
argument values equal to one or more of
the specified values.
given(bird.canChirp(volume: any(of: 1, 3)))
.willReturn(true)
given(bird.canChirp(volume: any(of: 2, 4)))
.willReturn(false)
print(bird.canChirp(volume: 1)) // Prints "true"
print(bird.canChirp(volume: 2)) // Prints "false"
print(bird.canChirp(volume: 3)) // Prints "true"
print(bird.canChirp(volume: 4)) // Prints "false"
Methods overloaded by parameter type can be disambiguated by explicitly specifying the type.
protocol Bird {
func send<T>(_ message: T) // Overloaded generically
func send(_ message: String) // Overloaded explicitly
func send(_ message: Data)
}
given(bird.send(any(String.self, of: "Hi", "Hello")))
.will { print($0) }
bird.send("Hi") // Prints "Hi"
bird.send("Hello") // Prints "Hello"
bird.send("Bye") // Error: Missing stubbed implementation
Parameters
Name | Type | Description |
---|---|---|
type | T.Type |
The parameter type used to disambiguate overloaded methods. |
objects | T |
A set of equatable objects that should result in a match. |