danielsaidi / MockingKit

MockingKit is a Swift SDK that lets you easily mock protocols and classes in `Swift`.
MIT License
87 stars 7 forks source link

Mock doesn't work when imported from another framework #7

Closed danielsaidi closed 4 years ago

danielsaidi commented 4 years ago

If you import a mock from another library, the function address will be different in the two libraries.

// In MyLibrary

public class MyMock: Mock {

    public func doit(thing: String) {
        invoke(doit, args: (thing))
    }

    public func getAddress() -> MemoryAddress {
        address(of: doit)
    }
}

// In MyLibraryTests

class GenericTests: QuickSpec {
    override func spec() {

        describe("memory address") {

            it("should be equal") {
                let obj = MyMock()
                obj.doit(thing: "")
                let addr1 = obj.getAddress()
                let addr2 = obj.address(of: obj.doit)  // Should be equal to addr1, will be different
                let inv = cl.invokations(of: cl.doit)      // Should be 1, will be 0
            }
        }
    }
}

This may seem like a non-problem, but we face problems when using mocks in our monorepo, since we want to provide a set of mocks across multiple test projects.

danielsaidi commented 4 years ago

This works in 0.4.0