简体   繁体   中英

Capture arguments of static method calls using Kiwi

This link shows how to capture an argument of a mock object using Kiwi.

Is there a way to capture arguments of static method calls? It seems to me that this only work with instance methods.

Considering that the same message dispatching mechanism is used for both instance and class methods, you can safely spy on class methods.

@interface MyObject: NSObject
+ (void)doNoOpWithObject:(NSObject*)obj;
@end

@implementation MyObject
+ (void)doNoOpWithObject:(id)object {}
@end


SPEC_BEGIN(StaticSpy)
it(@"captures static method arguments", ^{
    KWCaptureSpy *spy = [MyObject captureArgument:@selector(doNoOpWithObject:) atIndex:0];
    [MyObject doNoOpWithObject:@18];
    [[spy.argument should] equal:@18];
});
SPEC_END

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM