Skip to content

Commit 2d445e8

Browse files
authored
Merge pull request #116 from olexale/feature/gherkin-comments
Add Gherkin comments support
2 parents 45e0c20 + 6454564 commit 2d445e8

6 files changed

Lines changed: 53 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## [2.1.2] - Gherkin comments support
2+
3+
* Add support for Gherkin comments (lines starting with `#`)
4+
15
## [2.1.1] - Improve data table step detection
26

37
* Fix data table step detection when combined with scenario outline

lib/src/bdd_line.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ enum LineType {
1919
scenario,
2020
scenarioOutline,
2121
step,
22+
comment,
2223
dataTableStep,
2324
after,
2425
examples,
@@ -54,6 +55,9 @@ LineType _lineTypeFromString(String line) {
5455
if (tagMarkers.any((marker) => line.startsWith(marker))) {
5556
return LineType.tag;
5657
}
58+
if (commentMarkers.any((marker) => line.startsWith(marker))) {
59+
return LineType.comment;
60+
}
5761
return LineType.unknown;
5862
}
5963

@@ -66,6 +70,7 @@ const scenarioOutlineMarkers = ['Scenario Outline:'];
6670
const stepMarkers = ['Given', 'When', 'Then', 'And', 'But'];
6771
const examplesMarkers = ['|'];
6872
const examplesTitleMarkers = ['Examples:', 'Scenarios:'];
73+
const commentMarkers = ['#'];
6974

7075
String _removeLinePrefix(String rawLine) {
7176
final lines = rawLine.split(' ');

lib/src/feature_file.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ class FeatureFile {
9292
List<StepFile> getStepFiles() => _stepFiles;
9393

9494
static List<BddLine> _prepareLines(Iterable<BddLine> input) {
95-
final inputList = input.toList(growable: false);
95+
final inputList = input
96+
.where((line) => line.type != LineType.comment)
97+
.toList(growable: false);
9698
final lines = inputList
9799
.mapIndexed(
98100
(index, bddLine) {

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: bdd_widget_test
22
description: A BDD-style widget testing library. Generates Flutter widget tests from *.feature files.
3-
version: 2.1.1
3+
version: 2.1.2
44
repository: https://github.com/olexale/bdd_widget_test
55
issue_tracker: https://github.com/olexale/bdd_widget_test/issues
66

test/comment_test.dart

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,43 @@ import 'package:flutter_test/flutter_test.dart';
2222
2323
import './step/the_app_is_running.dart';
2424
25+
void main() {
26+
group(\'\'\'Testing feature\'\'\', () {
27+
testWidgets(\'\'\'Testing scenario\'\'\', (tester) async {
28+
await theAppIsRunning(tester);
29+
});
30+
});
31+
}
32+
''';
33+
34+
final feature = FeatureFile(
35+
featureDir: 'test.feature',
36+
package: 'test',
37+
input: featureFile,
38+
);
39+
expect(feature.dartContent, expectedFeatureDart);
40+
});
41+
42+
test('Gherkin comments are ignored', () {
43+
const featureFile = '''
44+
# This is a comment
45+
46+
Feature: Testing feature
47+
#One more comment
48+
Scenario: Testing scenario
49+
# Another comment
50+
Given the app is running
51+
''';
52+
53+
const expectedFeatureDart = '''
54+
// GENERATED CODE - DO NOT MODIFY BY HAND
55+
// ignore_for_file: type=lint, type=warning
56+
57+
import 'package:flutter/material.dart';
58+
import 'package:flutter_test/flutter_test.dart';
59+
60+
import './step/the_app_is_running.dart';
61+
2562
void main() {
2663
group(\'\'\'Testing feature\'\'\', () {
2764
testWidgets(\'\'\'Testing scenario\'\'\', (tester) async {

test/full_set_test.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ import 'package:test/test.dart';
55
void main() {
66
test('fully custom test ', () {
77
const featureFile = '''
8+
# This is a comment
89
@customFeatureTag
910
Feature: Counter
11+
This is a comment too
1012
Background:
1113
Given the app is running
1214
After:
@@ -19,6 +21,7 @@ Feature: Counter
1921
Then I see {'0'} text
2022
Feature: Counter 2
2123
Background:
24+
#One more comment
2225
Given the app is running
2326
Scenario: Initial counter value is 0
2427
Given the app is running

0 commit comments

Comments
 (0)