Upgrade to Pro — share decks privately, control downloads, hide ads and more …

BDD with Specta/Expecta

BDD with Specta/Expecta

This is a lightning talk I gave at CocoaHeads CGN on June 15.

Marc Kalmes

June 15, 2015
Tweet

More Decks by Marc Kalmes

Other Decks in Programming

Transcript

  1. @interface AFHTTPRequestOperationManager : NSObject <NSSecureCoding, NSCopying> @property (readonly, nonatomic, strong)

    NSURL *baseURL; @property (nonatomic, strong) AFHTTPRequestSerializer <AFURLRequestSerialization> * requestSerializer; @property (nonatomic, strong) AFHTTPResponseSerializer <AFURLResponseSerialization> * responseSerializer; @property (nonatomic, strong) NSOperationQueue *operationQueue; @property (nonatomic, assign) BOOL shouldUseCredentialStorage; @property (nonatomic, strong) NSURLCredential *credential; @property (nonatomic, strong) AFSecurityPolicy *securityPolicy; @property (readwrite, nonatomic, strong) AFNetworkReachabilityManager *reachabilityManager; #if OS_OBJECT_HAVE_OBJC_SUPPORT @property (nonatomic, strong) dispatch_queue_t completionQueue; #else @property (nonatomic, assign) dispatch_queue_t completionQueue; #endif
  2. BDD

  3. DSL

  4. describe(@"Class", ^{ before({ // Create states to be tested });

    it(@"should do stuff", ^{ // This is an example block. Place your assertions here. }); context(@"groups related specifications", ^{ // ... more specs }); });
  5. It is found by comparing two DNA strands and counting

    how many of the nucleotides are different from their equivalent in the other string. GAGCCTACTAACGGGAT CATCGTAATGACGGCCT ^ ^ ^ ^ ^ ^^ The Hamming distance between these two DNA strands is 7.
  6. - (void)setUp { [super setUp]; self.hamming = [[HammingTest alloc] initWithDNAStrands:@"GAGCCTACTAACGGGAT"];

    } - (void)testInit { XCTAssertNotNil(self.hamming); } - (void)testHammingDistanceWithSameLength { NSInteger length = [self.hamming hammingDistanceWithDNAStrands:@"CATCGTAATGACGGCCT"]; XCTAssertEqual(length, 7); } - (void)testHammingDistanceWithDifferentLength { NSInteger length = [self.hamming hammingDistanceWithDNAStrands:@"CATCGTAAT"]; XCTAssertEqual(length, NSIntegerMax); }
  7. - (void)testSameLengthWithSameStringLength { BOOL same = [self.hamming hasSameLengthAs:@"CATCGTAATGACGGCCT"]; XCTAssertTrue(same ==

    YES); } - (void)testSameLengthWithDifferentStringLength { BOOL same = [self.hamming hasSameLengthAs:@"CATCGTAAT"]; XCTAssertTrue(same == NO); } - (void)testIsNotDNAStrang { BOOL isDNAStrang = [self.hamming isDNAStrand:@"123456789"]; XCTAssertTrue(isDNAStrang == NO); }
  8. SpecBegin(HammingTest) describe(@"HammingTest", ^{ __block id hamming; before(^{ hamming = [[HammingTest

    alloc] initWithDNAStrands:@"GAGCCTACTAACGGGAT"]; }); it(@"should not be nil", ^{ expect(hamming).notTo.beNil(); }); describe(@"-hammingDistanceWithDNAString", ^{ context(@"with DNA strands of same length", ^{[...]}); context(@"with DNA strands of different length", ^{[...]}); }); }); }); SpecEnd
  9. context(@"with DNA strand of same length", ^{ it(@"should return the

    correct distance for different strands", ^{ NSInteger length = [hamming hammingDistanceWithDNAStrands:@"CATCGTAATGACGGCCT"]; expect(length).to.equal(7); }); it(@"should return zero for same strands", ^{ NSInteger length = [hamming hammingDistanceWithDNAStrands:@"GAGCCTACTAACGGGAT"]; expect(length).to.equal(0); }); });
  10. context(@"with DNA strands of different length", ^{ __block NSInteger length;

    before(^{ length = [hamming hammingDistanceWithDNAStrands:@"CATCGTAAT"]; }); it(@"should return NSIntegerMax", ^{ expect(length).to.equal(NSIntegerMax); }); });