Skip to content

Commit

Permalink
Renamed method to avoid clashes.
Browse files Browse the repository at this point in the history
This is an alternative to #429. Note that I removed the setting of the flag in `doesNotRecognizeSelector:`. This seemed superfluous now because the only code that checks the flag first checks whether the invocation threw. Because of that I chose the name didRecord, and not didReceive. The latter would have been more precise if I had kept the setting of the flag in `doesNotRecognizeSelector:`.

I am aware that using a prefix would have decreased chances of a clash even further, but I think this is good enough and it's more consistent with the rest of the codebase for now.
  • Loading branch information
erikdoe committed Jul 2, 2020
1 parent e9e61d1 commit 461c694
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 11 deletions.
4 changes: 2 additions & 2 deletions Source/OCMock/OCMMacroState.m
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ + (OCMStubRecorder *)endStubMacro
OCMStubRecorder *recorder = [[(OCMStubRecorder *)[globalState recorder] retain] autorelease];
BOOL didThrow = [globalState invocationDidThrow];
[threadDictionary removeObjectForKey:OCMGlobalStateKey];
if(didThrow == NO && [recorder wasUsed] == NO)
if(didThrow == NO && [recorder didRecordInvocation] == NO)
{
[NSException raise:NSInternalInconsistencyException
format:@"Did not record an invocation in OCMStub/OCMExpect/OCMReject.\n"
Expand Down Expand Up @@ -106,7 +106,7 @@ + (void)endVerifyMacro
OCMVerifier *verifier = [[(OCMVerifier *)[globalState recorder] retain] autorelease];
BOOL didThrow = [globalState invocationDidThrow];
[threadDictionary removeObjectForKey:OCMGlobalStateKey];
if(didThrow == NO && [verifier wasUsed] == NO)
if(didThrow == NO && [verifier didRecordInvocation] == NO)
{
[NSException raise:NSInternalInconsistencyException
format:@"Did not record an invocation in OCMVerify.\n"
Expand Down
2 changes: 1 addition & 1 deletion Source/OCMock/OCMObserverRecorder.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@

- (BOOL)argument:(id)expectedArg matchesArgument:(id)observedArg;

- (BOOL)wasUsed;
- (BOOL)didRecordInvocation __used;

@end
2 changes: 1 addition & 1 deletion Source/OCMock/OCMObserverRecorder.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ - (void)dealloc
[super dealloc];
}

- (BOOL)wasUsed
- (BOOL)didRecordInvocation
{
return YES; // Needed for macro use, and recorder can only end up in macro state if it was used.
}
Expand Down
4 changes: 2 additions & 2 deletions Source/OCMock/OCMRecorder.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
{
OCMockObject *mockObject;
OCMInvocationMatcher *invocationMatcher;
BOOL wasUsed;
BOOL didRecordInvocation;
BOOL shouldReturnMockFromInit;
}

Expand All @@ -36,7 +36,7 @@
- (void)setShouldReturnMockFromInit:(BOOL)flag;

- (OCMInvocationMatcher *)invocationMatcher;
- (BOOL)wasUsed;
- (BOOL)didRecordInvocation;

- (id)classMethod;
- (id)ignoringNonObjectArgs;
Expand Down
9 changes: 4 additions & 5 deletions Source/OCMock/OCMRecorder.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ @implementation OCMRecorder
- (instancetype)init
{
// no super, we're inheriting from NSProxy
wasUsed = NO;
didRecordInvocation = NO;
shouldReturnMockFromInit = NO;
return self;
}
Expand Down Expand Up @@ -65,9 +65,9 @@ - (OCMInvocationMatcher *)invocationMatcher
return invocationMatcher;
}

- (BOOL)wasUsed
- (BOOL)didRecordInvocation
{
return wasUsed;
return didRecordInvocation;
}


Expand Down Expand Up @@ -111,7 +111,7 @@ - (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector
- (void)forwardInvocation:(NSInvocation *)anInvocation
{
[anInvocation setTarget:nil];
wasUsed = YES;
didRecordInvocation = YES;
[invocationMatcher setInvocation:anInvocation];

// Code with ARC may retain the receiver of an init method before invoking it. In that case it
Expand All @@ -128,7 +128,6 @@ - (void)forwardInvocation:(NSInvocation *)anInvocation

- (void)doesNotRecognizeSelector:(SEL)aSelector __used
{
wasUsed = YES;
[NSException raise:NSInvalidArgumentException format:@"%@: cannot stub/expect/verify method '%@' because no such method exists in the mocked class.", mockObject, NSStringFromSelector(aSelector)];
}

Expand Down

0 comments on commit 461c694

Please sign in to comment.