forked from acuminous/yadda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFeatureParserTests.js
597 lines (495 loc) · 27.6 KB
/
FeatureParserTests.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
/* jslint node: true */
/* global describe, it, afterEach */
"use strict";
var fs = require('../lib/shims').fs,
proc = require('../lib/shims').process;
var path = require('../lib/shims').path;
var assert = require("assert");
var FeatureParser = require('../lib/index').parsers.FeatureParser;
var Localisation = require('../lib/index').localisation;
var Language = require('../lib/index').localisation.Language;
var Pirate = require('../lib/index').localisation.Pirate;
var English = require('../lib/index').localisation.English;
describe('FeatureParser', function() {
afterEach(function() {
Localisation.default = English;
});
describe('(Features)', function() {
it('should parse feature title', function() {
var feature = parse_file('feature/simple_feature');
assert.equal(feature.title, 'Simple Feature');
});
it('should parse feature descriptions', function() {
var feature = parse_file('feature/feature_description');
assert.equal(feature.title, 'Feature Description');
assert.equal(feature.description.join(' - '), 'As a wood chopper - I want to maintain a sharp axe - So that I can chop wood');
});
it('should only allow a single feature', function() {
assert.throws(function() {
parse_file('feature/multiple_features');
}, /Feature is unexpected/);
});
it('should report incomplete features', function() {
assert.throws(function() {
parse_file('feature/incomplete_feature');
}, /Feature requires one or more scenarios/);
});
});
describe('(Scenarios)', function() {
it('should parse a simple scenario', function() {
var scenarios = parse_file('scenario/simple_scenario').scenarios;
assert.equal(scenarios.length, 1);
assert.equal(scenarios[0].title, 'Simple Scenario');
assert.deepEqual(scenarios[0].steps, ['Given A', 'When B', 'Then C']);
});
it('should parse a complex scenario', function() {
var scenarios = parse_file('scenario/complex_scenario').scenarios;
assert.equal(scenarios.length, 1);
assert.equal(scenarios[0].title, 'Complex Scenario');
assert.deepEqual(scenarios[0].steps, ['Given A', 'When B', 'Then C']);
});
it('should parse multiple scenarios', function() {
var scenarios = parse_file('scenario/multiple_scenarios').scenarios;
assert.equal(scenarios.length, 2);
assert.equal(scenarios[0].title, 'First Scenario');
assert.equal(scenarios[1].title, 'Second Scenario');
});
it('should reset scenarios between parses', function() {
assert.equal(parse_file('scenario/simple_scenario').scenarios.length, 1);
assert.equal(parse_file('scenario/simple_scenario').scenarios.length, 1);
});
it('should report incomplete scenarios', function() {
assert.throws(function() {
parse_file('scenario/incomplete_scenario_1');
}, /Scenario requires one or more steps/);
assert.throws(function() {
parse_file('scenario/incomplete_scenario_2');
}, /Scenario requires one or more steps/);
assert.throws(function() {
parse_file('scenario/incomplete_scenario_3');
}, /Scenario requires one or more steps/);
assert.throws(function() {
parse_file('scenario/incomplete_scenario_4');
}, /Scenario requires one or more steps/);
});
it('should report steps with no scenario', function() {
assert.throws(function() {
parse_file('scenario/missing_scenario');
}, /A feature must contain one or more scenarios/);
});
it('should parse multline steps with no ending dash', function() {
var scenarios = parse_file('scenario/multiline_step_scenario').scenarios;
assert.equal(scenarios.length, 1);
assert.equal(scenarios[0].title, 'Multiline Step');
assert.equal(scenarios[0].steps[0], poem);
});
it('should parse multiline steps', function() {
var scenarios = parse_file('scenario/multiline_step_scenario_with_ending_dash').scenarios;
assert.equal(scenarios.length, 1);
assert.equal(scenarios[0].title, 'Multiline Step With Ending Dash');
assert.equal(scenarios[0].steps[0], poem);
});
it('should parse multiline steps with followers', function() {
var scenarios = parse_file('scenario/multiline_step_scenario_with_followers').scenarios;
assert.equal(scenarios.length, 5);
assert.equal(scenarios[0].title, 'Multiline Step Followed By Scenario');
assert.equal(scenarios[0].steps[0], poem);
assert.equal(scenarios[1].title, 'Another scenario');
assert.equal(scenarios[2].title, 'Multiline Step Followed By Annotation');
assert.equal(scenarios[2].steps[0], poem);
assert.equal(scenarios[3].title, 'Another scenario');
assert.equal(scenarios[4].title, 'Multiline Step Followed By Example Table');
assert.equal(JSON.stringify(scenarios[4].steps[0]), JSON.stringify(poem));
});
it('should parse multiple multiline steps in the same scenario', function() {
var scenarios = parse_file('scenario/multiline_step_scenario_with_multiple_blocks').scenarios;
assert.equal(scenarios.length, 1);
assert.equal(scenarios[0].title, 'Multiline Step With Multiple Blocks');
assert.equal(scenarios[0].steps[0], ['Verse 1'].concat(poem.split('\n').splice(1, 4)).join('\n'));
assert.equal(scenarios[0].steps[1], ['Verse 2'].concat(poem.split('\n').splice(6, 9)).join('\n'));
});
it('should append the final blank line in a multiple step', function() {
var scenarios = parse_file('scenario/multiline_step_scenario_with_multiple_blocks_and_blank').scenarios;
assert.equal(scenarios.length, 1);
assert.equal(scenarios[0].title, 'Multiline Step With Multiple Blocks And Blank');
assert.equal(scenarios[0].steps[0], ['Verse 1'].concat(poem.split('\n').splice(1, 4)).concat('').join('\n'));
assert.equal(scenarios[0].steps[1], ['Verse 2'].concat(poem.split('\n').splice(6, 9)).concat('').join('\n'));
});
it('should maintain indentation while parsing multiline steps', function() {
var scenarios = parse_file('scenario/multiline_step_scenario_with_indentation').scenarios;
assert.equal(scenarios.length, 1);
assert.equal(scenarios[0].title, 'Multiline Step With Indentation');
assert.equal(scenarios[0].steps[0], [
'LOLCODE',
'HAI',
'CAN HAS STDIO?',
'PLZ OPEN FILE "LOLCATS.TXT"?',
' AWSUM THX',
' VISIBLE FILE',
' O NOES',
' INVISIBLE "ERROR!"',
'KTHXBYE'
].join('\n'));
});
it('should report malformed multiline steps', function() {
assert.throws(function() {
parse_file('scenario/malformed_multiline_scenario_1');
}, /Dash is unexpected at this time/);
assert.throws(function() {
parse_file('scenario/malformed_multiline_scenario_2');
}, /Indentation error/);
assert.throws(function() {
parse_file('scenario/malformed_multiline_scenario_3');
}, /Dash is unexpected at this time/);
assert.throws(function() {
parse_file('scenario/malformed_multiline_scenario_4');
}, /Examples is unexpected at this time/);
assert.throws(function() {
parse_file('scenario/malformed_multiline_scenario_5');
}, /Annotation is unexpected at this time/);
});
});
describe('(Annotations)', function() {
it('should parse feature annotations', function() {
var feature = parse_file('annotated/annotated_feature');
assert.equal(feature.annotations.keyword1, 'value1');
assert.equal(feature.annotations.keyword2, 'value2');
assert(feature.annotations.keyword3);
assert.equal(Object.keys(feature.scenarios[0].annotations).length, 0);
});
it('should trim feature annotations', function() {
var feature = parse_file('annotated/untrimmed_annotated_feature');
assert.equal(feature.annotations.keyword1, 'value1');
assert.equal(feature.annotations.keyword2, 'value2');
assert(feature.annotations.keyword3);
assert.equal(Object.keys(feature.scenarios[0].annotations).length, 0);
});
it('should parse scenario annotations', function() {
var feature = parse_file('annotated/annotated_scenario');
assert.equal(Object.keys(feature.annotations).length, 0);
assert.equal(feature.scenarios[0].annotations.keyword1, 'value1');
assert.equal(feature.scenarios[0].annotations.keyword2, 'value2');
assert(feature.scenarios[0].annotations.keyword3);
});
it('should trim scenario annotations', function() {
var feature = parse_file('annotated/untrimmed_annotated_scenario');
assert.equal(Object.keys(feature.annotations).length, 0);
assert.equal(feature.scenarios[0].annotations.keyword1, 'value1');
assert.equal(feature.scenarios[0].annotations.keyword2, 'value2');
assert(feature.scenarios[0].annotations.keyword3);
});
it('should support annotations with non alphanumerics', function() {
var feature = parse_file('annotated/annotated_feature_non_alphanumeric');
assert.equal(feature.annotations['keyword+1'], 'value1');
assert.equal(feature.scenarios[0].annotations['keyword-1'], 'value1');
});
it('should expand scenarios from annotated singleline example table', function() {
var scenarios = parse_file('annotated/annotated_example_table').scenarios;
assert.equal(scenarios.length, 4);
assert.equal(scenarios[0].annotations.pending, true);
assert.equal(scenarios[0].title, 'First Scenario');
assert.equal(scenarios[0].steps[0], 'Step A11');
assert.equal(scenarios[0].steps[1], 'Step 1AA');
assert.equal(scenarios[1].annotations.pending, undefined);
assert.equal(scenarios[1].title, 'Second Scenario');
assert.equal(scenarios[1].steps[0], 'Step B22');
assert.equal(scenarios[1].steps[1], 'Step 2BB');
assert.equal(scenarios[2].annotations.pending, true);
assert.equal(scenarios[2].title, 'Third Scenario');
assert.equal(scenarios[2].steps[0], 'Step C33');
assert.equal(scenarios[2].steps[1], 'Step 3CC');
});
it('should expand scenarios from annotated multiline example table', function() {
var scenarios = parse_file('annotated/annotated_multiline_example_table').scenarios;
assert.equal(scenarios.length, 4);
assert.equal(scenarios[0].annotations.pending, true);
assert.equal(scenarios[0].title, 'First Scenario');
assert.equal(scenarios[0].steps[0], 'Step A11');
assert.equal(scenarios[0].steps[1], 'Step 1AA');
assert.equal(scenarios[1].annotations.pending, undefined);
assert.equal(scenarios[1].title, 'Second Scenario');
assert.equal(scenarios[1].steps[0], 'Step B22');
assert.equal(scenarios[1].steps[1], 'Step 2BB');
assert.equal(scenarios[2].annotations.pending, true);
assert.equal(scenarios[2].title, 'Third Scenario');
assert.equal(scenarios[2].steps[0], 'Step C33');
assert.equal(scenarios[2].steps[1], 'Step 3CC');
});
it('should merge scenario annotations with example table annotations', function() {
var scenarios = parse_file('annotated/annotated_example_table').scenarios;
assert.equal(scenarios.length, 4);
assert.equal(scenarios[0].annotations.pending, true);
assert.equal(scenarios[0].annotations.only, true);
assert.equal(scenarios[1].annotations.pending, undefined);
assert.equal(scenarios[1].annotations.only, true);
assert.equal(scenarios[2].annotations.pending, true);
assert.equal(scenarios[2].annotations.only, true);
delete scenarios[0].annotations.pending;
assert.equal(scenarios[2].annotations.pending, true);
});
it('should not confuse example table annotations and scenario annotations', function() {
var scenarios = parse_file('annotated/annotated_example_table').scenarios;
assert.equal(scenarios.length, 4);
assert.equal(scenarios[3].annotations.crystal, true);
});
it('should parse scenario annotations after background', function() {
var feature = parse_file('annotated/annotated_scenario_after_background');
assert.equal(feature.scenarios[0].steps[0], 'Given A');
});
});
describe('(Single line Example Tables)', function() {
it('should expand scenarios from example table', function() {
var scenarios = parse_file('example_table/example_table').scenarios;
assert.equal(scenarios.length, 2);
assert.equal(scenarios[0].title, 'First Scenario');
assert.equal(scenarios[0].steps[0], 'Step A11');
assert.equal(scenarios[0].steps[1], 'Step 1AA');
assert.equal(scenarios[1].title, 'Second Scenario');
assert.equal(scenarios[1].steps[0], 'Step B22');
assert.equal(scenarios[1].steps[1], 'Step 2BB');
});
it('should expand scenarios from example table with chevrons', function() {
var scenarios = parse_file('example_table/example_table_with_chevrons', {
leftPlaceholderChar: '<',
rightPlaceholderChar: '>'
}).scenarios;
assert.equal(scenarios.length, 2);
assert.equal(scenarios[0].title, 'First Scenario');
assert.equal(scenarios[0].steps[0], 'Step A11');
assert.equal(scenarios[0].steps[1], 'Step 1AA');
assert.equal(scenarios[1].title, 'Second Scenario');
assert.equal(scenarios[1].steps[0], 'Step B22');
assert.equal(scenarios[1].steps[1], 'Step 2BB');
});
it('should expand scenarios from example table using \\u2506 separator', function() {
var scenarios = parse_file('example_table/example_table_2506').scenarios;
assert.equal(scenarios.length, 2);
assert.equal(scenarios[0].title, 'First Scenario');
assert.equal(scenarios[0].steps[0], 'Step A11');
assert.equal(scenarios[0].steps[1], 'Step 1AA');
assert.equal(scenarios[1].title, 'Second Scenario');
assert.equal(scenarios[1].steps[0], 'Step B22');
assert.equal(scenarios[1].steps[1], 'Step 2BB');
});
it('should expand scenarios from example table with outer borders', function() {
var scenarios = parse_file('example_table/example_table_with_outer_borders').scenarios;
assert.equal(scenarios.length, 2);
assert.equal(scenarios[0].title, 'First Scenario');
assert.equal(scenarios[0].steps[0], 'Step A11');
assert.equal(scenarios[0].steps[1], 'Step 1AA');
assert.equal(scenarios[1].title, 'Second Scenario');
assert.equal(scenarios[1].steps[0], 'Step B22');
assert.equal(scenarios[1].steps[1], 'Step 2BB');
});
it('should stash annotations for following scenarios', function() {
var scenarios = parse_file('example_table/example_table_followed_by_annotated_scenario').scenarios;
assert.equal(scenarios.length, 3);
assert.equal(scenarios[2].title, 'Annotated Scenario');
assert(scenarios[2].annotations.pending);
});
it('should report malformed singleline example tables', function() {
assert.throws(function() {
parse_file('example_table/malformed_example_table_1').scenarios;
}, /Incorrect number of fields in example table/);
assert.throws(function() {
parse_file('example_table/malformed_example_table_2').scenarios;
}, /Blank is unexpected at this time/);
assert.throws(function() {
parse_file('example_table/malformed_example_table_3').scenarios;
}, /Text is unexpected at this time/);
});
it('should report incomplete example table', function() {
assert.throws(function() {
parse_file('example_table/incomplete_example_table_1');
}, /Examples table requires one or more headings/);
assert.throws(function() {
parse_file('example_table/incomplete_example_table_2');
}, /Examples table requires one or more rows/);
assert.throws(function() {
parse_file('example_table/incomplete_example_table_3');
}, /Scenario is unexpected at this time/);
assert.throws(function() {
parse_file('example_table/incomplete_example_table_4');
}, /Scenario is unexpected at this time/);
});
it('should expand feature background from example table', function() {
var feature = parse_file('example_table/feature_with_background_and_example_table');
assert.equal(feature.scenarios.length, 4);
assert.equal(feature.scenarios[0].steps[0], 'BG A1');
assert.equal(feature.scenarios[1].steps[0], 'BG B2');
assert.equal(feature.scenarios[2].steps[0], 'BG X3');
assert.equal(feature.scenarios[3].steps[0], 'BG Y4');
});
it('should add meta fields to example table', function() {
var scenarios = parse_file('example_table/meta_fields').scenarios;
assert.equal(scenarios.length, 2);
assert.equal(scenarios[0].title, 'First Scenario');
assert.equal(scenarios[0].steps[0], '1 First 9:5');
assert.equal(scenarios[0].steps[1], '1 A 9:14');
assert.equal(scenarios[0].steps[2], '1 1 9:23');
assert.equal(scenarios[1].title, 'Second Scenario');
assert.equal(scenarios[1].steps[0], '2 Second 10:5');
assert.equal(scenarios[1].steps[1], '2 B 10:14');
assert.equal(scenarios[1].steps[2], '2 2 10:23');
});
it('should expand multiline step scenarios from example table', function() {
var scenarios = parse_file('example_table/multiline_step_example_table').scenarios;
assert.equal(scenarios.length, 2);
assert.equal(scenarios[0].title, 'First Scenario');
assert.equal(scenarios[0].steps[0], 'Step\nA11\n1AA');
assert.equal(scenarios[1].title, 'Second Scenario');
assert.equal(scenarios[1].steps[0], 'Step\nB22\n2BB');
});
});
describe('(Multiline Example Tables)', function() {
it('should expand scenarios from simple multiline example table', function() {
var scenarios = parse_file('example_table/simple_multiline_example_table').scenarios;
assert.equal(scenarios.length, 2);
assert.equal(scenarios[0].title, 'Simple Multiline Example Table');
assert.equal(scenarios[0].steps.length, 2);
assert.equal(scenarios[0].steps[0], 'Step left 1');
assert.equal(scenarios[0].steps[1], ['Step right 1', 'right 2'].join('\n'));
assert.equal(scenarios[1].title, 'Simple Multiline Example Table');
assert.equal(scenarios[1].steps.length, 2);
assert.equal(scenarios[1].steps[0], ['Step left 3', 'left 4'].join('\n'));
assert.equal(scenarios[1].steps[1], 'Step right 3');
});
it('should expand scenarios from complex multiline examples', function() {
var scenarios = parse_file('example_table/complex_multiline_example_table').scenarios;
assert.equal(scenarios.length, 2);
assert.equal(scenarios[0].title, 'Complex Multiline Example Table');
assert.equal(scenarios[0].steps.length, 2);
assert.equal(scenarios[0].steps[0], 'Step x {\n y\n }');
assert.equal(scenarios[0].steps[1], 'Step foo');
assert.equal(scenarios[1].title, 'Complex Multiline Example Table');
assert.equal(scenarios[0].steps.length, 2);
assert.equal(scenarios[1].steps[0], 'Step ');
assert.equal(scenarios[1].steps[1], 'Step x {\n y\n }');
});
it('should expand scenarios from multiline example table with outer border', function() {
var scenarios = parse_file('example_table/multiline_example_table_with_outer_border').scenarios;
assert.equal(scenarios.length, 2);
assert.equal(scenarios[0].title, 'Multiline Example Table With Outer Border');
assert.equal(scenarios[0].steps.length, 2);
assert.equal(scenarios[0].steps[0], 'Step left 1');
assert.equal(scenarios[0].steps[1], ['Step right 1', 'right 2'].join('\n'));
assert.equal(scenarios[1].title, 'Multiline Example Table With Outer Border');
assert.equal(scenarios[1].steps.length, 2);
assert.equal(scenarios[1].steps[0], ['Step left 3', 'left 4'].join('\n'));
assert.equal(scenarios[1].steps[1], 'Step right 3');
});
it('should report malformed multiline examples', function() {
assert.throws(function() {
parse_file('example_table/malformed_multiline_example_table_1');
}, /Dash is unexpected at this time/);
assert.throws(function() {
parse_file('example_table/malformed_multiline_example_table_2');
}, /Indentation error/);
assert.throws(function() {
parse_file('example_table/malformed_multiline_example_table_3');
}, /Text is unexpected at this time/);
});
it('should add meta fields to multiline example table', function() {
var scenarios = parse_file('example_table/meta_fields_multiline_example_table').scenarios;
assert.equal(scenarios.length, 2);
assert.equal(scenarios[0].title, 'Meta Fields Multiline Example Table');
assert.equal(scenarios[0].steps.length, 2);
assert.equal(scenarios[0].steps[0], '1 left 1 9:5');
assert.equal(scenarios[0].steps[1], '1 right 1\nright 2 9:14');
assert.equal(scenarios[1].title, 'Meta Fields Multiline Example Table');
assert.equal(scenarios[1].steps.length, 2);
assert.equal(scenarios[1].steps[0], '2 left 3\nleft 4 12:5');
assert.equal(scenarios[1].steps[1], '2 right 3 12:14');
});
});
describe('(Localisation)', function() {
it('should support multiple languages', function() {
var feature = parse_file('localisation/pirate_feature', Pirate);
assert.equal(feature.title, 'Treasure Island');
var scenarios = feature.scenarios;
assert.equal(scenarios.length, 2);
assert.equal(scenarios[0].title, 'The Black Spot');
assert.deepEqual(scenarios[0].steps, ['Given A', 'When B', 'Then C']);
assert(scenarios[1].annotations.brig, 'Localised scenario was not marked as pending');
});
it('should support multiple languages using the options object', function() {
var feature = parse_file('localisation/pirate_feature', { language: Pirate });
assert.equal(feature.title, 'Treasure Island');
var scenarios = feature.scenarios;
assert.equal(scenarios.length, 2);
assert.equal(scenarios[0].title, 'The Black Spot');
assert.deepEqual(scenarios[0].steps, ['Given A', 'When B', 'Then C']);
assert(scenarios[1].annotations.brig, 'Localised scenario was not marked as pending');
});
it('should support changing the default language', function() {
Localisation.default = Pirate;
var feature = new FeatureParser().parse(load('localisation/pirate_feature'));
assert.equal(feature.title, 'Treasure Island');
var scenarios = feature.scenarios;
assert.equal(scenarios.length, 2);
assert.equal(scenarios[0].title, 'The Black Spot');
assert.deepEqual(scenarios[0].steps, ['Given A', 'When B', 'Then C']);
assert(scenarios[1].annotations.brig, 'Localised scenario was not marked as pending');
});
it('should report missing translations', function() {
var language = new Language('Incomplete', {});
assert.throws(function() {
parse_file('feature/multiple_features', language);
}, /Keyword "feature" has not been translated into Incomplete/);
});
});
describe('(Feature Backgrounds)', function() {
it('should parse feature background', function() {
var feature = parse_file('background/feature_with_background');
assert.equal(feature.scenarios[0].steps[0], 'Given A');
});
it('shoud parse multiline step background', function() {
var scenarios = parse_file('background/background_with_multiline_step').scenarios;
assert.equal(scenarios.length, 1);
assert.equal(scenarios[0].title, 'Simple Scenario');
assert.equal(scenarios[0].steps[0], poem);
assert.equal(scenarios[0].steps[1], 'Given A');
});
it('should report background annotations', function() {
assert.throws(function() {
parse_file('background/malformed_background_annotated');
}, /Background is unexpected at this time/);
});
});
describe('(Comments)', function() {
it('should support single line comments', function() {
var feature = parse_file('comment/singleline_comment');
var scenarios = feature.scenarios;
assert.equal(feature.title, 'Single Line Comments Feature');
assert.equal(scenarios.length, 1);
assert.equal(scenarios[0].title, 'Single Line Comments Scenario');
assert.deepEqual(scenarios[0].steps, ['Given A', 'When # B', 'Then C #']);
});
it('should parse multiline comments', function() {
var feature = parse_file('comment/multiline_comment');
var scenarios = feature.scenarios;
assert.equal(feature.title, 'Simple Feature');
assert.equal(scenarios.length, 1);
assert.equal(scenarios[0].title, 'Simple Scenario');
assert.deepEqual(scenarios[0].steps, ['Given A', 'When B', 'Then C']);
});
});
function parse_file(filename, options) {
return new FeatureParser(options).parse(load(filename));
}
function load(filename) {
return fs.readFileSync(path.join(__dirname, 'features', filename + '.feature'), 'utf8');
}
var poem = [
'Good Times',
'May we go our separate ways,',
'Finding fortune and new friends.',
'But let us not forget these days,',
'Or let the good times ever end.',
'',
'A poet with wiser words than mine,',
'Wrote that nothing gold can stay.',
'These are golden days we\'re in,',
'And so are bound to fade away.'
].join('\n');
});