Open geraldeersteling opened 3 years ago
Hi, @geraldeersteling. Cuckoo needs the source code to parse it and find out which methods are declared, which it can't do from just the type unfortunately. The OCMock integration in Cuckoo might help with this, take a look at the tests and try it out.
This is as well a problem with opensource classes/protocols:
public class ClassExample {
@Published private(set) public var greetings: String = "Hello, World!"
}
public protocol ProtocolExample: ClassExample {
}
public class Example: ClassExample, ProtocolExample {
}
will generate
//
// ERROR: 'ProtocolExample' requires that 'MockProtocolExample' inherit from 'ClassExample'
//
public class MockProtocolExample: ProtocolExample, Cuckoo.ProtocolMock {
// ...
public var greetings: String {
get {
return cuckoo_manager.getter("greetings",
superclassCall:
Cuckoo.MockManager.crashOnProtocolSuperclassCall()
,
defaultCall: __defaultImplStub!.greetings)
}
}
// ...
public struct __StubbingProxy_ProtocolExample: Cuckoo.StubbingProxy {
private let cuckoo_manager: Cuckoo.MockManager
public init(manager: Cuckoo.MockManager) {
self.cuckoo_manager = manager
}
//
// ERROR: Type 'MockProtocolExample' does not conform to protocol 'ClassMock'
//
var greetings: Cuckoo.ClassToBeStubbedReadOnlyProperty<MockProtocolExample, String> {
return .init(manager: cuckoo_manager, name: "greetings")
}
}
}
(see two errors in code comments)
@bspinner does the example work without the @Published
?
Hello,
I'm fairly new with Cuckoo and got everything up and running. I do encounter an issue and I'm unable to find a solution in the issues here on GitHub (or I'm not searching for it the right way...).
Take this protocol for example:
Now when I run Cuckoo this gave me the following generated code:
Generated code
```swift class MockSlideDelegate: SlideDelegate, Cuckoo.ProtocolMock { typealias MocksType = SlideDelegate typealias Stubbing = __StubbingProxy_SlideDelegate typealias Verification = __VerificationProxy_SlideDelegate let cuckoo_manager = Cuckoo.MockManager.preconfiguredManager ?? Cuckoo.MockManager(hasParent: false) private var __defaultImplStub: SlideDelegate? func enableDefaultImplementation(_ stub: SlideDelegate) { __defaultImplStub = stub cuckoo_manager.enableDefaultStubImplementation() } func nextPressed(forSlide: Slide) { return cuckoo_manager.call("nextPressed(forSlide: Slide)", parameters: (forSlide), escapingParameters: (forSlide), superclassCall: Cuckoo.MockManager.crashOnProtocolSuperclassCall() , defaultCall: __defaultImplStub!.nextPressed(forSlide: forSlide)) } func previousPressed(forSlide: Slide) { return cuckoo_manager.call("previousPressed(forSlide: Slide)", parameters: (forSlide), escapingParameters: (forSlide), superclassCall: Cuckoo.MockManager.crashOnProtocolSuperclassCall() , defaultCall: __defaultImplStub!.previousPressed(forSlide: forSlide)) } struct __StubbingProxy_SlideDelegate: Cuckoo.StubbingProxy { private let cuckoo_manager: Cuckoo.MockManager init(manager: Cuckoo.MockManager) { self.cuckoo_manager = manager } func nextPressedHowever the generated mocks are no UIView's rather just classes which conform to the
Slide
protocol. Subsequently giving me the following errors while compiling:Slide
requires thatMockSlide
inherit from `UIViewSlide
requires thatSlideStub
inherit from `UIViewHow can I fix this, or is this 'just how things work'?