defmastership 1.0.16 → 1.0.18
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.gitlab-ci.yml +50 -7
- data/.rubocop.yml +14 -6
- data/Gemfile +51 -1
- data/Rakefile +16 -47
- data/bin/defmastership +12 -9
- data/config/mutant.yml +23 -3
- data/defmastership.gemspec +22 -27
- data/features/definition_checksum.feature +31 -1
- data/features/export.feature +43 -1
- data/features/rename_included_files.feature +28 -0
- data/lib/defmastership/batch_modifier.rb +17 -12
- data/lib/defmastership/change_ref_modifier.rb +89 -5
- data/lib/defmastership/comment_filter.rb +1 -1
- data/lib/defmastership/constants.rb +5 -4
- data/lib/defmastership/csv_formatter.rb +20 -16
- data/lib/defmastership/csv_formatter_body.rb +18 -15
- data/lib/defmastership/csv_formatter_header.rb +1 -1
- data/lib/defmastership/definition.rb +58 -19
- data/lib/defmastership/document.rb +109 -74
- data/lib/defmastership/matching_line.rb +17 -0
- data/lib/defmastership/modifier.rb +42 -0
- data/lib/defmastership/modifier_factory.rb +12 -0
- data/lib/defmastership/parsing_state.rb +15 -9
- data/lib/defmastership/rename_included_files_modifier.rb +172 -5
- data/lib/defmastership/set_join_hack.rb +11 -0
- data/lib/defmastership/update_def_checksum_modifier.rb +8 -13
- data/lib/defmastership/update_def_modifier.rb +49 -0
- data/lib/defmastership/update_def_version_modifier.rb +56 -15
- data/lib/defmastership/version.rb +1 -1
- data/lib/defmastership.rb +7 -17
- data/spec/spec_helper.rb +4 -2
- data/spec/unit/{defmastership → def_mastership}/batch_modifier_spec.rb +42 -39
- data/spec/unit/{defmastership/change_ref_line_modifier_spec.rb → def_mastership/change_ref_modifier_spec.rb} +44 -66
- data/spec/unit/{defmastership → def_mastership}/csv_formatter_body_spec.rb +61 -32
- data/spec/unit/{defmastership → def_mastership}/csv_formatter_header_spec.rb +2 -2
- data/spec/unit/{defmastership → def_mastership}/csv_formatter_spec.rb +81 -86
- data/spec/unit/{defmastership → def_mastership}/definition_parser_spec.rb +2 -2
- data/spec/unit/{defmastership → def_mastership}/definition_spec.rb +17 -7
- data/spec/unit/{defmastership → def_mastership}/document_spec.rb +108 -53
- data/spec/unit/def_mastership/matching_line_spec.rb +37 -0
- data/spec/unit/def_mastership/modifier_factory_spec.rb +37 -0
- data/spec/unit/def_mastership/modifier_spec.rb +83 -0
- data/spec/unit/{defmastership → def_mastership}/parsing_state_spec.rb +16 -16
- data/spec/unit/{defmastership/rename_included_files_line_modifier_spec.rb → def_mastership/rename_included_files_modifier_spec.rb} +72 -36
- data/spec/unit/{defmastership/comment_filter_spec.rb → def_mastership/string_spec.rb} +1 -1
- data/spec/unit/def_mastership/update_def_checksum_modifier_spec.rb +107 -0
- data/spec/unit/def_mastership/update_def_modifier_spec.rb +119 -0
- data/spec/unit/def_mastership/update_def_version_modifier_spec.rb +159 -0
- data/spec/unit/{defmastership_spec.rb → def_mastership_spec.rb} +1 -1
- data/tasks/console.rake +8 -0
- data/tasks/package.task +9 -0
- data/tasks/smelling_code.rake +38 -0
- data/tasks/test.rake +45 -0
- metadata +37 -145
- data/lib/defmastership/change_ref_line_modifier.rb +0 -82
- data/lib/defmastership/line_modifier_base.rb +0 -29
- data/lib/defmastership/modifier_base.rb +0 -29
- data/lib/defmastership/rename_included_files_line_modifier.rb +0 -126
- data/lib/defmastership/update_def_checksum_line_modifier.rb +0 -38
- data/lib/defmastership/update_def_version_line_modifier.rb +0 -58
- data/spec/unit/defmastership/change_ref_modifier_spec.rb +0 -76
- data/spec/unit/defmastership/rename_included_files_modifier_spec.rb +0 -67
- data/spec/unit/defmastership/update_def_checksum_line_modifier_spec.rb +0 -78
- data/spec/unit/defmastership/update_def_checksum_modifier_spec.rb +0 -75
- data/spec/unit/defmastership/update_def_version_line_modifier_spec.rb +0 -127
- data/spec/unit/defmastership/update_def_version_modifier_spec.rb +0 -80
@@ -1,40 +1,37 @@
|
|
1
1
|
# Copyright (c) 2021 Jerome Arbez-Gindre
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
require('defmastership')
|
4
|
+
require('defmastership/rename_included_files_modifier')
|
5
5
|
|
6
|
-
RSpec.describe(DefMastership::
|
7
|
-
subject(:includeschanger) { described_class.new }
|
6
|
+
RSpec.describe(DefMastership::RenameIncludedFilesModifier) do
|
7
|
+
subject(:includeschanger) { described_class.new({}) }
|
8
8
|
|
9
9
|
describe '.new' do
|
10
|
-
it {
|
10
|
+
it { expect(described_class.ancestors).to(include(DefMastership::Modifier)) }
|
11
|
+
it { is_expected.not_to(be_nil) }
|
11
12
|
it { is_expected.to(have_attributes(from_regexp: '')) }
|
12
13
|
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
14
|
end
|
16
15
|
|
17
|
-
describe '.
|
18
|
-
|
19
|
-
|
20
|
-
from_regexp: 'Whatever.+',
|
21
|
-
to_template: 'Whatever'
|
22
|
-
)
|
23
|
-
end
|
16
|
+
describe '.replacement_methods' do
|
17
|
+
it { expect(described_class.replacement_methods).to(eq(%i[replace])) }
|
18
|
+
end
|
24
19
|
|
25
|
-
|
26
|
-
it {
|
27
|
-
it {
|
20
|
+
describe '.respond_to_missing?' do
|
21
|
+
it { expect(includeschanger.respond_to?(:add_new_definition)).to(be(true)) }
|
22
|
+
it { expect(includeschanger.respond_to?(:not_implemented_random_method)).to(be(false)) }
|
28
23
|
end
|
29
24
|
|
30
25
|
describe '#replace' do
|
31
26
|
context 'when NOT valid include' do
|
32
|
-
|
33
|
-
|
27
|
+
subject(:includeschanger) do
|
28
|
+
described_class.new(
|
34
29
|
from_regexp: 'orig',
|
35
|
-
cancel_if_match: 'REF',
|
36
30
|
to_template: 'dest'
|
37
31
|
)
|
32
|
+
end
|
33
|
+
|
34
|
+
before do
|
38
35
|
allow(File).to(receive(:rename))
|
39
36
|
end
|
40
37
|
|
@@ -74,21 +71,35 @@ RSpec.describe(DefMastership::RenameIncludedFilesLineModifier) do
|
|
74
71
|
end
|
75
72
|
end
|
76
73
|
|
77
|
-
context 'when the
|
74
|
+
context 'when the line is commented' do
|
78
75
|
before do
|
79
|
-
|
80
|
-
|
81
|
-
end
|
76
|
+
includeschanger.replace('[define,requirement,REFERENCE]')
|
77
|
+
includeschanger.replace('--')
|
82
78
|
end
|
83
79
|
|
84
80
|
it do
|
85
|
-
expect(includeschanger.replace('include::
|
86
|
-
.to(eq('include::
|
81
|
+
expect(includeschanger.replace('// include::orig[]'))
|
82
|
+
.to(eq('// include::orig[]'))
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
context 'when the cancel regexp is met' do
|
87
|
+
subject(:includeschanger) do
|
88
|
+
described_class.new(
|
89
|
+
from_regexp: 'orig',
|
90
|
+
cancel_if_match: 'orig',
|
91
|
+
to_template: 'dest'
|
92
|
+
)
|
93
|
+
end
|
94
|
+
|
95
|
+
before do
|
96
|
+
includeschanger.replace('[define,requirement,REFERENCE]')
|
97
|
+
includeschanger.replace('--')
|
87
98
|
end
|
88
99
|
|
89
100
|
it do
|
90
|
-
includeschanger.replace(
|
91
|
-
|
101
|
+
expect(includeschanger.replace("include::orig[]\n"))
|
102
|
+
.to(eq("include::orig[]\n"))
|
92
103
|
end
|
93
104
|
end
|
94
105
|
end
|
@@ -99,12 +110,15 @@ RSpec.describe(DefMastership::RenameIncludedFilesLineModifier) do
|
|
99
110
|
end
|
100
111
|
|
101
112
|
context 'when really simple rule' do
|
102
|
-
|
103
|
-
|
113
|
+
subject(:includeschanger) do
|
114
|
+
described_class.new(
|
104
115
|
from_regexp: 'orig',
|
105
|
-
cancel_if_match: '
|
116
|
+
cancel_if_match: '_no_cancel_',
|
106
117
|
to_template: 'dest'
|
107
118
|
)
|
119
|
+
end
|
120
|
+
|
121
|
+
before do
|
108
122
|
includeschanger.replace('[define,requirement,REFERENCE]')
|
109
123
|
includeschanger.replace('--')
|
110
124
|
end
|
@@ -119,6 +133,16 @@ RSpec.describe(DefMastership::RenameIncludedFilesLineModifier) do
|
|
119
133
|
expect(File).to(have_received(:rename).with('orig', 'dest'))
|
120
134
|
end
|
121
135
|
|
136
|
+
it do
|
137
|
+
expect(includeschanger.replace("include::orig[leveloffset=offset,lines=ranges]\n"))
|
138
|
+
.to(eq("include::dest[leveloffset=offset,lines=ranges]\n"))
|
139
|
+
end
|
140
|
+
|
141
|
+
it do
|
142
|
+
includeschanger.replace("include::orig[leveloffset=offset,lines=ranges]\n")
|
143
|
+
expect(File).to(have_received(:rename).with('orig', 'dest'))
|
144
|
+
end
|
145
|
+
|
122
146
|
it do
|
123
147
|
includeschanger.replace("include::orig[]\n")
|
124
148
|
expect(includeschanger).to(have_attributes(changes: [%w[orig dest]]))
|
@@ -141,11 +165,14 @@ RSpec.describe(DefMastership::RenameIncludedFilesLineModifier) do
|
|
141
165
|
end
|
142
166
|
|
143
167
|
context 'when complex from_regexp' do
|
144
|
-
|
145
|
-
|
168
|
+
subject(:includeschanger) do
|
169
|
+
described_class.new(
|
146
170
|
from_regexp: '(?<origin>.*\.extension)',
|
147
171
|
to_template: '%<reference>s_%<origin>s'
|
148
172
|
)
|
173
|
+
end
|
174
|
+
|
175
|
+
before do
|
149
176
|
includeschanger.replace('[define,requirement,REF]')
|
150
177
|
end
|
151
178
|
|
@@ -167,13 +194,17 @@ RSpec.describe(DefMastership::RenameIncludedFilesLineModifier) do
|
|
167
194
|
end
|
168
195
|
|
169
196
|
context 'when path with variable' do
|
170
|
-
|
171
|
-
|
197
|
+
subject(:includeschanger) do
|
198
|
+
described_class.new(
|
172
199
|
from_regexp: 'orig',
|
173
200
|
to_template: 'dest'
|
174
201
|
)
|
202
|
+
end
|
203
|
+
|
204
|
+
before do
|
175
205
|
includeschanger.replace(':any: one')
|
176
206
|
includeschanger.replace(':path: two')
|
207
|
+
includeschanger.replace(':var: three')
|
177
208
|
includeschanger.replace('[define,requirement,REFERENCE]')
|
178
209
|
includeschanger.replace('--')
|
179
210
|
end
|
@@ -184,8 +215,8 @@ RSpec.describe(DefMastership::RenameIncludedFilesLineModifier) do
|
|
184
215
|
end
|
185
216
|
|
186
217
|
it do
|
187
|
-
includeschanger.replace('include::{any}/orig[]')
|
188
|
-
expect(File).to(have_received(:rename).with('
|
218
|
+
includeschanger.replace('include::{any}{var}/orig[]')
|
219
|
+
expect(File).to(have_received(:rename).with('onethree/orig', 'onethree/dest'))
|
189
220
|
end
|
190
221
|
|
191
222
|
it do
|
@@ -193,6 +224,11 @@ RSpec.describe(DefMastership::RenameIncludedFilesLineModifier) do
|
|
193
224
|
expect(File).to(have_received(:rename).with('one_two/orig', 'one_two/dest'))
|
194
225
|
end
|
195
226
|
|
227
|
+
it do
|
228
|
+
expect { includeschanger.replace('include::{bad_variable}/orig[]') }
|
229
|
+
.to(raise_error(KeyError, 'key not found: :bad_variable'))
|
230
|
+
end
|
231
|
+
|
196
232
|
it do
|
197
233
|
includeschanger.replace('include::{any}_{path}/orig[]')
|
198
234
|
expect(includeschanger).to(have_attributes(changes: [%w[one_two/orig one_two/dest]]))
|
@@ -0,0 +1,107 @@
|
|
1
|
+
# Copyright (c) 2020 Jerome Arbez-Gindre
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require('defmastership/update_def_checksum_modifier')
|
5
|
+
|
6
|
+
RSpec.describe(DefMastership::UpdateDefChecksumModifier) do
|
7
|
+
subject(:modifier) { described_class.new({}) }
|
8
|
+
|
9
|
+
describe '.new' do
|
10
|
+
it { expect(described_class.ancestors).to(include(DefMastership::Modifier)) }
|
11
|
+
it { is_expected.not_to(be_nil) }
|
12
|
+
it { is_expected.to(have_attributes(def_type: '')) }
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '.replacement_methods' do
|
16
|
+
it { expect(described_class.replacement_methods).to(eq(%i[replace_reference])) }
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#do_modifications' do
|
20
|
+
subject(:modifier) { described_class.new({ def_type: 'req' }) }
|
21
|
+
|
22
|
+
let(:document) { instance_double(DefMastership::Document, 'document') }
|
23
|
+
let(:definition) { instance_double(DefMastership::Definition, 'definition') }
|
24
|
+
let(:definitions) { { 'REFERENCE' => definition } }
|
25
|
+
let(:adoc_sources) do
|
26
|
+
{
|
27
|
+
'file1.adoc' => "[define,req,REFERENCE]\nfile1 line2",
|
28
|
+
'file2.adoc' => "file2 line1\nfile2 line2"
|
29
|
+
}
|
30
|
+
end
|
31
|
+
let(:new_adoc_sources) { nil }
|
32
|
+
|
33
|
+
before do
|
34
|
+
allow(DefMastership::Document).to(receive(:new).and_return(document))
|
35
|
+
allow(document).to(receive(:parse_file_with_preprocessor))
|
36
|
+
allow(document).to(receive(:ref_to_def).with('REFERENCE').and_return(definition))
|
37
|
+
allow(definition).to(receive(:sha256_short).and_return('~abcd1234'))
|
38
|
+
|
39
|
+
modifier.do_modifications(adoc_sources)
|
40
|
+
end
|
41
|
+
|
42
|
+
it { expect(DefMastership::Document).to(have_received(:new)) }
|
43
|
+
|
44
|
+
it do
|
45
|
+
expect(document).to(
|
46
|
+
have_received(:parse_file_with_preprocessor)
|
47
|
+
.once.with('file1.adoc')
|
48
|
+
.once.with('file2.adoc')
|
49
|
+
)
|
50
|
+
end
|
51
|
+
|
52
|
+
it do
|
53
|
+
expect(modifier.do_modifications(adoc_sources).fetch('file1.adoc')).to(include('abcd1234'))
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe '#replace' do
|
58
|
+
subject(:modifier) do
|
59
|
+
described_class.new(
|
60
|
+
def_type: 'requirement'
|
61
|
+
)
|
62
|
+
end
|
63
|
+
|
64
|
+
let(:definition) { instance_double(DefMastership::Definition, 'definition') }
|
65
|
+
let(:document) { instance_double(DefMastership::Document, 'document') }
|
66
|
+
let(:definitions) { { 'REFERENCE' => definition } }
|
67
|
+
|
68
|
+
before do
|
69
|
+
allow(File).to(receive(:rename))
|
70
|
+
end
|
71
|
+
|
72
|
+
context 'when definition has not the good type' do
|
73
|
+
it do
|
74
|
+
expect(modifier.replace_reference('[define,req,REFERENCE]'))
|
75
|
+
.to(eq('[define,req,REFERENCE]'))
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
context 'when definition has the good type' do
|
80
|
+
before do
|
81
|
+
allow(DefMastership::Document).to(receive(:new).and_return(document))
|
82
|
+
allow(document).to(receive(:ref_to_def).with('REFERENCE').and_return(definition))
|
83
|
+
allow(definition).to(receive(:sha256_short).and_return('~abcd1234'))
|
84
|
+
end
|
85
|
+
|
86
|
+
it do
|
87
|
+
expect(modifier.replace_reference('[define,requirement,REFERENCE]'))
|
88
|
+
.to(eq('[define,requirement,REFERENCE(~abcd1234)]'))
|
89
|
+
end
|
90
|
+
|
91
|
+
it do
|
92
|
+
expect(modifier.replace_reference('[define,requirement,REFERENCE(~bad)]'))
|
93
|
+
.to(eq('[define,requirement,REFERENCE(~abcd1234)]'))
|
94
|
+
end
|
95
|
+
|
96
|
+
it do
|
97
|
+
expect(modifier.replace_reference('[define,requirement,REFERENCE(toto~bad)]'))
|
98
|
+
.to(eq('[define,requirement,REFERENCE(toto~abcd1234)]'))
|
99
|
+
end
|
100
|
+
|
101
|
+
it do
|
102
|
+
expect(modifier.replace_reference('[define,requirement,REFERENCE(toto)]'))
|
103
|
+
.to(eq('[define,requirement,REFERENCE(toto~abcd1234)]'))
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
@@ -0,0 +1,119 @@
|
|
1
|
+
# Copyright (c) 2020 Jerome Arbez-Gindre
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require('defmastership/update_def_modifier')
|
5
|
+
|
6
|
+
module DefMastership
|
7
|
+
class ConcreteRefModifier < UpdateDefModifier
|
8
|
+
private
|
9
|
+
|
10
|
+
def reference_replacement(reference, match)
|
11
|
+
"#{reference}_something_#{match[:explicit_version]}"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
RSpec.describe(DefMastership::UpdateDefModifier) do
|
17
|
+
subject(:modifier) { DefMastership::ConcreteRefModifier.new({}) }
|
18
|
+
|
19
|
+
describe '.new' do
|
20
|
+
it { expect(described_class.ancestors).to(include(DefMastership::Modifier)) }
|
21
|
+
it { is_expected.not_to(be_nil) }
|
22
|
+
it { is_expected.to(have_attributes(def_type: '')) }
|
23
|
+
end
|
24
|
+
|
25
|
+
describe '.replacement_methods' do
|
26
|
+
it { expect(described_class.replacement_methods).to(eq(%i[replace_reference])) }
|
27
|
+
end
|
28
|
+
|
29
|
+
describe '#do_modifications' do
|
30
|
+
subject(:modifier) { DefMastership::ConcreteRefModifier.new({ def_type: 'req' }) }
|
31
|
+
|
32
|
+
let(:document) { instance_double(DefMastership::Document, 'document') }
|
33
|
+
let(:definition) { instance_double(DefMastership::Definition, 'definition') }
|
34
|
+
let(:definitions) { { 'REFERENCE' => definition } }
|
35
|
+
let(:adoc_sources) do
|
36
|
+
{
|
37
|
+
'file1.adoc' => "[define,req,REFERENCE]\nfile1 line2",
|
38
|
+
'file2.adoc' => "file2 line1\nfile2 line2"
|
39
|
+
}
|
40
|
+
end
|
41
|
+
let(:new_adoc_sources) { nil }
|
42
|
+
|
43
|
+
before do
|
44
|
+
allow(DefMastership::Document).to(receive(:new).and_return(document))
|
45
|
+
allow(document).to(receive(:parse_file_with_preprocessor).with('file1.adoc'))
|
46
|
+
allow(document).to(receive(:parse_file_with_preprocessor).with('file2.adoc'))
|
47
|
+
|
48
|
+
modifier.do_modifications(adoc_sources)
|
49
|
+
end
|
50
|
+
|
51
|
+
it { expect(DefMastership::Document).to(have_received(:new)) }
|
52
|
+
|
53
|
+
it do
|
54
|
+
expect(document).to(
|
55
|
+
have_received(:parse_file_with_preprocessor)
|
56
|
+
.once.with('file1.adoc')
|
57
|
+
.once.with('file2.adoc')
|
58
|
+
)
|
59
|
+
end
|
60
|
+
|
61
|
+
it do
|
62
|
+
expect(modifier.do_modifications(adoc_sources).fetch('file1.adoc'))
|
63
|
+
.to(include('REFERENCE_something_'))
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe '#replace_reference' do
|
68
|
+
subject(:modifier) do
|
69
|
+
DefMastership::ConcreteRefModifier.new(
|
70
|
+
def_type: 'requirement'
|
71
|
+
)
|
72
|
+
end
|
73
|
+
|
74
|
+
let(:definition) { instance_double(DefMastership::Definition, 'definition') }
|
75
|
+
let(:document) { instance_double(DefMastership::Document, 'document') }
|
76
|
+
let(:definitions) { { 'REFERENCE' => definition } }
|
77
|
+
|
78
|
+
before do
|
79
|
+
allow(File).to(receive(:rename))
|
80
|
+
end
|
81
|
+
|
82
|
+
context 'when line do not match' do
|
83
|
+
it do
|
84
|
+
expect(modifier.replace_reference('[define---,req,REFERENCE(abcd)]'))
|
85
|
+
.to(eq('[define---,req,REFERENCE(abcd)]'))
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
context 'when definition has not the good type' do
|
90
|
+
it do
|
91
|
+
expect(modifier.replace_reference('[define,req,REFERENCE(abcd)]'))
|
92
|
+
.to(eq('[define,req,REFERENCE(abcd)]'))
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
context 'when definition has the good type' do
|
97
|
+
before do
|
98
|
+
allow(DefMastership::Document).to(receive(:new).and_return(document))
|
99
|
+
allow(document).to(receive(:ref_to_def).with('REFERENCE').and_return(definition))
|
100
|
+
allow(definition).to(receive(:sha256_short).and_return('~abcd1234'))
|
101
|
+
end
|
102
|
+
|
103
|
+
it do
|
104
|
+
expect(modifier.replace_reference('[define,requirement,REFERENCE(abcd)]'))
|
105
|
+
.to(eq('[define,requirement,REFERENCE_something_abcd]'))
|
106
|
+
end
|
107
|
+
|
108
|
+
it do
|
109
|
+
expect(modifier.replace_reference('[define,requirement,REFERENCE(abcd~bad)]'))
|
110
|
+
.to(eq('[define,requirement,REFERENCE_something_abcd]'))
|
111
|
+
end
|
112
|
+
|
113
|
+
it do
|
114
|
+
expect(modifier.replace_reference('// [define,requirement,REFERENCE(abcd~bad)]'))
|
115
|
+
.to(eq('// [define,requirement,REFERENCE(abcd~bad)]'))
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
@@ -0,0 +1,159 @@
|
|
1
|
+
# Copyright (c) 2020 Jerome Arbez-Gindre
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require('defmastership/update_def_version_modifier')
|
5
|
+
|
6
|
+
RSpec.describe(DefMastership::UpdateDefVersionModifier) do
|
7
|
+
subject(:modifier) { described_class.new({}) }
|
8
|
+
|
9
|
+
describe '.new' do
|
10
|
+
it { expect(described_class.ancestors).to(include(DefMastership::Modifier)) }
|
11
|
+
it { is_expected.not_to(be_nil) }
|
12
|
+
it { is_expected.to(have_attributes(def_type: '')) }
|
13
|
+
it { is_expected.to(have_attributes(ref_document: '')) }
|
14
|
+
it { is_expected.to(have_attributes(first_version: '')) }
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '.replacement_methods' do
|
18
|
+
it { expect(described_class.replacement_methods).to(eq(%i[replace_reference])) }
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '#do_modifications' do
|
22
|
+
subject(:modifier) do
|
23
|
+
described_class.new(
|
24
|
+
ref_document: 'ref_doc.adoc',
|
25
|
+
def_type: 'req',
|
26
|
+
first_version: 'a'
|
27
|
+
)
|
28
|
+
end
|
29
|
+
|
30
|
+
let(:document) { instance_double(DefMastership::Document, 'document') }
|
31
|
+
let(:ref_document) { instance_double(DefMastership::Document, 'ref_document') }
|
32
|
+
let(:definition) { instance_double(DefMastership::Definition, 'definition') }
|
33
|
+
let(:ref_definition) { instance_double(DefMastership::Definition, 'ref_definitions') }
|
34
|
+
let(:adoc_sources) do
|
35
|
+
{
|
36
|
+
'file1.adoc' => "[define,req,REFERENCE]\nfile1 line2",
|
37
|
+
'file2.adoc' => "file2 line1\nfile2 line2"
|
38
|
+
}
|
39
|
+
end
|
40
|
+
|
41
|
+
before do
|
42
|
+
allow(DefMastership::Document).to(receive(:new).twice.and_return(ref_document, document))
|
43
|
+
allow(document).to(receive(:parse_file_with_preprocessor).with('file1.adoc'))
|
44
|
+
allow(document).to(receive(:parse_file_with_preprocessor).with('file2.adoc'))
|
45
|
+
allow(ref_document).to(receive(:parse_file_with_preprocessor).with('ref_doc.adoc'))
|
46
|
+
allow(document).to(receive(:ref_to_def).with('REFERENCE').and_return(definition))
|
47
|
+
allow(ref_document).to(receive(:ref_to_def).with('REFERENCE').and_return(ref_definition))
|
48
|
+
allow(ref_definition).to(receive(:explicit_version).with(no_args).and_return(nil))
|
49
|
+
allow(definition).to(receive(:sha256_short).with(no_args).and_return('something'))
|
50
|
+
allow(ref_definition).to(receive(:sha256_short).with(no_args).and_return('something_else'))
|
51
|
+
|
52
|
+
modifier.do_modifications(adoc_sources)
|
53
|
+
end
|
54
|
+
|
55
|
+
it { expect(DefMastership::Document).to(have_received(:new).twice) }
|
56
|
+
it { expect(document).to(have_received(:parse_file_with_preprocessor).twice) }
|
57
|
+
it { expect(ref_document).to(have_received(:parse_file_with_preprocessor).with('ref_doc.adoc')) }
|
58
|
+
|
59
|
+
it do
|
60
|
+
expect(modifier.do_modifications(adoc_sources).fetch('file1.adoc')).to(include('REFERENCE(a)'))
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe '#replace_reference' do
|
65
|
+
subject(:modifier) do
|
66
|
+
described_class.new(
|
67
|
+
def_type: 'requirement',
|
68
|
+
first_version: 'a'
|
69
|
+
)
|
70
|
+
end
|
71
|
+
|
72
|
+
let(:document) { instance_double(DefMastership::Document, 'document') }
|
73
|
+
let(:ref_document) { instance_double(DefMastership::Document, 'ref_document') }
|
74
|
+
let(:definition) { instance_double(DefMastership::Definition, 'definition') }
|
75
|
+
let(:ref_definition) { instance_double(DefMastership::Definition, 'ref_definitions') }
|
76
|
+
|
77
|
+
before do
|
78
|
+
allow(File).to(receive(:rename))
|
79
|
+
allow(DefMastership::Document).to(receive(:new).with(no_args).and_return(ref_document, document))
|
80
|
+
end
|
81
|
+
|
82
|
+
context 'when definition has not the good type' do
|
83
|
+
it do
|
84
|
+
expect(modifier.replace_reference('[define,req,REFERENCE]'))
|
85
|
+
.to(eq('[define,req,REFERENCE]'))
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
context 'when definition has the good type' do
|
90
|
+
before do
|
91
|
+
allow(document).to(receive(:ref_to_def).with('REFERENCE').and_return(definition))
|
92
|
+
allow(definition).to(receive(:sha256_short).and_return('~abcd1234'))
|
93
|
+
end
|
94
|
+
|
95
|
+
context 'when definition has NOT changed' do
|
96
|
+
before do
|
97
|
+
allow(ref_document).to(receive(:ref_to_def).with('REFERENCE').and_return(ref_definition))
|
98
|
+
allow(ref_definition).to(receive(:sha256_short).and_return('~abcd1234'))
|
99
|
+
end
|
100
|
+
|
101
|
+
it do
|
102
|
+
allow(ref_definition).to(receive(:explicit_version).and_return(nil))
|
103
|
+
expect(modifier.replace_reference('[define,requirement,REFERENCE]'))
|
104
|
+
.to(eq('[define,requirement,REFERENCE]'))
|
105
|
+
end
|
106
|
+
|
107
|
+
it do
|
108
|
+
allow(ref_definition).to(receive(:explicit_version).and_return('c'))
|
109
|
+
expect(modifier.replace_reference('[define,requirement,REFERENCE]'))
|
110
|
+
.to(eq('[define,requirement,REFERENCE(c)]'))
|
111
|
+
end
|
112
|
+
|
113
|
+
it do
|
114
|
+
allow(ref_definition).to(receive(:explicit_version).and_return('c'))
|
115
|
+
expect(modifier.replace_reference('[define,requirement,REFERENCE(tyty~1234)]'))
|
116
|
+
.to(eq('[define,requirement,REFERENCE(c~1234)]'))
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
context 'when definition has changed' do
|
121
|
+
before do
|
122
|
+
allow(ref_document).to(receive(:ref_to_def).with('REFERENCE').and_return(ref_definition))
|
123
|
+
allow(ref_definition).to(receive(:sha256_short).and_return('~4321aaaa'))
|
124
|
+
end
|
125
|
+
|
126
|
+
[
|
127
|
+
[nil, '', '(a)'],
|
128
|
+
['c', '', '(d)'],
|
129
|
+
['c', '(tyty~1234)', '(d~1234)'],
|
130
|
+
['2', '', '(3)'],
|
131
|
+
['1222', '', '(1223)'],
|
132
|
+
['abb', '', '(abc)']
|
133
|
+
].each do |ref, from, to|
|
134
|
+
it do
|
135
|
+
allow(ref_definition).to(receive(:explicit_version).and_return(ref))
|
136
|
+
expect(modifier.replace_reference("[define,requirement,REFERENCE#{from}]"))
|
137
|
+
.to(eq("[define,requirement,REFERENCE#{to}]"))
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
context 'when definition is new' do
|
143
|
+
before do
|
144
|
+
allow(ref_document).to(receive(:ref_to_def).with('REFERENCE').and_return(nil))
|
145
|
+
end
|
146
|
+
|
147
|
+
it do
|
148
|
+
expect(modifier.replace_reference('[define,requirement,REFERENCE(whatever)]'))
|
149
|
+
.to(eq('[define,requirement,REFERENCE]'))
|
150
|
+
end
|
151
|
+
|
152
|
+
it do
|
153
|
+
expect(modifier.replace_reference('[define,requirement,REFERENCE(~1234)]'))
|
154
|
+
.to(eq('[define,requirement,REFERENCE(~1234)]'))
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
data/tasks/console.rake
ADDED
data/tasks/package.task
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# Copyright (c) 2023 Jerome Arbez-Gindre
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
namespace 'quality' do
|
5
|
+
begin
|
6
|
+
require('rubocop/rake_task')
|
7
|
+
|
8
|
+
RuboCop::RakeTask.new do |task|
|
9
|
+
task.options << '--display-cop-names'
|
10
|
+
end
|
11
|
+
rescue LoadError
|
12
|
+
task(:rubocop) do
|
13
|
+
puts('Install rubocop to run its rake tasks')
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
begin
|
18
|
+
require('reek/rake/task')
|
19
|
+
|
20
|
+
Reek::Rake::Task.new do |t|
|
21
|
+
t.fail_on_error = true
|
22
|
+
t.verbose = false
|
23
|
+
end
|
24
|
+
rescue LoadError
|
25
|
+
task(:reek) do
|
26
|
+
puts('Install reek to run its rake tasks')
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
desc 'Runs all quality code check'
|
31
|
+
task(all: ['quality:rubocop', 'quality:reek'])
|
32
|
+
end
|
33
|
+
|
34
|
+
desc 'Synonym for quality:rubocop'
|
35
|
+
task(rubocop: 'quality:rubocop')
|
36
|
+
|
37
|
+
desc 'Synonym for quality:reek'
|
38
|
+
task(reek: 'quality:reek')
|