I am creating a small library for processing files and uploading files for me, and I am trying to integrate a test suite into it. Instead of using delegate callback methods, I process asynchronous responses in the completion handler block as follows:
SyncKit *engine = [[SyncKit alloc] init]; NSURL *localFilePath = [NSURL URLWithString:@"/Users/justin/Desktop/FileTest.png"]; [engine uploadFileWithFilename:@"FileTest.png" toRemotePath:@"/" fromLocalPath:localFilePath withCompletionHandler:^(id response, NSError *error) { if (error) { NSLog(@"error = %@", error); return; } NSLog(@"File uploaded and return JSON response = %@", response); }];
The main uploadFileWithFilename... method looks like this:
- (void)uploadFileWithFilename:(NSString *)filename toRemotePath:(NSString *)remotePath fromLocalPath:(NSURL *)localPath withCompletionHandler:(SKCompletionHandler)handler { if ((![[NSFileManager defaultManager] fileExistsAtPath:[localPath path]])) { NSDictionary *userInfo = [NSDictionary dictionaryWithObject:localPath forKey:@"localPath"]; NSError *error = [NSError errorWithDomain:SKDropboxErrorDomain code:SKDropboxErrorFileNotFound userInfo:userInfo]; handler(nil, error); return; }
I saw one example where a guy used a preprocessor to identify and inject OCMock into the actual code base. This seems to me wrong.
What would be the best strategy for checking code?
source share