Share
Embed
Transcript
42 slides
-
Executable Specification describe(@"NSNumber", ^{ context(@"when created with an integer value",
^{ __block NSNumber *numberUnderTest; beforeEach(^{ numberUnderTest = [NSNumber numberWithInteger:5]; }); it(@"should hold the correct value", ^{ [[theValue([numberUnderTest integerValue]) should] equal:theValue(5)]; }); }); }); -
Better Architecture describe(@"my custom view with a text field", ^{
context(@"when the value of the text field changes", ^{ it(@"should update the model object", ^{ // change value // model should be updated }); }); }); -
Better Architecture describe(@"my custom view with a text field", ^{
context(@"when the value of the text field changes", ^{ it(@"should update the model object", ^{ // change value // model should be updated }); }); }); MVC, anyone? -
Mocks // create mock object id carMock = [Car mock];
// configure mock object [[carMock should] beMemberOfClass:[Car class]]; [[carMock should] receive:@selector(weight) andReturn:theValue(1500)]; // use mock object [garage parkCar:carMock]; [[theValue(garage.totalWeight) should] equal:theValue(1500)]; -
Stubs // create real object id cruiser = [Cruiser cruiser];
// stub method [[cruiser stubAndReturn:theValue(42.0f)] energyLevelInWarpCore:7]; // access stubbed method float energyLevel = [cruiser energyLevelInWarpCore:7]; [[theValue(energyLevel) should] equal:theValue(42.0f)]; -
Asynchronous Car *car = [[Car alloc] init]; [car tankUpWithSpeed:1.0f]; [[expectFutureValue(theValue(car.gasTankFillLevel))
shouldEventually] equal:theValue(1.0f)]; -
Asynchronous Car *car = [[Car alloc] init]; [car tankUpWithSpeed:0.5f]; [[expectFutureValue(theValue(car.gasTankFillLevel))
shouldEventuallyBeforeTimingOutAfter(10)] equal:theValue(1.0f)]; -
https://github.com/AliSoftware/OHHTTPStubs OHHTTPStubs Super easy network request stubbing [OHHTTPStubs shouldStubRequestsPassingTest:^BOOL(NSURLRequest *request)
{ // Only stub requests to "*.json" files return [request.URL.absoluteString.lastPathComponent.pathExtension isEqualToString:@"json"]; } withStubResponse:^OHHTTPStubsResponse*(NSURLRequest *request) { // Stub it with our "response.json" stub file return [OHHTTPStubsResponse responseWithFile:@"response.json" contentType:@"text/json" responseTime:2.0]; }]; -
https://github.com/AliSoftware/OHHTTPStubs OHHTTPStubs Super easy network request stubbing [OHHTTPStubs shouldStubRequestsPassingTest:^BOOL(NSURLRequest *request)
{ // Only stub requests to "*.json" files return [request.URL.absoluteString.lastPathComponent.pathExtension isEqualToString:@"json"]; } withStubResponse:^OHHTTPStubsResponse*(NSURLRequest *request) { // Stub it with our "response.json" stub file return [OHHTTPStubsResponse responseWithFile:@"response.json" contentType:@"text/json" responseTime:2.0]; }]; -
https://github.com/AliSoftware/OHHTTPStubs OHHTTPStubs Super easy network request stubbing [OHHTTPStubs shouldStubRequestsPassingTest:^BOOL(NSURLRequest *request)
{ // Only stub requests to "*.json" files return [request.URL.absoluteString.lastPathComponent.pathExtension isEqualToString:@"json"]; } withStubResponse:^OHHTTPStubsResponse*(NSURLRequest *request) { // Stub it with our "response.json" stub file return [OHHTTPStubsResponse responseWithFile:@"response.json" contentType:@"text/json" responseTime:2.0]; }]; -
https://github.com/AliSoftware/OHHTTPStubs OHHTTPStubs Super easy network request stubbing [OHHTTPStubs shouldStubRequestsPassingTest:^BOOL(NSURLRequest *request)
{ // Only stub requests to "*.json" files return [request.URL.absoluteString.lastPathComponent.pathExtension isEqualToString:@"json"]; } withStubResponse:^OHHTTPStubsResponse*(NSURLRequest *request) { // Stub it with our "response.json" stub file return [OHHTTPStubsResponse responseWithFile:@"response.json" contentType:@"text/json" responseTime:2.0]; }]; OHHTTPStubsDownloadSpeedGPRS OHHTTPStubsDownloadSpeedEDGE OHHTTPStubsDownloadSpeed3G OHHTTPStubsDownloadSpeed3GPlus OHHTTPStubsDownloadSpeedWifi -
Async + Network context(@"when creating a task", ^{ beforeEach(^{ [OHHTTPStubs
shouldStubRequestsPassingTest:^BOOL(NSURLRequest *request) { return [request.URL.lastPathComponent isEqualToString:@"tasks.json"]; } withStubResponse:^OHHTTPStubsResponse *(NSURLRequest *request) { return [OHHTTPStubsResponse responseWithFile:@"todo_create.json" contentType:@"application/json" responseTime:1.0]; }]; }); it(@"should parse the response", ^{ task.text = @"new task"; [task create]; [[expectFutureValue(theValue(task.remoteIDValue)) shouldEventuallyBeforeTimingOutAfter(3)] equal:theValue(75704)]; }); }); -
Core Data NSBundle *bundle = [NSBundle bundleForClass:klass]; NSManagedObjectModel *managedObjectModel =
[NSManagedObjectModel mergedModelFromBundles:[NSArray arrayWithObject:bundle]]; NSPersistentStoreCoordinator *persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:managedObjectModel]; [persistentStoreCoordinator addPersistentStoreWithType:NSInMemoryStoreType configuration:nil URL:nil options:nil error:nil]; NSManagedObjectContext *managedObjectContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSMainQueueConcurrencyType]; managedObjectContext.persistentStoreCoordinator = persistentStoreCoordinator; https://github.com/rheinfabrik/RFTesting -
Core Data NSBundle *bundle = [NSBundle bundleForClass:klass]; NSManagedObjectModel *managedObjectModel =
[NSManagedObjectModel mergedModelFromBundles:[NSArray arrayWithObject:bundle]]; NSPersistentStoreCoordinator *persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:managedObjectModel]; [persistentStoreCoordinator addPersistentStoreWithType:NSInMemoryStoreType configuration:nil URL:nil options:nil error:nil]; NSManagedObjectContext *managedObjectContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSMainQueueConcurrencyType]; managedObjectContext.persistentStoreCoordinator = persistentStoreCoordinator; https://github.com/rheinfabrik/RFTesting -
Core Data NSBundle *bundle = [NSBundle bundleForClass:klass]; NSManagedObjectModel *managedObjectModel =
[NSManagedObjectModel mergedModelFromBundles:[NSArray arrayWithObject:bundle]]; NSPersistentStoreCoordinator *persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:managedObjectModel]; [persistentStoreCoordinator addPersistentStoreWithType:NSInMemoryStoreType configuration:nil URL:nil options:nil error:nil]; NSManagedObjectContext *managedObjectContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSMainQueueConcurrencyType]; managedObjectContext.persistentStoreCoordinator = persistentStoreCoordinator; https://github.com/rheinfabrik/RFTesting -
nibs/xibs // Use in initializers NSBundle *bundle = [NSBundle bundleForClass:[self
class]]; // OS X — NSWindowController NSString *path = [bundle pathForResource:@"FooWindowController" ofType:@"nib"]; self = [self initWithWindowNibPath:path owner:self]; // iOS — UIViewController self = [super initWithNibName:@"FooViewController" bundle:bundle];