pawan963
pawan963

Reputation: 1

Crash when using ignoringNonObjectArgs in OCMock in modern style

I am trying to mock a method mentioned bellow using the OCMock framework which takes an integer variable as the second argument. I also tried with old style OCMock stub call too with the same result. Using modern syntax the code I wrote is as bellow.

@interface Session : NSObject 
- (Request *)RequestForURL:(NSURL *)url 
                     flags:(unsigned int)flags
                     error:(NSError **)error;
@end

This session class is mocked and I want to return the mocked Request from this mocked method.

id session = OCMClassMock(Session.class);
id Request = OCMClassMock(Request.class);

OCMStub([[session ignoringNonObjectArgs] RequestForURL:(NSURL *)OCMArg.anyObjectRef flags:0 error:OCMArg.anyObjectRef]).andReturn(Request);

This gets compiled fine. But while running the test it crashes while calling RequestForURL I am aware that I am using the modern OCMock syntax. I think the error occurs in flags that somehow is not ignored.

Upvotes: 0

Views: 620

Answers (1)

pawan963
pawan963

Reputation: 1

Well, turned out one of my stupid mistakes. anyObjectRef is the reference and any is an id and here we need an id and I was using ref and casting it to NSURL * ... [facepalm on me]

correct way:

OCMStub([[session ignoringNonObjectArgs] RequestForURL:OCMArg.any flags:0 error:OCMArg.any]).andReturn(Request);

Upvotes: 0

Related Questions