Permalink
Browse files

updates to add passing feature file defining how basic cucumber shoul…

…d work. also fixes issue where tables and text attached to steps weren't passed through on a step that had no regex arguments
  • Loading branch information...
David Siebecker
David Siebecker committed Jul 26, 2016
1 parent 1769e81 commit 29b001dd9466c394b72a8dc0eeae0d4e6d586ab6
@@ -90,18 +90,20 @@ - (CCIStepDefinition *)findMatchDefinitionForStep:(CCIStep *)step
- (CCIStepDefinition *)findDefinitionForStep:(CCIStep *)step amongDefinitions:(NSArray *)definitions
{
NSError * error;
CCIStepDefinition *ret = nil;
for(CCIStepDefinition * d in definitions){
NSString * pattern = d.regexString;
if ([d.regexString isEqualToString:step.text]) {
//It has no params, it is just plain perfect match
return [d copy];
ret = [d copy];
break;
}
NSRegularExpression * regex = [NSRegularExpression regularExpressionWithPattern:pattern options:NSRegularExpressionAnchorsMatchLines error:&error];
if(error && d == definitions.lastObject){
//Only return nil if we reached the last definition without finding a match
return nil;
break;
}
NSRange searchRange = NSMakeRange(0, [step.text lengthOfBytesUsingEncoding:NSUTF8StringEncoding]);
NSTextCheckingResult * match = [[regex matchesInString:step.text options:NSMatchingReportCompletion range:searchRange] firstObject];
@@ -115,19 +117,22 @@ - (CCIStepDefinition *)findDefinitionForStep:(CCIStep *)step amongDefinitions:(N
NSString * value = [step.text substringWithRange:range];
[values addObject:value];
}
if(step.argument.rows.count > 0){
definition.additionalContent = @{@"DataTable" : step.argument.rows};
}else if(step.argument.content.length > 0){
definition.additionalContent = @{@"DocString" : step.argument.content};
}
definition.matchedValues = values;
return definition;
ret = definition;
break;
}
}
if (ret) {
if(step.argument.rows.count > 0){
ret.additionalContent = @{@"DataTable" : step.argument.rows};
}else if(step.argument.content.length > 0){
ret.additionalContent = @{@"DocString" : step.argument.content};
}
}
return nil;
return ret;
}
- (void)executeStep:(CCIStep *)step
@@ -149,6 +154,7 @@ - (void)executeStep:(CCIStep *)step
if(step.keyword.length > 0){
NSLog(@"Step: \"%@ %@\" passed", step.keyword, step.text);
}
step.status = CCIStepStatusPassed;
}
@@ -29,6 +29,12 @@
#import "CCILocation.h"
#import "CCIArgument.h"
typedef NS_ENUM(NSInteger,CCIStepStatus) {
CCIStepStatusNotExecuted = 0,
CCIStepStatusPassed,
CCIStepStatusFailed
};
/**
Represents a step in a scenario
Step contains information about its argument, location and keyword (When, Then, Given, etc...)
@@ -55,6 +61,11 @@
*/
@property (nonatomic, copy) NSString * text;
/**
The step status
*/
@property (nonatomic,assign) CCIStepStatus status;
/**
Creates an instance with properties filled from the passed dictionary
@@ -451,6 +451,7 @@ void executeSteps(XCTestCase * testCase, NSArray * steps, id parentScenario)
[testCase recordFailureWithDescription:exception.reason inFile:filePath atLine:step.location.line expected:YES];
if([parentScenario isKindOfClass:[CCIScenarioDefinition class]]){
CCIScenarioDefinition * scenario = (CCIScenarioDefinition *)parentScenario;
step.status = CCIStepStatusFailed;
scenario.success = NO;
scenario.failureReason = exception.reason;
}
@@ -0,0 +1,24 @@
//
// NSArray+Hashes.h
// CucumberishExample
//
// Created by David Siebecker on 7/26/16.
// Copyright © 2016 Ahmed Ali. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface NSArray (Hashes)
/**
* Converts an NSArray<NSArray> to an array of dictionaries where the keys for the dictionary are the elements in the first array in self
* @return the row hashes
*/
-(NSArray*)rowHashes;
/**
* Converts an NSArray<NSArray> to an array of dictionaries where the kesy for the dictionary are the first elements in each array in self
* @return the column hashes
*/
-(NSArray*)columnHashes;
@end
@@ -0,0 +1,44 @@
//
// NSArray+Hashes.m
// CucumberishExample
//
// Created by David Siebecker on 7/26/16.
// Copyright © 2016 Ahmed Ali. All rights reserved.
//
#import "NSArray+Hashes.h"
@implementation NSArray (Hashes)
-(NSArray *)rowHashes
{
NSMutableArray *array = [NSMutableArray arrayWithCapacity:self.count];
NSArray *keys = self[0];
for (NSInteger i = 1; i < self.count; i++) {
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
NSArray *values = self[i];
[keys enumerateObjectsUsingBlock:^(NSString * _Nonnull key, NSUInteger idx, BOOL * _Nonnull stop) {
dict[key] = values[idx];
}];
[array addObject:dict];
}
return array;
}
-(NSArray *)columnHashes
{
NSMutableArray *array = [NSMutableArray arrayWithCapacity:[self[0] count]-1];
NSArray *keys = [self valueForKey:@"firstObject"];
for (NSInteger i = 0; i < keys.count; i++) {
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
[self enumerateObjectsUsingBlock:^(NSString * _Nonnull key, NSUInteger idx, BOOL * _Nonnull stop) {
if (idx != 0) {
dict[key] = self[i][idx];
}
}];
[array addObject:dict];
}
return array;
}
@end
Oops, something went wrong.

0 comments on commit 29b001d

Please sign in to comment.