defmastership 1.0.5 → 1.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/bin/defmastership +33 -22
- data/cucumber.yml +1 -1
- data/defmastership.gemspec +12 -6
- data/features/changeref.feature +82 -129
- data/features/definition_checksum.feature +298 -0
- data/features/definition_version.feature +204 -0
- data/features/export.feature +35 -34
- data/features/modify.feature +165 -0
- data/features/rename_included_files.feature +121 -0
- data/lib/defmastership.rb +17 -3
- data/lib/defmastership/batch_modifier.rb +35 -0
- data/lib/defmastership/{ref_changer.rb → change_ref_line_modifier.rb} +18 -35
- data/lib/defmastership/change_ref_modifier.rb +15 -0
- data/lib/defmastership/constants.rb +14 -1
- data/lib/defmastership/csv_formatter.rb +22 -17
- data/lib/defmastership/csv_formatter_body.rb +19 -11
- data/lib/defmastership/csv_formatter_header.rb +15 -10
- data/lib/defmastership/definition.rb +14 -3
- data/lib/defmastership/definition_parser.rb +46 -0
- data/lib/defmastership/document.rb +59 -85
- data/lib/defmastership/filters.rb +30 -0
- data/lib/defmastership/line_modifier_base.rb +29 -0
- data/lib/defmastership/modifier_base.rb +29 -0
- data/lib/defmastership/rename_included_files_line_modifier.rb +126 -0
- data/lib/defmastership/rename_included_files_modifier.rb +15 -0
- data/lib/defmastership/update_def_checksum_line_modifier.rb +38 -0
- data/lib/defmastership/update_def_checksum_modifier.rb +21 -0
- data/lib/defmastership/update_def_version_line_modifier.rb +58 -0
- data/lib/defmastership/update_def_version_modifier.rb +25 -0
- data/lib/defmastership/version.rb +1 -1
- data/spec/spec_helper.rb +1 -0
- data/spec/unit/defmastership/batch_modifier_spec.rb +123 -0
- data/spec/unit/defmastership/{ref_changer_spec.rb → change_ref_line_modifier_spec.rb} +48 -26
- data/spec/unit/defmastership/change_ref_modifier_spec.rb +76 -0
- data/spec/unit/defmastership/comment_filter_spec.rb +8 -4
- data/spec/unit/defmastership/csv_formatter_body_spec.rb +88 -82
- data/spec/unit/defmastership/csv_formatter_header_spec.rb +68 -22
- data/spec/unit/defmastership/csv_formatter_spec.rb +207 -109
- data/spec/unit/defmastership/definition_parser_spec.rb +63 -0
- data/spec/unit/defmastership/definition_spec.rb +45 -4
- data/spec/unit/defmastership/document_spec.rb +236 -35
- data/spec/unit/defmastership/rename_included_files_line_modifier_spec.rb +203 -0
- data/spec/unit/defmastership/rename_included_files_modifier_spec.rb +67 -0
- data/spec/unit/defmastership/update_def_checksum_line_modifier_spec.rb +78 -0
- data/spec/unit/defmastership/update_def_checksum_modifier_spec.rb +75 -0
- data/spec/unit/defmastership/update_def_version_line_modifier_spec.rb +127 -0
- data/spec/unit/defmastership/update_def_version_modifier_spec.rb +80 -0
- metadata +44 -9
- data/lib/defmastership/batch_changer.rb +0 -41
- data/lib/defmastership/project_ref_changer.rb +0 -28
- data/spec/unit/defmastership/batch_changer_spec.rb +0 -109
- data/spec/unit/defmastership/project_ref_changer_spec.rb +0 -80
@@ -0,0 +1,203 @@
|
|
1
|
+
# Copyright (c) 2021 Jerome Arbez-Gindre
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require('defmastership')
|
5
|
+
|
6
|
+
RSpec.describe(DefMastership::RenameIncludedFilesLineModifier) do
|
7
|
+
subject(:includeschanger) { described_class.new }
|
8
|
+
|
9
|
+
describe '.new' do
|
10
|
+
it { is_expected.not_to(be(nil)) }
|
11
|
+
it { is_expected.to(have_attributes(from_regexp: '')) }
|
12
|
+
it { is_expected.to(have_attributes(to_template: '')) }
|
13
|
+
it { is_expected.to(have_attributes(changes: [])) }
|
14
|
+
it { expect { includeschanger.user_defined_attribute }.to(raise_error(NoMethodError)) }
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '.from_config' do
|
18
|
+
subject(:includeschanger) do
|
19
|
+
described_class.from_config(
|
20
|
+
from_regexp: 'Whatever.+',
|
21
|
+
to_template: 'Whatever'
|
22
|
+
)
|
23
|
+
end
|
24
|
+
|
25
|
+
it { is_expected.not_to(be(nil)) }
|
26
|
+
it { is_expected.to(have_attributes(from_regexp: 'Whatever.+')) }
|
27
|
+
it { is_expected.to(have_attributes(to_template: 'Whatever')) }
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '#replace' do
|
31
|
+
context 'when NOT valid include' do
|
32
|
+
before do
|
33
|
+
includeschanger.from_config(
|
34
|
+
from_regexp: 'orig',
|
35
|
+
cancel_if_match: 'REF',
|
36
|
+
to_template: 'dest'
|
37
|
+
)
|
38
|
+
allow(File).to(receive(:rename))
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'when the include statement do not match' do
|
42
|
+
before do
|
43
|
+
['[define,requirement,REFERENCE]', '--'].each do |line|
|
44
|
+
includeschanger.replace(line)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
it do
|
49
|
+
expect(includeschanger.replace('badinclude::orig[]'))
|
50
|
+
.to(eq('badinclude::orig[]'))
|
51
|
+
end
|
52
|
+
|
53
|
+
it do
|
54
|
+
includeschanger.replace('badinclude::orig[]')
|
55
|
+
expect(includeschanger).to(have_attributes(changes: []))
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context 'when the include is not in a definition' do
|
60
|
+
before do
|
61
|
+
['[define,requirement,REFERENCE]', '--', 'text', '--'].each do |line|
|
62
|
+
includeschanger.replace(line)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
it do
|
67
|
+
expect(includeschanger.replace('include::orig[]'))
|
68
|
+
.to(eq('include::orig[]'))
|
69
|
+
end
|
70
|
+
|
71
|
+
it do
|
72
|
+
includeschanger.replace('include::orig[]')
|
73
|
+
expect(includeschanger).to(have_attributes(changes: []))
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
context 'when the cancel regexp is met' do
|
78
|
+
before do
|
79
|
+
['[define,requirement,REFERENCE]', '--'].each do |line|
|
80
|
+
includeschanger.replace(line)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
it do
|
85
|
+
expect(includeschanger.replace('include::REFERENCE_orig[]'))
|
86
|
+
.to(eq('include::REFERENCE_orig[]'))
|
87
|
+
end
|
88
|
+
|
89
|
+
it do
|
90
|
+
includeschanger.replace('include::REFERENCE_orig[]')
|
91
|
+
expect(includeschanger).to(have_attributes(changes: []))
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
context 'when valid include' do
|
97
|
+
before do
|
98
|
+
allow(File).to(receive(:rename))
|
99
|
+
end
|
100
|
+
|
101
|
+
context 'when really simple rule' do
|
102
|
+
before do
|
103
|
+
includeschanger.from_config(
|
104
|
+
from_regexp: 'orig',
|
105
|
+
cancel_if_match: 'REF',
|
106
|
+
to_template: 'dest'
|
107
|
+
)
|
108
|
+
includeschanger.replace('[define,requirement,REFERENCE]')
|
109
|
+
includeschanger.replace('--')
|
110
|
+
end
|
111
|
+
|
112
|
+
it do
|
113
|
+
expect(includeschanger.replace('include::orig[]'))
|
114
|
+
.to(eq('include::dest[]'))
|
115
|
+
end
|
116
|
+
|
117
|
+
it do
|
118
|
+
includeschanger.replace('include::orig[]')
|
119
|
+
expect(File).to(have_received(:rename).with('orig', 'dest'))
|
120
|
+
end
|
121
|
+
|
122
|
+
it do
|
123
|
+
includeschanger.replace('include::orig[]')
|
124
|
+
expect(includeschanger).to(have_attributes(changes: [%w[orig dest]]))
|
125
|
+
end
|
126
|
+
|
127
|
+
it do
|
128
|
+
expect(includeschanger.replace('include::toto/orig[]'))
|
129
|
+
.to(eq('include::toto/dest[]'))
|
130
|
+
end
|
131
|
+
|
132
|
+
it do
|
133
|
+
includeschanger.replace('include::toto/orig[]')
|
134
|
+
expect(File).to(have_received(:rename).with('toto/orig', 'toto/dest'))
|
135
|
+
end
|
136
|
+
|
137
|
+
it do
|
138
|
+
includeschanger.replace('include::toto/orig[]')
|
139
|
+
expect(includeschanger).to(have_attributes(changes: [%w[toto/orig toto/dest]]))
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
context 'when complex from_regexp' do
|
144
|
+
before do
|
145
|
+
includeschanger.from_config(
|
146
|
+
from_regexp: '(?<origin>.*\.extension)',
|
147
|
+
to_template: '%<reference>s_%<origin>s'
|
148
|
+
)
|
149
|
+
includeschanger.replace('[define,requirement,REF]')
|
150
|
+
end
|
151
|
+
|
152
|
+
it do
|
153
|
+
expect(includeschanger.replace('include::any_path/one_file.extension[]'))
|
154
|
+
.to(eq('include::any_path/REF_one_file.extension[]'))
|
155
|
+
end
|
156
|
+
|
157
|
+
it do
|
158
|
+
includeschanger.replace('include::any_path/one_file.extension[]')
|
159
|
+
expect(File).to(have_received(:rename).with('any_path/one_file.extension', 'any_path/REF_one_file.extension'))
|
160
|
+
end
|
161
|
+
|
162
|
+
it do
|
163
|
+
changes = [%w[any_path/one_file.extension any_path/REF_one_file.extension]]
|
164
|
+
includeschanger.replace('include::any_path/one_file.extension[]')
|
165
|
+
expect(includeschanger).to(have_attributes(changes: changes))
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
context 'when path with variable' do
|
170
|
+
before do
|
171
|
+
includeschanger.from_config(
|
172
|
+
from_regexp: 'orig',
|
173
|
+
to_template: 'dest'
|
174
|
+
)
|
175
|
+
includeschanger.replace(':any: one')
|
176
|
+
includeschanger.replace(':path: two')
|
177
|
+
includeschanger.replace('[define,requirement,REFERENCE]')
|
178
|
+
includeschanger.replace('--')
|
179
|
+
end
|
180
|
+
|
181
|
+
it do
|
182
|
+
expect(includeschanger.replace('include::{any}/orig[]'))
|
183
|
+
.to(eq('include::{any}/dest[]'))
|
184
|
+
end
|
185
|
+
|
186
|
+
it do
|
187
|
+
includeschanger.replace('include::{any}/orig[]')
|
188
|
+
expect(File).to(have_received(:rename).with('one/orig', 'one/dest'))
|
189
|
+
end
|
190
|
+
|
191
|
+
it do
|
192
|
+
includeschanger.replace('include::{any}_{path}/orig[]')
|
193
|
+
expect(File).to(have_received(:rename).with('one_two/orig', 'one_two/dest'))
|
194
|
+
end
|
195
|
+
|
196
|
+
it do
|
197
|
+
includeschanger.replace('include::{any}_{path}/orig[]')
|
198
|
+
expect(includeschanger).to(have_attributes(changes: [%w[one_two/orig one_two/dest]]))
|
199
|
+
end
|
200
|
+
end
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# Copyright (c) 2021 Jerome Arbez-Gindre
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require('defmastership')
|
5
|
+
|
6
|
+
RSpec.describe(DefMastership::RenameIncludedFilesModifier) do
|
7
|
+
subject(:modifier) do
|
8
|
+
described_class.new(
|
9
|
+
'fake config'
|
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: 'fake config')) }
|
23
|
+
it { is_expected.to(have_attributes(changes: [])) }
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '#do_modifications' do
|
27
|
+
let(:line_modifier) { instance_double(DefMastership::RenameIncludedFilesLineModifier, 'lineModifier') }
|
28
|
+
|
29
|
+
before do
|
30
|
+
allow(DefMastership::RenameIncludedFilesLineModifier).to(
|
31
|
+
receive(:from_config).with('fake config').and_return(line_modifier)
|
32
|
+
)
|
33
|
+
allow(line_modifier).to(receive(:replace).with("file1 line1\n").and_return("new file1 line1\n"))
|
34
|
+
allow(line_modifier).to(receive(:replace).with('file1 line2').and_return('new file1 line2'))
|
35
|
+
allow(line_modifier).to(receive(:replace).with("file2 line1\n").and_return("new file2 line1\n"))
|
36
|
+
allow(line_modifier).to(receive(:replace).with('file2 line2').and_return('new file2 line2'))
|
37
|
+
allow(line_modifier).to(receive(:changes).and_return([%w[from1 to1], %w[from2 to2]]))
|
38
|
+
allow(line_modifier).to(receive(:config).and_return('fake config'))
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'when detailed expectations' do
|
42
|
+
before { modifier.do_modifications(adoc_texts) }
|
43
|
+
|
44
|
+
it do
|
45
|
+
expect(DefMastership::RenameIncludedFilesLineModifier).to(
|
46
|
+
have_received(:from_config).with('fake config')
|
47
|
+
)
|
48
|
+
end
|
49
|
+
|
50
|
+
it { expect(line_modifier).to(have_received(:replace).with("file1 line1\n")) }
|
51
|
+
it { expect(line_modifier).to(have_received(:replace).with('file1 line2')) }
|
52
|
+
it { expect(line_modifier).to(have_received(:replace).with("file2 line1\n")) }
|
53
|
+
it { expect(line_modifier).to(have_received(:replace).with('file2 line2')) }
|
54
|
+
it { expect(line_modifier).to(have_received(:changes)) }
|
55
|
+
it { is_expected.to(have_attributes(config: 'fake config')) }
|
56
|
+
it { is_expected.to(have_attributes(changes: [%w[from1 to1], %w[from2 to2]])) }
|
57
|
+
end
|
58
|
+
|
59
|
+
it do
|
60
|
+
expected_adoc = {
|
61
|
+
'file1.adoc' => "new file1 line1\nnew file1 line2",
|
62
|
+
'file2.adoc' => "new file2 line1\nnew file2 line2"
|
63
|
+
}
|
64
|
+
expect(modifier.do_modifications(adoc_texts)).to(eq(expected_adoc))
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# Copyright (c) 2020 Jerome Arbez-Gindre
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require('defmastership')
|
5
|
+
|
6
|
+
RSpec.describe(DefMastership::UpdateDefChecksumLineModifier) 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
|
+
)
|
21
|
+
end
|
22
|
+
|
23
|
+
it { is_expected.not_to(be(nil)) }
|
24
|
+
it { is_expected.to(have_attributes(def_type: 'requirement')) }
|
25
|
+
it { is_expected.to(have_attributes(document: nil)) }
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '#replace' do
|
29
|
+
subject(:linemodifier) do
|
30
|
+
described_class.from_config(
|
31
|
+
def_type: 'requirement'
|
32
|
+
)
|
33
|
+
end
|
34
|
+
|
35
|
+
let(:definition) { instance_double(DefMastership::Definition, 'definition') }
|
36
|
+
let(:document) { instance_double(DefMastership::Document, 'document') }
|
37
|
+
let(:definitions) { { 'REFERENCE' => definition } }
|
38
|
+
|
39
|
+
before do
|
40
|
+
linemodifier.document = document
|
41
|
+
allow(File).to(receive(:rename))
|
42
|
+
end
|
43
|
+
|
44
|
+
context 'when definition has not the good type' do
|
45
|
+
it do
|
46
|
+
expect(linemodifier.replace('[define,req,REFERENCE]'))
|
47
|
+
.to(eq('[define,req,REFERENCE]'))
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'when definition has the good type' do
|
52
|
+
before do
|
53
|
+
allow(document).to(receive(:ref_to_def).with('REFERENCE').and_return(definition))
|
54
|
+
allow(definition).to(receive(:sha256).and_return('~abcd1234'))
|
55
|
+
end
|
56
|
+
|
57
|
+
it do
|
58
|
+
expect(linemodifier.replace('[define,requirement,REFERENCE]'))
|
59
|
+
.to(eq('[define,requirement,REFERENCE(~abcd1234)]'))
|
60
|
+
end
|
61
|
+
|
62
|
+
it do
|
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)]'))
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
# Copyright (c) 2020 Jerome Arbez-Gindre
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require('defmastership')
|
5
|
+
|
6
|
+
RSpec.describe(DefMastership::UpdateDefChecksumModifier) do
|
7
|
+
subject(:modifier) do
|
8
|
+
described_class.new(
|
9
|
+
'fake config'
|
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: 'fake config')) }
|
23
|
+
it { is_expected.to(have_attributes(changes: [])) }
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '#do_modifications' do
|
27
|
+
let(:line_modifier) { instance_double(DefMastership::UpdateDefChecksumLineModifier, 'lineModifier') }
|
28
|
+
let(:document) { instance_double(DefMastership::Document, 'document') }
|
29
|
+
|
30
|
+
before do
|
31
|
+
allow(DefMastership::UpdateDefChecksumLineModifier).to(
|
32
|
+
receive(:from_config).with('fake config').and_return(line_modifier)
|
33
|
+
)
|
34
|
+
allow(DefMastership::Document).to(receive(:new).and_return(document))
|
35
|
+
allow(document).to(receive(:parse_file_with_preprocessor))
|
36
|
+
allow(line_modifier).to(receive(:'document=').with(document))
|
37
|
+
allow(line_modifier).to(receive(:replace).with("file1 line1\n").and_return("new file1 line1\n"))
|
38
|
+
allow(line_modifier).to(receive(:replace).with('file1 line2').and_return('new file1 line2'))
|
39
|
+
allow(line_modifier).to(receive(:replace).with("file2 line1\n").and_return("new file2 line1\n"))
|
40
|
+
allow(line_modifier).to(receive(:replace).with('file2 line2').and_return('new file2 line2'))
|
41
|
+
allow(line_modifier).to(receive(:config).and_return('new fake config'))
|
42
|
+
allow(line_modifier).to(receive(:changes).and_return([%w[from1 to1], %w[from2 to2]]))
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'when detailed expectations' do
|
46
|
+
before { modifier.do_modifications(adoc_texts) }
|
47
|
+
|
48
|
+
it do
|
49
|
+
expect(DefMastership::UpdateDefChecksumLineModifier).to(
|
50
|
+
have_received(:from_config).with('fake config')
|
51
|
+
)
|
52
|
+
end
|
53
|
+
|
54
|
+
it { expect(document).to(have_received(:parse_file_with_preprocessor).with('file1.adoc')) }
|
55
|
+
it { expect(document).to(have_received(:parse_file_with_preprocessor).with('file2.adoc')) }
|
56
|
+
it { expect(line_modifier).to(have_received(:'document=').with(document)) }
|
57
|
+
it { expect(line_modifier).to(have_received(:replace).with("file1 line1\n")) }
|
58
|
+
it { expect(line_modifier).to(have_received(:replace).with('file1 line2')) }
|
59
|
+
it { expect(line_modifier).to(have_received(:replace).with("file2 line1\n")) }
|
60
|
+
it { expect(line_modifier).to(have_received(:replace).with('file2 line2')) }
|
61
|
+
it { expect(line_modifier).to(have_received(:config)) }
|
62
|
+
it { expect(line_modifier).to(have_received(:changes)) }
|
63
|
+
it { is_expected.to(have_attributes(config: 'new fake config')) }
|
64
|
+
it { is_expected.to(have_attributes(changes: [%w[from1 to1], %w[from2 to2]])) }
|
65
|
+
end
|
66
|
+
|
67
|
+
it do
|
68
|
+
expected_adoc = {
|
69
|
+
'file1.adoc' => "new file1 line1\nnew file1 line2",
|
70
|
+
'file2.adoc' => "new file2 line1\nnew file2 line2"
|
71
|
+
}
|
72
|
+
expect(modifier.do_modifications(adoc_texts)).to(eq(expected_adoc))
|
73
|
+
end
|
74
|
+
end
|
75
|
+
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
|