How to drown out CocoaLumberjack or NSLog with OCMockito

I can stub / check the class method, but I'm having difficulty with certain macros. I am trying to verify that one of my methods calls DDLogInfo.

It is defined as in CocoaLumberjack source

#define DDLogInfo(frmt, ...) LOG_MAYBE(LOG_ASYNC_ENABLED, LOG_LEVEL_DEF, DDLogFlagInfo, 0, nil, __PRETTY_FUNCTION__, frmt, ##__VA_ARGS__) 

thanks!

+5
source share
1 answer

All standard DDLog macros call +[DDLog log:level:flag:context:file:function:line:tag:format:] , so with OCMock you need to make sure that DDLogInfo was called:

 - (void)testMethodCallsDDLogInfo { id mockDDLog = OCMClassMock([DDLog class]); [obj methodThatCallsDDLogInfo]; OCMVerify([mockDDLog log:YES level:DDLogLevelAll flag:DDLogFlagInfo context:0 file:[OCMArg anyPointer] function:[OCMArg anyPointer] line:58 tag:[OCMArg any] format:[OCMArg any]]); } 

Unfortunately, with this strategy, you must hard-code multiple values, since there is no way in OCMock to specify a universal argument without a pointer.

+1
source

All Articles