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

Fulfill Expectation in an asynchronous Test #84

Closed
wants to merge 4 commits into from

Conversation

anagromataf
Copy link
Contributor

Extend the stubbing mechanism to let a stub fulfill an expectation of the asynchronous testing extension intruded in Xcode 6.

This extension lets you use a stub to fulfill an asynchronous test. This is useful, if you are testing a component and you have to wait until a certain delegate method has been called.

To use this, you have to enable the expectation matching (requires Xcode 6):

#define MOCKITO_EXPECTATION
#define MOCKITO_SHORTHAND
#import <OCMockito/OCMockito.h>

In your test you can now mock for example a delegate protocol and wait until a delegate method has been called.

// Prepare the stub and add an expectation …
id <MyDelegate> delegate = mockProtocol(@protocol(MyDelegate));
[given([delegate didFinish]) willFulfill:expectation(@"Did finish")];

// … start you test ...

// … and wait for the expectation.
[self waitForExpectationsWithTimeout:20 handler:nil];

This extension works as expected in the project where I want to use it. But I'm not so familiar the insides of OCMockito, thus I don't know, if there is a better way to implement this feature.

@jonreid
Copy link
Owner

jonreid commented Jun 24, 2015

Tobias, thanks for giving this a try. But I'm going to go with #35 which puts the async verification as part of verify which is more in line with the Mockito pattern of specifying expectations at the end of a test, not the beginning.

@jonreid jonreid closed this Jun 24, 2015
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

Successfully merging this pull request may close these issues.

2 participants