You can do what I think you're trying to achieve by creating a mock object that stands in for the delegate, and then checking that the mock object receives the delegate callbacks that you expect. So the process would look like:
- create a mock object that conforms to the delegate protocol:
id delegateMock = [KWMock mockForProtocol:@protocol(YourProtocol)];
- set the mock as the delegate of your manager class:
[manager setDelegate:delegateMock];
- create an object containing the data that will be returned by your manager class:
NSString *response = @"foo";
- set the assertion that the mock should eventually be called with the method and response object (in this case, I'm expecting to receive
managerRepliedWithResponse
and foo
)
[[[delegateMock shouldEventually] receive] managerRepliedWithResponse:response];
- call the method under test:
[manager performMyMethod];
The key is setting the expectation before you call the method, and using shouldEventually
which delays the assertion being checked and gives the manager
object time to perform the method.
There's a range of expectations you can also use that are listed on the Kiwi wiki - https://github.com/allending/Kiwi/wiki/Expectations
I've written the process up in more detail in a post on my site, albeit that it's more specifically geared-up to the situation I was dealing with.