Skip to content

Commit

Permalink
[QuickSpec] Track the current example within `imp_implementationWithB…
Browse files Browse the repository at this point in the history
…lock`

This eliminates Objective-C's associated objects usage and overriding `-setInvocation:`.
  • Loading branch information
ikesyo committed Feb 7, 2017
1 parent 9f873b6 commit 9bf7b14
Showing 1 changed file with 1 addition and 17 deletions.
18 changes: 1 addition & 17 deletions Sources/QuickObjectiveC/QuickSpec.m
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
#import "QuickSpec.h"
#import "QuickConfiguration.h"
#import "World.h"
#import <objc/runtime.h>
#import <Quick/Quick-Swift.h>

static QuickSpec *currentSpec = nil;

const void * const QCKExampleKey = &QCKExampleKey;

@interface QuickSpec ()
@property (nonatomic, strong) Example *example;
@end
Expand Down Expand Up @@ -71,16 +68,6 @@ + (NSArray *)testInvocations {
return invocations;
}

/**
XCTest sets the invocation for the current test case instance using this setter.
QuickSpec hooks into this event to give the test case a reference to the current example.
It will need this reference to correctly report its name to XCTest.
*/
- (void)setInvocation:(NSInvocation *)invocation {
self.example = objc_getAssociatedObject(invocation, QCKExampleKey);
[super setInvocation:invocation];
}

#pragma mark - Public Interface

- (void)spec { }
Expand All @@ -105,6 +92,7 @@ - (void)spec { }
*/
+ (SEL)addInstanceMethodForExample:(Example *)example classSelectorNames:(NSMutableSet<NSString*> *)selectorNames {
IMP implementation = imp_implementationWithBlock(^(QuickSpec *self){
self.example = example;
currentSpec = self;
[example run];
});
Expand Down Expand Up @@ -132,10 +120,6 @@ + (NSInvocation *)invocationForInstanceMethodWithSelector:(SEL)selector
NSMethodSignature *signature = [self instanceMethodSignatureForSelector:selector];
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature];
invocation.selector = selector;
objc_setAssociatedObject(invocation,
QCKExampleKey,
example,
OBJC_ASSOCIATION_RETAIN_NONATOMIC);
return invocation;
}

Expand Down

0 comments on commit 9bf7b14

Please sign in to comment.