Consideration of a method argument on a mock-up of an object with kiwi

I need help with the following: I am writing several BDD tests for the client API with the following structure:

@protocol MyAPIClientDelegate <NSObject> -(void)myCallbackMethod:(id)response; @end // BEGIN: MyAPIClientSpec.h SPEC_BEGIN(MyAPIClientSpec) describe(@"MyAPIClientAPI ", ^{ __block MyAPI *api = nil; __block id delegateMock = nil; beforeEach(^{ delegateMock = [KWMock mockForProtocol:@protocol(MyAPIClientDelegate)]; api = [MyAPI APIClientWithDelegate:delegateMock]; }); afterEach(^{ delegateMock = nil; api = nil; }); it(@"should return a JSON { result: 'ok', token: <SOME_TOKEN> }", ^{ [[api should] receive:@selector(myMethodCall:)]; [[[delegateMock shouldEventually] receive] myCallbackMethod:any()]; [api myMethodCall]; }); }); SPEC_END 

As you can see in the above code, I use any () to verify that at least there is a parameter sent to the delegate.

Is there a way to define a function (or an objective-c block) to check a parameter?

Thanks!

+4
source share
1 answer

Try using a spy capture :

 it(@"should return a JSON { result: 'ok', token: <SOME_TOKEN> }", ^{ [[api should] receive:@selector(myMethodCall:)]; KWCaptureSpy *spy = [delegateMock captureArgument:@selector(myCallbackMethod:) atIndex:0]; [api myMethodCall]; [[spy.argument should] equal:/* ... */]; }); 
+2
source

Source: https://habr.com/ru/post/1490810/


All Articles