Mockingbird Documentation 0.14.1

Function any(_:​)

public func any<T>(_ type: T.Type = T.self) -> T

Matches all argument values.

Argument matching allows you to stub or verify specific invocations of parameterized methods. Use the wildcard argument matcher any as a type safe placeholder for matching any argument value.

given(bird.canChirp(volume: any())).willReturn(true)
given(bird.setName(any())).will { print($0) }

print(bird.canChirp(volume: 10))  // Prints "true"
bird.name = "Ryan"  // Prints "Ryan"

verify(bird.canChirp(volume: any())).wasCalled()
verify(bird.setName(any())).wasCalled()

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))).will { print($0) }

bird.send("Hello")  // Prints "Hello"

verify(bird.send(any(String.self))).wasCalled()
verify(bird.send(any(Data.self))).wasNeverCalled()

Parameters

type T.​Type

The parameter type used to disambiguate overloaded methods.