Stubbilino 0 ruby CocoaPods

Simple stubbing for Objective-C


Simple stubbing for Objective-C

NSObject<SBStub> *stub = [Stubbilino stubObject:[[NSObject alloc] init]];

[stub stubMethod:@selector(description)
       withBlock:^{ return @"Stubbilino is awesome!"; }];

expect(stub.description).to.equal(@"Stubbilino is awesome!");

Getting started

Stubbilino allows you to selectively stub methods on an object, if you don’t provide a stub, the default implementation will be used.

UITableViewController *viewcontroller = [[UITableViewController alloc] init];
UITableViewCell *myCell = [[UITableViewCell alloc] init];

UITableViewController<SBStub> *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];


You can also remove the stubs once you’re done.

[stub removeStub:@selector(numberOfSectionsInTableView:)];

Alternatively, you can also unstub the object, returning it to its original state.

[Stubbilino unstubObject:stub];

Class Methods

Class methods can also be stubbed.

Class<SBClassStub> uiimage = [Stubbilino stubClass:UIImage.class];

[uiimage stubMethod:@selector(imageNamed:)
          withBlock:^(NSString *name) { return myImage; }];

Make sure to unstub the classes once you’re done.

[Stubbilino unstubClass:uiimage];


Copyright © 2013 Robert Böhnke. This software is licensed under the MIT License.

Related Repositories



Simple stubbing for Objective-C ...

Top Contributors

robb itsthejb mxcl


-   0.2.1 zip tar
-   0.2.0 zip tar
-   0.1.1 zip tar
-   0.1.0 zip tar