2014-10-23 2 views
0

У меня есть тест, где я хочу загрузить UICollectionViewCell (CustomCollectionViewCell), передать некоторые данные ему и проверить, обновлены ли эти метки ячейки этими данными.Подпрограммы UICollectionViewCell не обновляются при модульном тесте

cell.nameLabel является UILabel ячейки и вызывается метод setText, но сам текст никогда не обновляется.

cell.nameLabel.text всегда возвращает исходный текст, определенный в xib.

Метка определяется следующим образом:

@property (nonatomic, weak) IBOutlet UILabel *nameLabel; 

И спецификации:

SPEC_BEGIN(CustomCollectionViewCellSpec) 

describe(@"CustomCollectionViewCell", ^{ 

    __block CustomCollectionViewCell *cell = nil; 
    __block CustomCollectionViewCellData *cellData = nil; 

    beforeEach(^{ 

     NSArray *objects = [[NSBundle mainBundle] loadNibNamed:@"CustomCollectionViewCell" 
                 owner:self 
                 options:nil]; 

     for (id object in objects) { 

      if ([object isKindOfClass:[CustomCollectionViewCell class]]) { 

       cell = (CustomCollectionViewCell *)object; 

       break; 
      } 
     } 

     cellData = [[CustomCollectionViewCellData alloc] init]; 
     cellData.name = @"Custom name"; 
    }); 

    afterEach(^{ 

     cell = nil; 
     cellData = nil; 
    }); 

    it(@"should populate the views with the cell data", ^{ 

     [[cell.nameLabel should] receive:@selector(setText:) 
          withArguments:cellData.name]; 

     [cell configureWithCellData:cellData]; 

     [[cell.cellData should] equal:cellData]; 

     [[cell.nameLabel.text should] equal:cellData.name]; 
    }); 
}); 

SPEC_END 

ответ

0

Проблема в том, как вы создаете ячейку. Вы не можете выделить init ячейку или получить ниб. Вы спрашиваете об этом коллекцию.

Для коллекций вам нужно:

UICollectionView *collection = [[UICollectionView alloc] init]; 
    UICollectionCell *cell = [collection dequeueReusableCellWithReuseIdentifier:@"yourCellIdentifier" forIndexPath:0]; 

После этого вы сможете получить ячейку и изменять его не все его свойства, как ноль свойств.