I'm using Kiwi to write tests for an app. I am trying to verify that the cell returned from tableView:cellForRowAtIndexPath:
has the correct values set after the call. I've done a unch of different variations of this with no luck:
describe(@"tableView:cellForRowAtIndexPath:", ^{
it(@"Should return a cell with proper label values",
^{
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
id mockTableView = [UITableView mock];
id mockCell = [UITableViewCell mock];
[mockTableView stub:@selector(dequeueReusableCellWithIdentifier:forIndexPath:) andReturn:mockCell withArguments:any(), indexPath];
[mockCell stub:@selector(label1)
andReturn:[[UILabel alloc] init]];
[mockCell stub:@selector(label2)
andReturn:[UILabel alloc]];
CustomTableViewCell *cell = (CustomTableViewCell *)
[dataSource tableView:mockTableView
cellForRowAtIndexPath:indexPath];
[[cell.label1.text should]
equal:@"abc"];
[[cell.label2.text should] equal:@"xyz"];
});
});
The actual method looks like this:
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
CustomTableViewCell *cell =
[tableView dequeueReusableCellWithIdentifier:kCustomCellReuseIdentifier
forIndexPath:indexPath];
CustomObject *obj = [self objAtIndexPath:indexPath];
[self setupCell:cell withObj:obj];
return cell;
}
- (void)setupCell:(
CustomTableViewCell *)cell withObj:(CustomObject *)obj
{
cell.label1.text = @"abc";
cell.label2.text = @"xyz";
}
It seems to get caught on cell.label1
being nil
- however, I do stub those earlier.
Any thoughts on how to actually write this test are welcome.