NSURLConnectionRACSupportSpec.m 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. //
  2. // NSURLConnectionRACSupportSpec.m
  3. // ReactiveCocoa
  4. //
  5. // Created by Justin Spahr-Summers on 2013-10-01.
  6. // Copyright (c) 2013 GitHub, Inc. All rights reserved.
  7. //
  8. #import <Quick/Quick.h>
  9. #import <Nimble/Nimble.h>
  10. #import "NSURLConnection+RACSupport.h"
  11. #import "RACSignal+Operations.h"
  12. #import "RACTuple.h"
  13. QuickSpecBegin(NSURLConnectionRACSupportSpec)
  14. qck_it(@"should fetch a JSON file", ^{
  15. NSURL *fileURL = [[NSBundle bundleForClass:self.class] URLForResource:@"test-data" withExtension:@"json"];
  16. expect(fileURL).notTo(beNil());
  17. NSURLRequest *request = [NSURLRequest requestWithURL:fileURL];
  18. BOOL success = NO;
  19. NSError *error = nil;
  20. RACTuple *result = [[NSURLConnection rac_sendAsynchronousRequest:request] firstOrDefault:nil success:&success error:&error];
  21. expect(@(success)).to(beTruthy());
  22. expect(error).to(beNil());
  23. expect(result).to(beAKindOf(RACTuple.class));
  24. NSURLResponse *response = result.first;
  25. expect(response).to(beAKindOf(NSURLResponse.class));
  26. NSData *data = result.second;
  27. expect(data).to(beAKindOf(NSData.class));
  28. expect(data).to(equal([NSData dataWithContentsOfURL:fileURL]));
  29. });
  30. QuickSpecEnd