How can I verify that passing block is execute correctly ?
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
[self updatePostalCode:newLocation withHandler:^(NSArray *placemarks, NSError *error) {
// code that want to test
CLPlacemark *placemark = [placemarks objectAtIndex:0];
self.postalCode = [placemark postalCode];
_geocodePending = NO;
}];
....
}
I want to know that postalCode, _geocodePending is set correctly, but I can't figure out how to do this with OCMock.
Added code
id mockSelf = [OCMockObject partialMockForObject:_location];
id mockPlacemart = (id)[OCMockObject mockForClass:[CLPlacemark class]];
[[[mockPlacemart stub] andReturn:@"10170"] postalCode];
[mockSelf setGeocodePending:YES];
[mockSelf setPostalCode:@"00000"];
[self.location handleLocationUpdate]([NSArray arrayWithObject:mockPlacemart], nil);
STAssertFalse([mockSelf geocodePending], @"geocodePending should be FALSE");
STAssertTrue([[mockSelf postalCode] isEqualToString:@"10170"], @"10170", @"postal is expected to be 10170 but was %@" , [mockSelf postalCode]);