Mockingbird Documentation 0.17.0

Function any(_:​containing:​)

public func any<T: Collection>(_ type: T.Type = T.self, containing values: T.Element...) -> T  

Matches any collection containing all of the values.

Argument matching allows you to stub or verify specific invocations of parameterized methods. Use the argument matcher any(containing:) to match collections that contain all specified values.

protocol Bird {
  func send(_ messages: [String])
}

given(bird.send(any(containing: "Hi", "Hello")))
  .will { print($0) }

bird.send(["Hi", "Hello"])  // Prints ["Hi", "Hello"]
bird.send(["Hi", "Bye"])    // Error: Missing stubbed implementation
bird.send(["Bye"])          // 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, containing: ["Hi", "Hello"])))
  .will { print($0) }

bird.send(["Hi", "Hello"])       // Prints ["Hi", "Hello"]
bird.send([Data([1]), Data(2)])  // Error: Missing stubbed implementation

Parameters

type T.​Type

The parameter type used to disambiguate overloaded methods.

values T.​Element

A set of values that must all exist in the collection to match.