????????block????
????OCMock????????block?????????block????????????????????????????????κ????????С???????????У????????????????
????- (void)downloadWeatherDataForZip:(NSString *)zip
????callback:(void (^)(NSDictionary *response))callback;
??????????????У??????????????????????????????????????????????dictionary????????block?????С???????У???????????????????????????????????????????????????????????????????????????????????????
// 1. stub using OCMock andDo: operator.
[[[groupModelMock stub] andDo:^(NSInvocation *invoke) {
//2. declare a block with same signature
void (^weatherStubResponse)(NSDictionary *dict);
//3. link argument 3 with with our block callback
[invoke getArgument:&weatherStubResponse atIndex:3];
//4. invoke block with pre-defined input
NSDictionary *testResponse = @{@"high": 43 ?? @"low": 12};
weatherStubResponse(groupMemberMock);
}]downloadWeatherDataForZip@"80304" callback:[OCMArg any] ];
OCMock3 ?°汾???API
// 1. stub using OCMock andDo: operator.
OCMStub([groupModelMock downloadWeatherDataForZip:@"80304" callback:[OCMArg any]]]).andDo(^(NSInvocation *invocation){
//2. declare a block with same signature
void (^weatherStubResponse)(NSDictionary *dict);
//3. link argument 3 with with our block callback
[invoke getArgument:&weatherStubResponse atIndex:3];
//4. invoke block with pre-defined input
NSDictionary *testResponse = @{@"high": 43 ?? @"low": 12};
weatherStubResponse(groupMemberMock);
});
?????????????????????????????????????????Щ?????
????1.???mock????????NSInvocation??????“andDo”?????????NSInvocation??????????‘objectivetified’????????????????????????????á???????NSinvocation?????????????????????????block???????????
????2.???????????????????????????????????block??????
????3.NSInvocation???????"getArgument:atIndex:"????????麯??????????????ж????麯???С??????Objective-C?У???????????????????????????“self”??“_cmd”.??????????????С??????????±??????NSInvocation??????????????????????
????4.??????????????????????