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

Rename "wasUsed" to "ocm_wasUsed" #429

Closed
wants to merge 1 commit into from
Closed

Conversation

dmaclach
Copy link
Contributor

Objects that we were mocking had a wasUsed field that prevented them from being easily mocked using OCMStub, OCMExpect etc.

All future methods in recorders should be prefixed with ocm_ to prevent potential conflicts.

Objects that we were mocking had a wasUsed field that prevented them from being
easily mocked using OCMStub, OCMExpect etc.

All future methods in recorders should be prefixed with ocm_ to prevent
potential conflicts.
@erikdoe
Copy link
Owner

erikdoe commented Jun 4, 2020

To be honest, conceptually I get the issue, but I'm not sure about changing one method and stating future methods should have a prefix and then changing one of the existing ones, but not all of them. Of course, I see (now) that wasUsed has a much higher chance of a clash than the other methods. Maybe the solution to your problem would be to rename wasUsed to didRecordMethod or something similar, which has an equally low chance to clash as the other methods on recorder.

@dmaclach
Copy link
Contributor Author

dmaclach commented Jun 6, 2020 via email

@carllindberg
Copy link
Contributor

Technically that guidance is adding methods to classes you don't "own", i.e. categories. Granted, these are NSProxy subclasses, and any method on them will prevent the forwardInvocation: stuff from being called, meaning methods of the same names in "real" classes cannot be mocked -- so this is something of a similar situation. I generally agree that the proxy subclasses should not have generically-named methods.

On the other hand, I can understand not wanting to use an "ocm_" prefix, but use other method names that somewhat scope things to OCMock internals to make name collisions very unlikely. People can always adjust their own method names to avoid collisions, too, if OCMock's names are specific enough. The "location" method could be "recordingLocation" or "mockLocation" or something else that reads better than having explicit prefixes. That's more a stylistic thing so more Erik's call -- though I would agree that it would be best to be consistent, and either change all of them or none, and don't mix.

@erikdoe erikdoe added this to the OCMock 3.7 milestone Jun 22, 2020
erikdoe added a commit that referenced this pull request Jul 2, 2020
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.
@erikdoe
Copy link
Owner

erikdoe commented Jul 2, 2020

So, I ended up with not using a prefix but a method name that is much less likely to cause a clash. I've left more detail in the commit message on 461c694.

@erikdoe erikdoe closed this Jul 2, 2020
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.

None yet

3 participants