I followed the example from github and try testing my own RKModels:
After starting my unit testing on Restkit using fixtures, I cannot find pass the test case which they test the mapping of nested relationship data.
My Fixture - articles.json:
{
"articles": [
{
"title": "RestKit Unit Testing",
"author": "Blake Watters",
"tags": [
"RestKit",
"testing",
"tutorials"
]
},
{
"title": "RestKit Unit Testing2",
"author": "Blake Watters",
"tags": [
"RestKit",
"testing",
"tutorials"
]
},
{
"title": "RestKit Unit Testing3",
"author": "Blake Watters",
"tags": [
"RestKit",
"testing",
"tutorials"
]
}
]
}
My Test Case:
- (void)testArticlesMapping
{
id parsedJSON = [RKTestFixture parsedObjectWithContentsOfFixture:@"articles.json"];
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[RKArticle class]];
[mapping addAttributeMappingsFromDictionary:@{
@"title": @"title",
@"author": @"author",
@"tags": @"tags"
}];
RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:mapping method:RKRequestMethodAny pathPattern:nil keyPath:@"articles" statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
[[RKObjectManager sharedManager] addResponseDescriptor:responseDescriptor];
RKMappingTest *test = [RKMappingTest testForMapping:mapping sourceObject:parsedJSON destinationObject:nil];
[test addExpectation:[RKPropertyMappingTestExpectation expectationWithSourceKeyPath:@"title" destinationKeyPath:@"title" value:@"RestKit Unit Testing"]];
[test addExpectation:[RKPropertyMappingTestExpectation expectationWithSourceKeyPath:@"author" destinationKeyPath:@"author" value:@"Blake Watters"]];
[test addExpectation:[RKPropertyMappingTestExpectation expectationWithSourceKeyPath:@"tags" destinationKeyPath:@"tags" value:@[ @"RestKit", @"testing", @"tutorials"]]];
XCTAssertTrue([test evaluate]);
XCTAssertNoThrow([test verify]);
}
The fixture is loaded, however it received an error:
(([test evaluate]) is true) failed: throwing "0x112701a20: failed with error: Error Domain=org.restkit.RestKit.ErrorDomain Code=1003 "No mappable values found for any of the attributes or relationship mappings" UserInfo=0x112703bb0 {NSLocalizedDescription=No mappable values found for any of the attributes or relationship mappings}
It seems it cannot find the nested value because the responseDescriptor is not set yet. How can I solve these testing of nested relationship data?
Great Thanks!