defmastership 1.0.5 → 1.0.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -1
  3. data/bin/defmastership +33 -22
  4. data/cucumber.yml +1 -1
  5. data/defmastership.gemspec +12 -6
  6. data/features/changeref.feature +82 -129
  7. data/features/definition_checksum.feature +298 -0
  8. data/features/definition_version.feature +204 -0
  9. data/features/export.feature +35 -34
  10. data/features/modify.feature +165 -0
  11. data/features/rename_included_files.feature +121 -0
  12. data/lib/defmastership.rb +17 -3
  13. data/lib/defmastership/batch_modifier.rb +35 -0
  14. data/lib/defmastership/{ref_changer.rb → change_ref_line_modifier.rb} +18 -35
  15. data/lib/defmastership/change_ref_modifier.rb +15 -0
  16. data/lib/defmastership/constants.rb +14 -1
  17. data/lib/defmastership/csv_formatter.rb +22 -17
  18. data/lib/defmastership/csv_formatter_body.rb +19 -11
  19. data/lib/defmastership/csv_formatter_header.rb +15 -10
  20. data/lib/defmastership/definition.rb +14 -3
  21. data/lib/defmastership/definition_parser.rb +46 -0
  22. data/lib/defmastership/document.rb +59 -85
  23. data/lib/defmastership/filters.rb +30 -0
  24. data/lib/defmastership/line_modifier_base.rb +29 -0
  25. data/lib/defmastership/modifier_base.rb +29 -0
  26. data/lib/defmastership/rename_included_files_line_modifier.rb +126 -0
  27. data/lib/defmastership/rename_included_files_modifier.rb +15 -0
  28. data/lib/defmastership/update_def_checksum_line_modifier.rb +38 -0
  29. data/lib/defmastership/update_def_checksum_modifier.rb +21 -0
  30. data/lib/defmastership/update_def_version_line_modifier.rb +58 -0
  31. data/lib/defmastership/update_def_version_modifier.rb +25 -0
  32. data/lib/defmastership/version.rb +1 -1
  33. data/spec/spec_helper.rb +1 -0
  34. data/spec/unit/defmastership/batch_modifier_spec.rb +123 -0
  35. data/spec/unit/defmastership/{ref_changer_spec.rb → change_ref_line_modifier_spec.rb} +48 -26
  36. data/spec/unit/defmastership/change_ref_modifier_spec.rb +76 -0
  37. data/spec/unit/defmastership/comment_filter_spec.rb +8 -4
  38. data/spec/unit/defmastership/csv_formatter_body_spec.rb +88 -82
  39. data/spec/unit/defmastership/csv_formatter_header_spec.rb +68 -22
  40. data/spec/unit/defmastership/csv_formatter_spec.rb +207 -109
  41. data/spec/unit/defmastership/definition_parser_spec.rb +63 -0
  42. data/spec/unit/defmastership/definition_spec.rb +45 -4
  43. data/spec/unit/defmastership/document_spec.rb +236 -35
  44. data/spec/unit/defmastership/rename_included_files_line_modifier_spec.rb +203 -0
  45. data/spec/unit/defmastership/rename_included_files_modifier_spec.rb +67 -0
  46. data/spec/unit/defmastership/update_def_checksum_line_modifier_spec.rb +78 -0
  47. data/spec/unit/defmastership/update_def_checksum_modifier_spec.rb +75 -0
  48. data/spec/unit/defmastership/update_def_version_line_modifier_spec.rb +127 -0
  49. data/spec/unit/defmastership/update_def_version_modifier_spec.rb +80 -0
  50. metadata +44 -9
  51. data/lib/defmastership/batch_changer.rb +0 -41
  52. data/lib/defmastership/project_ref_changer.rb +0 -28
  53. data/spec/unit/defmastership/batch_changer_spec.rb +0 -109
  54. data/spec/unit/defmastership/project_ref_changer_spec.rb +0 -80
