diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ec9cef..e27cda4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## [2.1.2] - Gherkin comments support + +* Add support for Gherkin comments (lines starting with `#`) + ## [2.1.1] - Improve data table step detection * Fix data table step detection when combined with scenario outline diff --git a/lib/src/bdd_line.dart b/lib/src/bdd_line.dart index 07237ab..b6afa52 100644 --- a/lib/src/bdd_line.dart +++ b/lib/src/bdd_line.dart @@ -19,6 +19,7 @@ enum LineType { scenario, scenarioOutline, step, + comment, dataTableStep, after, examples, @@ -54,6 +55,9 @@ LineType _lineTypeFromString(String line) { if (tagMarkers.any((marker) => line.startsWith(marker))) { return LineType.tag; } + if (commentMarkers.any((marker) => line.startsWith(marker))) { + return LineType.comment; + } return LineType.unknown; } @@ -66,6 +70,7 @@ const scenarioOutlineMarkers = ['Scenario Outline:']; const stepMarkers = ['Given', 'When', 'Then', 'And', 'But']; const examplesMarkers = ['|']; const examplesTitleMarkers = ['Examples:', 'Scenarios:']; +const commentMarkers = ['#']; String _removeLinePrefix(String rawLine) { final lines = rawLine.split(' '); diff --git a/lib/src/feature_file.dart b/lib/src/feature_file.dart index 6330161..cb8d306 100644 --- a/lib/src/feature_file.dart +++ b/lib/src/feature_file.dart @@ -92,7 +92,9 @@ class FeatureFile { List getStepFiles() => _stepFiles; static List _prepareLines(Iterable input) { - final inputList = input.toList(growable: false); + final inputList = input + .where((line) => line.type != LineType.comment) + .toList(growable: false); final lines = inputList .mapIndexed( (index, bddLine) { diff --git a/pubspec.yaml b/pubspec.yaml index c251cc3..cc4d5b9 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: bdd_widget_test description: A BDD-style widget testing library. Generates Flutter widget tests from *.feature files. -version: 2.1.1 +version: 2.1.2 repository: https://github.com/olexale/bdd_widget_test issue_tracker: https://github.com/olexale/bdd_widget_test/issues diff --git a/test/comment_test.dart b/test/comment_test.dart index b43b331..a69bc46 100644 --- a/test/comment_test.dart +++ b/test/comment_test.dart @@ -22,6 +22,43 @@ import 'package:flutter_test/flutter_test.dart'; import './step/the_app_is_running.dart'; +void main() { + group(\'\'\'Testing feature\'\'\', () { + testWidgets(\'\'\'Testing scenario\'\'\', (tester) async { + await theAppIsRunning(tester); + }); + }); +} +'''; + + final feature = FeatureFile( + featureDir: 'test.feature', + package: 'test', + input: featureFile, + ); + expect(feature.dartContent, expectedFeatureDart); + }); + + test('Gherkin comments are ignored', () { + const featureFile = ''' +# This is a comment + +Feature: Testing feature + #One more comment + Scenario: Testing scenario +# Another comment + Given the app is running +'''; + + const expectedFeatureDart = ''' +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint, type=warning + +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; + +import './step/the_app_is_running.dart'; + void main() { group(\'\'\'Testing feature\'\'\', () { testWidgets(\'\'\'Testing scenario\'\'\', (tester) async { diff --git a/test/full_set_test.dart b/test/full_set_test.dart index a04166c..26e90f5 100644 --- a/test/full_set_test.dart +++ b/test/full_set_test.dart @@ -5,8 +5,10 @@ import 'package:test/test.dart'; void main() { test('fully custom test ', () { const featureFile = ''' +# This is a comment @customFeatureTag Feature: Counter + This is a comment too Background: Given the app is running After: @@ -19,6 +21,7 @@ Feature: Counter Then I see {'0'} text Feature: Counter 2 Background: + #One more comment Given the app is running Scenario: Initial counter value is 0 Given the app is running