???Kiwi??????????
???????????? ???????[ 2017/7/3 16:14:47 ] ??????????????? ???????
????????????梅???
????Stub??
????????????婊�??stub?????????????????????梅????????魏?????婕�??????
???????????????榉�????????????貌?????谩????????????????????????????stub??????????梅???????????????????????????
context(@"when select count of termStudyInfo"?? ^{
beforeEach(^{
// stub????魏蔚??????[EduTermStudyInfo countOfTermStudyInfoWithLearnerId:]??????????3??
// ????????[EduTermStudyInfo countOfTermStudyInfoWithLearnerId:]????????????????
[EduTermStudyInfo stub:@selector(countOfTermStudyInfoWithLearnerId:) andReturn:theValue(3)];
});
it(@"the count should always be 3"?? ^{
[[theValue([EduTermStudyInfo countOfTermStudyInfoWithLearnerId:110]) should] equal:theValue(3)];
});
});
????????????????it?????尾??stub????????
Mock??
??????渭??????????????????????????mock??????????????????????mock?????????????????????????????
// ????nullMock??????????????XXSectionDataSource?????????XXSectionDataSource????魏???????????????????
XXSectionDataSource *mockLiveSection = [XXSectionDataSource nullMock];
// ?????[mockLiveSection viewType]???????XXViewTypeLive???????stub??mock?????viewType????
[mockLiveSection stub:@selector(viewType) andReturn:theValue(XXViewTypeLive)];
// ????????nullMock?????????mock??????????mock?????????mock?????????stub????????????crash
XXCellDataSource *mockCell = [XXCellDataSource nullMock];
[mockCell stub:@selector(viewType) andReturn:theValue(XXViewTypeLive)];
[mockLiveSection stub:@selector(cellDataSources) andReturn:@[mockCell?? mockCell]];
???????
??????????????????????胁???????卸?????????????????????????expectFutureValue+shouldEventually ?婊�????????should??
expectFutureValue+shouldEventually?????????block??????1s??????????????????????????????????????????????????
????????慰???https://github.com/kiwi-bdd/Kiwi/issues/532
describe(@"XXViewModel"?? ^{
context(@"when request lern data"?? ^{
__block XXViewModel *viewModel = nil;
__block BOOL isExecuteSuccess = NO;
beforeEach(^{
viewModel = [[XXViewModel alloc] init];
[viewModel requestLearnData:^{
isExecuteSuccess = YES;
} failure:nil target:self];
});
it(@"should eventually call successBlock"?? ^{
//???????????卸??????????????
[[expectFutureValue(theValue(isExecuteSuccess)) shouldEventually] beYes];
});
}????
OHHTTPStubs???
????NSURLProtocol???????????stub????stub?????????????????????????????????????????Charles??local map?????
???????????????????????????????????????????????????????????????????????y???????API??????小?
?梅????????beforeEach?????????stub??
// ????url?邪???learn/v1????????????????learn_v1.json????械?????
[OHHTTPStubs stubRequestsPassingTest:^BOOL(NSURLRequest * _Nonnull request) {
return [request.URL.absoluteString containsString:@"learn/v1"];
} withStubResponse:^OHHTTPStubsResponse * _Nonnull(NSURLRequest * _Nonnull request) {
NSString *filePath = OHPathForFile(@"learn_v1.json"?? self.class);
NSData *data = [NSData dataWithContentsOfFile:filePath];
return [OHHTTPStubsResponse responseWithData:data statusCode:kK12TestHTTPSuccessCode headers:nil];
// ??????????????????NSError
//return [OHHTTPStubsResponse responseWithError:[NSError errorWithDomain:@"kK12TestSystemErrorDomain" code:-1 userInfo:nil]];
}];
????????
????????Kiwi??EXC_BAD_ACCESS??????????Kiwi?master?掳姹�??https://github.com/kiwi-bdd/Kiwi/pull/649
????????????????????????????????pch??????????
??RACBacktrace??RACBacktraceBlock??debug?????EXC_BAD_ACCESS???????????ReactiveCocoa?姹�??
??????

???路???
??????????????????
2023/3/23 14:23:39???写?貌??????????
2023/3/22 16:17:39????????????????????些??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???路???????路
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11