defmastership 1.0.7 → 1.0.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +4 -0
  3. data/bin/defmastership +1 -1
  4. data/features/changeref.feature +33 -0
  5. data/features/{checksum.feature → definition_checksum.feature} +85 -31
  6. data/features/definition_version.feature +204 -0
  7. data/features/export.feature +21 -21
  8. data/features/modify.feature +23 -1
  9. data/features/rename_included_files.feature +4 -0
  10. data/lib/defmastership.rb +3 -0
  11. data/lib/defmastership/batch_modifier.rb +2 -0
  12. data/lib/defmastership/change_ref_line_modifier.rb +2 -1
  13. data/lib/defmastership/constants.rb +4 -2
  14. data/lib/defmastership/csv_formatter.rb +12 -6
  15. data/lib/defmastership/csv_formatter_body.rb +8 -5
  16. data/lib/defmastership/csv_formatter_header.rb +5 -1
  17. data/lib/defmastership/definition.rb +4 -4
  18. data/lib/defmastership/document.rb +11 -15
  19. data/lib/defmastership/rename_included_files_line_modifier.rb +1 -1
  20. data/lib/defmastership/update_def_checksum_line_modifier.rb +2 -3
  21. data/lib/defmastership/update_def_checksum_modifier.rb +1 -1
  22. data/lib/defmastership/update_def_version_line_modifier.rb +58 -0
  23. data/lib/defmastership/update_def_version_modifier.rb +25 -0
  24. data/lib/defmastership/version.rb +1 -1
  25. data/spec/unit/defmastership/batch_modifier_spec.rb +8 -0
  26. data/spec/unit/defmastership/change_ref_line_modifier_spec.rb +15 -0
  27. data/spec/unit/defmastership/csv_formatter_body_spec.rb +42 -60
  28. data/spec/unit/defmastership/csv_formatter_header_spec.rb +23 -1
  29. data/spec/unit/defmastership/csv_formatter_spec.rb +204 -67
  30. data/spec/unit/defmastership/definition_spec.rb +19 -4
  31. data/spec/unit/defmastership/document_spec.rb +71 -4
  32. data/spec/unit/defmastership/rename_included_files_line_modifier_spec.rb +8 -8
  33. data/spec/unit/defmastership/update_def_checksum_line_modifier_spec.rb +14 -4
  34. data/spec/unit/defmastership/update_def_version_line_modifier_spec.rb +127 -0
  35. data/spec/unit/defmastership/update_def_version_modifier_spec.rb +80 -0
  36. metadata +8 -3
@@ -23,6 +23,7 @@ RSpec.describe(DefMastership::Definition) do
23
23
  it { is_expected.to(have_attributes(attributes: {})) }
24
24
  it { is_expected.to(have_attributes(labels: Set.new)) }
25
25
  it { is_expected.to(have_attributes(wrong_explicit_checksum: nil)) }
26
+ it { is_expected.to(have_attributes(explicit_version: nil)) }
26
27
  end
27
28
 
28
29
  context 'with labels' do
@@ -42,13 +43,13 @@ RSpec.describe(DefMastership::Definition) do
42
43
  described_class.new(
43
44
  type: 'req',
44
45
  reference: 'TUTU-001',
45
- explicit_checksum: '8cc259e6'
46
+ explicit_checksum: '~8cc259e6'
46
47
  )
47
48
  end
48
49
 
49
50
  it do
50
- definition << 'def value with a checksum != 8cc259e6'
51
- expect(definition).to(have_attributes(wrong_explicit_checksum: '8cc259e6'))
51
+ definition << 'def value with a checksum != ~8cc259e6'
52
+ expect(definition).to(have_attributes(wrong_explicit_checksum: '~8cc259e6'))
52
53
  end
53
54
 
54
55
  it do
@@ -56,6 +57,20 @@ RSpec.describe(DefMastership::Definition) do
56
57
  expect(definition).to(have_attributes(wrong_explicit_checksum: nil))
57
58
  end
58
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
59
74
  end
60
75
 
61
76
  describe '#<<' do
@@ -88,7 +103,7 @@ RSpec.describe(DefMastership::Definition) do
88
103
 
89
104
  it 'calculates sha256 of value' do
90
105
  definition << 'first line' << 'second line'
