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

OCMExpect() broken for OCMockObject::notificationWithName:object:userInfo: #227

Closed
markeissler opened this issue Aug 21, 2015 · 2 comments
Closed

Comments

@markeissler
Copy link

In short, this doesn't work (returns "unrecognized selector sent to instance"):

OCMExpect([mockObserver notificationWithName:@"MyNotification" object:[OCMArg any] userInfo:[OCMArg any]]);

But this (the old syntax) does...

[[mockObserver expect] notificationWithName:@"MyNotification" object:[OCMArg any] userInfo:[OCMArg any]];

Omitting the userInfo: parameter in the first example works provided that the notification sends nil for userInfo.

@erikdoe
Copy link
Owner

erikdoe commented Aug 27, 2015

Observer mocks are not supported by the (now not so) new syntax with macros. The documentation deliberately shows only the selector-based syntax: http://ocmock.org/reference/#observer-mocks

I'll leave this issue open as a reminder that I should add something for observer mocks to make them work with the new syntax.

The underlying issue is that the macro always creates a recorder for normal methods (

OCMExpectationRecorder *recorder = [[[OCMExpectationRecorder alloc] init] autorelease];
) but the expect method on the observer mock returns a special notification recorder (
OCMObserverRecorder *recorder = [[[OCMObserverRecorder alloc] init] autorelease];
[recorders addObject:recorder];
return recorder;
).

When I got to the release of OCMock 3, I couldn't think of a good way to resolve this, short of merging the observer recorder functionality into the other recorder, which I didn't like. Any ideas?

@erikdoe
Copy link
Owner

erikdoe commented Nov 19, 2019

This was implemented a long time ago. Forgot to close this issue.

@erikdoe erikdoe closed this as completed Nov 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants