OCMock和块

斯特里克兰

我有一个具有以下签名的方法,我想使用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]];

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章