Mockingbird Documentation 0.18.0

Class Dynamic​Stubbing​Manager

public class DynamicStubbingManager<ReturnType>:
  StubbingManager<AnyDeclaration, Any?, ReturnType>  

An intermediate object used for stubbing Objective-C declarations returned by given.

Stubbed implementations are type erased to allow Swift to apply arguments with minimal type information. See StubbingContext+ObjCReturnValue for more context.

DynamicStubbingManager DynamicStubbingManager StubbingManager<AnyDeclaration, Any?, ReturnType> StubbingManager<AnyDeclaration, Any?, ReturnType> DynamicStubbingManager->StubbingManager<AnyDeclaration, Any?, ReturnType>

Conforms To

StubbingManager<AnyDeclaration, Any?, ReturnType>

Methods

will​Return(_:​)

@discardableResult
  override public func willReturn(_ value: ReturnType) -> Self  

Stub a mocked method or property by returning a single value.

Stubbing allows you to define custom behavior for mocks to perform.

given(bird.doMethod()).willReturn(someValue)
given(bird.property).willReturn(someValue)

Match exact or wildcard argument values when stubbing methods with parameters. Stubs added later have a higher precedence, so add stubs with specific matchers last.

given(bird.canChirp(volume: any())).willReturn(true)     // Any volume
given(bird.canChirp(volume: notNil())).willReturn(true)  // Any non-nil volume
given(bird.canChirp(volume: 10)).willReturn(true)        // Volume = 10

Parameters

value Return​Type

A stubbed value to return.

Returns

The current stubbing manager which can be used to chain additional stubs.

will​Throw(_:​)

@discardableResult
  public func willThrow(_ error: Error) -> Self  

Stub a mocked method that throws with an error.

Stubbing allows you to define custom behavior for mocks to perform. Methods that throw or rethrow errors can be stubbed with a throwable object.

struct BirdError: Error {}
given(bird.throwingMethod()).willThrow(BirdError())

Parameters

error Error

A stubbed error object to throw.

Returns

The current stubbing manager which can be used to chain additional stubs.

will(_:​)

@discardableResult
  public func will(
    _ implementation: @escaping () -> ReturnType
  ) -> Self  

Stub a mocked method or property with a closure implementation.

Use a closure to implement stubs that contain logic, interact with arguments, or throw errors.

given(bird.canChirp(volume: any()))
  .will { volume in
    return volume < 42
  }

Parameters

implementation @escaping () -> Return​Type

A closure implementation stub to evaluate.

Returns

The current stubbing manager which can be used to chain additional stubs.

will(_:​)

@discardableResult
  public func will<P0>(
    _ implementation: @escaping (P0) -> ReturnType
  ) -> Self  

Stub a mocked method or property with a closure implementation.

Use a closure to implement stubs that contain logic, interact with arguments, or throw errors.

given(bird.canChirp(volume: any()))
  .will { volume in
    return volume < 42
  }

Parameters

implementation @escaping (P0) -> Return​Type

A closure implementation stub to evaluate.

Returns

The current stubbing manager which can be used to chain additional stubs.

will(_:​)

@discardableResult
  public func will<P0,P1>(
    _ implementation: @escaping (P0,P1) -> ReturnType
  ) -> Self  

Stub a mocked method or property with a closure implementation.

Use a closure to implement stubs that contain logic, interact with arguments, or throw errors.

given(bird.canChirp(volume: any()))
  .will { volume in
    return volume < 42
  }

Parameters

implementation @escaping (P0,P1) -> Return​Type

A closure implementation stub to evaluate.

Returns

The current stubbing manager which can be used to chain additional stubs.

will(_:​)

@discardableResult
  public func will<P0,P1,P2>(
    _ implementation: @escaping (P0,P1,P2) -> ReturnType
  ) -> Self  

Stub a mocked method or property with a closure implementation.

Use a closure to implement stubs that contain logic, interact with arguments, or throw errors.

