Created
October 4, 2014 22:19
-
-
Save HeidiHansen/80e04008975fee74698c to your computer and use it in GitHub Desktop.
Specta/Expecta testing - basic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "Specta.h" | |
#define EXP_SHORTHAND | |
#import "Expecta.h" | |
#import "KIF.h" | |
#import "Swizzlean.h" | |
SpecBegin(GenericTestSpec) | |
describe(@"GenericTestSpec", ^{ | |
describe(@"Simple testing techniques", ^{ | |
describe(@"how to use beKindOf", ^{ | |
it(@"creates an NSString and tests that it is kind of class NSString",^{ | |
NSString *theString = @"The String"; | |
expect(theString).to.beKindOf([NSString class]); | |
}); | |
it(@"creates an NSArray and tests that it is kind of class NSArray",^{ | |
NSArray *theArray = @[]; | |
expect(theArray).to.beKindOf([NSArray class]); | |
}); | |
}); | |
describe(@"how to use .to.equal matcher", ^{ | |
it(@"tests that 4+4 is equal to 8",^{ | |
expect(4+4).to.equal(8); | |
}); | |
it(@"creates an NSString variable called 'name', tests that it is equal to @\"Chris\"",^{ | |
NSString *name = @"Chris"; | |
expect(name).to.equal(@"Chris"); | |
}); | |
it(@"creates an NSArray, uses a test to verify that the array is identical to @[@\"poptarts\", @\"hotpockets\"]",^{ | |
NSArray *healthyFood = @[@"poptarts", @"hot pockets"]; | |
expect(healthyFood).to.equal(@[@"poptarts", @"hot pockets"]); | |
}); | |
}); | |
describe(@"how to use the notTo.equal matcher", ^{ | |
it(@"creates an NSString and tests that it is not equal to the NSString @\"Joe\"",^{ | |
NSString *name = @"Chris"; | |
expect(name).notTo.equal(@"Joe"); | |
}); | |
it(@"test that 4+4 is not equal to 18",^{ | |
expect(4+4).notTo.equal(18); | |
}); | |
it(@"creates an NSArray variable, sets it equal to an array with the NSStrings 'poptarts' and 'hot pockets', uses a test to verify that the array is not equal to @[@\"celery\", @\"spinach\"]",^{ | |
NSArray *healthyFood = @[@"poptarts", @"hot pockets"]; | |
expect(healthyFood).notTo.equal(@[@"celery", @"spinach"]); | |
}); | |
it(@"creates an NSArray variable, sets it equal to an array with the NSStrings 'poptarts' and 'hot pockets', tests to verify that it is not equal to @[@\"hotpockets\", @\"poptarts\"]",^{ | |
NSArray *healthyFood = @[@"poptarts", @"hot pockets"]; | |
expect(healthyFood).notTo.equal(@[@"hotpockets", @"poptarts"]); | |
}); | |
}); | |
describe(@"using beTruthy matcher", ^{ | |
it(@"tests that 4+4 == 8 to be true",^{ | |
expect(4+4==8).to.beTruthy; | |
}); | |
it(@"creates an NSString, tests that it is equal to @\"Chris\"",^{ | |
NSString *name = @"Chris"; | |
expect([name isEqualToString:@"Chris"]).to.beTruthy; | |
}); | |
}); | |
describe(@"using the beFalsy matcher", ^{ | |
it(@"creates an NSString variable called 'name' with the value Chris. test that your variable is not equal to the NSString @\"Joe\"",^{ | |
NSString *name = @"Chris"; | |
expect([name isEqualToString:@"Joe"]).to.beFalsy; | |
}); | |
it(@"tests that 4+4 is not equal to 18",^{ | |
expect(4+4 == 18).to.beFalsy; | |
}); | |
}); | |
describe(@"how to use beginsWith and endsWith", ^{ | |
it(@"re-create the 'healthyFood' array, tests that 'healthyFood' begins with @\"poptarts\"",^{ | |
NSArray *healthyFood = @[@"poptarts", @"hot pockets"]; | |
expect(healthyFood).to.beginWith(@"poptarts"); | |
}); | |
it(@"re-creates the 'healthyFood' array from earlier in the exercise. test that 'healthyFood' ends with with @\"hot pockets\"",^{ | |
NSArray *healthyFood = @[@"poptarts", @"hot pockets"]; | |
expect(healthyFood).to.endWith(@"hot pockets"); | |
}); | |
}); | |
}); | |
}); | |
SpecEnd |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment