cuketagger 1.5 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1548 @@
1
+ require "#{File.dirname(__FILE__)}/spec_helper"
2
+
3
+
4
+ describe 'Tagger, Integration' do
5
+
6
+ clazz = CukeTagger::Tagger
7
+
8
+ let(:tagger) { clazz.new }
9
+ let(:source_text) { ['',
10
+ 'Feature:',
11
+ '',
12
+ 'Scenario:',
13
+ ' * a step',
14
+ '',
15
+ 'Scenario Outline:',
16
+ ' * a step',
17
+ '',
18
+ 'Examples:',
19
+ ' | param |',
20
+ ' | value |'].join("\n") }
21
+ let(:file_path) { "#{@default_file_directory}/#{@default_feature_file_name}" }
22
+
23
+ before(:each) do
24
+ File.open(file_path, 'w') { |file| file.write(source_text) }
25
+ end
26
+
27
+
28
+ describe 'adding tags' do
29
+
30
+ it 'can add a tag to a file' do
31
+ args = "add:bar #{file_path}"
32
+
33
+ output = CukeTaggerHelper.run_cuketagger(args)
34
+
35
+ expect(output).to eq(['@bar',
36
+ 'Feature:',
37
+ '',
38
+ 'Scenario:',
39
+ ' * a step',
40
+ '',
41
+ 'Scenario Outline:',
42
+ ' * a step',
43
+ '',
44
+ 'Examples:',
45
+ ' | param |',
46
+ ' | value |'].join("\n"))
47
+ end
48
+
49
+ it 'can add a tag to a part of a file' do
50
+ args = "add:bar #{file_path}:4"
51
+
52
+ output = CukeTaggerHelper.run_cuketagger(args)
53
+
54
+ expect(output).to eq(['',
55
+ 'Feature:',
56
+ '@bar',
57
+ 'Scenario:',
58
+ ' * a step',
59
+ '',
60
+ 'Scenario Outline:',
61
+ ' * a step',
62
+ '',
63
+ 'Examples:',
64
+ ' | param |',
65
+ ' | value |'].join("\n"))
66
+ end
67
+
68
+ it 'can intermix full and partial file taggings' do
69
+ args = "add:bar #{file_path} #{file_path}:7"
70
+
71
+ output = CukeTaggerHelper.run_cuketagger(args)
72
+
73
+ expect(output).to eq(['@bar',
74
+ 'Feature:',
75
+ '',
76
+ 'Scenario:',
77
+ ' * a step',
78
+ '@bar',
79
+ 'Scenario Outline:',
80
+ ' * a step',
81
+ '',
82
+ 'Examples:',
83
+ ' | param |',
84
+ ' | value |'].join("\n"))
85
+ end
86
+
87
+ it 'tags multiple files' do
88
+ source_text_1 = ['',
89
+ 'Feature: Foo',
90
+ '',
91
+ 'Scenario:',
92
+ ' * a step',
93
+ '',
94
+ 'Scenario Outline:',
95
+ ' * a step',
96
+ '',
97
+ 'Examples:',
98
+ ' | param |',
99
+ ' | value |',
100
+ ''].join("\n")
101
+
102
+ source_text_2 = ['',
103
+ 'Feature: Bar',
104
+ '',
105
+ 'Scenario:',
106
+ ' * a step',
107
+ '',
108
+ 'Scenario Outline:',
109
+ ' * a step',
110
+ '',
111
+ 'Examples:',
112
+ ' | param |',
113
+ ' | value |'].join("\n")
114
+
115
+ File.open("#{@default_file_directory}/foo.feature", 'w') { |file_1| file_1.write(source_text_1) }
116
+ File.open("#{@default_file_directory}/bar.feature", 'w') { |file_2| file_2.write(source_text_2) }
117
+
118
+ args = "add:foo #{@default_file_directory}/foo.feature #{@default_file_directory}/bar.feature"
119
+
120
+ output = CukeTaggerHelper.run_cuketagger(args)
121
+
122
+ expect(output).to include(['@foo',
123
+ 'Feature: Foo',
124
+ '',
125
+ 'Scenario:',
126
+ ' * a step',
127
+ '',
128
+ 'Scenario Outline:',
129
+ ' * a step',
130
+ '',
131
+ 'Examples:',
132
+ ' | param |',
133
+ ' | value |'].join("\n"))
134
+
135
+ expect(output).to include(['@foo',
136
+ 'Feature: Bar',
137
+ '',
138
+ 'Scenario:',
139
+ ' * a step',
140
+ '',
141
+ 'Scenario Outline:',
142
+ ' * a step',
143
+ '',
144
+ 'Examples:',
145
+ ' | param |',
146
+ ' | value |'].join("\n"))
147
+ end
148
+
149
+ it 'correctly adds a tag to a feature' do
150
+ args = "add:bar #{file_path}:2"
151
+
152
+ output = CukeTaggerHelper.run_cuketagger(args)
153
+
154
+ expect(output).to eq(['@bar',
155
+ 'Feature:',
156
+ '',
157
+ 'Scenario:',
158
+ ' * a step',
159
+ '',
160
+ 'Scenario Outline:',
161
+ ' * a step',
162
+ '',
163
+ 'Examples:',
164
+ ' | param |',
165
+ ' | value |'].join("\n"))
166
+ end
167
+
168
+ it 'correctly adds a tag to a scenario' do
169
+ args = "add:bar #{file_path}:4"
170
+
171
+ output = CukeTaggerHelper.run_cuketagger(args)
172
+
173
+ expect(output).to eq(['',
174
+ 'Feature:',
175
+ '@bar',
176
+ 'Scenario:',
177
+ ' * a step',
178
+ '',
179
+ 'Scenario Outline:',
180
+ ' * a step',
181
+ '',
182
+ 'Examples:',
183
+ ' | param |',
184
+ ' | value |'].join("\n"))
185
+ end
186
+
187
+ it 'correctly adds a tag to an outline' do
188
+ args = "add:bar #{file_path}:7"
189
+
190
+ output = CukeTaggerHelper.run_cuketagger(args)
191
+
192
+ expect(output).to eq(['',
193
+ 'Feature:',
194
+ '',
195
+ 'Scenario:',
196
+ ' * a step',
197
+ '@bar',
198
+ 'Scenario Outline:',
199
+ ' * a step',
200
+ '',
201
+ 'Examples:',
202
+ ' | param |',
203
+ ' | value |'].join("\n"))
204
+ end
205
+
206
+ it 'correctly adds a tag to an example' do
207
+ args = "add:bar #{file_path}:10"
208
+
209
+ output = CukeTaggerHelper.run_cuketagger(args)
210
+
211
+ expect(output).to eq(['',
212
+ 'Feature:',
213
+ '',
214
+ 'Scenario:',
215
+ ' * a step',
216
+ '',
217
+ 'Scenario Outline:',
218
+ ' * a step',
219
+ '@bar',
220
+ 'Examples:',
221
+ ' | param |',
222
+ ' | value |'].join("\n"))
223
+ end
224
+
225
+ it 'correctly tags multiple parts of a file' do
226
+ args = "add:bar #{file_path}:2 #{file_path}:7"
227
+
228
+ output = CukeTaggerHelper.run_cuketagger(args)
229
+
230
+ expect(output).to eq(['@bar',
231
+ 'Feature:',
232
+ '',
233
+ 'Scenario:',
234
+ ' * a step',
235
+ '@bar',
236
+ 'Scenario Outline:',
237
+ ' * a step',
238
+ '',
239
+ 'Examples:',
240
+ ' | param |',
241
+ ' | value |'].join("\n"))
242
+ end
243
+
244
+
245
+ describe 'tag indentation' do
246
+
247
+ it 'correctly adds new tags to the end of an empty tag line' do
248
+ source_text = ['',
249
+ ' Feature:',
250
+ ' ',
251
+ 'Scenario:',
252
+ ' * a step',
253
+ ' ',
254
+ ' Scenario Outline:',
255
+ ' * a step',
256
+ ' ',
257
+ ' Examples:',
258
+ ' | param |',
259
+ ' | value |'].join("\n")
260
+
261
+ File.open("#{file_path}", 'w') { |file| file.write(source_text) }
262
+
263
+ args = "add:bar #{file_path}:2 #{file_path}:4 #{file_path}:7 #{file_path}:10"
264
+
265
+ output = CukeTaggerHelper.run_cuketagger(args)
266
+
267
+ expect(output).to eq([' @bar',
268
+ ' Feature:',
269
+ '@bar',
270
+ 'Scenario:',
271
+ ' * a step',
272
+ ' @bar',
273
+ ' Scenario Outline:',
274
+ ' * a step',
275
+ ' @bar',
276
+ ' Examples:',
277
+ ' | param |',
278
+ ' | value |'].join("\n"))
279
+ end
280
+
281
+ it 'correctly adds new tags to the end of a full tag line' do
282
+ source_text = ['@existing_tag',
283
+ ' Feature:',
284
+ ' @existing_tag',
285
+ 'Scenario:',
286
+ ' * a step',
287
+ ' @existing_tag',
288
+ ' Scenario Outline:',
289
+ ' * a step',
290
+ ' @existing_tag',
291
+ ' Examples:',
292
+ ' | param |',
293
+ ' | value |'].join("\n")
294
+
295
+ File.open("#{file_path}", 'w') { |file| file.write(source_text) }
296
+
297
+ args = "add:bar #{file_path}:2 #{file_path}:4 #{file_path}:7 #{file_path}:10"
298
+
299
+ output = CukeTaggerHelper.run_cuketagger(args)
300
+
301
+ expect(output).to eq(['@existing_tag @bar',
302
+ ' Feature:',
303
+ ' @existing_tag @bar',
304
+ 'Scenario:',
305
+ ' * a step',
306
+ ' @existing_tag @bar',
307
+ ' Scenario Outline:',
308
+ ' * a step',
309
+ ' @existing_tag @bar',
310
+ ' Examples:',
311
+ ' | param |',
312
+ ' | value |'].join("\n"))
313
+ end
314
+
315
+ end
316
+
317
+ it 'trims extra whitespace from a line when adding new tags' do
318
+ source_text = [' ',
319
+ 'Feature:',
320
+ '',
321
+ 'Scenario:',
322
+ ' * a step',
323
+ '',
324
+ 'Scenario Outline:',
325
+ ' * a step',
326
+ '',
327
+ 'Examples:',
328
+ ' | param |',
329
+ ' | value |'].join("\n")
330
+
331
+ File.open("#{file_path}", 'w') { |file| file.write(source_text) }
332
+
333
+ args = "add:foo #{file_path}"
334
+
335
+ output = CukeTaggerHelper.run_cuketagger(args)
336
+
337
+ expect(output).to eq(['@foo',
338
+ 'Feature:',
339
+ '',
340
+ 'Scenario:',
341
+ ' * a step',
342
+ '',
343
+ 'Scenario Outline:',
344
+ ' * a step',
345
+ '',
346
+ 'Examples:',
347
+ ' | param |',
348
+ ' | value |'].join("\n"))
349
+ end
350
+
351
+ it 'ignores duplicate tag addition arguments' do
352
+ args = "add:bar add:bar add:bar #{file_path}"
353
+
354
+ output = CukeTaggerHelper.run_cuketagger(args)
355
+
356
+ expect(output).to eq(['@bar',
357
+ 'Feature:',
358
+ '',
359
+ 'Scenario:',
360
+ ' * a step',
361
+ '',
362
+ 'Scenario Outline:',
363
+ ' * a step',
364
+ '',
365
+ 'Examples:',
366
+ ' | param |',
367
+ ' | value |'].join("\n"))
368
+ end
369
+
370
+
371
+ describe 'line adjustments' do
372
+
373
+ it 'will add a new line above an element if no tag line or blank line exists' do
374
+ source_text = ['',
375
+ 'Feature:',
376
+ '# A comment',
377
+ 'Scenario:',
378
+ ' * a step',
379
+ '',
380
+ 'Scenario Outline:',
381
+ ' * a step',
382
+ '',
383
+ 'Examples:',
384
+ ' | param |',
385
+ ' | value |'].join("\n")
386
+
387
+ File.open("#{file_path}", 'w') { |file| file.write(source_text) }
388
+
389
+ args = "add:foo #{file_path}:4"
390
+
391
+ output = CukeTaggerHelper.run_cuketagger(args)
392
+
393
+ expect(output).to eq(['',
394
+ 'Feature:',
395
+ '# A comment',
396
+ '@foo',
397
+ 'Scenario:',
398
+ ' * a step',
399
+ '',
400
+ 'Scenario Outline:',
401
+ ' * a step',
402
+ '',
403
+ 'Examples:',
404
+ ' | param |',
405
+ ' | value |'].join("\n"))
406
+ end
407
+
408
+ it 'correctly adds new lines to multiple parts of a file' do
409
+ source_text = ['# A comment',
410
+ 'Feature:',
411
+ '# A comment',
412
+ 'Scenario:',
413
+ ' * a step',
414
+ '# A comment',
415
+ 'Scenario Outline:',
416
+ ' * a step',
417
+ '# A comment',
418
+ 'Examples:',
419
+ ' | param |',
420
+ ' | value |'].join("\n")
421
+
422
+ File.open("#{file_path}", 'w') { |file| file.write(source_text) }
423
+
424
+ args = "add:foo #{file_path}:2 #{file_path}:4 #{file_path}:7 #{file_path}:10"
425
+
426
+ output = CukeTaggerHelper.run_cuketagger(args)
427
+
428
+ expect(output).to eq(['# A comment',
429
+ '@foo',
430
+ 'Feature:',
431
+ '# A comment',
432
+ '@foo',
433
+ 'Scenario:',
434
+ ' * a step',
435
+ '# A comment',
436
+ '@foo',
437
+ 'Scenario Outline:',
438
+ ' * a step',
439
+ '# A comment',
440
+ '@foo',
441
+ 'Examples:',
442
+ ' | param |',
443
+ ' | value |'].join("\n"))
444
+ end
445
+
446
+ it 'correctly adds a new line to the beginning of a file' do
447
+ source_text = ['Feature:',
448
+ '',
449
+ 'Scenario:',
450
+ ' * a step',
451
+ '',
452
+ 'Scenario Outline:',
453
+ ' * a step',
454
+ '',
455
+ 'Examples:',
456
+ ' | param |',
457
+ ' | value |'].join("\n")
458
+
459
+ File.open("#{file_path}", 'w') { |file| file.write(source_text) }
460
+
461
+ args = "add:foo #{file_path}"
462
+
463
+ output = CukeTaggerHelper.run_cuketagger(args)
464
+
465
+ expect(output).to eq(['@foo',
466
+ 'Feature:',
467
+ '',
468
+ 'Scenario:',
469
+ ' * a step',
470
+ '',
471
+ 'Scenario Outline:',
472
+ ' * a step',
473
+ '',
474
+ 'Examples:',
475
+ ' | param |',
476
+ ' | value |'].join("\n"))
477
+ end
478
+
479
+ end
480
+
481
+ end
482
+
483
+
484
+ describe 'removing tags' do
485
+
486
+ let(:source_text) { ['@foo @bar',
487
+ 'Feature:',
488
+ '',
489
+ '@foo @bar',
490
+ 'Scenario:',
491
+ ' * a step',
492
+ '',
493
+ '@foo @bar',
494
+ 'Scenario Outline:',
495
+ ' * a step',
496
+ '',
497
+ '@foo @bar',
498
+ 'Examples:',
499
+ ' | param |',
500
+ ' | value |'].join("\n") }
501
+
502
+
503
+ it 'can remove a tag from a file' do
504
+ args = "remove:bar #{file_path}"
505
+
506
+ output = CukeTaggerHelper.run_cuketagger(args)
507
+
508
+ expect(output).to eq(['@foo',
509
+ 'Feature:',
510
+ '',
511
+ '@foo @bar',
512
+ 'Scenario:',
513
+ ' * a step',
514
+ '',
515
+ '@foo @bar',
516
+ 'Scenario Outline:',
517
+ ' * a step',
518
+ '',
519
+ '@foo @bar',
520
+ 'Examples:',
521
+ ' | param |',
522
+ ' | value |'].join("\n"))
523
+ end
524
+
525
+ it 'can remove a tag from a part of a file' do
526
+ args = "remove:bar #{file_path}:5"
527
+
528
+ output = CukeTaggerHelper.run_cuketagger(args)
529
+
530
+ expect(output).to eq(['@foo @bar',
531
+ 'Feature:',
532
+ '',
533
+ '@foo',
534
+ 'Scenario:',
535
+ ' * a step',
536
+ '',
537
+ '@foo @bar',
538
+ 'Scenario Outline:',
539
+ ' * a step',
540
+ '',
541
+ '@foo @bar',
542
+ 'Examples:',
543
+ ' | param |',
544
+ ' | value |'].join("\n"))
545
+ end
546
+
547
+ it 'correctly removes a tag that is not immediately above its element' do
548
+ source_text = ['@foo @bar',
549
+ 'Feature:',
550
+ '',
551
+ '',
552
+ '@foo @bar',
553
+ '',
554
+ '@baz',
555
+ '',
556
+ 'Scenario:',
557
+ ' * a step',
558
+ '',
559
+ '@foo @bar',
560
+ 'Scenario Outline:',
561
+ ' * a step',
562
+ '',
563
+ '@foo @bar',
564
+ 'Examples:',
565
+ ' | param |',
566
+ ' | value |'].join("\n")
567
+
568
+ File.open(file_path, 'w') { |file| file.write(source_text) }
569
+
570
+ args = "remove:foo remove:baz #{file_path}:9"
571
+
572
+ output = CukeTaggerHelper.run_cuketagger(args)
573
+
574
+ expect(output).to eq(['@foo @bar',
575
+ 'Feature:',
576
+ '',
577
+ '',
578
+ '@bar',
579
+ '',
580
+ '',
581
+ 'Scenario:',
582
+ ' * a step',
583
+ '',
584
+ '@foo @bar',
585
+ 'Scenario Outline:',
586
+ ' * a step',
587
+ '',
588
+ '@foo @bar',
589
+ 'Examples:',
590
+ ' | param |',
591
+ ' | value |'].join("\n"))
592
+ end
593
+
594
+ it 'can handle removing a tag from an element that does not have it' do
595
+ args = "remove:not_a_real_tag #{file_path}:5"
596
+
597
+ output = CukeTaggerHelper.run_cuketagger(args)
598
+
599
+ expect(output).to eq(['@foo @bar',
600
+ 'Feature:',
601
+ '',
602
+ '@foo @bar',
603
+ 'Scenario:',
604
+ ' * a step',
605
+ '',
606
+ '@foo @bar',
607
+ 'Scenario Outline:',
608
+ ' * a step',
609
+ '',
610
+ '@foo @bar',
611
+ 'Examples:',
612
+ ' | param |',
613
+ ' | value |'].join("\n"))
614
+ end
615
+
616
+ it 'can intermix full and partial file tag removals' do
617
+ args = "remove:bar #{file_path} #{file_path}:9"
618
+
619
+ output = CukeTaggerHelper.run_cuketagger(args)
620
+
621
+ expect(output).to eq(['@foo',
622
+ 'Feature:',
623
+ '',
624
+ '@foo @bar',
625
+ 'Scenario:',
626
+ ' * a step',
627
+ '',
628
+ '@foo',
629
+ 'Scenario Outline:',
630
+ ' * a step',
631
+ '',
632
+ '@foo @bar',
633
+ 'Examples:',
634
+ ' | param |',
635
+ ' | value |'].join("\n"))
636
+ end
637
+
638
+ it 'removes tags from multiple files' do
639
+ source_text_1 = ['@foo @bar',
640
+ 'Feature: Foo',
641
+ '',
642
+ '@foo @bar',
643
+ 'Scenario:',
644
+ ' * a step',
645
+ '',
646
+ '@foo @bar',
647
+ 'Scenario Outline:',
648
+ ' * a step',
649
+ '',
650
+ '@foo @bar',
651
+ 'Examples:',
652
+ ' | param |',
653
+ ' | value |',
654
+ ''].join("\n")
655
+ source_text_2 = ['@foo @bar',
656
+ 'Feature: Bar',
657
+ '',
658
+ '@foo @bar',
659
+ 'Scenario:',
660
+ ' * a step',
661
+ '',
662
+ '@foo @bar',
663
+ 'Scenario Outline:',
664
+ ' * a step',
665
+ '',
666
+ '@foo @bar',
667
+ 'Examples:',
668
+ ' | param |',
669
+ ' | value |'].join("\n")
670
+
671
+ File.open("#{@default_file_directory}/foo.feature", 'w') { |file_1| file_1.write(source_text_1) }
672
+ File.open("#{@default_file_directory}/bar.feature", 'w') { |file_2| file_2.write(source_text_2) }
673
+
674
+ args = "remove:bar #{@default_file_directory}/foo.feature #{@default_file_directory}/bar.feature"
675
+
676
+ output = CukeTaggerHelper.run_cuketagger(args)
677
+
678
+ expect(output).to include(['@foo',
679
+ 'Feature: Foo',
680
+ '',
681
+ '@foo @bar',
682
+ 'Scenario:',
683
+ ' * a step',
684
+ '',
685
+ '@foo @bar',
686
+ 'Scenario Outline:',
687
+ ' * a step',
688
+ '',
689
+ '@foo @bar',
690
+ 'Examples:',
691
+ ' | param |',
692
+ ' | value |'].join("\n"))
693
+
694
+ expect(output).to include(['@foo',
695
+ 'Feature: Bar',
696
+ '',
697
+ '@foo @bar',
698
+ 'Scenario:',
699
+ ' * a step',
700
+ '',
701
+ '@foo @bar',
702
+ 'Scenario Outline:',
703
+ ' * a step',
704
+ '',
705
+ '@foo @bar',
706
+ 'Examples:',
707
+ ' | param |',
708
+ ' | value |'].join("\n"))
709
+ end
710
+
711
+ it 'correctly removes a tag from a feature' do
712
+ args = "remove:bar #{file_path}:2"
713
+
714
+ output = CukeTaggerHelper.run_cuketagger(args)
715
+
716
+ expect(output).to eq(['@foo',
717
+ 'Feature:',
718
+ '',
719
+ '@foo @bar',
720
+ 'Scenario:',
721
+ ' * a step',
722
+ '',
723
+ '@foo @bar',
724
+ 'Scenario Outline:',
725
+ ' * a step',
726
+ '',
727
+ '@foo @bar',
728
+ 'Examples:',
729
+ ' | param |',
730
+ ' | value |'].join("\n"))
731
+ end
732
+
733
+ it 'correctly removes a tag from a scenario' do
734
+ args = "remove:bar #{file_path}:5"
735
+
736
+ output = CukeTaggerHelper.run_cuketagger(args)
737
+
738
+ expect(output).to eq(['@foo @bar',
739
+ 'Feature:',
740
+ '',
741
+ '@foo',
742
+ 'Scenario:',
743
+ ' * a step',
744
+ '',
745
+ '@foo @bar',
746
+ 'Scenario Outline:',
747
+ ' * a step',
748
+ '',
749
+ '@foo @bar',
750
+ 'Examples:',
751
+ ' | param |',
752
+ ' | value |'].join("\n"))
753
+ end
754
+
755
+ it 'correctly removes a tag from an outline' do
756
+ args = "remove:bar #{file_path}:9"
757
+
758
+ output = CukeTaggerHelper.run_cuketagger(args)
759
+
760
+ expect(output).to eq(['@foo @bar',
761
+ 'Feature:',
762
+ '',
763
+ '@foo @bar',
764
+ 'Scenario:',
765
+ ' * a step',
766
+ '',
767
+ '@foo',
768
+ 'Scenario Outline:',
769
+ ' * a step',
770
+ '',
771
+ '@foo @bar',
772
+ 'Examples:',
773
+ ' | param |',
774
+ ' | value |'].join("\n"))
775
+ end
776
+
777
+ it 'correctly removes a tag from an example' do
778
+ args = "remove:bar #{file_path}:13"
779
+
780
+ output = CukeTaggerHelper.run_cuketagger(args)
781
+
782
+ expect(output).to eq(['@foo @bar',
783
+ 'Feature:',
784
+ '',
785
+ '@foo @bar',
786
+ 'Scenario:',
787
+ ' * a step',
788
+ '',
789
+ '@foo @bar',
790
+ 'Scenario Outline:',
791
+ ' * a step',
792
+ '',
793
+ '@foo',
794
+ 'Examples:',
795
+ ' | param |',
796
+ ' | value |'].join("\n"))
797
+ end
798
+
799
+ it 'correctly removes tags from multiple parts of a file' do
800
+ args = "remove:bar #{file_path}:2 #{file_path}:9"
801
+
802
+ output = CukeTaggerHelper.run_cuketagger(args)
803
+
804
+ expect(output).to eq(['@foo',
805
+ 'Feature:',
806
+ '',
807
+ '@foo @bar',
808
+ 'Scenario:',
809
+ ' * a step',
810
+ '',
811
+ '@foo',
812
+ 'Scenario Outline:',
813
+ ' * a step',
814
+ '',
815
+ '@foo @bar',
816
+ 'Examples:',
817
+ ' | param |',
818
+ ' | value |'].join("\n"))
819
+ end
820
+
821
+ it 'trims extra whitespace from a line when removing tags' do
822
+ source_text = ['@foo @bar @baz',
823
+ 'Feature:',
824
+ '',
825
+ '@foo @bar',
826
+ 'Scenario:',
827
+ ' * a step',
828
+ '',
829
+ '@foo @bar ',
830
+ 'Scenario Outline:',
831
+ ' * a step',
832
+ '@bar @foo',
833
+ 'Examples:',
834
+ ' | param |',
835
+ ' | value |'].join("\n")
836
+
837
+ File.open("#{file_path}", 'w') { |file| file.write(source_text) }
838
+
839
+ args = "remove:bar #{file_path}:2 #{file_path}:5 #{file_path}:9 #{file_path}:12"
840
+
841
+ output = CukeTaggerHelper.run_cuketagger(args)
842
+
843
+ expect(output).to eq(['@foo @baz',
844
+ 'Feature:',
845
+ '',
846
+ '@foo',
847
+ 'Scenario:',
848
+ ' * a step',
849
+ '',
850
+ '@foo',
851
+ 'Scenario Outline:',
852
+ ' * a step',
853
+ '@foo',
854
+ 'Examples:',
855
+ ' | param |',
856
+ ' | value |'].join("\n"))
857
+ end
858
+
859
+ it 'ignores duplicate tag removal arguments' do
860
+ source_text = ['@foo @bar @bar @bar',
861
+ 'Feature:',
862
+ '',
863
+ '@foo @bar',
864
+ 'Scenario:',
865
+ ' * a step',
866
+ '',
867
+ '@foo @bar',
868
+ 'Scenario Outline:',
869
+ ' * a step',
870
+ '',
871
+ '@foo @bar',
872
+ 'Examples:',
873
+ ' | param |',
874
+ ' | value |'].join("\n")
875
+
876
+ File.open(file_path, 'w') { |file| file.write(source_text) }
877
+
878
+ args = "remove:bar remove:bar remove:bar #{file_path}"
879
+
880
+ output = CukeTaggerHelper.run_cuketagger(args)
881
+
882
+ expect(output).to eq(['@foo @bar @bar',
883
+ 'Feature:',
884
+ '',
885
+ '@foo @bar',
886
+ 'Scenario:',
887
+ ' * a step',
888
+ '',
889
+ '@foo @bar',
890
+ 'Scenario Outline:',
891
+ ' * a step',
892
+ '',
893
+ '@foo @bar',
894
+ 'Examples:',
895
+ ' | param |',
896
+ ' | value |'].join("\n"))
897
+ end
898
+
899
+
900
+ describe 'line adjustments' do
901
+
902
+ it 'will remove an existing line if it is empty after tag removal' do
903
+ args = "remove:foo remove:bar #{file_path}:5"
904
+
905
+ output = CukeTaggerHelper.run_cuketagger(args)
906
+
907
+ expect(output).to eq(['@foo @bar',
908
+ 'Feature:',
909
+ '',
910
+ 'Scenario:',
911
+ ' * a step',
912
+ '',
913
+ '@foo @bar',
914
+ 'Scenario Outline:',
915
+ ' * a step',
916
+ '',
917
+ '@foo @bar',
918
+ 'Examples:',
919
+ ' | param |',
920
+ ' | value |'].join("\n"))
921
+ end
922
+
923
+ it 'correctly removes empty lines from multiple parts of a file' do
924
+ args = "remove:foo remove:bar #{file_path}:5 #{file_path}:13"
925
+
926
+ output = CukeTaggerHelper.run_cuketagger(args)
927
+
928
+ expect(output).to eq(['@foo @bar',
929
+ 'Feature:',
930
+ '',
931
+ 'Scenario:',
932
+ ' * a step',
933
+ '',
934
+ '@foo @bar',
935
+ 'Scenario Outline:',
936
+ ' * a step',
937
+ '',
938
+ 'Examples:',
939
+ ' | param |',
940
+ ' | value |'].join("\n"))
941
+ end
942
+
943
+ it 'correctly removes an empty line from the beginning of a file' do
944
+ args = "remove:foo remove:bar #{file_path}"
945
+
946
+ output = CukeTaggerHelper.run_cuketagger(args)
947
+
948
+ expect(output).to eq(['Feature:',
949
+ '',
950
+ '@foo @bar',
951
+ 'Scenario:',
952
+ ' * a step',
953
+ '',
954
+ '@foo @bar',
955
+ 'Scenario Outline:',
956
+ ' * a step',
957
+ '',
958
+ '@foo @bar',
959
+ 'Examples:',
960
+ ' | param |',
961
+ ' | value |'].join("\n"))
962
+ end
963
+
964
+ end
965
+
966
+ end
967
+
968
+
969
+ describe 'replacing tags' do
970
+
971
+ let(:source_text) { ['@foo',
972
+ 'Feature:',
973
+ '',
974
+ '@foo',
975
+ 'Scenario:',
976
+ ' * a step',
977
+ '',
978
+ '@foo',
979
+ 'Scenario Outline:',
980
+ ' * a step',
981
+ '',
982
+ '@foo',
983
+ 'Examples:',
984
+ ' | param |',
985
+ ' | value |'].join("\n") }
986
+
987
+
988
+ it 'can replace a tag on a file' do
989
+ args = "replace:foo:bar #{file_path}"
990
+
991
+ output = CukeTaggerHelper.run_cuketagger(args)
992
+
993
+ expect(output).to eq(['@bar',
994
+ 'Feature:',
995
+ '',
996
+ '@foo',
997
+ 'Scenario:',
998
+ ' * a step',
999
+ '',
1000
+ '@foo',
1001
+ 'Scenario Outline:',
1002
+ ' * a step',
1003
+ '',
1004
+ '@foo',
1005
+ 'Examples:',
1006
+ ' | param |',
1007
+ ' | value |'].join("\n"))
1008
+ end
1009
+
1010
+ it 'can replace a tag on a part of a file' do
1011
+ args = "replace:foo:bar #{file_path}:5"
1012
+
1013
+ output = CukeTaggerHelper.run_cuketagger(args)
1014
+
1015
+ expect(output).to eq(['@foo',
1016
+ 'Feature:',
1017
+ '',
1018
+ '@bar',
1019
+ 'Scenario:',
1020
+ ' * a step',
1021
+ '',
1022
+ '@foo',
1023
+ 'Scenario Outline:',
1024
+ ' * a step',
1025
+ '',
1026
+ '@foo',
1027
+ 'Examples:',
1028
+ ' | param |',
1029
+ ' | value |'].join("\n"))
1030
+ end
1031
+
1032
+ it 'can intermix full and partial file replacements' do
1033
+ args = "replace:foo:bar #{file_path} #{file_path}:5"
1034
+
1035
+ output = CukeTaggerHelper.run_cuketagger(args)
1036
+
1037
+ expect(output).to eq(['@bar',
1038
+ 'Feature:',
1039
+ '',
1040
+ '@bar',
1041
+ 'Scenario:',
1042
+ ' * a step',
1043
+ '',
1044
+ '@foo',
1045
+ 'Scenario Outline:',
1046
+ ' * a step',
1047
+ '',
1048
+ '@foo',
1049
+ 'Examples:',
1050
+ ' | param |',
1051
+ ' | value |'].join("\n"))
1052
+ end
1053
+
1054
+ it 'correctly replaces a tag that is not immediately above its element' do
1055
+ source_text = ['Feature:',
1056
+ '',
1057
+ '',
1058
+ '@foo @bar',
1059
+ '',
1060
+ '@baz',
1061
+ '',
1062
+ 'Scenario:',
1063
+ ' * a step',
1064
+ '',
1065
+ 'Scenario Outline:',
1066
+ ' * a step',
1067
+ '',
1068
+ 'Examples:',
1069
+ ' | param |',
1070
+ ' | value |'].join("\n")
1071
+
1072
+ File.open(file_path, 'w') { |file| file.write(source_text) }
1073
+
1074
+ args = "replace:foo:baz replace:baz:foo #{file_path}:8"
1075
+
1076
+ output = CukeTaggerHelper.run_cuketagger(args)
1077
+
1078
+ expect(output).to eq(['Feature:',
1079
+ '',
1080
+ '',
1081
+ '@baz @bar',
1082
+ '',
1083
+ '@foo',
1084
+ '',
1085
+ 'Scenario:',
1086
+ ' * a step',
1087
+ '',
1088
+ 'Scenario Outline:',
1089
+ ' * a step',
1090
+ '',
1091
+ 'Examples:',
1092
+ ' | param |',
1093
+ ' | value |'].join("\n"))
1094
+ end
1095
+
1096
+ it 'replaces tags in multiple files' do
1097
+ source_text_1 = ['@foo',
1098
+ 'Feature: Foo',
1099
+ '',
1100
+ '@foo',
1101
+ 'Scenario:',
1102
+ ' * a step',
1103
+ '',
1104
+ '@foo',
1105
+ 'Scenario Outline:',
1106
+ ' * a step',
1107
+ '',
1108
+ '@foo',
1109
+ 'Examples:',
1110
+ ' | param |',
1111
+ ' | value |',
1112
+ ''].join("\n")
1113
+ source_text_2 = ['@foo',
1114
+ 'Feature: Bar',
1115
+ '',
1116
+ '@foo',
1117
+ 'Scenario:',
1118
+ ' * a step',
1119
+ '',
1120
+ '@foo',
1121
+ 'Scenario Outline:',
1122
+ ' * a step',
1123
+ '',
1124
+ '@foo',
1125
+ 'Examples:',
1126
+ ' | param |',
1127
+ ' | value |'].join("\n")
1128
+
1129
+ File.open("#{@default_file_directory}/foo.feature", 'w') { |file_1| file_1.write(source_text_1) }
1130
+ File.open("#{@default_file_directory}/bar.feature", 'w') { |file_2| file_2.write(source_text_2) }
1131
+
1132
+ args = "replace:foo:bar #{@default_file_directory}/foo.feature #{@default_file_directory}/bar.feature:5"
1133
+
1134
+ output = CukeTaggerHelper.run_cuketagger(args)
1135
+
1136
+ expect(output).to include(['@bar',
1137
+ 'Feature: Foo',
1138
+ '',
1139
+ '@foo',
1140
+ 'Scenario:',
1141
+ ' * a step',
1142
+ '',
1143
+ '@foo',
1144
+ 'Scenario Outline:',
1145
+ ' * a step',
1146
+ '',
1147
+ '@foo',
1148
+ 'Examples:',
1149
+ ' | param |',
1150
+ ' | value |'].join("\n"))
1151
+
1152
+ expect(output).to include(['@foo',
1153
+ 'Feature: Bar',
1154
+ '',
1155
+ '@bar',
1156
+ 'Scenario:',
1157
+ ' * a step',
1158
+ '',
1159
+ '@foo',
1160
+ 'Scenario Outline:',
1161
+ ' * a step',
1162
+ '',
1163
+ '@foo',
1164
+ 'Examples:',
1165
+ ' | param |',
1166
+ ' | value |'].join("\n"))
1167
+ end
1168
+
1169
+ it 'correctly replaces a tag on a feature' do
1170
+ args = "replace:foo:bar #{file_path}:2"
1171
+
1172
+ output = CukeTaggerHelper.run_cuketagger(args)
1173
+
1174
+ expect(output).to eq(['@bar',
1175
+ 'Feature:',
1176
+ '',
1177
+ '@foo',
1178
+ 'Scenario:',
1179
+ ' * a step',
1180
+ '',
1181
+ '@foo',
1182
+ 'Scenario Outline:',
1183
+ ' * a step',
1184
+ '',
1185
+ '@foo',
1186
+ 'Examples:',
1187
+ ' | param |',
1188
+ ' | value |'].join("\n"))
1189
+ end
1190
+
1191
+ it 'correctly replaces a tag on a scenario' do
1192
+ args = "replace:foo:bar #{file_path}:5"
1193
+
1194
+ output = CukeTaggerHelper.run_cuketagger(args)
1195
+
1196
+ expect(output).to eq(['@foo',
1197
+ 'Feature:',
1198
+ '',
1199
+ '@bar',
1200
+ 'Scenario:',
1201
+ ' * a step',
1202
+ '',
1203
+ '@foo',
1204
+ 'Scenario Outline:',
1205
+ ' * a step',
1206
+ '',
1207
+ '@foo',
1208
+ 'Examples:',
1209
+ ' | param |',
1210
+ ' | value |'].join("\n"))
1211
+
1212
+ end
1213
+
1214
+ it 'correctly replaces a tag on an outline' do
1215
+ args = "replace:foo:bar #{file_path}:9"
1216
+
1217
+ output = CukeTaggerHelper.run_cuketagger(args)
1218
+
1219
+ expect(output).to eq(['@foo',
1220
+ 'Feature:',
1221
+ '',
1222
+ '@foo',
1223
+ 'Scenario:',
1224
+ ' * a step',
1225
+ '',
1226
+ '@bar',
1227
+ 'Scenario Outline:',
1228
+ ' * a step',
1229
+ '',
1230
+ '@foo',
1231
+ 'Examples:',
1232
+ ' | param |',
1233
+ ' | value |'].join("\n"))
1234
+
1235
+ end
1236
+
1237
+ it 'correctly replaces a tag on an example' do
1238
+ args = "replace:foo:bar #{file_path}:13"
1239
+
1240
+ output = CukeTaggerHelper.run_cuketagger(args)
1241
+
1242
+ expect(output).to eq(['@foo',
1243
+ 'Feature:',
1244
+ '',
1245
+ '@foo',
1246
+ 'Scenario:',
1247
+ ' * a step',
1248
+ '',
1249
+ '@foo',
1250
+ 'Scenario Outline:',
1251
+ ' * a step',
1252
+ '',
1253
+ '@bar',
1254
+ 'Examples:',
1255
+ ' | param |',
1256
+ ' | value |'].join("\n"))
1257
+ end
1258
+
1259
+ it 'correctly replaces tags in multiple parts of a file' do
1260
+ args = "replace:foo:bar #{file_path}:2 #{file_path}:13"
1261
+
1262
+ output = CukeTaggerHelper.run_cuketagger(args)
1263
+
1264
+ expect(output).to eq(['@bar',
1265
+ 'Feature:',
1266
+ '',
1267
+ '@foo',
1268
+ 'Scenario:',
1269
+ ' * a step',
1270
+ '',
1271
+ '@foo',
1272
+ 'Scenario Outline:',
1273
+ ' * a step',
1274
+ '',
1275
+ '@bar',
1276
+ 'Examples:',
1277
+ ' | param |',
1278
+ ' | value |'].join("\n"))
1279
+ end
1280
+
1281
+ # todo - emit notice when removing a tag that doesn't exist as well
1282
+ it 'emits a notice when replacing a tag from an element that does not have it' do
1283
+ args = "replace:not_a_real_tag:foo #{file_path}:5"
1284
+
1285
+ output = CukeTaggerHelper.run_cuketagger(args)
1286
+
1287
+ expect(output).to include("expected \"@not_a_real_tag\" at #{File.basename(file_path)}:5, skipping")
1288
+ expect(output).to include(['@foo',
1289
+ 'Feature:',
1290
+ '',
1291
+ '@foo',
1292
+ 'Scenario:',
1293
+ ' * a step',
1294
+ '',
1295
+ '@foo',
1296
+ 'Scenario Outline:',
1297
+ ' * a step',
1298
+ '',
1299
+ '@foo',
1300
+ 'Examples:',
1301
+ ' | param |',
1302
+ ' | value |'].join("\n"))
1303
+ end
1304
+
1305
+ it 'does not trim white extra whitespace when replacing tags' do
1306
+ source_text = ['@bar @foo @baz',
1307
+ 'Feature:',
1308
+ '',
1309
+ ' @foo @bar',
1310
+ 'Scenario:',
1311
+ ' * a step',
1312
+ '',
1313
+ '@bar @foo ',
1314
+ 'Scenario Outline:',
1315
+ ' * a step',
1316
+ '',
1317
+ 'Examples:',
1318
+ ' | param |',
1319
+ ' | value |'].join("\n")
1320
+
1321
+ File.open("#{file_path}", 'w') { |file| file.write(source_text) }
1322
+
1323
+ args = "replace:foo:new_tag #{file_path}:2 #{file_path}:5 #{file_path}:9"
1324
+
1325
+ output = CukeTaggerHelper.run_cuketagger(args)
1326
+
1327
+ expect(output).to eq(['@bar @new_tag @baz',
1328
+ 'Feature:',
1329
+ '',
1330
+ ' @new_tag @bar',
1331
+ 'Scenario:',
1332
+ ' * a step',
1333
+ '',
1334
+ '@bar @new_tag ',
1335
+ 'Scenario Outline:',
1336
+ ' * a step',
1337
+ '',
1338
+ 'Examples:',
1339
+ ' | param |',
1340
+ ' | value |'].join("\n"))
1341
+ end
1342
+
1343
+ it 'ignores duplicate tag replacement arguments' do
1344
+ source_text = ['@bar @bar @bar',
1345
+ 'Feature:',
1346
+ '',
1347
+ 'Scenario:',
1348
+ ' * a step',
1349
+ '',
1350
+ 'Scenario Outline:',
1351
+ ' * a step',
1352
+ '',
1353
+ 'Examples:',
1354
+ ' | param |',
1355
+ ' | value |'].join("\n")
1356
+
1357
+ File.open(file_path, 'w') { |file| file.write(source_text) }
1358
+
1359
+ args = "replace:bar:foo replace:bar:foo replace:bar:foo #{file_path}"
1360
+
1361
+ output = CukeTaggerHelper.run_cuketagger(args)
1362
+
1363
+ expect(output).to eq(['@foo @bar @bar',
1364
+ 'Feature:',
1365
+ '',
1366
+ 'Scenario:',
1367
+ ' * a step',
1368
+ '',
1369
+ 'Scenario Outline:',
1370
+ ' * a step',
1371
+ '',
1372
+ 'Examples:',
1373
+ ' | param |',
1374
+ ' | value |'].join("\n"))
1375
+ end
1376
+
1377
+ end
1378
+
1379
+
1380
+ describe 'intermixing actions' do
1381
+
1382
+ it 'can intermix tag addition, removal, and replacement' do
1383
+ source_text = ['@foo @bar @baz',
1384
+ 'Feature:',
1385
+ '',
1386
+ 'Scenario:',
1387
+ ' * a step',
1388
+ '',
1389
+ 'Scenario Outline:',
1390
+ ' * a step',
1391
+ '',
1392
+ 'Examples:',
1393
+ ' | param |',
1394
+ ' | value |'].join("\n")
1395
+
1396
+ File.open(file_path, 'w') { |file| file.write(source_text) }
1397
+
1398
+ args = "add:new_tag remove:bar replace:baz:bazzz #{file_path}"
1399
+
1400
+ output = CukeTaggerHelper.run_cuketagger(args)
1401
+
1402
+ expect(output).to eq(['@foo @bazzz @new_tag',
1403
+ 'Feature:',
1404
+ '',
1405
+ 'Scenario:',
1406
+ ' * a step',
1407
+ '',
1408
+ 'Scenario Outline:',
1409
+ ' * a step',
1410
+ '',
1411
+ 'Examples:',
1412
+ ' | param |',
1413
+ ' | value |'].join("\n"))
1414
+ end
1415
+
1416
+ it 'applies tag actions in the order specified' do
1417
+ source_text = ['@foo @bar @baz',
1418
+ 'Feature:',
1419
+ '',
1420
+ 'Scenario:',
1421
+ ' * a step',
1422
+ '',
1423
+ 'Scenario Outline:',
1424
+ ' * a step',
1425
+ '',
1426
+ 'Examples:',
1427
+ ' | param |',
1428
+ ' | value |'].join("\n")
1429
+
1430
+ File.open(file_path, 'w') { |file| file.write(source_text) }
1431
+
1432
+ args = "remove:bar replace:bar:new_tag #{file_path}"
1433
+
1434
+ output = CukeTaggerHelper.run_cuketagger(args)
1435
+
1436
+ expect(output).to eq(['@foo @baz',
1437
+ 'Feature:',
1438
+ '',
1439
+ 'Scenario:',
1440
+ ' * a step',
1441
+ '',
1442
+ 'Scenario Outline:',
1443
+ ' * a step',
1444
+ '',
1445
+ 'Examples:',
1446
+ ' | param |',
1447
+ ' | value |'].join("\n"))
1448
+
1449
+ args = "replace:bar:new_tag remove:bar #{file_path}"
1450
+
1451
+ output = CukeTaggerHelper.run_cuketagger(args)
1452
+
1453
+ expect(output).to eq(['@foo @new_tag @baz',
1454
+ 'Feature:',
1455
+ '',
1456
+ 'Scenario:',
1457
+ ' * a step',
1458
+ '',
1459
+ 'Scenario Outline:',
1460
+ ' * a step',
1461
+ '',
1462
+ 'Examples:',
1463
+ ' | param |',
1464
+ ' | value |'].join("\n"))
1465
+ end
1466
+
1467
+ end
1468
+
1469
+
1470
+ describe 'rewriting files' do
1471
+
1472
+ it 'does not rewrite a file by default' do
1473
+ args = "add:bar #{file_path}"
1474
+
1475
+ CukeTaggerHelper.run_cuketagger(args)
1476
+
1477
+ expect(File.read(file_path)).to eq(['',
1478
+ 'Feature:',
1479
+ '',
1480
+ 'Scenario:',
1481
+ ' * a step',
1482
+ '',
1483
+ 'Scenario Outline:',
1484
+ ' * a step',
1485
+ '',
1486
+ 'Examples:',
1487
+ ' | param |',
1488
+ ' | value |'].join("\n"))
1489
+ end
1490
+
1491
+ it 'rewrites a file when forced' do
1492
+ args = "add:bar #{file_path} -f"
1493
+
1494
+ CukeTaggerHelper.run_cuketagger(args)
1495
+
1496
+ expect(File.read(file_path)).to eq(['@bar',
1497
+ 'Feature:',
1498
+ '',
1499
+ 'Scenario:',
1500
+ ' * a step',
1501
+ '',
1502
+ 'Scenario Outline:',
1503
+ ' * a step',
1504
+ '',
1505
+ 'Examples:',
1506
+ ' | param |',
1507
+ ' | value |'].join("\n"))
1508
+ end
1509
+
1510
+ end
1511
+
1512
+
1513
+ describe 'arguments' do
1514
+
1515
+ it 'can understand multiple changes in the same file' do
1516
+ source_text = ['@bar @foo @baz',
1517
+ 'Feature:',
1518
+ '',
1519
+ ' @foo @bar',
1520
+ 'Scenario:',
1521
+ ' * a step',
1522
+ '',
1523
+ '@bar @foo ',
1524
+ 'Scenario Outline:',
1525
+ ' * a step',
1526
+ '',
1527
+ 'Examples:',
1528
+ ' | param |',
1529
+ ' | value |'].join("\n")
1530
+
1531
+ File.open("#{file_path}", 'w') { |file| file.write(source_text) }
1532
+
1533
+ args = "replace:foo:new_tag #{file_path}:2 #{file_path}:5 #{file_path}:9"
1534
+ separate_output = CukeTaggerHelper.run_cuketagger(args)
1535
+
1536
+ args = "replace:foo:new_tag #{file_path}:2:5:9"
1537
+ combined_output = CukeTaggerHelper.run_cuketagger(args)
1538
+
1539
+ expect(separate_output).to eq(combined_output)
1540
+ end
1541
+
1542
+ it 'does other things' do
1543
+ skip('write more argument tests')
1544
+ end
1545
+
1546
+ end
1547
+
1548
+ end