OCMock: Mocking protocols with excluding optional methods

Viewed 2450

I'm using OCMock for creating mocks in my tests for my iOS app, and I'd like to create mocks of protocols that don't implement all of the optional methods.

If it's not clear what I mean... here's some code:

// Protocol definition
@protocol MyAwesomeProtocol
    - (void)doThatRequiredThing;
    @optional
    - (void)doThatOptionalThing;
@end

...

// In a test
id mock = [OCMockObject mockObjectForProtocol:@protocol(MyAwesomeProtocol)];

// This should return YES:
[mock respondsToSelector:@selector(doThatRequiredThing)];
// This should return NO:
[mock respondsToSelector:@selector(doThatOptionalThing)];
2 Answers
Related