@@ -0,0 +1,63 @@
1
+ # Copyright (c) 2020 Jerome Arbez-Gindre
2
+ # frozen_string_literal: true
3
+
4
+ require('defmastership')
5
+
6
+ RSpec.describe(DefMastership::DefinitionParser) do
7
+ subject(:parser) { described_class.new(callback_object) }
8
+
9
+ let(:callback_object) { instance_double('callback_object') }
10
+
11
+ before do
12
+ allow(callback_object).to(receive(:add_new_definition).with(any_args))
13
+ allow(callback_object).to(receive(:add_line).with(any_args))
14
+ end
15
+
16
+ describe 'transitions' do
17
+ it { is_expected.to(have_state(:idle)) }
18
+
19
+ it { is_expected.to(transition_from(:idle).to(:wait_content).on_event(:new_definition, :whatever)) }
20
+
21
+ it { is_expected.to(transition_from(:wait_content).to(:in_block).on_event(:block_delimiter, :whatever)) }
22
+ it { is_expected.to(transition_from(:in_block).to(:idle).on_event(:block_delimiter, :whatever)) }
23
+ it { is_expected.to(transition_from(:idle).to(:idle).on_event(:block_delimiter, :whatever)) }
24
+ it { is_expected.to(transition_from(:single_para).to(:idle).on_event(:block_delimiter, :whatever)) }
25
+
26
+ it { is_expected.to(transition_from(:wait_content).to(:single_para).on_event(:new_line, :whatever)) }
27
+ it { is_expected.to(transition_from(:single_para).to(:single_para).on_event(:new_line, :whatever)) }
28
+ it { is_expected.to(transition_from(:in_block).to(:in_block).on_event(:new_line, :whatever)) }
29
+ it { is_expected.to(transition_from(:idle).to(:idle).on_event(:new_line, :whatever)) }
30
+
31
+ it { is_expected.to(transition_from(:wait_content).to(:idle).on_event(:empty_line, :whatever)) }
32
+ it { is_expected.to(transition_from(:single_para).to(:idle).on_event(:empty_line, :whatever)) }
33
+ it { is_expected.to(transition_from(:idle).to(:idle).on_event(:empty_line, :whatever)) }
34
+ it { is_expected.to(transition_from(:in_block).to(:in_block).on_event(:empty_line, :whatever)) }
35
+ end
36
+
37
+ describe 'actions' do
38
+ it do
39
+ parser.new_definition(:whatever)
40
+ expect(callback_object).to(have_received(:add_new_definition).with(:whatever))
41
+ end
42
+
43
+ it do
44
+ parser.new_definition(:whatever)
45
+ parser.new_line(:other_whatever)
46
+ expect(callback_object).to(have_received(:add_line).with(:other_whatever))
47
+ end
48
+
49
+ it do
50
+ parser.new_definition(:whatever)
51
+ parser.new_line(:other_whatever)
52
+ parser.new_line(:other_whatever2)
53
+ expect(callback_object).to(have_received(:add_line).with(:other_whatever2))
54
+ end
55
+
56
+ it do
57
+ parser.new_definition(:whatever)
58
+ parser.block_delimiter(:other_whatever)
59
+ parser.new_line(:other_whatever2)
60
+ expect(callback_object).to(have_received(:add_line).with(:other_whatever2))
61
+ end
62
+ end
63
+ end
@@ -5,7 +5,7 @@ require('defmastership')
5
5
 
6
6
  RSpec.describe(DefMastership::Definition) do
7
7
  describe '.new' do
8
- context 'without labels' do
8
+ context 'when minimal' do
9
9
  subject do
