Mockingbird Documentation 0.14.1

Function any(_:​containing:​)

public func any<K, V>(_ type: Dictionary<K, V>.Type = Dictionary<K, V>.self, containing values: V) -> Dictionary<K, V>

Matches any dictionary 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 dictionaries that contain all specified values.

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

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

bird.send([
  UUID(): "Hi",
  UUID(): "Hello",
])  // Prints ["Hi", "Hello"]

bird.send([
  UUID(): "Hi",
  UUID(): "Bye",
])  // Error: Missing stubbed implementation

bird.send([
  UUID(): "Bye",
]) // Error: Missing stubbed implementation

Methods overloaded by parameter type can be disambiguated by explicitly specifying the type.

protocol Bird {
  func send<T>(_ messages: [UUID: T])    // Overloaded generically
  func send(_ messages: [UUID: String])  // Overloaded explicitly
  func send(_ messages: [UUID: Data])
}

given(bird.send(any([UUID: String].self, containing: "Hi", "Hello")))
  .will { print($0) }

bird.send([
  UUID(): "Hi",
  UUID(): "Hello",
])  // Prints ["Hi", "Hello"]

bird.send([
  UUID(): Data([1]),
  UUID(): Data([2]),
])  // Error: Missing stubbed implementation

Parameters

type Dictionary<K, V>.​Type

The parameter type used to disambiguate overloaded methods.

values V

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