Skip to content

Commit

Permalink
Merge pull request #72 from TitouanVanBelle/67_steps_in_report
Browse files Browse the repository at this point in the history
67: Use XCTContext runActivityNamed:block: to insert the step's title in the report
  • Loading branch information
brentleyjones authored Jul 18, 2017
2 parents 3fa1ee1 + 1b0e79d commit 7726a9e
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions Cucumberish/Core/Managers/CCIStepsManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#import "CCIStep.h"
#import "CCIStepDefinition.h"

typedef void (^XCTContextActivityBlock)(id _Nullable activity);

static CCIStepsManager * instance = nil;


Expand Down Expand Up @@ -197,27 +199,27 @@ - (void)executeStep:(CCIStep *)step inTestCase:(id)testCase
implementation.type = @"And";
}

XCTContextActivityBlock activityBlock = ^(id activity) {
implementation.body(implementation.matchedValues, implementation.additionalContent);
};

id xctContextClass = NSClassFromString(@"XCTContext");
if (xctContextClass) {
SEL aSelector = NSSelectorFromString(@"runActivityNamed:block:");

id block = ^(id activity) {
implementation.body(implementation.matchedValues, implementation.additionalContent);
};

if ([xctContextClass respondsToSelector:aSelector]) {
NSInvocation *inv = [NSInvocation invocationWithMethodSignature:[xctContextClass methodSignatureForSelector:aSelector]];
[inv setSelector:aSelector];
[inv setTarget:xctContextClass];

NSString *name = [NSString stringWithFormat:@"%@ %@", step.keyword, step.text];
[inv setArgument:&(name) atIndex:2];
[inv setArgument:&(block) atIndex:3];
[inv setArgument:&(activityBlock) atIndex:3];

[inv invoke];
}
} else {
implementation.body(implementation.matchedValues, implementation.additionalContent);
activityBlock(nil);
}

//Clean up the step additional content to avoid keeping unwanted objects in memory
Expand Down

0 comments on commit 7726a9e

Please sign in to comment.