Use OCMock to calculate block expectations

I am new to OCMock and I plan on making fun of the request. The API to be mocked is executed as defined below.

[ProductRequest requestProductUpdateUrl: @"testUrl" withParameters:params error:^(NSString *updateUrl, NSError *error){ if (!error && [updateUrl length] !=0 ) { NSLog(@"Success"); } else { NSLog(@"Error"); } }]; 

Any idea on how I can mock the requestProductUpdateUrl method using OCMock?

+4
source share
1 answer

This feature has not yet been implemented, although I think they are working on it. I also had to do something like this:

 semaphore = dispatch_semaphore_create(0); [myObject myFunctionWithCallback:^(BOOL success){ if(success) dispatch_semaphore_signal(semaphore); else STFail(@"Call failed"); dispatch_semaphore_signal(semaphore); }]; [self waitForSemaphore]; 

With the wait function, something like this:

 - (void)waitForSemaphore; { float step_duration = .1; float wait_steps = 2 / step_duration; while (dispatch_semaphore_wait(semaphore, dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_SEC / 10)) && wait_steps > 0){ CFRunLoopRunInMode(kCFRunLoopDefaultMode,step_duration, YES); wait_steps--; } if (wait_steps <= 0) { STFail(@"Timeout!"); } 

}

0
source

Source: https://habr.com/ru/post/1439128/


All Articles