0.0.5 introduced relaxed mode for literal expressible types.
There are two issues with the current implementation though:
If a type conforms to more than 1 of the ...LiteralExpressible protocols, the generated mock implementation will not build as the generic mock function overloads will be ambigous.
Services rarely return literal expressible values like Int or String, instead they usually return some custom type which is not supported by the current implementation of relaxed mode
This PR replaces the literal expressible overloads of the mock function with a single overload that uses a custom Mockable protocol to infer auto-mockable types.
Mockable in combination with the relaxed Mockable option of MockerPolicycan be used
to set an implicit return value for custom types:
struct Car {
var name: String
var seats: Int
}
extension Car: Mockable {
static var mock: Car {
Car(name: "Mock Car", seats: 4)
}
// Defaults to [mock] but we can
// provide a custom array of cars:
static var mocks: [Car] {
[
Car(name: "Mock Car 1", seats: 4),
Car(name: "Mock Car 2", seats: 4)
]
}
}
@Mockable
protocol CarService {
func getCar() -> Car
func getCars() -> [Car]
}
func testCarService() {
func test() {
let mock = MockCarService(policy: .relaxedMockable)
// Implictly mocked without a given registration:
let car = mock.getCar()
let cars = mock.getCars()
}
}
0.0.5 introduced relaxed mode for literal expressible types.
There are two issues with the current implementation though:
...LiteralExpressible
protocols, the generated mock implementation will not build as the generic mock function overloads will be ambigous.Int
orString
, instead they usually return some custom type which is not supported by the current implementation of relaxed modeThis PR replaces the literal expressible overloads of the mock function with a single overload that uses a custom
Mockable
protocol to infer auto-mockable types.Mockable
in combination with therelaxed Mockable
option ofMockerPolicy
can be used to set an implicit return value for custom types: