describe(@"URServiceDiscoveryWrapper", ^{
context(@"method getHomeCountryWithCompletion:", ^{
__block id mockedServiceDiscovery;
beforeEach(^{
mockedServiceDiscovery = [KWMock mockForProtocol:@protocol(AIServiceDiscoveryProtocol)];
});
it(@"should return error if ServiceDiscovery fails to return country", ^{
[[mockedServiceDiscovery should] receive:@selector(getHomeCountry:)];
KWCaptureSpy *serviceDiscoverySpy = [mockedServiceDiscovery captureArgument:@selector(getHomeCountry:) atIndex:0];
__block NSError *receivedError = nil;
URServiceDiscoveryWrapper *serviceDiscoveryWrapper = [[URServiceDiscoveryWrapper alloc] initWithServiceDiscovery:mockedServiceDiscovery];
[serviceDiscoveryWrapper getHomeCountryWithCompletion:^(NSString *countryCode, NSString *locale, NSDictionary *serviceURLs, NSError *error) {
[[countryCode should] beNil];
[[locale should] beNil];
[[serviceURLs should] beNil];
receivedError = error;
}];
void(^handler)(NSString *countryCode, NSString *sourceType, NSError *error);
handler = serviceDiscoverySpy.argument;
handler(nil, nil, [NSError errorWithDomain:@"ServiceDiscovery Domain" code:1002 userInfo:nil]);
[[expectFutureValue(receivedError) shouldNotEventuallyBeforeTimingOutAfter(3.0)] beNil];
});
What would be the equivalent code in Quick Nimble framework for the above test? I am new to Swift and testing frameworks. Hence, facing difficulty in adapting to Quick Nimble framework.
I tried doing this:
describe("URServiceDiscoveryWrapper") {
context("method getHomeCountryWithCompletion:") {
beforeEach {
class MockedServiceDiscovery: AIServiceDiscoveryProtocol {
func getHomeCountry(_ completionHandler: @escaping (_ countryCode: String, _ sourceType: String, _ error: Error?) -> Void) {
}
}
}
it("should return error if ServiceDiscovery fails to return country") {
var receivedError = nil;
var serviceDiscoveryWrapper = URServiceDiscoveryWrapper(init: MockedServiceDiscovery)
serviceDiscoveryWrapper.getHomeCountry(withCompletion: {(_ countryCode: String?, _ locale: String?, _ serviceURLs: Dictionary <String, String>?, _ error: Error?) -> Void in
expect(countryCode).to(beNil())
expect(locale).to(beNil())
expect(serviceURLs).to(beNil())
expect(receivedError).to(equal(error))
})
}
}
}
What I am not getting is how to mock and stub in Quick Nimble framework and I want to write the same test written in Kiwi framework in Quick Nimble framework. Anyone please help me out with this.