Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

67: Use XCTContext runActivityNamed:block: to insert the step's title in the report #72

Merged
merged 8 commits into from
Jul 18, 2017
30 changes: 23 additions & 7 deletions Cucumberish/Core/Managers/CCIStepsManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,29 @@ - (void)executeStep:(CCIStep *)step inTestCase:(id)testCase
implementation.type = @"And";
}

implementation.body(implementation.matchedValues, implementation.additionalContent);
id xctContextClass = NSClassFromString(@"XCTContext");
if (xctContextClass) {
SEL aSelector = NSSelectorFromString(@"runActivityNamed:block:");

id block = ^(id activity) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You an pull out this block before the check and then execute it in the else case. That way if we need to change what it does we only change it in one spot. Also, it makes the if case have a single responsibility of wrapping the activity.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. Done

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 invoke];
}
} else {
implementation.body(implementation.matchedValues, implementation.additionalContent);
}

//Clean up the step additional content to avoid keeping unwanted objects in memory
implementation.additionalContent = nil;
if(step.keyword.length > 0){
Expand Down Expand Up @@ -257,9 +279,3 @@ void SStep(id testCase, NSString * stepLine)
step(testCase, stepLine);
}







1 change: 0 additions & 1 deletion Cucumberish/Cucumberish.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#import "CCIStepsManager.h"
#import "CCIBlockDefinitions.h"


/**
Cucumberish is the main class you will need to parse your feature files and execute them.
You should not create instances of this class directly, instead you need to use the instance method.
Expand Down