A way of observing invocations of nice mocks

Discussion of the OCMock framework. If you have patches we would prefer you to send them to the mailing list, but attaching them to a topic is possible, too.

A way of observing invocations of nice mocks

Postby yonix » 10 Nov 2011, 15:31

It would be really awesome if it was possible to run asserts on invocations that a mock object received.
Especially since there's no OCMOCK_ANY for primitive values (which is a real pain BTW).

I could simply tell a mock to be nice, make my code interact with it, and have something like:
Code: Select all
STAssertEquals(mock.numInvocations, 7, @"...");
double aDouble;
[[mock invocationAtIndex:0] getArgument:&aDouble atIndex:2];
STAssertTrue(aDouble > 1.0, @"...");


Is it already possible somehow?
If not - adding it to OCMockObject seems pretty easy to implement. (I might even step in and do it myself - but I want your opinion first).
yonix
 

Re: A way of observing invocations of nice mocks

Postby yonix » 08 Dec 2011, 11:37

An alternative approach would be to implement something like Mockito's ArgumentCaptor in Java (http://docs.mockito.googlecode.com/hg/org/mockito/ArgumentCaptor.html)

this way we could expect and pass a captor instead of an expected value.

This is useful in many levels.
I hope this will be added to OCMock (but I doubt it, since no one seems to watch this forum...)
yonix
 
Posts: 2
Joined: 10 Nov 2011, 16:10


Return to OCMock