4

私は OCMock を初めて使用し、リクエスト呼び出しをモックする予定です。モックする必要がある API は、以下に定義されているように実行されます。

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

requestProductUpdateUrlOCMock を使用してメソッドをモックする方法について何か考えはありますか?

4

1 に答える 1

0

この機能はまだ実装されていませんが、取り組んでいると思います。私もこのようなことをしなければなりませんでした:

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];

待機関数を使用すると、次のようになります。

- (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!");
}

}

于 2013-11-28T20:23:11.927 に答える