Class
DynamicStubbingManager
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.
Relationships
Conforms To
StubbingManager<AnyDeclaration, Any?, ReturnType>
Methods
willReturn(_:)
@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
Name | Type | Description |
---|---|---|
value | ReturnType |
A stubbed value to return. |
Returns
The current stubbing manager which can be used to chain additional stubs.
willThrow(_:)
@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
Name | Type | Description |
---|---|---|
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
Name | Type | Description |
---|---|---|
implementation | @escaping () -> ReturnType |
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
Name | Type | Description |
---|---|---|
implementation | @escaping (P0) -> ReturnType |
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
Name | Type | Description |
---|---|---|
implementation | @escaping (P0,P1) -> ReturnType |
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
Name | Type | Description |
---|---|---|
implementation | @escaping (P0,P1,P2) -> ReturnType |
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
Name | Type | Description |
---|---|---|
implementation | @escaping (P0,P1,P2,P3) -> ReturnType |
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
Name | Type | Description |
---|---|---|
implementation | @escaping (P0,P1,P2,P3,P4) -> ReturnType |
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
Name | Type | Description |
---|---|---|
implementation | @escaping (P0,P1,P2,P3,P4,P5) -> ReturnType |
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
Name | Type | Description |
---|---|---|
implementation | @escaping (P0,P1,P2,P3,P4,P5,P6) -> ReturnType |
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
Name | Type | Description |
---|---|---|
implementation | @escaping (P0,P1,P2,P3,P4,P5,P6,P7) -> ReturnType |
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
Name | Type | Description |
---|---|---|
implementation | @escaping (P0,P1,P2,P3,P4,P5,P6,P7,P8) -> ReturnType |
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
Name | Type | Description |
---|---|---|
implementation | @escaping (P0,P1,P2,P3,P4,P5,P6,P7,P8,P9) -> ReturnType |
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
Name | Type | Description |
---|---|---|
implementation | @escaping () throws -> ReturnType |
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
Name | Type | Description |
---|---|---|
implementation | @escaping (P0) throws -> ReturnType |
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
Name | Type | Description |
---|---|---|
implementation | @escaping (P0,P1) throws -> ReturnType |
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
Name | Type | Description |
---|---|---|
implementation | @escaping (P0,P1,P2) throws -> ReturnType |
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
Name | Type | Description |
---|---|---|
implementation | @escaping (P0,P1,P2,P3) throws -> ReturnType |
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
Name | Type | Description |
---|---|---|
implementation | @escaping (P0,P1,P2,P3,P4) throws -> ReturnType |
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
Name | Type | Description |
---|---|---|
implementation | @escaping (P0,P1,P2,P3,P4,P5) throws -> ReturnType |
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
Name | Type | Description |
---|---|---|
implementation | @escaping (P0,P1,P2,P3,P4,P5,P6) throws -> ReturnType |
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
Name | Type | Description |
---|---|---|
implementation | @escaping (P0,P1,P2,P3,P4,P5,P6,P7) throws -> ReturnType |
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
Name | Type | Description |
---|---|---|
implementation | @escaping (P0,P1,P2,P3,P4,P5,P6,P7,P8) throws -> ReturnType |
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
Name | Type | Description |
---|---|---|
implementation | @escaping (P0,P1,P2,P3,P4,P5,P6,P7,P8,P9) throws -> ReturnType |
A closure implementation stub to evaluate. |
Returns
The current stubbing manager which can be used to chain additional stubs.