Mockingbird Documentation 0.18.0

Function not​Nil(_:​)

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

Matches any non-nil argument value.

Argument matching allows you to stub or verify specific invocations of parameterized methods. Use the argument matcher notNil to match non-nil argument values.

protocol Bird {
  func send(_ message: String?)
}

given(bird.send(notNil())).will { print($0) }

bird.send("Hello")  // Prints Optional("Hello")
bird.send(nil)      // Error: Missing stubbed implementation

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(_ messages: Data?)
}

given(bird.send(notNil(String?.self)))
  .will { print($0) }

bird.send("Hello")  // Prints Optional("Hello")
bird.send(nil)      // Error: Missing stubbed implementation

Parameters

type T.​Type

The parameter type used to disambiguate overloaded methods.