使用OCMock时捕获块传入方法

时间:2022-04-28 20:49:33

I'm looking to capture a block that is passed into a mock object. Here is the concrete function of class being mocked:

我想捕获一个传递给模拟对象的块。这是被嘲笑的类的具体功能:

[self.imageFetcher fetchImageWithURL:url success:^(NSURL *successUrl, UIImage *image) {
       //Implementation Details here
}];

Here is the my attempt to capturing the block:

这是我尝试捕获块:

OCMExpect([imageFetcher fetchImageWithURL:urlForSuccess success:[OCMArg checkWithBlock:^(void(^myBlock)(NSURL *,UIImage *)){
        myBlock(urlForSuccess,[UIImage new]);
        return YES;
    }]]);

However, this doesn't seem to be working. How can I use the checkWithBlock to capture the block and be able to call that block with parameters I choose?

但是,这似乎不起作用。如何使用checkWithBlock捕获块并能够使用我选择的参数调用该块?

1 个解决方案

#1


1  

If you want to invoke the block that is passed to the mock, then you should use [OCMArg invokeBlock]. See section 2.6 in the documentation for details: http://ocmock.org/reference/#stubing-methods

如果要调用传递给mock的块,则应使用[OCMArg invokeBlock]。有关详细信息,请参阅文档中的第2.6节:http://ocmock.org/reference/#stubing-methods

#1


1  

If you want to invoke the block that is passed to the mock, then you should use [OCMArg invokeBlock]. See section 2.6 in the documentation for details: http://ocmock.org/reference/#stubing-methods

如果要调用传递给mock的块,则应使用[OCMArg invokeBlock]。有关详细信息,请参阅文档中的第2.6节:http://ocmock.org/reference/#stubing-methods