Sha256: ec02474e7c0ae82151e3126877bd226743bc51ab0643530a2689642dc13fb04f

Contents?: true

Size: 1.37 KB

Versions: 6

Compression:

Stored size: 1.37 KB

Contents

#import "XCTestLog+Specta.h"
#import "SPTReporter.h"
#import <objc/runtime.h>

static void spt_swizzleInstanceMethod(Class class, SEL originalSelector, SEL swizzledSelector) {
  Method originalMethod = class_getInstanceMethod(class, originalSelector);
  Method swizzledMethod = class_getInstanceMethod(class, swizzledSelector);

  method_exchangeImplementations(originalMethod, swizzledMethod);
}

@implementation XCTestLog (Specta)

+ (void)load {
  spt_swizzleInstanceMethod(self, @selector(startObserving), @selector(XCTestLog_startObserving));
  spt_swizzleInstanceMethod(self, @selector(stopObserving), @selector(XCTestLog_stopObserving));
}

- (BOOL)spt_shouldProxyToSPTReporter {
  // Instances of XCTestLog (but not subclasses) simply forward to -[SPTReporter sharedReporter]
  return [self isMemberOfClass:[XCTestLog class]];
}

- (void)spt_pauseObservationInBlock:(void (^)(void))block {
  [self XCTestLog_stopObserving];
  block();
  [self XCTestLog_startObserving];
}

#pragma mark - XCTestObserver

- (void)XCTestLog_startObserving {
  if ([self spt_shouldProxyToSPTReporter]) {
    [[SPTReporter sharedReporter] startObserving];
  } else {
    [self XCTestLog_startObserving];
  }
}

- (void)XCTestLog_stopObserving {
  if ([self spt_shouldProxyToSPTReporter]) {
    [[SPTReporter sharedReporter] stopObserving];
  } else {
    [self XCTestLog_stopObserving];
    usleep(100000);
  }
}

@end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
second_curtain-0.6.0 Demo/Pods/Specta/src/XCTestLog+Specta.m
second_curtain-0.5.0 Demo/Pods/Specta/src/XCTestLog+Specta.m
second_curtain-0.4.0 Demo/Pods/Specta/src/XCTestLog+Specta.m
second_curtain-0.3.0 Demo/Pods/Specta/src/XCTestLog+Specta.m
second_curtain-0.2.4 Demo/Pods/Specta/src/XCTestLog+Specta.m
second_curtain-0.2.3 Demo/Pods/Specta/src/XCTestLog+Specta.m