Sto provando a verificare il risultato di un RACCommand in esecuzione sul mio modello di vista.Test RACCommand on View Modello
ho impostato il mio comando presentare fino in questo modo:
- (void) createSubmitCommand
{
@weakify(self);
self.submitCommand = [RACCommand commandWithCanExecuteSignal: [self validSignal]];
self.submitSignal = [self.submitCommand
addSignalBlock:^RACSignal *(id value) {
@strongify(self);
return [self save];
}];
}
- (RACSignal *) save
{
RACSubject *saveSubject = [RACSubject subject];
[self.model.managedObjectContext MR_saveOnlySelfWithCompletion:^(BOOL success, NSError *error) {
if (!success)
{
[saveSubject sendError: error];
}
else
{
[saveSubject sendNext: nil];
[saveSubject sendCompleted];
}
}];
return saveSubject;
}
createSubmitCommand viene chiamato quando ho init mio punto di vista del modello e validSignal è valida nel contesto di prova.
Sto usando MagicalRecord per la persistenza dei dati di base e Kiwi per il test. Devo testarlo quando chiamo [[viewModel submitCommand] eseguire: nil] che il mio modello sta salvando.
Il mio test simile a questa:
__block NSArray *models = nil;
[[vm submitSignal] subscribeNext:^(id x) {
models = [Model MR_findAll];
}];
[[vm submitCommand] execute: nil];
[[expectFutureValue(models) should] haveCountOf: 2];
Il problema è che Save è asincrono e non blocca quindi le finiture di test e abbatte la mia NSManagedObjectContext e il test fallisce. Sento che ho sbagliato completamente il test per quello che sto cercando di fare o sto abusando di RACCommand ma non so quale ...