Christoph
Christoph

Reputation: 2073

How to mock nil object passed to a block in OCMock

To stub a the following method of the class Network

- (void)userLogin:(NSDictionary *)credentials
completionHandler:(void (^)(BOOL, id, NSError *))handler;

I create a mock like this:

id mock = OCMClassMock([Network class]);

I want to stub this method so the block gets called with arguments YES,nil,nil. How to stub the values for objects like NSError and id with nil?

Upvotes: 0

Views: 372

Answers (1)

Christoph
Christoph

Reputation: 2073

You have to do this:

id mock = OCMClassMock([Network class]);

OCMStub([mock userLogin:[OCMArg any]
    completionErrorHandler:([OCMArg invokeBlockWithArgs:OCMOCK_VALUE(YES), [NSNull null],
                                    [NSNull null], nil])]);

Upvotes: 1

Related Questions