Skip to content

Commit

Permalink
tests(feature-paths): fixed tests after change to allow absolute paths
Browse files Browse the repository at this point in the history
chore(release): updated release and changelog
  • Loading branch information
jonsamwell committed May 25, 2021
1 parent ea39e76 commit 8df7314
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 21 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## [2.0.2] - 25/05/2021
* Fix #45 executing feature files outside of the current working directory

## [2.0.1] - 02/05/2021

* BREAKING CHANGE: `TestFailure` is no longer thrown when an `expect` fails. Instead, use `GherkinTestFailure` when catching errors (i.e. replace `on TestFailure catch` with `on GherkinTestFailure catch`) (#37).
Expand Down
2 changes: 1 addition & 1 deletion example/report.json

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion lib/src/configuration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@ import 'package:gherkin/src/io/feature_file_matcher.dart';
import 'package:gherkin/src/io/io_feature_file_accessor.dart';
import 'package:gherkin/src/io/feature_file_reader.dart';

import '../gherkin.dart';
import './gherkin/parameters/custom_parameter.dart';
import './gherkin/steps/world.dart';
import './hooks/hook.dart';
import './reporters/reporter.dart';

import 'gherkin/attachments/attachment_manager.dart';
import 'gherkin/steps/step_definition.dart';
import 'reporters/json/json_reporter.dart';
import 'reporters/message_level.dart';
import 'reporters/progress_reporter.dart';
import 'reporters/stdout_reporter.dart';
import 'reporters/test_run_summary_reporter.dart';

typedef CreateWorld = Future<World> Function(TestConfiguration config);
typedef CreateAttachmentManager = Future<AttachmentManager> Function(
Expand Down
2 changes: 1 addition & 1 deletion lib/src/feature_file_runner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import 'dart:async';
import 'package:gherkin/src/gherkin/runnables/scenario_type_enum.dart';
import 'package:collection/collection.dart';

import '../gherkin.dart';
import './reporters/message_level.dart';
import './hooks/hook.dart';
import './reporters/reporter.dart';
Expand All @@ -20,6 +19,7 @@ import './gherkin/steps/step_run_result.dart';
import './gherkin/steps/world.dart';
import './reporters/messages.dart';
import './gherkin/attachments/attachment_manager.dart';
import 'gherkin/exceptions/gherkin_exception.dart';

class FeatureFileRunner {
final TestConfiguration _config;
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: gherkin
version: 2.0.1
version: 2.0.2
description: A Gherkin parsers and runner for Dart which is very similar to Cucumber, it provides the base BDD functionality ready for use in platform specific implementations i.e. flutter/web
homepage: https://github.com/jonsamwell/dart_gherkin

Expand Down
16 changes: 9 additions & 7 deletions test/io/io_feature_file_accessor_gnu_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import 'package:gherkin/gherkin.dart';
import 'package:glob/glob.dart';
import 'package:test/test.dart';

import 'path_part_matcher.dart';

void main() {
group('Matcher', () {
final indexer = IoFeatureFileAccessor();
Expand All @@ -12,7 +14,7 @@ void main() {
test('lists all matching files', () async {
expect(
await indexer.listFiles(RegExp(r'test/test_resources/(.*).feature')),
containsAll([
PathPartMatcher([
r'test/test_resources/a.feature',
r'test/test_resources/subdir/b.feature',
r'test/test_resources/subdir/c.feature',
Expand All @@ -24,7 +26,7 @@ void main() {
expect(
await indexer
.listFiles(RegExp(r'test/test_resources/subdir/.*\.feature')),
containsAll([
PathPartMatcher([
r'test/test_resources/subdir/b.feature',
r'test/test_resources/subdir/c.feature',
]),
Expand All @@ -36,7 +38,7 @@ void main() {
test('lists all matching files', () async {
expect(
await indexer.listFiles(Glob('test/test_resources/**.feature')),
containsAll([
PathPartMatcher([
r'test/test_resources/a.feature',
r'test/test_resources/subdir/b.feature',
r'test/test_resources/subdir/c.feature',
Expand All @@ -47,9 +49,9 @@ void main() {
test('list all matching file without subdirectories', () async {
expect(
await indexer.listFiles(Glob('test/test_resources/*.feature')),
[
PathPartMatcher([
r'test/test_resources/a.feature',
],
]),
);
});
});
Expand All @@ -58,9 +60,9 @@ void main() {
test('lists one specified file', () async {
expect(
await indexer.listFiles(r'test/test_resources/a.feature'),
[
PathPartMatcher([
r'test/test_resources/a.feature',
],
]),
);
});
});
Expand Down
22 changes: 12 additions & 10 deletions test/io/io_feature_file_accessor_windows_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import 'package:gherkin/gherkin.dart';
import 'package:glob/glob.dart';
import 'package:test/test.dart';

import 'path_part_matcher.dart';

void main() {
group('Matcher', () {
final indexer = IoFeatureFileAccessor();
Expand All @@ -13,22 +15,22 @@ void main() {
expect(
await indexer
.listFiles(RegExp(r'test\\test_resources\\(.*).feature')),
[
PathPartMatcher([
r'test\test_resources\a.feature',
r'test\test_resources\subdir\b.feature',
r'test\test_resources\subdir\c.feature',
],
]),
);
});

test('lists files from subdirectory', () async {
expect(
await indexer
.listFiles(RegExp(r'test\\test_resources\\subdir\\.*\.feature')),
[
PathPartMatcher([
r'test\test_resources\subdir\b.feature',
r'test\test_resources\subdir\c.feature',
],
]),
);
});
});
Expand All @@ -37,20 +39,20 @@ void main() {
test('lists all matching files', () async {
expect(
await indexer.listFiles(Glob('test/test_resources/**.feature')),
[
PathPartMatcher([
r'test\test_resources\a.feature',
r'test\test_resources\subdir\b.feature',
r'test\test_resources\subdir\c.feature',
],
]),
);
});

test('list all matching file without subdirectories', () async {
expect(
await indexer.listFiles(Glob('test/test_resources/*.feature')),
[
PathPartMatcher([
r'test\test_resources\a.feature',
],
]),
);
});
});
Expand All @@ -59,9 +61,9 @@ void main() {
test('lists one specified file', () async {
expect(
await indexer.listFiles(r'test\test_resources\a.feature'),
[
PathPartMatcher([
r'test\test_resources\a.feature',
],
]),
);
});
});
Expand Down
33 changes: 33 additions & 0 deletions test/io/path_part_matcher.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import 'package:matcher/matcher.dart';

class PathPartMatcher extends Matcher {
late final Iterable<String> relativePaths;
final description = StringDescription();

PathPartMatcher(this.relativePaths);

@override
Description describe(Description description) {
return description..add(description.toString());
}

@override
bool matches(dynamic absolutePaths, Map matchState) {
var match = true;

for (var absPath in (absolutePaths as Iterable<String>)) {
var internalMatch = false;

for (var relativePath in relativePaths) {
if (absPath.contains(relativePath)) {
internalMatch = true;
break;
}
}

match = match && internalMatch;
}

return match;
}
}

0 comments on commit 8df7314

Please sign in to comment.