Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c OCMock和block_Objective C_Objective C Blocks_Ocmock - Fatal编程技术网

Objective c OCMock和block

Objective c OCMock和block,objective-c,objective-c-blocks,ocmock,Objective C,Objective C Blocks,Ocmock,我有一个具有以下签名的方法,我想使用OCMock的存根特性对其进行测试: - (void)signInWithEmail:(NSString *)email andWithPassword:(NSString *)password andWithBlock:(void (^)(GNCustomer *customer, NSError *error))block 我将如何通过模拟来处理返回的块 我试过: [[_mockAuthenticationRepository stub] signInW

我有一个具有以下签名的方法,我想使用OCMock的存根特性对其进行测试:

- (void)signInWithEmail:(NSString *)email andWithPassword:(NSString *)password andWithBlock:(void (^)(GNCustomer *customer, NSError *error))block
我将如何通过模拟来处理返回的块

我试过:

[[_mockAuthenticationRepository stub] signInWithEmail:[OCMArg any] andWithPassword:[OCMArg any] andWithBlock:^(GNCustomer *customer, NSError *error) {

            }];
当我尝试使用这种方法存根时,我收到了调用的意外方法,这表明我的存根没有被使用

谢谢

我想出来了:)答案如下:

[[[_mockAuthenticationRepository stub] andDo:^(NSInvocation *invocation) {
                void (^successBlock)(GNCustomer *customer, NSError *error) = nil;

                [invocation getArgument:&successBlock atIndex:4];

                NSDictionary *details = @{ NSLocalizedDescriptionKey : [OCMArg any] };
                NSError *error = [NSError errorWithDomain:@"Some Domain" code:401 userInfo:details];

                successBlock(nil, error);
            }] signInWithEmail:[OCMArg any] andWithPassword:[OCMArg any] andWithBlock:[OCMArg any]];

atIndex选项还引用方法签名中的点,该块从第一个参数的索引2开始调用。