91
- expect(definition.sha256).to(eq('beb0535a'))
106
+ expect(definition.sha256).to(eq('~beb0535a'))
92
107
  end
93
108
  end
94
109
 
@@ -52,12 +52,12 @@ RSpec.describe(DefMastership::Document) do
52
52
  end
53
53
 
54
54
  context 'when simple definition line with explicit checksum' do
55
- let(:input_lines) { ['[define, requirement, TOTO-0001(ab12)]'] }
55
+ let(:input_lines) { ['[define, requirement, TOTO-0001(~ab12)]'] }
56
56
 
57
57
  before do
58
58
  allow(DefMastership::Definition).to(
59
59
  receive(:new).with(
60
- matchdata_including(type: 'requirement', reference: 'TOTO-0001', explicit_checksum: 'ab12')
60
+ matchdata_including(type: 'requirement', reference: 'TOTO-0001', explicit_checksum: '~ab12')
61
61
  ).and_return(definition)
62
62
  )
63
63
  document.parse(input_lines)
@@ -66,7 +66,28 @@ RSpec.describe(DefMastership::Document) do
66
66
  it do
67
67
  expect(DefMastership::Definition).to(
68
68
  have_received(:new).with(
69
- matchdata_including(type: 'requirement', reference: 'TOTO-0001', explicit_checksum: 'ab12')
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')
70
91
  )
71
92
  )
72
93
  end
@@ -503,6 +524,52 @@ RSpec.describe(DefMastership::Document) do
503
524
  end
504
525
  end
505
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
+
506
573
  describe '#ref_to_def?' do
507
574
  let(:def1) { instance_double(DefMastership::Definition, 'definition') }
508
575
  let(:def2) { instance_double(DefMastership::Definition, 'definition') }
@@ -511,7 +578,7 @@ RSpec.describe(DefMastership::Document) do
511
578
  '[define, requirement, TOTO-0001]',
512
579
  'def one',
513
580
  '',
514
- '[define, requirement, TOTO-0002(1234)]',
581
+ '[define, requirement, TOTO-0002(~1234)]',
515
582
  'def two'
516
583
  ]
517
584
  end
@@ -110,32 +110,32 @@ RSpec.describe(DefMastership::RenameIncludedFilesLineModifier) do
110
110
  end
111
111
 
112
112
  it do
113
- expect(includeschanger.replace('include::orig[]'))
114
- .to(eq('include::dest[]'))
113
+ expect(includeschanger.replace("include::orig[]\n"))
114
+ .to(eq("include::dest[]\n"))
115
115
  end
116
116
 
117
117
  it do
118
- includeschanger.replace('include::orig[]')
118
+ includeschanger.replace("include::orig[]\n")
119
119
  expect(File).to(have_received(:rename).with('orig', 'dest'))
120
120
  end
121
121
 
122
122
  it do
123
- includeschanger.replace('include::orig[]')
123
+ includeschanger.replace("include::orig[]\n")
124
124
  expect(includeschanger).to(have_attributes(changes: [%w[orig dest]]))
125
125
  end
126
126
 
127
127
  it do
128
- expect(includeschanger.replace('include::toto/orig[]'))
129
- .to(eq('include::toto/dest[]'))
128
+ expect(includeschanger.replace("include::toto/orig[]\n"))
129
+ .to(eq("include::toto/dest[]\n"))
130
130
  end
131
131
 
132
132
  it do
133
- includeschanger.replace('include::toto/orig[]')
133
+ includeschanger.replace("include::toto/orig[]\n")
134
134
  expect(File).to(have_received(:rename).with('toto/orig', 'toto/dest'))
135
135
  end
136
136
 
137
137
  it do
138
- includeschanger.replace('include::toto/orig[]')
138
+ includeschanger.replace("include::toto/orig[]\n")
139
139
  expect(includeschanger).to(have_attributes(changes: [%w[toto/orig toto/dest]]))
140
140
  end
141
141
  end
@@ -51,17 +51,27 @@ RSpec.describe(DefMastership::UpdateDefChecksumLineModifier) do
51
51
  context 'when definition has the good type' do
52
52
  before do
53
53
  allow(document).to(receive(:ref_to_def).with('REFERENCE').and_return(definition))
54
- allow(definition).to(receive(:sha256).and_return('abcd1234'))
54
+ allow(definition).to(receive(:sha256).and_return('~abcd1234'))
55
55
  end