10
10
  described_class.new(
11
11
  type: 'req',
@@ -22,12 +22,14 @@ RSpec.describe(DefMastership::Definition) do
22
22
  it { is_expected.to(have_attributes(iref: [])) }
23
23
  it { is_expected.to(have_attributes(attributes: {})) }
24
24
  it { is_expected.to(have_attributes(labels: Set.new)) }
25
+ it { is_expected.to(have_attributes(wrong_explicit_checksum: nil)) }
26
+ it { is_expected.to(have_attributes(explicit_version: nil)) }
25
27
  end
26
28
 
27
29
  context 'with labels' do
28
30
  subject do
29
31
  described_class.new(
30
- gtype: 'req',
32
+ type: 'req',
31
33
  reference: 'TUTU-001',
32
34
  labels: 'something'
33
35
  )
@@ -35,6 +37,40 @@ RSpec.describe(DefMastership::Definition) do
35
37
 
36
38
  it { is_expected.to(have_attributes(labels: Set['something'])) }
37
39
  end
40
+
41
+ context 'with explicit_checksum' do
42
+ subject(:definition) do
43
+ described_class.new(
44
+ type: 'req',
45
+ reference: 'TUTU-001',
46
+ explicit_checksum: '~8cc259e6'
47
+ )
48
+ end
49
+
50
+ it do
51
+ definition << 'def value with a checksum != ~8cc259e6'
52
+ expect(definition).to(have_attributes(wrong_explicit_checksum: '~8cc259e6'))
53
+ end
54
+
55
+ it do
56
+ definition << 'def value with a good checksum'
57
+ expect(definition).to(have_attributes(wrong_explicit_checksum: nil))
58
+ end
59
+ end
60
+
61
+ context 'with explicit_version' do
62
+ subject(:definition) do
63
+ described_class.new(
64
+ type: 'req',
65
+ reference: 'TUTU-001',
66
+ explicit_version: 'pouet'
67
+ )
68
+ end
69
+
70
+ it do
71
+ expect(definition).to(have_attributes(explicit_version: 'pouet'))
72
+ end
73
+ end
38
74
  end
39
75
 
40
76
  describe '#<<' do
@@ -50,7 +86,7 @@ RSpec.describe(DefMastership::Definition) do
50
86
  expect(definition.value).to(eq('first line'))
51
87
  end
52
88
 
53
- it 'store line when added' do
89
+ it 'stores line when added' do
54
90
  definition << 'first line'
55
91
  expect(definition.lines).to(eq(['first line']))
56
92
  end
@@ -60,10 +96,15 @@ RSpec.describe(DefMastership::Definition) do
60
96
  expect(definition.value).to(eq("first line\nsecond line"))
61
97
  end
62
98
 
63
- it 'store each line when added' do
99
+ it 'stores each line when added' do
64
100
  definition << 'first line' << 'second line'
65
101
  expect(definition.lines).to(eq(['first line', 'second line']))
66
102
  end
103
+
104
+ it 'calculates sha256 of value' do
105
+ definition << 'first line' << 'second line'
106
+ expect(definition.sha256).to(eq('~beb0535a'))
107
+ end
67
108
  end
68
109
 
69
110
  describe '#add_eref' do
@@ -4,6 +4,8 @@
4
4
  require('defmastership')
5
5
 
6
6
  RSpec.describe(DefMastership::Document) do
7
+ subject(:document) { described_class.new }
8
+
7
9
  describe '.new' do
8
10
  it { is_expected.not_to(be(nil)) }
9
11
  it { is_expected.to(have_attributes(definitions: [])) }
@@ -14,8 +16,6 @@ RSpec.describe(DefMastership::Document) do
14
16
  end
15
17
 
16
18
  describe '#parse' do
17
- subject(:document) { described_class.new }
18
-
19
19
  context 'with valid definitions' do
20
20
  let(:definition) { instance_double(DefMastership::Definition, 'definition') }
21
21
 
@@ -31,22 +31,66 @@ RSpec.describe(DefMastership::Document) do
31
31
  let(:input_lines) { ['[define, requirement, TOTO-0001]'] }
32
32
 
33
33
  before do
34
- allow(DefMastership::Definition).to(receive(:new).with(
35
- matchdata_including(
36
- type: 'requirement',
37
- reference: 'TOTO-0001'
38
- )
39
- ).and_return(definition))
34
+ allow(DefMastership::Definition).to(
35
+ receive(:new).with(
36
+ matchdata_including(type: 'requirement', reference: 'TOTO-0001')
37
+ ).and_return(definition)
38
+ )
40
39
  document.parse(input_lines)
41
40
  end
42
41
 
43
42
  it do
44
- expect(DefMastership::Definition).to(have_received(:new).with(
45
- matchdata_including(type: 'requirement', reference: 'TOTO-0001')
46
- ))
43
+ expect(DefMastership::Definition).to(
44
+ have_received(:new).with(
45
+ matchdata_including(type: 'requirement', reference: 'TOTO-0001')
46
+ )
47
+ )
47
48
  end
48
49
 
49
50
  it { expect(document).to(have_attributes(definitions: [definition])) }
51
+ it { expect(definition).to(have_received(:labels)) }
52
+ end
53
+
54
+ context 'when simple definition line with explicit checksum' do
55
+ let(:input_lines) { ['[define, requirement, TOTO-0001(~ab12)]'] }
56
+
57
+ before do
58
+ allow(DefMastership::Definition).to(
59
+ receive(:new).with(
60
+ matchdata_including(type: 'requirement', reference: 'TOTO-0001', explicit_checksum: '~ab12')
61
+ ).and_return(definition)
62
+ )
63
+ document.parse(input_lines)
64
+ end
65
+
66
+ it do
67
+ expect(DefMastership::Definition).to(
68
+ have_received(:new).with(
69
+ matchdata_including(type: 'requirement', reference: 'TOTO-0001', explicit_checksum: '~ab12')
70
+ )
71
+ )
72
+ end
73
+ end
74
+
75
+ context 'when simple definition line with explicit version' do
76
+ let(:input_lines) { ['[define, requirement, TOTO-0001(pouet)]'] }
77
+
78
+ before do
79
+ allow(DefMastership::Definition).to(
80
+ receive(:new).with(
81
+ matchdata_including(type: 'requirement', reference: 'TOTO-0001', explicit_version: 'pouet')
82
+ ).and_return(definition)
83
+ )
84
+ document.parse(input_lines)
85
+ end
86
+
87
+ it do
88
+ expect(DefMastership::Definition).to(
89
+ have_received(:new).with(
90
+ matchdata_including(type: 'requirement', reference: 'TOTO-0001', explicit_version: 'pouet')
91
+ )
92
+ )
93
+ end
50
94
  end
51
95
 
52
96
  context 'when complete definition with content' do
@@ -133,11 +177,11 @@ RSpec.describe(DefMastership::Document) do
133
177
  end
134
178
 
135
179
  it do
136
- expect(DefMastership::Definition).to(have_received(:new).with(matchdata_including(
137
- type: 'requirement',
138
- reference: 'TOTO-0001',
139
- labels: 'label1, label2'
140
- )))
180
+ expect(DefMastership::Definition).to(
181
+ have_received(:new).with(
182
+ matchdata_including(type: 'requirement', reference: 'TOTO-0001', labels: 'label1, label2')
183
+ )
184
+ )
141
185
  end
142
186
 
143
187
  it { expect(document.labels).to(eq(Set['bla1', 'bla2'])) }
@@ -158,11 +202,11 @@ RSpec.describe(DefMastership::Document) do
158
202
  end
159
203
 
160
204
  it do
161
- expect(DefMastership::Definition).to(have_received(:new).with(matchdata_including(
162
- type: 'requirement',
163
- reference: 'TOTO-0001',
164
- labels: 'label1,label2'
165
- )))
205
+ expect(DefMastership::Definition).to(
206
+ have_received(:new).with(
207
+ matchdata_including(type: 'requirement', reference: 'TOTO-0001', labels: 'label1,label2')
208
+ )
209
+ )
166
210
  end
167
211
 
168
212
  it { expect(document.labels).to(eq(Set['bla1', 'bla2'])) }
@@ -209,8 +253,10 @@ RSpec.describe(DefMastership::Document) do
209
253
  end
210
254
 
211
255
  before do
212
- allow(definition).to(receive(:add_eref).with(:implements, 'SYSTEM-0012, SYSTEM-0014')
213
- .and_return(definition))
256
+ allow(definition).to(
257
+ receive(:add_eref).with(:implements, 'SYSTEM-0012, SYSTEM-0014')
258
+ .and_return(definition)
259
+ )
214
260
  document.parse(input_lines)
215
261
  end
216
262
 
@@ -289,18 +335,20 @@ RSpec.describe(DefMastership::Document) do
289
335
  end
290
336
 
291
337
  before do
292
- allow(DefMastership::Definition).to(receive(:new).with(matchdata_including(
293
- type: 'requirement',
294
- reference: 'TOTO-0001'
295
- )).and_return(definition))
338
+ allow(DefMastership::Definition).to(
339
+ receive(:new).with(
340
+ matchdata_including(type: 'requirement', reference: 'TOTO-0001')
341
+ ).and_return(definition)
342
+ )
296
343
  document.parse(input_lines)
297
344
  end
298
345
 
299
346
  it do
300
- expect(DefMastership::Definition).to(have_received(:new).with(matchdata_including(
301
- type: 'requirement',
302
- reference: 'TOTO-0001'
303
- )))
347
+ expect(DefMastership::Definition).to(
348
+ have_received(:new).with(
349
+ matchdata_including(type: 'requirement', reference: 'TOTO-0001')
350
+ )
351
+ )
304
352
  end
305
353
  end
306
354
  end
@@ -365,8 +413,9 @@ RSpec.describe(DefMastership::Document) do
365
413
  end
366
414
 
367
415
  before do
368
- allow(DefMastership::Definition).to(receive(:new)
369
- .and_raise('not a valide definition'))
416
+ allow(DefMastership::Definition).to(
417
+ receive(:new).and_raise('not a valide definition')
418
+ )
370
419
  end
371
420
 
372
421
  it do
@@ -385,8 +434,9 @@ RSpec.describe(DefMastership::Document) do
385
434
  end
386
435
 
387
436
  before do
388
- allow(DefMastership::Definition).to(receive(:new)
389
- .and_raise('not a valide definition'))
437
+ allow(DefMastership::Definition).to(
438
+ receive(:new).and_raise('not a valide definition')
439
+ )
390
440
  end
391
441
 
392
442
  it do
@@ -396,4 +446,155 @@ RSpec.describe(DefMastership::Document) do
396
446
  end
397
447
  end
398
448
  end
449
+
450
+ describe '#parse_file_with_preprocessor' do
451
+ let(:definition) { instance_double(DefMastership::Definition, 'definition') }
452
+ let(:input_lines) { ['[define, requirement, TOTO-0001]'] }
453
+ let(:adoc_doc) { instance_double(Asciidoctor::Document, 'adoc_doc') }
454
+ let(:adoc_reader) { instance_double(Asciidoctor::Reader, 'adoc_reader') }
455
+
456
+ before do
457
+ allow(Asciidoctor).to(
458
+ receive(:load_file).with('the_file.adoc', { parse: false, safe: :unsafe }).and_return(adoc_doc)
459
+ )
460
+ allow(adoc_doc).to(receive(:reader).and_return(adoc_reader))
461
+ allow(adoc_reader).to(receive(:read_lines).and_return(input_lines))
462
+ allow(DefMastership::Definition).to(receive(:new).and_return(definition))
463
+ allow(definition).to(receive(:<<).and_return(definition))
464
+ allow(definition).to(receive(:labels).and_return(Set.new))
465
+ document.parse_file_with_preprocessor('the_file.adoc')
466
+ end
467
+
468
+ it { expect(Asciidoctor).to(have_received(:load_file).with('the_file.adoc', { parse: false, safe: :unsafe })) }
469
+ it { expect(adoc_doc).to(have_received(:reader).with(no_args)) }
470
+ it { expect(adoc_reader).to(have_received(:read_lines).with(no_args)) }
471
+
472
+ it do
473
+ expect(DefMastership::Definition).to(
474
+ have_received(:new).with(
475
+ matchdata_including(type: 'requirement', reference: 'TOTO-0001')
476
+ )
477
+ )
478
+ end
479
+ end
480
+
481
+ describe '#wrong_explicit_checksum?' do
482
+ let(:def1) { instance_double(DefMastership::Definition, 'definition') }
483
+ let(:def2) { instance_double(DefMastership::Definition, 'definition') }
484
+ let(:input_lines) do
485
+ [
486
+ '[define, requirement, TOTO-0001]',
487
+ 'def one',
488
+ '',
489
+ '[define, requirement, TOTO-0002]',
490
+ 'def two'
491
+ ]
492
+ end
493
+
494
+ before do
495
+ allow(DefMastership::Definition).to(receive(:new).twice.and_return(def1, def2))
496
+ allow(def1).to(receive(:labels)).and_return([])
497
+ allow(def2).to(receive(:labels)).and_return([])
498
+ allow(def1).to(receive(:<<).and_return(def1))
499
+ allow(def2).to(receive(:<<).and_return(def2))
500
+ end
501
+
502
+ context 'when no wrong explicit checksum' do
503
+ before do
504
+ allow(def1).to(receive(:wrong_explicit_checksum)).and_return(nil)
505
+ allow(def2).to(receive(:wrong_explicit_checksum)).and_return(nil)
506
+ document.parse(input_lines)
507
+ document.wrong_explicit_checksum?
508
+ end
509
+
510
+ it { expect(def1).to(have_received(:wrong_explicit_checksum)) }
511
+ it { expect(def2).to(have_received(:wrong_explicit_checksum)) }
512
+ it { expect(document.wrong_explicit_checksum?).to(eq(false)) }
513
+ end
514
+
515
+ context 'when one req has wrong explicit checksum' do
516
+ before do
517
+ allow(def1).to(receive(:wrong_explicit_checksum)).and_return(nil)
518
+ allow(def2).to(receive(:wrong_explicit_checksum)).and_return('toto')
519
+ document.parse(input_lines)
520
+ document.wrong_explicit_checksum?
521
+ end
522
+
523
+ it { expect(document.wrong_explicit_checksum?).to(eq(true)) }
524
+ end
525
+ end
526
+
527
+ describe '#explicit_version?' do
528
+ let(:def1) { instance_double(DefMastership::Definition, 'definition') }
529
+ let(:def2) { instance_double(DefMastership::Definition, 'definition') }
530
+ let(:input_lines) do
531
+ [
532
+ '[define, requirement, TOTO-0001]',
533
+ 'def one',
534
+ '',
535
+ '[define, requirement, TOTO-0002]',
536
+ 'def two'
537
+ ]
538
+ end
539
+
540
+ before do
541
+ allow(DefMastership::Definition).to(receive(:new).twice.and_return(def1, def2))
542
+ allow(def1).to(receive(:labels)).and_return([])
543
+ allow(def2).to(receive(:labels)).and_return([])
544
+ allow(def1).to(receive(:<<).and_return(def1))
545
+ allow(def2).to(receive(:<<).and_return(def2))
546
+ end
547
+
548
+ context 'when no explicit version' do
549
+ before do
550
+ allow(def1).to(receive(:explicit_version)).and_return(nil)
551
+ allow(def2).to(receive(:explicit_version)).and_return(nil)
552
+ document.parse(input_lines)
553
+ document.explicit_version?
554
+ end
555
+
556
+ it { expect(def1).to(have_received(:explicit_version)) }
557
+ it { expect(def2).to(have_received(:explicit_version)) }
558
+ it { expect(document.explicit_version?).to(eq(false)) }
559
+ end
560
+
561
+ context 'when one req has explicit version' do
562
+ before do
563
+ allow(def1).to(receive(:explicit_version)).and_return(nil)
564
+ allow(def2).to(receive(:explicit_version)).and_return('toto')
565
+ document.parse(input_lines)
566
+ document.explicit_version?
567
+ end
568
+
569
+ it { expect(document.explicit_version?).to(eq(true)) }
570
+ end
571
+ end
572
+
573
+ describe '#ref_to_def?' do
574
+ let(:def1) { instance_double(DefMastership::Definition, 'definition') }
575
+ let(:def2) { instance_double(DefMastership::Definition, 'definition') }
576
+ let(:input_lines) do
577
+ [
578
+ '[define, requirement, TOTO-0001]',
579
+ 'def one',
580
+ '',
581
+ '[define, requirement, TOTO-0002(~1234)]',
582
+ 'def two'
583
+ ]
584
+ end
585
+
586
+ before do
587
+ allow(DefMastership::Definition).to(receive(:new).twice.and_return(def1, def2))
588
+ allow(def1).to(receive(:labels)).and_return([])
589
+ allow(def2).to(receive(:labels)).and_return([])
590
+ allow(def1).to(receive(:<<).and_return(def1))
591
+ allow(def2).to(receive(:<<).and_return(def2))
592
+ allow(def1).to(receive(:reference).and_return('TOTO-0001'))
593
+ allow(def2).to(receive(:reference).and_return('TOTO-0002'))
594
+ document.parse(input_lines)
595
+ end
596
+
597
+ it { expect(document.ref_to_def('TOTO-0001')).to(eq(def1)) }
598
+ it { expect(document.ref_to_def('TOTO-0002')).to(eq(def2)) }
599
+ end
399
600
  end