I'm working with a very simple web service that uses a base class to reuse some commonly used functionality. The main method under test simply builds a url and then it uses a super / base method with this argument.
- (void)getPlacesForLocation:(Location *)location WithKeyword:(NSString *)keyword
{
NSString *gps = [NSString stringWithFormat:@"?location=%@,%@", location.lat, location.lng];
NSURL *url = [[NSURL alloc] initWithString:[NSString stringWithFormat:@"%@%@", self.baseurl, gps]];
[super makeGetRequestWithURL:url];
}
Here is the base method definition
@implementation WebService
@synthesize responseData = _responseData;
- (id)init
{
if (self == [super init])
{
self.responseData = [NSMutableData new];
}
return self;
}
- (void)makeGetRequestWithURL:(NSURL *)url
{
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
request.HTTPMethod = @"GET";
[[NSURLConnection alloc] initWithRequest:request delegate:self];
}
In my test I created a partial mock because I still want to call into my object under test, but I need the ability to verify the super method is invoked in a specific way.
- (void)testGetRequestMadeWithUrl
{
self.sut = [[SomeWebService alloc] init];
Location *location = [[Location alloc] initWithLatitude:@"-33.8670522" AndLongitude:@"151.1957362"];
NSURL *url = [[NSURL alloc] initWithString:[NSString stringWithFormat:@"%@%@", self.sut.baseurl, @"?location=-33.8670522,151.1957362"]];
id mockWebService = [OCMockObject partialMockForObject: self.sut];
[[mockWebService expect] makeGetRequestWithURL:url];
[self.sut getPlacesForLocation:location WithKeyword:@"foo"];
[mockWebService verify];
}
Yet when I run this test I fail with the following error:
expected method was not invoked: makeGetRequestWithURL:https://...
I can tell this method isn't being mock because if I put an NSLog into the base method it shows up when I run the ocunit test (clearly it's running, just not mocking it as I would like).
How can I modify my test / refactor my implementation code to get the assertion I'm looking for?