Skip to content

Commit 7239c18

Browse files
authored
Merge pull request #58 from ron-brosh/Cucumber-data-table-documentation
Cucumber-data-table-documentation
2 parents d172e0d + 39ddbc7 commit 7239c18

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,38 @@ Feature: Sample
125125
Then I see {'Do not forget your towel!'} text
126126
```
127127

128+
While the `DataTable`-like syntax is a good practice for scenarios that require repeated steps, for example, entering text in different fields, sometimes we want to prepare test data in a readable way and mock our scneario's prerequisites and assert the expected result in an explicit domain driven way.
129+
To handle this, we create a data table:
130+
```ruby
131+
Feature: Search songs
132+
133+
Scenario: Searched text matches a song's details
134+
Given available songs
135+
| 'artist' | 'name' |
136+
| 'The Doors' | 'Riders on the storm' |
137+
| 'Bob Dylan' | "Knockin' On Heaven's Door" |
138+
| 'The Beatles' | 'Here Comes the Sun' |
139+
When I search for text {'door'}
140+
Then I see songs
141+
| 'artist' | 'name' |
142+
| 'The Doors' | 'Riders on the storm' |
143+
| 'Bob Dylan' | "Knockin' On Heaven's Door" |
144+
```
145+
For each of the above step lines that are followed by a table, in the related generate step file, the created function will have an object parameter of type `DataTable`:
146+
```dart
147+
import 'package:bdd_widget_test/data_table.dart' as bdd;
148+
import 'package:flutter_test/flutter_test.dart';
149+
150+
/// Usage: Given available songs
151+
Future<void> availableSongs(WidgetTester tester, bdd.DataTable dataTable) async {
152+
throw UnimplementedError();
153+
}
154+
```
155+
Use the `DataTable` parameter to get access to the data:
156+
```dart
157+
final dataAsList = dataTable.asLists(); // [['artist', 'name'], ['The Doors', 'Riders on the storm'], ...]
158+
final dataAsMaps = dataTable.asMaps(); // [{'artist: 'The Doors', 'name: 'Riders on the storm'}, ...]
159+
```
128160
## Tags
129161
130162
Tags are used to filter scenarios in the test runner. Here are some examples:

0 commit comments

Comments
 (0)