MakeAWishFoundation / SwiftyMocky

Framework for automatic mock generation. Adds a set of handy methods, simplifying testing. One of the best and most complete solutions, including generics support and much more.
MIT License
1.04k stars 106 forks source link

Invalid redeclaration error when generating some async method mocks #304

Open hufkens opened 2 years ago

hufkens commented 2 years ago

We are using async functions and we ran into a problem while generating mocks.

We have an APIClient that has these methods:

func request<T: Decodable>(_ request: URLRequestConvertible) async throws -> T
func request(_ request: URLRequestConvertible) async throws

After generating the mocks SwiftyMocky v 4.1.0 we get this error: Invalid redeclaration of 'request(_:willThrow:)' because 2 methods have been generated.

public static func request(_ request: Parameter<URLRequestConvertible>, willThrow: Error...) -> MethodStub {
    return Given(method: .m_request__request_1(`request`), products: willThrow.map({ StubProduct.throw($0) }))
}

public static func request(_ request: Parameter<URLRequestConvertible>, willThrow: Error...) -> MethodStub {
    return Given(method: .m_request__request_2(`request`), products: willThrow.map({ StubProduct.throw($0) }))
}

We found this closed ticket https://github.com/MakeAWishFoundation/SwiftyMocky/issues/290 and for most of our code the tests without async work fine.

But we also saw that the new Sourcery added support for parsing async methods in their latest 1.7.0 update. https://github.com/krzysztofzablocki/Sourcery/blob/master/CHANGELOG.md

Would it be possible to look into supporting async in the new version?

Thanks Alain