FixtureHelpers.m 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. //
  2. // FixtureHelpers.m
  3. // Magical Record
  4. //
  5. // Created by Saul Mora on 7/15/11.
  6. // Copyright 2011 Magical Panda Software LLC. All rights reserved.
  7. //
  8. #import "FixtureHelpers.h"
  9. @implementation FixtureHelpers
  10. + (id) dataFromPListFixtureNamed:(NSString *)fixtureName
  11. {
  12. NSBundle *testBundle = [NSBundle bundleForClass:[self class]];
  13. NSString *resource = [testBundle pathForResource:fixtureName ofType:@"plist"];
  14. NSData *plistData = [NSData dataWithContentsOfFile:resource];
  15. return [NSPropertyListSerialization propertyListWithData:plistData options:NSPropertyListImmutable format:nil error:nil];
  16. }
  17. + (id) dataFromJSONFixtureNamed:(NSString *)fixtureName
  18. {
  19. NSBundle *testBundle = [NSBundle bundleForClass:[self class]];
  20. NSString *resource = [testBundle pathForResource:fixtureName ofType:@"json"];
  21. NSInputStream *inputStream = [NSInputStream inputStreamWithFileAtPath:resource];
  22. [inputStream open];
  23. return [NSJSONSerialization JSONObjectWithStream:inputStream options:0 error:nil];
  24. }
  25. @end
  26. @implementation XCTest (FixtureHelpers)
  27. - (id) dataFromJSONFixture;
  28. {
  29. NSString *className = NSStringFromClass([self class]);
  30. className = [className stringByReplacingOccurrencesOfString:@"Import" withString:@""];
  31. className = [className stringByReplacingOccurrencesOfString:@"Spec" withString:@""];
  32. className = [className stringByReplacingOccurrencesOfString:@"Tests" withString:@""];
  33. return [FixtureHelpers dataFromJSONFixtureNamed:className];
  34. }
  35. @end