Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
446 views
in Technique[技术] by (71.8m points)

unit testing - Using Cuckoo with Swift, why is the call to `stub` complaining that the class from GeneratedMocks doesn't conform to Mock protocol?

Using Cuckoo 1.4.1, I get the error

Global function 'stub(_:block:)' requires that 'DeepFileManager' conform to 'Mock'

I don't know how to proceed, because the instance passed to the stub function was created from the class in GeneratedMocks.swift. The reference to DeepFileManager is the class that is mocked.

So it's a mystery to me why Swift 4 would complain about the conformance of the superclass of the instance I've passed to it. Can you lead me out of this conundrum?

Here's the code for the test:

class RecordingTests: QuickSpec {
    override func spec() {
        let FAKE_ID = "String";
        let mockFileManager: MockDeepFileManager = MockDeepFileManager()
        let cut = Recording(id: FAKE_ID, date: nil, status: nil, device: nil, deviceId: nil, deviceName: nil, fileManager: mockFileManager)
        describe("A recording") {
            context("when it's not on disk") {
                it("responds that filePresent is false") {
                    stub(mockFileManager) {stub in
                        when(stub.fileExists(audioId: FAKE_ID)).then()
                    }
                    expect(cut.filePresent()).to(equal(false))
                    verify(mockFileManager).fileExists(audioId: "Matchable")
                }
            }
        }
    }

And here's the declaration of MockDeepFileManager from GeneratedMocks.swift:

 class MockDeepFileManager: DeepFileManager, Cuckoo.ClassMock {
question from:https://stackoverflow.com/questions/65672067/using-cuckoo-with-swift-why-is-the-call-to-stub-complaining-that-the-class-fr

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...