Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Dec 22nd, 2012  |  syntax: None  |  size: 1.40 KB  |  views: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. - (void)testApiClass {
  2.     //Check object
  3.     NSString* classKey = @"Api";
  4.     id obj = NSClassFromString(classKey);
  5.     STAssertNotNil(obj, [NSString stringWithFormat:@"Model '%@' not found.", classKey]);
  6.     //Check properties
  7.     NSArray* properties =
  8.     @[
  9.         @"performSyncRequestWithUri::",
  10.         @"performAsyncRequestWithUri:::",
  11.     ];
  12.     for (NSString* property in properties) {
  13.         SEL propertySel = NSSelectorFromString(property);
  14.         BOOL isRespondsToSel = [obj respondsToSelector:propertySel];
  15.         STAssertTrue(isRespondsToSel, [NSString stringWithFormat:@"Property '%@' not found on object of class name '%@'", property, [obj class]]);
  16.     }    
  17. }
  18.  
  19.  
  20. @interface Api : NSObject
  21.  
  22. - (NSDictionary*)performSyncRequestWithUri:(NSString *)requestUri params:(NSDictionary *)params;
  23. - (void)performAsyncRequestWithUri:(NSString *)requestUri params:(NSDictionary *)params completionHandler:(void (^)(NSDictionary *, NSError *))completionBlock;
  24.  
  25. @end
  26.        
  27. SEL selectors[] = {
  28.     @selector(performSyncRequestWithUri:params:),
  29.     @selector(performAsyncRequestWithUri:params:completionHandler:),
  30.     NULL
  31. };
  32.  
  33. for (size_t i = 0; selectors[i]; ++i) {
  34.     SEL selector = selectors[i];
  35.     BOOL respondsToSelector = [obj respondsToSelector:selector];
  36.     STAssertTrue(respondsToSelector, [NSString stringWithFormat:
  37.         @"Object %@ doesn't respond to selector %s",
  38.         obj, sel_getName(selector)]);
  39. }