You can do what I think you are trying to achieve by creating a mock object that stands for the delegate and then checking that the mock object receives the delegate responses you expect. Thus, the process will look like this:
- Create a mock object that matches the delegate protocol:
id delegateMock = [KWMock mockForProtocol:@protocol(YourProtocol)];
- set mock as a 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";
- establish a statement that the layout should be called using the method and the response object (in this case, I expect to get
managerRepliedWithResponse and foo )
[[[delegateMock shouldEventually] receive] managerRepliedWithResponse:response];
[manager performMyMethod];
The key sets the expected value before the method is called and uses shouldEventually , which delays the checked statement and gives the manager object time to execute the method.
There are a number of expectations you can also use that are listed on the Kiwi wiki - https://github.com/allending/Kiwi/wiki/Expectations
I wrote the process in more detail in a post on my site , although it is more specifically oriented to the situation I was dealing with.
source share