InstantMock
InstantMock copied to clipboard
Arg.eq(protocol)
How to do that since I cant make a protocol extends MockUsable?
@pirishd Hello? Could you help me?
hi, @igordeoliveirasa the trick is to have a class or a struct which will conform to both a protocol of an argument which you want to constraint and MockUsable
protocol URLProtocol {}
class URLProtocolStub: URLProtocol {}
extension URLProtocolStub: MockUsable {
public static let anyValue: MockUsable = URLProtocolStub()
public func equal(to value: MockUsable?) -> Bool {
if let value = value as? Self {
return self === value
}
return false
}
}
class NetworkClientMock: Mock {
func fetch(from url: URLProtocol) {
super.call(url)
}
}
func test() {
let mock = NetworkClientMock()
let urlStub = URLProtocolStub()
mock.expect().call(mock.fetch(from: Arg<URLProtocolStub>.eq(urlStub)))
}