56
56
 
57
57
  it do
58
58
  expect(linemodifier.replace('[define,requirement,REFERENCE]'))
59
- .to(eq('[define,requirement,REFERENCE(abcd1234)]'))
59
+ .to(eq('[define,requirement,REFERENCE(~abcd1234)]'))
60
60
  end
61
61
 
62
62
  it do
63
- expect(linemodifier.replace('[define,requirement,REFERENCE(bad)]'))
64
- .to(eq('[define,requirement,REFERENCE(abcd1234)]'))
63
+ expect(linemodifier.replace('[define,requirement,REFERENCE(~bad)]'))
64
+ .to(eq('[define,requirement,REFERENCE(~abcd1234)]'))
65
+ end
66
+
67
+ it do
68
+ expect(linemodifier.replace('[define,requirement,REFERENCE(toto~bad)]'))
69
+ .to(eq('[define,requirement,REFERENCE(toto~abcd1234)]'))
70
+ end
71
+
72
+ it do
73
+ expect(linemodifier.replace('[define,requirement,REFERENCE(toto)]'))
74
+ .to(eq('[define,requirement,REFERENCE(toto~abcd1234)]'))
65
75
  end
66
76
  end
67
77
  end
@@ -0,0 +1,127 @@
1
+ # Copyright (c) 2020 Jerome Arbez-Gindre
2
+ # frozen_string_literal: true
3
+
4
+ require('defmastership')
5
+
6
+ RSpec.describe(DefMastership::UpdateDefVersionLineModifier) do
7
+ subject(:linemodifier) { described_class.new }
8
+
9
+ describe '.new' do
10
+ it { is_expected.not_to(be(nil)) }
11
+ it { is_expected.to(have_attributes(def_type: '')) }
12
+ it { is_expected.to(have_attributes(changes: [])) }
13
+ it { expect { linemodifier.user_defined_attribute }.to(raise_error(NoMethodError)) }
14
+ end
15
+
16
+ describe '.from_config' do
17
+ subject(:linemodifier) do
18
+ described_class.from_config(
19
+ def_type: 'requirement',
20
+ first_version: 'a'
21
+ )
22
+ end
23
+
24
+ it { is_expected.not_to(be(nil)) }
25
+ it { is_expected.to(have_attributes(def_type: 'requirement')) }
26
+ it { is_expected.to(have_attributes(first_version: 'a')) }
27
+ it { is_expected.to(have_attributes(document: nil)) }
28
+ it { is_expected.to(have_attributes(ref_document: nil)) }
29
+ end
30
+
31
+ describe '#replace' do
32
+ subject(:linemodifier) do
33
+ described_class.from_config(
34
+ def_type: 'requirement',
35
+ first_version: 'a'
36
+ )
37
+ end
38
+
39
+ let(:document) { instance_double(DefMastership::Document, 'document') }
40
+ let(:ref_document) { instance_double(DefMastership::Document, 'ref_document') }
41
+ let(:definition) { instance_double(DefMastership::Definition, 'definition') }
42
+ let(:ref_definition) { instance_double(DefMastership::Definition, 'ref_definitions') }
43
+
44
+ before do
45
+ linemodifier.document = document
46
+ linemodifier.ref_document = ref_document
47
+ allow(File).to(receive(:rename))
48
+ end
49
+
50
+ context 'when definition has not the good type' do
51
+ it do
52
+ expect(linemodifier.replace('[define,req,REFERENCE]'))
53
+ .to(eq('[define,req,REFERENCE]'))
54
+ end
55
+ end
56
+
57
+ context 'when definition has the good type' do
58
+ before do
59
+ allow(document).to(receive(:ref_to_def).with('REFERENCE').and_return(definition))
60
+ allow(definition).to(receive(:sha256).and_return('~abcd1234'))
61
+ end
62
+
63
+ context 'when definition has NOT changed' do
64
+ before do
65
+ allow(ref_document).to(receive(:ref_to_def).with('REFERENCE').and_return(ref_definition))
66
+ allow(ref_definition).to(receive(:sha256).and_return('~abcd1234'))
67
+ end
68
+
69
+ it do
70
+ allow(ref_definition).to(receive(:explicit_version).and_return(nil))
71
+ expect(linemodifier.replace('[define,requirement,REFERENCE]'))
72
+ .to(eq('[define,requirement,REFERENCE]'))
73
+ end
74
+
75
+ it do
76
+ allow(ref_definition).to(receive(:explicit_version).and_return('c'))
77
+ expect(linemodifier.replace('[define,requirement,REFERENCE]'))
78
+ .to(eq('[define,requirement,REFERENCE(c)]'))
79
+ end
80
+
81
+ it do
82
+ allow(ref_definition).to(receive(:explicit_version).and_return('c'))
83
+ expect(linemodifier.replace('[define,requirement,REFERENCE(tyty~1234)]'))
84
+ .to(eq('[define,requirement,REFERENCE(c~1234)]'))
85
+ end
86
+ end
87
+
88
+ context 'when definition has changed' do
89
+ before do
90
+ allow(ref_document).to(receive(:ref_to_def).with('REFERENCE').and_return(ref_definition))
91
+ allow(ref_definition).to(receive(:sha256).and_return('~4321aaaa'))
92
+ end
93
+
94
+ [
95
+ [nil, '', '(a)'],
96
+ ['c', '', '(d)'],
97
+ ['c', '(tyty~1234)', '(d~1234)'],
98
+ ['2', '', '(3)'],
99
+ ['1222', '', '(1223)'],
100
+ ['abb', '', '(abc)']
101
+ ].each do |ref, from, to|
102
+ it do
103
+ allow(ref_definition).to(receive(:explicit_version).and_return(ref))
104
+ expect(linemodifier.replace("[define,requirement,REFERENCE#{from}]"))
105
+ .to(eq("[define,requirement,REFERENCE#{to}]"))
106
+ end
107
+ end
108
+ end
109
+
110
+ context 'when definition is new' do
111
+ before do
112
+ allow(ref_document).to(receive(:ref_to_def).with('REFERENCE').and_return(nil))
113
+ end
114
+
115
+ it do
116
+ expect(linemodifier.replace('[define,requirement,REFERENCE(whatever)]'))
117
+ .to(eq('[define,requirement,REFERENCE]'))
118
+ end
119
+
120
+ it do
121
+ expect(linemodifier.replace('[define,requirement,REFERENCE(~1234)]'))
122
+ .to(eq('[define,requirement,REFERENCE(~1234)]'))
123
+ end
124
+ end
125
+ end
126
+ end
127
+ end
@@ -0,0 +1,80 @@
1
+ # Copyright (c) 2020 Jerome Arbez-Gindre
2
+ # frozen_string_literal: true
3
+
4
+ require('defmastership')
5
+
6
+ RSpec.describe(DefMastership::UpdateDefVersionModifier) do
7
+ subject(:modifier) do
8
+ described_class.new(
9
+ ref_document: 'ref.adoc'
10
+ )
11
+ end
12
+
13
+ let(:adoc_texts) do
14
+ {
15
+ 'file1.adoc' => "file1 line1\nfile1 line2",
16
+ 'file2.adoc' => "file2 line1\nfile2 line2"
17
+ }
18
+ end
19
+
20
+ describe '.new' do
21
+ it { is_expected.not_to(be(nil)) }
22
+ it { is_expected.to(have_attributes(config: { ref_document: 'ref.adoc' })) }
23
+ it { is_expected.to(have_attributes(changes: [])) }
24
+ end
25
+
26
+ describe '#do_modifications' do
27
+ let(:line_modifier) { instance_double(DefMastership::UpdateDefVersionLineModifier, 'lineModifier') }
28
+ let(:document) { instance_double(DefMastership::Document, 'document') }
29
+ let(:ref_document) { instance_double(DefMastership::Document, 'ref_document') }
30
+
31
+ before do
32
+ allow(DefMastership::UpdateDefVersionLineModifier).to(
33
+ receive(:from_config).with(ref_document: 'ref.adoc').and_return(line_modifier)
34
+ )
35
+ allow(DefMastership::Document).to(receive(:new).and_return(document, ref_document))
36
+ allow(document).to(receive(:parse_file_with_preprocessor))
37
+ allow(ref_document).to(receive(:parse_file_with_preprocessor))
38
+ allow(line_modifier).to(receive(:'document=').with(document))
39
+ allow(line_modifier).to(receive(:'ref_document=').with(ref_document))
40
+ allow(line_modifier).to(receive(:replace).with("file1 line1\n").and_return("new file1 line1\n"))
41
+ allow(line_modifier).to(receive(:replace).with('file1 line2').and_return('new file1 line2'))
42
+ allow(line_modifier).to(receive(:replace).with("file2 line1\n").and_return("new file2 line1\n"))
43
+ allow(line_modifier).to(receive(:replace).with('file2 line2').and_return('new file2 line2'))
44
+ allow(line_modifier).to(receive(:config).and_return(ref_document: 'ref.adoc'))
45
+ allow(line_modifier).to(receive(:changes).and_return([%w[from1 to1], %w[from2 to2]]))
46
+ end
47
+
48
+ context 'when detailed expectations' do
49
+ before { modifier.do_modifications(adoc_texts) }
50
+
51
+ it do
52
+ expect(DefMastership::UpdateDefVersionLineModifier).to(
53
+ have_received(:from_config).with(ref_document: 'ref.adoc')
54
+ )
55
+ end
56
+
57
+ it { expect(document).to(have_received(:parse_file_with_preprocessor).with('file1.adoc')) }
58
+ it { expect(document).to(have_received(:parse_file_with_preprocessor).with('file2.adoc')) }
59
+ it { expect(ref_document).to(have_received(:parse_file_with_preprocessor).with('ref.adoc')) }
60
+ it { expect(line_modifier).to(have_received(:'document=').with(document)) }
61
+ it { expect(line_modifier).to(have_received(:'ref_document=').with(ref_document)) }
62
+ it { expect(line_modifier).to(have_received(:replace).with("file1 line1\n")) }
63
+ it { expect(line_modifier).to(have_received(:replace).with('file1 line2')) }
64
+ it { expect(line_modifier).to(have_received(:replace).with("file2 line1\n")) }
65
+ it { expect(line_modifier).to(have_received(:replace).with('file2 line2')) }
66
+ it { expect(line_modifier).to(have_received(:config)) }
67
+ it { expect(line_modifier).to(have_received(:changes)) }
68
+ it { is_expected.to(have_attributes(config: { ref_document: 'ref.adoc' })) }
69
+ it { is_expected.to(have_attributes(changes: [%w[from1 to1], %w[from2 to2]])) }
70
+ end
71
+
72
+ it do
73
+ expected_adoc = {
74
+ 'file1.adoc' => "new file1 line1\nnew file1 line2",
75
+ 'file2.adoc' => "new file2 line1\nnew file2 line2"
76
+ }
77
+ expect(modifier.do_modifications(adoc_texts)).to(eq(expected_adoc))
78
+ end
79
+ end
80
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: defmastership
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.7
4
+ version: 1.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jérôme Arbez-Gindre
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-02-27 00:00:00.000000000 Z
11
+ date: 2021-04-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aruba
@@ -193,7 +193,8 @@ files:
193
193
  - defmastership.gemspec