given(bird.canChirp(volume: any()))
  .will { volume in
    return volume < 42
  }

Parameters

implementation @escaping (P0,P1,P2) -> Return​Type

A closure implementation stub to evaluate.

Returns

The current stubbing manager which can be used to chain additional stubs.

will(_:​)

@discardableResult
  public func will<P0,P1,P2,P3>(
    _ implementation: @escaping (P0,P1,P2,P3) -> ReturnType
  ) -> Self  

Stub a mocked method or property with a closure implementation.

Use a closure to implement stubs that contain logic, interact with arguments, or throw errors.

given(bird.canChirp(volume: any()))
  .will { volume in
    return volume < 42
  }

Parameters

implementation @escaping (P0,P1,P2,P3) -> Return​Type

A closure implementation stub to evaluate.

Returns

The current stubbing manager which can be used to chain additional stubs.

will(_:​)

@discardableResult
  public func will<P0,P1,P2,P3,P4>(
    _ implementation: @escaping (P0,P1,P2,P3,P4) -> ReturnType
  ) -> Self  

Stub a mocked method or property with a closure implementation.

Use a closure to implement stubs that contain logic, interact with arguments, or throw errors.

given(bird.canChirp(volume: any()))
  .will { volume in
    return volume < 42
  }

Parameters

implementation @escaping (P0,P1,P2,P3,P4) -> Return​Type

A closure implementation stub to evaluate.

Returns

The current stubbing manager which can be used to chain additional stubs.

will(_:​)

@discardableResult
  public func will<P0,P1,P2,P3,P4,P5>(
    _ implementation: @escaping (P0,P1,P2,P3,P4,P5) -> ReturnType
  ) -> Self  

Stub a mocked method or property with a closure implementation.

Use a closure to implement stubs that contain logic, interact with arguments, or throw errors.

given(bird.canChirp(volume: any()))
  .will { volume in
    return volume < 42
  }

Parameters

implementation @escaping (P0,P1,P2,P3,P4,P5) -> Return​Type

A closure implementation stub to evaluate.

Returns

The current stubbing manager which can be used to chain additional stubs.

will(_:​)

@discardableResult
  public func will<P0,P1,P2,P3,P4,P5,P6>(
    _ implementation: @escaping (P0,P1,P2,P3,P4,P5,P6) -> ReturnType
  ) -> Self  

Stub a mocked method or property with a closure implementation.

Use a closure to implement stubs that contain logic, interact with arguments, or throw errors.

given(bird.canChirp(volume: any()))
  .will { volume in
    return volume < 42
  }

Parameters

implementation @escaping (P0,P1,P2,P3,P4,P5,P6) -> Return​Type

A closure implementation stub to evaluate.

Returns

The current stubbing manager which can be used to chain additional stubs.

will(_:​)

@discardableResult
  public func will<P0,P1,P2,P3,P4,P5,P6,P7>(
    _ implementation: @escaping (P0,P1,P2,P3,P4,P5,P6,P7) -> ReturnType
  ) -> Self  

Stub a mocked method or property with a closure implementation.

Use a closure to implement stubs that contain logic, interact with arguments, or throw errors.

given(bird.canChirp(volume: any()))
  .will { volume in
    return volume < 42
  }

Parameters

implementation @escaping (P0,P1,P2,P3,P4,P5,P6,P7) -> Return​Type

A closure implementation stub to evaluate.

Returns

The current stubbing manager which can be used to chain additional stubs.

will(_:​)

@discardableResult
  public func will<P0,P1,P2,P3,P4,P5,P6,P7,P8>(
    _ implementation: @escaping (P0,P1,P2,P3,P4,P5,P6,P7,P8) -> ReturnType
  ) -> Self  

Stub a mocked method or property with a closure implementation.

Use a closure to implement stubs that contain logic, interact with arguments, or throw errors.

given(bird.canChirp(volume: any()))
  .will { volume in
    return volume < 42
  }

