I am trying to test the RestKit object mapping to an array of elements using RKTestFixtures.
When I try testing just 1 element of my Tutorial-object (which has a name and a description), everything works fine using the test-method below.
- (RKObjectMapping *)tutorialMapping {
RKObjectMapping *objectMapping = [RKObjectMapping mappingForClass:[Tutorial class]];
[objectMapping addAttributeMappingsFromDictionary:@{
@"name" : @"name",
@"description" : @"description"
}];
return objectMapping;
}
- (void)testMappingOfDescriptionWithValue {
RKMappingTest *mappingTest = [RKMappingTest testForMapping:[self tutorialMapping] sourceObject:self.parsedJSON destinationObject:nil];
[mappingTest addExpectation:[RKPropertyMappingTestExpectation expectationWithSourceKeyPath:@"description"
destinationKeyPath:@"description"
value:@"This is an example description"]];
XCTAssert([mappingTest evaluate]);
}
But, when I try testing an array of Tutorial-objects like the one below using evaluationBlocks, I can't get the mapping right...
[
{
"name": "Tutorial name 1",
"description": "This is an example description"
},
{
"name": "Tutorial name 2",
"description": "This is an example description"
}
]
Does anyone have a solution to this problem? Google didn't get me right through it...
UPDATE
I am sending my JSON using the Fixtures feature:
NSBundle *testTargetBundle = [NSBundle bundleForClass:[self class]];
[RKTestFixture setFixtureBundle:testTargetBundle];
self.parsedJSON = [RKTestFixture parsedObjectWithContentsOfFixture:@"tutorials.json"];
And in my test-method:
RKMappingTest *mappingTest = [RKMappingTest testForMapping:[self tutorialMapping] sourceObject:self.parsedJSON destinationObject:nil];