194
194
  - defmastership.rdoc
195
195
  - features/changeref.feature
196
- - features/checksum.feature
196
+ - features/definition_checksum.feature
197
+ - features/definition_version.feature
197
198
  - features/defmastership.feature
198
199
  - features/export.feature
199
200
  - features/modify.feature
@@ -219,6 +220,8 @@ files:
219
220
  - lib/defmastership/rename_included_files_modifier.rb
220
221
  - lib/defmastership/update_def_checksum_line_modifier.rb
221
222
  - lib/defmastership/update_def_checksum_modifier.rb
223
+ - lib/defmastership/update_def_version_line_modifier.rb
224
+ - lib/defmastership/update_def_version_modifier.rb
222
225
  - lib/defmastership/version.rb
223
226
  - spec/spec_helper.rb
224
227
  - spec/unit/defmastership/batch_modifier_spec.rb
@@ -235,6 +238,8 @@ files:
235
238
  - spec/unit/defmastership/rename_included_files_modifier_spec.rb
236
239
  - spec/unit/defmastership/update_def_checksum_line_modifier_spec.rb
237
240
  - spec/unit/defmastership/update_def_checksum_modifier_spec.rb
241
+ - spec/unit/defmastership/update_def_version_line_modifier_spec.rb
242
+ - spec/unit/defmastership/update_def_version_modifier_spec.rb
238
243
  - spec/unit/defmastership_spec.rb
239
244
  homepage: https://gitlab.com/jjag/defmastership/
240
245
  licenses: