How to I capture an argument sent to a mock?

ios, objective-c, ocmock

Solution

If you want to validate your parameter maybe you can do it directly while you are setting your stub with something like :

id mock = [OCMockObject mockForClass:someClass];
NSObject* captureThisArgument;
[[mock expect] foo:[OCMArg checkWithBlock:^(id value){ 
    // Capture argument here...
}]];

Regards, Quentin A

Problem

Does anyone know how to capture an argument sent to an OCMock object? ``` id mock = [OCMockObject mockForClass:someClass] NSObject* captureThisArgument; [[mock expect] foo:<captureThisArgument>] [mock foo:someThing] GHAssertEquals[captured, someThing, nil]; ``` How do I go about validating the argument to foo? I'm happy to do it within a block in the mock definition too, but if I could get the object out so that I can assert on feature of it later that would be brilliant. Is this possible with OCMock?

Original source