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

Fix multiple calls in same recorder #485

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dmaclach
Copy link
Contributor

@dmaclach dmaclach commented Feb 2, 2021

This is intended as a fix for #478

Comment on lines +98 to +104
if([self didRecordInvocation] && [self currentlyRecordingInMacro])
{
[NSException raise:NSInvalidArgumentException
format:@"Recorder attempting to record `%s` but recorder has already recorded a stub for: `%@`. "
@"Are there multiple invocations on mocks in a single macro?",
sel_getName(aSelector), [self description]];
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not move this block into forwardInvocation:? There's another assert there anyway, and I cannot see a benefit for detecting this case here.

{
returnValue = mockObject;
}
else if ([anInvocation methodIsInCreateFamily])
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure this needs to be in an else branch. Somehow I find the implementation confusing. First we set a "default" return value outside the if statement, then we overwrite it in the if statement, or, alternatively, we manipulate the original value in an else-if. I get why the inCreateFamily check is there, and it's a good additional fix to the change in the PR, but I think I'd restructure this when merging. (No action needed on your part.)

Comment on lines +89 to +92
- (BOOL)currentlyRecordingInMacro
{
return [[OCMMacroState globalState] recorder] == self;
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we move the check from methodSignatureForSelector: to forwardInvocation: then the code in this method is only needed once. I find the name confusing and can't think of a better name. In any case, I think any name wouldn't add much to explain what's happening and given this method is only needed once I'd inline it.

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

Successfully merging this pull request may close these issues.

2 participants