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

Multiprotocols mocking and class+protocols combination mocking #309

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

tarbayev
Copy link

@tarbayev tarbayev commented Aug 25, 2016

It's now possible to create mocks for multiple protocols and also for class and protocols combination.

@tarbayev tarbayev closed this Aug 25, 2016
@tarbayev tarbayev reopened this Aug 26, 2016
@tarbayev tarbayev changed the title Class with protocols combo mock Multiprotocols mocking and class+protocols combination mocking Aug 26, 2016
@@ -22,7 +22,7 @@
Class originalMetaClass;
}

- (id)initWithClass:(Class)aClass;
- (id)initWithClass:(Class)aClass protocols:(NSArray *)protocols;
Copy link
Owner

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, ...
Copy link
Owner

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, ...
Copy link
Owner

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"
Copy link
Owner

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));
Copy link
Owner

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?

@erikdoe
Copy link
Owner

erikdoe commented Dec 13, 2016

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)?

@tarbayev
Copy link
Author

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.

@erikdoe
Copy link
Owner

erikdoe commented Dec 15, 2016

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants