You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello!
Cuckoo works well to create mocks for some of my simpler classes, but it is not working for models that have a pretty complicated hierarchy - appreciate if someone can help me get around this problem!
For classes that implement a protocol, cuckoo tries to override read only properties in generated mocks which doesn't compile. Best to explain with an example.
eg
protocol DemoProtocol {
var id: String { get }
}
class Demo: DemoProtocol {
let id: String
let name: String
init(id: String, name: String) {
self.id = id
self.name = name
}
}
Since the protocol needs to declare id as a var (Swift protocols cannot require properties to be immutable), Cuckoo tries to override id, which of course doesn't compile.
Generated mocks for this file:
class MockDemo: Demo, Cuckoo.ClassMock {
typealias MocksType = Demo
typealias Stubbing = __StubbingProxy_Demo
typealias Verification = __VerificationProxy_Demo
let cuckoo_manager = Cuckoo.MockManager.preconfiguredManager ?? Cuckoo.MockManager(hasParent: true)
private var __defaultImplStub: Demo?
func enableDefaultImplementation(_ stub: Demo) {
__defaultImplStub = stub
cuckoo_manager.enableDefaultStubImplementation()
}
override var id: String { //⚠️ Compile error: Cannot override immutable 'let' property 'id' with the getter of a 'var'
get {
return cuckoo_manager.getter("id",
superclassCall:
super.id
,
defaultCall: __defaultImplStub!.id)
}
}
Compiler error:
Error: Cannot override immutable 'let' property 'id' with the getter of a 'var'
Any advice on how to get around this?
The text was updated successfully, but these errors were encountered:
Hello!
Cuckoo works well to create mocks for some of my simpler classes, but it is not working for models that have a pretty complicated hierarchy - appreciate if someone can help me get around this problem!
For classes that implement a protocol, cuckoo tries to override read only properties in generated mocks which doesn't compile. Best to explain with an example.
eg
Since the protocol needs to declare
id
as a var (Swift protocols cannot require properties to be immutable), Cuckoo tries to overrideid
, which of course doesn't compile.Generated mocks for this file:
Compiler error:
Error: Cannot override immutable 'let' property 'id' with the getter of a 'var'
Any advice on how to get around this?
The text was updated successfully, but these errors were encountered: