Instance Method

mockable(_:function:file:line:)

Creates a MockableSubscript.Writable for a subcript.

Declaration

func mockable<ReturnType>(_ parameters: ParameterType..., function: String = #function, file: StaticString = #file, line: UInt = #line) -> MockableSubscript.Writable<ReturnType>

Return Value

A new MockableSubscript.Writable<ReturnType> that will be able to create stubs for the subcript.

Parameters

function

Function concerned by the MockableSubscript.

file

The file name where the method is called.

line

The line where the method is called.

Discussion

You must use it during the extension of Given.


protocol CustomType {
  subscript(parameter1: String, parameter2: Int) -> Int { get set }
}
extension Given where WrappedType == CustomType {
  subscript(parameter1: String, parameter2: Int) -> MockableSubscript.Writable<Int> {
    mockable(parameter1, parameter2)
  }
}