Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Capturing arguments? #15

Closed
codyaray opened this issue Feb 6, 2013 · 5 comments
Closed

Capturing arguments? #15

codyaray opened this issue Feb 6, 2013 · 5 comments

Comments

@codyaray
Copy link

codyaray commented Feb 6, 2013

Is there a mechanism to capture arguments?

Most asynchronous APIs (especially for networking libraries) accept completion blocks. It'd be awesome to be able to capture the completion block and test against it.

For example, suppose I mock a NSURLConnector. (Thanks for showing me we can mock class methods earlier today on StackOverflow!) Then I want to verify that my code calls sendAsynchronousRequest:queue:completionHandler. I'd love to capture the completionBlock and verify the operations in the completion handler.

myblock = //... something I can test against
[verify(connector) sendAsynchronousRequest:urlRequest queue:queue completionHandler:capture(myblock)];

This request is similar to this request for Kiwi.

@jonreid
Copy link
Owner

jonreid commented Feb 22, 2013

Argument capturing isn't present today, but has been on my wish list.

@codyaray
Copy link
Author

codyaray commented Jun 6, 2013

@jonreid - are we any closer to this elusive dream? :)

@crispinb
Copy link

crispinb commented Aug 8, 2013

Another reason for wanting argument capture is that it makes it possible to then use asserts on the captured arguments. These are more informative on failure than the messages emitted when using hamcrest matchers directly in a verify().

@jonreid
Copy link
Owner

jonreid commented Oct 2, 2013

I've started on this

@jonreid
Copy link
Owner

jonreid commented Oct 14, 2013

Give it a try! See ArgumentCaptorTest.m for examples.

@jonreid jonreid closed this as completed Oct 14, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants