-
Notifications
You must be signed in to change notification settings - Fork 608
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
Multiprotocols mocking and class+protocols combination mocking #309
base: master
Are you sure you want to change the base?
Conversation
51227bd
to
bfa3496
Compare
@@ -22,7 +22,7 @@ | |||
Class originalMetaClass; | |||
} | |||
|
|||
- (id)initWithClass:(Class)aClass; | |||
- (id)initWithClass:(Class)aClass protocols:(NSArray *)protocols; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is way too invasive. At an absolute minimum we'd have to keep the original initWithClass:
method, and make it forward to the proposed new initWithClass:protocols:
method. That way, the number of changes in the PR would be greatly reduced.
} | ||
|
||
+ (id)mockForProtocol:(Protocol *)aProtocol | ||
+ (id)mockForProtocols:(Protocol *)aProtocol, ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above. This change is way too invasive. At an absolute minimum we'd have to keep the original mockForProtocol:
method, and make it forward to the proposed new mockForProtocols:
method. That way, the number of changes in the PR would be greatly reduced.
} | ||
|
||
+ (id)partialMockForObject:(NSObject *)anObject | ||
{ | ||
return [[[OCPartialMockObject alloc] initWithObject:anObject] autorelease]; | ||
} | ||
|
||
|
||
+ (id)niceMockForClass:(Class)aClass | ||
+ (id)niceMockForClass:(Class)aClass protocols:(Protocol *)aProtocol, ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above.
@@ -16,19 +16,13 @@ | |||
|
|||
#import <XCTest/XCTest.h> | |||
#import <OCMock/OCMock.h> | |||
#import "TestProtocol.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please do not move classes that are for tests only to their own files. This just increases clutter.
|
||
- (void)testCanMockMultipleProtocols | ||
{ | ||
id mock = OCMProtocolMock(@protocol(NSLocking), @protocol(TestProtocol)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why use the macro version here?
I like the general idea. And thank you for putting the effort into including unit tests. That said, the way the change is written now it is way too invasive. My main concern is that existing init methods were changed, which results in a large number of changes. I've commented on some of them. Was there a reason why you didn't keep the old methods (without protocols / with single protocol) and have them forward to the new ones (with protocol / with multiple protocols)? |
Well, it's just better to have single entry point for unit testing instead of multiple ones, the latter increase the amount of paths to be covered. Verification of forwarding methods is tricky (we cannot use OCMock partial mocking for testing OCMock itself) and I always try to avoid that. But I respect your concern, so I'll put old methods back. |
My main issue is compatibility. If this was application code, owned by a single team, I would also make the changes as you suggested. However, OCMock is a framework that is used by lots of different people. In that case, I believe keeping the API backwards compatible is the more important concern. |
It's now possible to create mocks for multiple protocols and also for class and protocols combination.