NSObject*stub = [Stubbilino stubObject:[[NSObject alloc] init]]; [stub stubMethod:@selector(description) withBlock:^{ return @"Stubbilino is awesome!"; }]; expect(stub.description).to.equal(@"Stubbilino is awesome!");
UITableViewControllerのスタブ例。
UITableViewController *viewcontroller = [[UITableViewController alloc] init]; UITableViewCell *myCell = [[UITableViewCell alloc] init]; UITableViewController*stub = (id)[Stubbilino stubObject:viewcontroller]; [stub stubMethod:@selector(numberOfSectionsInTableView:) withBlock:^{ return 1; }]; [stub stubMethod:@selector(tableView:numberOfRowsInSection:) withBlock:^{ return 1; }]; [stub stubMethod:@selector(tableView:cellForRowAtIndexPath:) withBlock:^{ return myCell; }]; [viewcontroller.tableView reloadData]; NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0]; id cell = [viewcontroller.tableView cellForRowAtIndexPath:indexPath]; expect(cell).to.equal(myCell);
クラスメソッドも書ける。
Classuiimage = [Stubbilino stubClass:UIImage.class]; [uiimage stubMethod:@selector(imageNamed:) withBlock:^(NSString *name) { return myImage; }];
関連)