Parameters

implementation @escaping (P0,P1,P2,P3,P4,P5,P6,P7,P8) -> Return​Type

A closure implementation stub to evaluate.

Returns

The current stubbing manager which can be used to chain additional stubs.

will(_:​)

@discardableResult
  public func will<P0,P1,P2,P3,P4,P5,P6,P7,P8,P9>(
    _ implementation: @escaping (P0,P1,P2,P3,P4,P5,P6,P7,P8,P9) -> ReturnType
  ) -> Self  

Stub a mocked method or property with a closure implementation.

Use a closure to implement stubs that contain logic, interact with arguments, or throw errors.

given(bird.canChirp(volume: any()))
  .will { volume in
    return volume < 42
  }

Parameters

implementation @escaping (P0,P1,P2,P3,P4,P5,P6,P7,P8,P9) -> Return​Type

A closure implementation stub to evaluate.

Returns

The current stubbing manager which can be used to chain additional stubs.

will(_:​)

@discardableResult
  public func will(
    _ implementation: @escaping () throws -> ReturnType
  ) -> Self  

Stub a mocked method or property with a closure implementation.

Use a closure to implement stubs that contain logic, interact with arguments, or throw errors.

given(bird.canChirp(volume: any()))
  .will { volume in
    return volume < 42
  }

Parameters

implementation @escaping () throws -> Return​Type

A closure implementation stub to evaluate.

Returns

The current stubbing manager which can be used to chain additional stubs.

will(_:​)

@discardableResult
  public func will<P0>(
    _ implementation: @escaping (P0) throws -> ReturnType
  ) -> Self  

Stub a mocked method or property with a closure implementation.

Use a closure to implement stubs that contain logic, interact with arguments, or throw errors.

given(bird.canChirp(volume: any()))
  .will { volume in
    return volume < 42
  }

Parameters

implementation @escaping (P0) throws -> Return​Type

A closure implementation stub to evaluate.

Returns

The current stubbing manager which can be used to chain additional stubs.

will(_:​)

@discardableResult
  public func will<P0,P1>(
    _ implementation: @escaping (P0,P1) throws -> ReturnType
  ) -> Self  

Stub a mocked method or property with a closure implementation.

Use a closure to implement stubs that contain logic, interact with arguments, or throw errors.

given(bird.canChirp(volume: any()))
  .will { volume in
    return volume < 42
  }

Parameters

implementation @escaping (P0,P1) throws -> Return​Type

A closure implementation stub to evaluate.

Returns

The current stubbing manager which can be used to chain additional stubs.

will(_:​)

@discardableResult
  public func will<P0,P1,P2>(
    _ implementation: @escaping (P0,P1,P2) throws -> ReturnType
  ) -> Self  

Stub a mocked method or property with a closure implementation.

Use a closure to implement stubs that contain logic, interact with arguments, or throw errors.

given(bird.canChirp(volume: any()))
  .will { volume in
    return volume < 42
  }

Parameters

implementation @escaping (P0,P1,P2) throws -> Return​Type

A closure implementation stub to evaluate.

Returns

The current stubbing manager which can be used to chain additional stubs.

will(_:​)

@discardableResult
  public func will<P0,P1,P2,P3>(
    _ implementation: @escaping (P0,P1,P2,P3) throws -> ReturnType
  ) -> Self  

Stub a mocked method or property with a closure implementation.

Use a closure to implement stubs that contain logic, interact with arguments, or throw errors.

given(bird.canChirp(volume: any()))
  .will { volume in
    return volume < 42
  }

Parameters

implementation @escaping (P0,P1,P2,P3) throws -> Return​Type

A closure implementation stub to evaluate.

Returns

The current stubbing manager which can be used to chain additional stubs.

will(_:​)

@discardableResult
  public func will<P0,P1,P2,P3,P4>(
    _ implementation: @escaping (P0,P1,P2,P3,P4) throws -> ReturnType
  ) -> Self  

