user481610
user481610

Reputation: 3270

Capturing Block passed into method when using OCMock

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?

Upvotes: 0

Views: 283

Answers (1)

Erik Doernenburg
Erik Doernenburg

Reputation: 3014

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

Upvotes: 1

Related Questions