Stub a mocked method or property with a closure implementation.

Use a closure to implement stubs that contain logic, interact with arguments, or throw errors.

given(bird.canChirp(volume: any()))
  .will { volume in
    return volume < 42
  }

Parameters

implementation @escaping (P0,P1,P2,P3,P4) throws -> Return​Type

A closure implementation stub to evaluate.

Returns

The current stubbing manager which can be used to chain additional stubs.

will(_:​)

@discardableResult
  public func will<P0,P1,P2,P3,P4,P5>(
    _ implementation: @escaping (P0,P1,P2,P3,P4,P5) throws -> ReturnType
  ) -> Self  

Stub a mocked method or property with a closure implementation.

Use a closure to implement stubs that contain logic, interact with arguments, or throw errors.

given(bird.canChirp(volume: any()))
  .will { volume in
    return volume < 42
  }

Parameters

implementation @escaping (P0,P1,P2,P3,P4,P5) throws -> Return​Type

A closure implementation stub to evaluate.

Returns

The current stubbing manager which can be used to chain additional stubs.

will(_:​)

@discardableResult
  public func will<P0,P1,P2,P3,P4,P5,P6>(
    _ implementation: @escaping (P0,P1,P2,P3,P4,P5,P6) throws -> ReturnType
  ) -> Self  

Stub a mocked method or property with a closure implementation.

Use a closure to implement stubs that contain logic, interact with arguments, or throw errors.

given(bird.canChirp(volume: any()))
  .will { volume in
    return volume < 42
  }

Parameters

implementation @escaping (P0,P1,P2,P3,P4,P5,P6) throws -> Return​Type

A closure implementation stub to evaluate.

Returns

The current stubbing manager which can be used to chain additional stubs.

will(_:​)

@discardableResult
  public func will<P0,P1,P2,P3,P4,P5,P6,P7>(
    _ implementation: @escaping (P0,P1,P2,P3,P4,P5,P6,P7) throws -> ReturnType
  ) -> Self  

Stub a mocked method or property with a closure implementation.

Use a closure to implement stubs that contain logic, interact with arguments, or throw errors.

given(bird.canChirp(volume: any()))
  .will { volume in
    return volume < 42
  }

Parameters

implementation @escaping (P0,P1,P2,P3,P4,P5,P6,P7) throws -> Return​Type

A closure implementation stub to evaluate.

Returns

The current stubbing manager which can be used to chain additional stubs.

will(_:​)

@discardableResult
  public func will<P0,P1,P2,P3,P4,P5,P6,P7,P8>(
    _ implementation: @escaping (P0,P1,P2,P3,P4,P5,P6,P7,P8) throws -> ReturnType
  ) -> Self  

Stub a mocked method or property with a closure implementation.

Use a closure to implement stubs that contain logic, interact with arguments, or throw errors.

given(bird.canChirp(volume: any()))
  .will { volume in
    return volume < 42
  }

Parameters

implementation @escaping (P0,P1,P2,P3,P4,P5,P6,P7,P8) throws -> Return​Type

A closure implementation stub to evaluate.

Returns

The current stubbing manager which can be used to chain additional stubs.

will(_:​)

@discardableResult
  public func will<P0,P1,P2,P3,P4,P5,P6,P7,P8,P9>(
    _ implementation: @escaping (P0,P1,P2,P3,P4,P5,P6,P7,P8,P9) throws -> ReturnType
  ) -> Self  

Stub a mocked method or property with a closure implementation.

Use a closure to implement stubs that contain logic, interact with arguments, or throw errors.

given(bird.canChirp(volume: any()))
  .will { volume in
    return volume < 42
  }

Parameters

implementation @escaping (P0,P1,P2,P3,P4,P5,P6,P7,P8,P9) throws -> Return​Type

A closure implementation stub to evaluate.

Returns

The current stubbing manager which can be used to chain additional stubs.