defmastership 1.3.0 → 1.3.1
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.
- checksums.yaml +4 -4
- data/.gitlab-ci.yml +7 -44
- data/Gemfile +29 -57
- data/bin/defmastership +1 -109
- data/config/mutant.yml +27 -22
- data/config/rubocop.yml +5 -2
- data/defmastership.gemspec +9 -8
- data/features/changeref.feature +112 -1
- data/features/definition_version.feature +41 -1
- data/features/step_definitions/git_steps.rb +1 -1
- data/lib/defmastership/app.rb +115 -0
- data/lib/defmastership/batch_modifier.rb +2 -0
- data/lib/defmastership/config_preserver.rb +45 -0
- data/lib/defmastership/definition.rb +4 -2
- data/lib/defmastership/document.rb +6 -1
- data/lib/defmastership/export/body_formatter.rb +0 -2
- data/lib/defmastership/export/header_formatter.rb +0 -2
- data/lib/defmastership/hash_merge_no_new.rb +24 -0
- data/lib/defmastership/modifier/change_ref.rb +72 -7
- data/lib/defmastership/modifier/factory.rb +5 -0
- data/lib/defmastership/modifier/rename_included_files.rb +1 -3
- data/lib/defmastership/modifier/update_def.rb +1 -3
- data/lib/defmastership/modifier/update_def_checksum.rb +1 -1
- data/lib/defmastership/modifier/update_def_version.rb +4 -5
- data/lib/defmastership/version.rb +1 -1
- data/spec/spec_helper.rb +1 -10
- data/spec/unit/defmastership/app_spec.rb +235 -0
- data/spec/unit/defmastership/config_preserver_spec.rb +127 -0
- data/spec/unit/defmastership/export/csv/formatter_spec.rb +0 -2
- data/spec/unit/defmastership/hash_spec.rb +27 -0
- data/spec/unit/defmastership/modifier/change_ref_spec.rb +116 -1
- data/spec/unit/defmastership/modifier/modifier_common_spec.rb +0 -2
- data/spec/unit/defmastership/modifier/update_def_spec.rb +0 -2
- data/spec/unit/defmastership/modifier/update_def_version_spec.rb +4 -4
- metadata +38 -24
- data/lib/defmastership/set_join_hack.rb +0 -13
- data/lib/defmastership.rb +0 -19
@@ -0,0 +1,235 @@
|
|
1
|
+
# Copyright (c) 2025 Jerome Arbez-Gindre
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require('defmastership/app')
|
5
|
+
|
6
|
+
RSpec.describe(Defmastership::App) do
|
7
|
+
it { expect(described_class.singleton_class).to(include(GLI::App)) }
|
8
|
+
|
9
|
+
describe('.run') do
|
10
|
+
context('when "help" command') do
|
11
|
+
it { expect(described_class.run(['help'])).to(be(0)) }
|
12
|
+
|
13
|
+
it do
|
14
|
+
expect { described_class.run(['help']) }
|
15
|
+
.to(output(/Tool to handle Asciidoctor definition extension/).to_stdout_from_any_process)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context('when "--version" option') do
|
20
|
+
it {
|
21
|
+
expect { described_class.run(['--version']) }
|
22
|
+
.to(output(/version/).to_stdout)
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
context('when "export --help" subcommand') do
|
27
|
+
it { expect(described_class.run(['export', '--help'])).to(be(0)) }
|
28
|
+
|
29
|
+
[
|
30
|
+
/Export\s+the\s+definition\s+database\s+in\s+CSV$/,
|
31
|
+
/\bexport\b.*\basciidoctor_file\b$/,
|
32
|
+
/--separator, --sep, -s arg.*CSV\s+separator\s+\(default: ,\)$/,
|
33
|
+
/--\[no-\]no-fail.*Exit\s+success\s+even\s+in\s+
|
34
|
+
case\s+of\s+wrong\s+explicit\s+checksum$/mx
|
35
|
+
].each do |content|
|
36
|
+
it do
|
37
|
+
expect { described_class.run(['export', '--help']) }
|
38
|
+
.to(output(content).to_stdout_from_any_process)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context('when "export" with more than one argument') do
|
44
|
+
it { expect(described_class.run(%w[export arg1 arg2])).to(be(64)) }
|
45
|
+
|
46
|
+
it do
|
47
|
+
expect { described_class.run(%w[export arg1 arg2]) }
|
48
|
+
.to(output(/error: export expected only 1 arguments, but received 2/).to_stderr_from_any_process)
|
49
|
+
end
|
50
|
+
|
51
|
+
it { expect(described_class.run(['export'])).to(be(64)) }
|
52
|
+
|
53
|
+
it do
|
54
|
+
expect { described_class.run(['export']) }
|
55
|
+
.to(output(/error: export expected at least 1 arguments, but was given only 0/).to_stderr_from_any_process)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context('when "export toto.adoc" subcommand') do
|
60
|
+
let(:document) { instance_double(Defmastership::Document, 'document') }
|
61
|
+
let(:formatter) { instance_double(Defmastership::Export::CSV::Formatter, 'formatter') }
|
62
|
+
let(:defs) do
|
63
|
+
[
|
64
|
+
instance_double(Defmastership::Definition, 'def1'),
|
65
|
+
instance_double(Defmastership::Definition, 'def2')
|
66
|
+
]
|
67
|
+
end
|
68
|
+
|
69
|
+
before do
|
70
|
+
allow(Defmastership::Document).to(receive(:new).and_return(document))
|
71
|
+
allow(Defmastership::Export::CSV::Formatter).to(receive(:new).and_return(formatter))
|
72
|
+
allow(formatter).to(receive(:export_to).with(an_instance_of(String)))
|
73
|
+
allow(document).to(receive(:parse_file_with_preprocessor).with(an_instance_of(String)))
|
74
|
+
allow(document).to(receive(:definitions).and_return(defs))
|
75
|
+
allow(defs.first).to(receive(:wrong_explicit_checksum).and_return(nil))
|
76
|
+
allow(defs.last).to(
|
77
|
+
receive_messages(
|
78
|
+
wrong_explicit_checksum: true,
|
79
|
+
reference: 'the_ref',
|
80
|
+
sha256_short: '1234'
|
81
|
+
)
|
82
|
+
)
|
83
|
+
|
84
|
+
described_class.run(['export', 'toto.adoc'])
|
85
|
+
end
|
86
|
+
|
87
|
+
context 'when there is wrong_explicit_checksum' do
|
88
|
+
before do
|
89
|
+
allow(document).to(receive(:wrong_explicit_checksum?).and_return(true))
|
90
|
+
end
|
91
|
+
|
92
|
+
it { expect(Defmastership::Document).to(have_received(:new).with(no_args)) }
|
93
|
+
it { expect(document).to(have_received(:parse_file_with_preprocessor).once.with('toto.adoc')) }
|
94
|
+
it { expect(Defmastership::Export::CSV::Formatter).to(have_received(:new).with(document, ',')) }
|
95
|
+
it { expect(formatter).to(have_received(:export_to).once.with('toto.csv')) }
|
96
|
+
it { expect(document).to(have_received(:wrong_explicit_checksum?)) }
|
97
|
+
|
98
|
+
# the commented test does not work whereas the following one needs the call to :definitions
|
99
|
+
# it { expect(document).to(have_received(:definitions).with(no_args)) }
|
100
|
+
it do
|
101
|
+
expect { described_class.run(['export', 'toto.adoc']) }
|
102
|
+
.to(output(/warning: the_ref has a wrong explicit checksum \(should be 1234\)/).to_stderr_from_any_process)
|
103
|
+
end
|
104
|
+
|
105
|
+
it { expect(described_class.run(['export', 'toto.adoc'])).to(be(1)) }
|
106
|
+
it { expect(described_class.run(['export', '--no-fail', 'toto.adoc'])).to(be(0)) }
|
107
|
+
end
|
108
|
+
|
109
|
+
context 'when there is NO wrong_explicit_checksum' do
|
110
|
+
before do
|
111
|
+
allow(document).to(receive(:wrong_explicit_checksum?).and_return(nil))
|
112
|
+
end
|
113
|
+
|
114
|
+
it { expect(described_class.run(['export', 'toto.adoc'])).to(be(0)) }
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
context('when "modify --help" subcommand') do
|
119
|
+
it { expect(described_class.run(['modify', '--help'])).to(be(0)) }
|
120
|
+
|
121
|
+
[
|
122
|
+
/Apply\s+one\s+or\s+more\s+modifications$/,
|
123
|
+
/\bmodify\b.*\basciidoctor_file\b\s+\[asciidoctor_file\]\.\.\.$/,
|
124
|
+
/--modifications,\s+--mod,\s+-m\s+arg\s+-\s+comma\s+separated\s+
|
125
|
+
list\s+of\s+modifications\s+to\s+apply\s+\(default:\s+all\)$/mx,
|
126
|
+
/--modifications-file,\s+--mf=arg\s+-\s+modifications\s+description\s+
|
127
|
+
file\s+\(default:\s+modifications.yml\)$/mx,
|
128
|
+
/--changes-summary,\s+-s\s+arg\s+-\s+generates\s+a\s+change\s+summary\s+
|
129
|
+
in\s+a\s+CSV\s+file\s+\(default:\s+none\)$/mx
|
130
|
+
].each do |content|
|
131
|
+
it do
|
132
|
+
expect { described_class.run(['modify', '--help']) }
|
133
|
+
.to(output(content).to_stdout_from_any_process)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
context('when "modify" with more than one argument') do
|
139
|
+
it do
|
140
|
+
expect { described_class.run(['modify']) }
|
141
|
+
.to(output(/error: modify expected at least 1 arguments, but was given only 0/).to_stderr_from_any_process)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
context('when "modify -m=,mod1 toto.adoc tutu.adoc" subcommand') do
|
146
|
+
it {
|
147
|
+
expect(described_class.run(['modify', '--modifications="modif11!modif2"', 'toto.adoc', 'tutu.adoc'])).to(be(64))
|
148
|
+
}
|
149
|
+
|
150
|
+
it { expect(described_class.run(['modify', '-m=,modif1', 'toto.adoc', 'tutu.adoc'])).to(be(64)) }
|
151
|
+
end
|
152
|
+
|
153
|
+
context('when "modify --modifications=mod1,mod2 toto.adoc" subcommand') do
|
154
|
+
let(:config_preserver) { instance_double(Defmastership::ConfigPreserver, 'config_preserver') }
|
155
|
+
let(:changer) { instance_double(Defmastership::BatchModifier, 'changer') }
|
156
|
+
let(:csv) { instance_double(CSV, 'csv') }
|
157
|
+
|
158
|
+
before do
|
159
|
+
allow(Defmastership::ConfigPreserver).to(receive(:new).and_return(config_preserver))
|
160
|
+
allow(config_preserver).to(receive(:config).and_return(:one_config))
|
161
|
+
allow(Defmastership::BatchModifier).to(receive(:new).and_return(changer))
|
162
|
+
allow(File).to(receive(:read).with('toto.adoc').and_return('content toto_adoc'))
|
163
|
+
allow(File).to(receive(:read).with('tutu.adoc').and_return('content tutu_adoc'))
|
164
|
+
allow(changer).to(receive(:apply))
|
165
|
+
allow(File).to(receive(:write).with('toto.adoc', 'new content toto_adoc'))
|
166
|
+
allow(File).to(receive(:write).with('tutu.adoc', 'new content tutu_adoc'))
|
167
|
+
allow(config_preserver).to(receive(:save))
|
168
|
+
allow(changer).to(
|
169
|
+
receive_messages(
|
170
|
+
adoc_sources: { 'toto.adoc' => 'new content toto_adoc', 'tutu.adoc' => 'new content tutu_adoc' },
|
171
|
+
config: :the_new_config,
|
172
|
+
changes: []
|
173
|
+
)
|
174
|
+
)
|
175
|
+
described_class.run(['modify', '--modifications=mod1,mod2', 'toto.adoc', 'tutu.adoc'])
|
176
|
+
end
|
177
|
+
|
178
|
+
it { expect(described_class.run(['modify', '--modifications=mod1,mod2', 'toto.adoc', 'tutu.adoc'])).to(be(0)) }
|
179
|
+
|
180
|
+
it { expect(Defmastership::ConfigPreserver).to(have_received(:new).with('modifications.yml')) }
|
181
|
+
it { expect(config_preserver).to(have_received(:config)) }
|
182
|
+
|
183
|
+
it do
|
184
|
+
expect(Defmastership::BatchModifier)
|
185
|
+
.to(have_received(:new)
|
186
|
+
.with(:one_config,
|
187
|
+
{ 'toto.adoc' => 'content toto_adoc', 'tutu.adoc' => 'content tutu_adoc' }))
|
188
|
+
end
|
189
|
+
|
190
|
+
it { expect(changer).to(have_received(:apply).with(%i[mod1 mod2])) }
|
191
|
+
it { expect(changer).to(have_received(:adoc_sources)) }
|
192
|
+
it { expect(File).to(have_received(:write).with('toto.adoc', 'new content toto_adoc')) }
|
193
|
+
it { expect(File).to(have_received(:write).with('tutu.adoc', 'new content tutu_adoc')) }
|
194
|
+
it { expect(changer).to(have_received(:config)) }
|
195
|
+
it { expect(config_preserver).to(have_received(:save).with(:the_new_config)) }
|
196
|
+
end
|
197
|
+
|
198
|
+
context('when "modify" subcommand with changes summary') do
|
199
|
+
let(:config_preserver) { instance_double(Defmastership::ConfigPreserver, 'config_preserver') }
|
200
|
+
let(:changer) { instance_double(Defmastership::BatchModifier, 'changer') }
|
201
|
+
let(:csv) { instance_double(CSV, 'csv') }
|
202
|
+
|
203
|
+
before do
|
204
|
+
allow(Defmastership::ConfigPreserver).to(receive(:new).and_return(config_preserver))
|
205
|
+
allow(config_preserver).to(receive(:config).and_return(:one_config))
|
206
|
+
allow(Defmastership::BatchModifier).to(receive(:new).and_return(changer))
|
207
|
+
allow(File).to(receive(:read).with('toto.adoc').and_return('content toto_adoc'))
|
208
|
+
allow(changer).to(receive(:apply))
|
209
|
+
allow(File).to(receive(:write).with('toto.adoc', 'new content toto_adoc'))
|
210
|
+
allow(config_preserver).to(receive(:save))
|
211
|
+
allow(changer).to(
|
212
|
+
receive_messages(
|
213
|
+
adoc_sources: { 'toto.adoc' => 'new content toto_adoc' },
|
214
|
+
config: :the_new_config,
|
215
|
+
changes: []
|
216
|
+
)
|
217
|
+
)
|
218
|
+
allow(CSV).to(receive(:open).and_yield(csv))
|
219
|
+
allow(csv).to(receive(:<<))
|
220
|
+
allow(changer).to(receive(:changes).and_return(%w[row1 row2]))
|
221
|
+
described_class.run(['modify', '--modifications=mod1', '--changes-summary=changes.csv', 'toto.adoc'])
|
222
|
+
end
|
223
|
+
|
224
|
+
it do
|
225
|
+
params = ['modify', '--modifications=mod1', '--changes-summary=changes.csv', 'toto.adoc']
|
226
|
+
expect(described_class.run(params)).to(be(0))
|
227
|
+
end
|
228
|
+
|
229
|
+
it { expect(CSV).to(have_received(:open).with('changes.csv', 'wb')) }
|
230
|
+
it { expect(csv).to(have_received(:<<).with(%w[Modifier Was Becomes])) }
|
231
|
+
it { expect(csv).to(have_received(:<<).with('row1')) }
|
232
|
+
it { expect(csv).to(have_received(:<<).with('row2')) }
|
233
|
+
end
|
234
|
+
end
|
235
|
+
end
|
@@ -0,0 +1,127 @@
|
|
1
|
+
# Copyright (c) 2025 Jerome Arbez-Gindre
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require('defmastership/config_preserver')
|
5
|
+
|
6
|
+
RSpec.describe(Defmastership::ConfigPreserver) do
|
7
|
+
subject(:preserver) do
|
8
|
+
described_class.new('configuration.yml')
|
9
|
+
end
|
10
|
+
|
11
|
+
describe '.new' do
|
12
|
+
it { is_expected.not_to(be_nil) }
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '.config' do
|
16
|
+
let(:original_config) do
|
17
|
+
{
|
18
|
+
simple_item: 12,
|
19
|
+
nested_item: { subitem: 123 }
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
before do
|
24
|
+
allow(YAML).to(receive(:load_file).with('configuration.yml').and_return(original_config))
|
25
|
+
end
|
26
|
+
|
27
|
+
it do
|
28
|
+
preserver.config
|
29
|
+
expect(YAML).to(have_received(:load_file).with('configuration.yml'))
|
30
|
+
end
|
31
|
+
|
32
|
+
it { expect(preserver.config).to(eq(original_config)) }
|
33
|
+
it { expect(preserver.config).not_to(be(original_config)) }
|
34
|
+
it { expect(preserver.config[:nested_item]).not_to(be(original_config[:nested_item])) }
|
35
|
+
end
|
36
|
+
|
37
|
+
describe '.save' do
|
38
|
+
context 'when one Modifier has modified config items' do
|
39
|
+
let(:original_config) do
|
40
|
+
{
|
41
|
+
simple_item: 12,
|
42
|
+
nested_item: { subitem: 123 }
|
43
|
+
}
|
44
|
+
end
|
45
|
+
let(:original_file_content) do
|
46
|
+
<<~YAML_CONFIG
|
47
|
+
---
|
48
|
+
:simple_item: 12
|
49
|
+
:nested_item:
|
50
|
+
:subitem: 123
|
51
|
+
YAML_CONFIG
|
52
|
+
end
|
53
|
+
let(:file) { instance_double(File, 'file') }
|
54
|
+
let(:new_file_content) do
|
55
|
+
<<~YAML_CONFIG
|
56
|
+
---
|
57
|
+
:simple_item: pouet
|
58
|
+
:nested_item:
|
59
|
+
:subitem: 132
|
60
|
+
YAML_CONFIG
|
61
|
+
end
|
62
|
+
|
63
|
+
before do
|
64
|
+
allow(YAML).to(receive(:load_file).with('configuration.yml').and_return(original_config))
|
65
|
+
allow(File).to(receive(:open).with('configuration.yml', 'r').and_return(file))
|
66
|
+
allow(file).to(receive(:each_line).with(chomp: true).and_return(original_file_content.each_line(chomp: true)))
|
67
|
+
allow(File).to(receive(:write))
|
68
|
+
end
|
69
|
+
|
70
|
+
it do
|
71
|
+
preserver.save({ simple_item: 'pouet', nested_item: { subitem: 132 } })
|
72
|
+
expect(File).to(have_received(:write).with('configuration.yml', new_file_content))
|
73
|
+
end
|
74
|
+
|
75
|
+
it do
|
76
|
+
preserver.save({ simple_item: 'pouet', new_item: 'titi', nested_item: { subitem: 132, new_subitem: 345 } })
|
77
|
+
expect(File).to(have_received(:write).with('configuration.yml', new_file_content))
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
context 'when there are some empty lines and comments' do
|
82
|
+
let(:original_config) do
|
83
|
+
{
|
84
|
+
simple_item: 12,
|
85
|
+
nested_item: { subitem: 123, subitem2: 'abcd' }
|
86
|
+
}
|
87
|
+
end
|
88
|
+
let(:original_file_content) do
|
89
|
+
<<~YAML_CONFIG
|
90
|
+
---
|
91
|
+
:simple_item: 12 #
|
92
|
+
|
93
|
+
:nested_item:
|
94
|
+
# comment on its own line
|
95
|
+
#
|
96
|
+
:subitem: 123 # comment on a useful line
|
97
|
+
:subitem2: abcd# comment on a useful line
|
98
|
+
YAML_CONFIG
|
99
|
+
end
|
100
|
+
let(:file) { instance_double(File, 'file') }
|
101
|
+
let(:new_file_content) do
|
102
|
+
<<~YAML_CONFIG
|
103
|
+
---
|
104
|
+
:simple_item: pouet #
|
105
|
+
|
106
|
+
:nested_item:
|
107
|
+
# comment on its own line
|
108
|
+
#
|
109
|
+
:subitem: 132 # comment on a useful line
|
110
|
+
:subitem2: abcd# comment on a useful line
|
111
|
+
YAML_CONFIG
|
112
|
+
end
|
113
|
+
|
114
|
+
before do
|
115
|
+
allow(YAML).to(receive(:load_file).with('configuration.yml').and_return(original_config))
|
116
|
+
allow(File).to(receive(:open).with('configuration.yml', 'r').and_return(file))
|
117
|
+
allow(file).to(receive(:each_line).with(chomp: true).and_return(original_file_content.each_line(chomp: true)))
|
118
|
+
allow(File).to(receive(:write))
|
119
|
+
end
|
120
|
+
|
121
|
+
it do
|
122
|
+
preserver.save({ simple_item: 'pouet', nested_item: { subitem: 132 } })
|
123
|
+
expect(File).to(have_received(:write).with('configuration.yml', new_file_content))
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
@@ -1,9 +1,7 @@
|
|
1
1
|
# Copyright (c) 2020 Jerome Arbez-Gindre
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
require('csv')
|
5
4
|
require('defmastership/export/csv/formatter')
|
6
|
-
require('ostruct')
|
7
5
|
|
8
6
|
RSpec.describe(Defmastership::Export::CSV::Formatter) do
|
9
7
|
subject(:formatter) { described_class.new(document, ';') }
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# Copyright (c) 2025 Jerome Arbez-Gindre
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
RSpec.describe(Hash) do
|
5
|
+
describe '.merge_no_new' do
|
6
|
+
context 'when we don\'t want to modiy original Hash' do
|
7
|
+
subject(:hash) { { key1: :toto } }
|
8
|
+
|
9
|
+
let(:other) { { key1: :titi } }
|
10
|
+
|
11
|
+
it { expect(hash.merge_no_new(hash)).not_to(equal(hash)) }
|
12
|
+
it { expect(hash.merge_no_new(other)).not_to(equal(other)) }
|
13
|
+
end
|
14
|
+
|
15
|
+
[
|
16
|
+
[{ key1: :foo }, { key1: :bar }, { key1: :bar }],
|
17
|
+
[{ key1: :foo }, {}, { key1: :foo }],
|
18
|
+
[{ key1: { key1key1: :foo } }, {}, { key1: { key1key1: :foo } }],
|
19
|
+
[{ key1: :foo }, { key2: :bar }, { key1: :foo }],
|
20
|
+
[{ key1: :foo1, key2: :foo2 }, { key1: :bar1, key2: :foo2 }, { key1: :bar1, key2: :foo2 }],
|
21
|
+
[{ key1: { key1key1: :foo } }, { key1: { key1key1: :bar } }, { key1: { key1key1: :bar } }],
|
22
|
+
[{ key1: { key1key1: :foo } }, { key1: { key1key2: :bar } }, { key1: { key1key1: :foo } }]
|
23
|
+
].each do |original, modified, updated|
|
24
|
+
it { expect(original.merge_no_new(modified)).to(eq(updated)) }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -15,7 +15,10 @@ RSpec.describe(Defmastership::Modifier::ChangeRef) do
|
|
15
15
|
end
|
16
16
|
|
17
17
|
describe '.replacement_methods' do
|
18
|
-
it
|
18
|
+
it do
|
19
|
+
expect(described_class.replacement_methods)
|
20
|
+
.to(eq(%i[replace_refdef replace_irefs replace_include_tags replace_tags_in_included_files]))
|
21
|
+
end
|
19
22
|
end
|
20
23
|
|
21
24
|
describe '#config' do
|
@@ -193,4 +196,116 @@ RSpec.describe(Defmastership::Modifier::ChangeRef) do
|
|
193
196
|
).to(eq('defs:iref[TOTO-0132] defs:iref[TOTO-0132] bla'))
|
194
197
|
end
|
195
198
|
end
|
199
|
+
|
200
|
+
describe '#replace_include_tags' do
|
201
|
+
subject(:refchanger) do
|
202
|
+
described_class.new(
|
203
|
+
from_regexp: '(?<cg>TOTO|TITI)-TEMP[\d]*',
|
204
|
+
to_template: '%<cg>s-%<next_ref>04d',
|
205
|
+
next_ref: 132
|
206
|
+
)
|
207
|
+
end
|
208
|
+
|
209
|
+
before do
|
210
|
+
refchanger.replace_refdef('[define, whatever, TOTO-TEMP123]')
|
211
|
+
refchanger.replace_refdef('[define, whatever, TITI-TEMP421]')
|
212
|
+
end
|
213
|
+
|
214
|
+
it do
|
215
|
+
expect(refchanger.replace_irefs('include::target[tags=TOTO-TEMP1234]'))
|
216
|
+
.to(eq('include::target[tags=TOTO-TEMP1234]'))
|
217
|
+
end
|
218
|
+
|
219
|
+
[
|
220
|
+
['tags=TOTO-TEMP123', 'tags=TOTO-0132'],
|
221
|
+
['tag=TITI-TEMP421', 'tag=TITI-0133'],
|
222
|
+
['tag=!TOTO-TEMP123', 'tag=!TOTO-0132'],
|
223
|
+
['lines = "1..7,9", tag=TOTO-TEMP123, leveloffset=1', 'lines = "1..7,9", tag=TOTO-0132, leveloffset=1'],
|
224
|
+
['lines=1..7;9, tag=TOTO-TEMP123', 'lines=1..7;9, tag=TOTO-0132'],
|
225
|
+
['tag=!TITI-TEMP421;TOTO-TEMP123', 'tag=!TITI-0133;TOTO-0132']
|
226
|
+
].each do |from, to|
|
227
|
+
it do
|
228
|
+
expect(refchanger.replace_include_tags("include::path/target[#{from}]"))
|
229
|
+
.to(eq("include::path/target[#{to}]"))
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
[
|
234
|
+
'include::target[tag=TITI-TEMP42112]',
|
235
|
+
'inc::target[tag=TITI-TEMP421]',
|
236
|
+
'include:target[tag=TITI-TEMP421]',
|
237
|
+
'# include::target[tag=TITI-TEMP421]'
|
238
|
+
].each do |unchanged|
|
239
|
+
it { expect(refchanger.replace_include_tags(unchanged)).to(eq(unchanged)) }
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
describe '#replace_tags_in_included_files' do
|
244
|
+
subject(:refchanger) do
|
245
|
+
described_class.new(
|
246
|
+
from_regexp: '(?<cg>TOTO|TITI)-TEMP[\d]*',
|
247
|
+
to_template: '%<cg>s-%<next_ref>04d',
|
248
|
+
next_ref: 132
|
249
|
+
)
|
250
|
+
end
|
251
|
+
|
252
|
+
let(:original_included_file) do
|
253
|
+
<<OIF
|
254
|
+
# tag::TOTO-TEMP123[]
|
255
|
+
# end::TOTO-TEMP123[]
|
256
|
+
/* tag::TOTO-TEMP123[] */
|
257
|
+
<!-- tag::TOTO-TEMP123[] -->
|
258
|
+
; end::TOTO-TEMP123[]
|
259
|
+
# wrong tags
|
260
|
+
; tags::TOTO-TEMP123[]
|
261
|
+
; end::TOTO-TEMP123
|
262
|
+
; ends::TOTO-TEMP123[]
|
263
|
+
; tag:TOTO-TEMP123[]
|
264
|
+
; end:TOTO-TEMP123[]
|
265
|
+
OIF
|
266
|
+
end
|
267
|
+
|
268
|
+
let(:mofified_included_file) do
|
269
|
+
<<MIF
|
270
|
+
# tag::TOTO-0132[]
|
271
|
+
# end::TOTO-0132[]
|
272
|
+
/* tag::TOTO-0132[] */
|
273
|
+
<!-- tag::TOTO-0132[] -->
|
274
|
+
; end::TOTO-0132[]
|
275
|
+
# wrong tags
|
276
|
+
; tags::TOTO-TEMP123[]
|
277
|
+
; end::TOTO-TEMP123
|
278
|
+
; ends::TOTO-TEMP123[]
|
279
|
+
; tag:TOTO-TEMP123[]
|
280
|
+
; end:TOTO-TEMP123[]
|
281
|
+
MIF
|
282
|
+
end
|
283
|
+
|
284
|
+
before do
|
285
|
+
refchanger.replace_refdef('[define, whatever, TOTO-TEMP123]')
|
286
|
+
refchanger.replace_refdef('[define, whatever, TITI-TEMP421]')
|
287
|
+
|
288
|
+
allow(File).to(receive(:readlines)).with('target').and_return(['# tag::TOTO-TEMP123'])
|
289
|
+
allow(File).to(receive(:readlines)).with('path/target').and_return(original_included_file.split)
|
290
|
+
|
291
|
+
allow(File).to(receive(:writelines))
|
292
|
+
|
293
|
+
refchanger.replace_tags_in_included_files('include::path/target[]')
|
294
|
+
refchanger.replace_tags_in_included_files('includ::otherpath/othertarget[]')
|
295
|
+
end
|
296
|
+
|
297
|
+
it { expect(File).to(have_received(:readlines).with('path/target')) }
|
298
|
+
|
299
|
+
it do
|
300
|
+
expect(File).to(
|
301
|
+
have_received(:writelines).with('path/target', mofified_included_file.split)
|
302
|
+
)
|
303
|
+
end
|
304
|
+
|
305
|
+
it { expect(File).not_to(have_received(:readlines).with('otherpath/othertarget')) }
|
306
|
+
|
307
|
+
it { expect(refchanger.replace_tags_in_included_files('include::target[]')).to(eq('include::target[]')) }
|
308
|
+
|
309
|
+
it { expect(refchanger.replace_tags_in_included_files('include::path/target[]')).to(eq('include::path/target[]')) }
|
310
|
+
end
|
196
311
|
end
|
@@ -2,7 +2,6 @@
|
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
require('defmastership/modifier/update_def_version')
|
5
|
-
require('git')
|
6
5
|
|
7
6
|
RSpec.describe(Defmastership::Modifier::UpdateDefVersion) do
|
8
7
|
subject(:modifier) { described_class.new({}) }
|
@@ -69,6 +68,7 @@ RSpec.describe(Defmastership::Modifier::UpdateDefVersion) do
|
|
69
68
|
described_class.new(
|
70
69
|
ref_document: ['ref_doc1.adoc', 'ref_doc2.adoc'],
|
71
70
|
def_type: 'req',
|
71
|
+
ref_tag: +'',
|
72
72
|
first_version: 'a'
|
73
73
|
)
|
74
74
|
end
|
@@ -281,13 +281,13 @@ RSpec.describe(Defmastership::Modifier::UpdateDefVersion) do
|
|
281
281
|
context 'when definition has the good type' do
|
282
282
|
before do
|
283
283
|
allow(document).to(receive(:ref_to_def).with('REFERENCE').and_return(definition))
|
284
|
-
allow(definition).to(receive(:sha256_short).and_return('~abcd1234'))
|
284
|
+
allow(definition).to(receive(:sha256_short).and_return(+'~abcd1234'))
|
285
285
|
end
|
286
286
|
|
287
287
|
context 'when definition has NOT changed' do
|
288
288
|
before do
|
289
289
|
allow(ref_document).to(receive(:ref_to_def).with('REFERENCE').and_return(ref_definition))
|
290
|
-
allow(ref_definition).to(receive(:sha256_short).and_return('~abcd1234'))
|
290
|
+
allow(ref_definition).to(receive(:sha256_short).and_return(+'~abcd1234'))
|
291
291
|
end
|
292
292
|
|
293
293
|
it do
|
@@ -312,7 +312,7 @@ RSpec.describe(Defmastership::Modifier::UpdateDefVersion) do
|
|
312
312
|
context 'when definition has changed' do
|
313
313
|
before do
|
314
314
|
allow(ref_document).to(receive(:ref_to_def).with('REFERENCE').and_return(ref_definition))
|
315
|
-
allow(ref_definition).to(receive(:sha256_short).and_return('~4321aaaa'))
|
315
|
+
allow(ref_definition).to(receive(:sha256_short).and_return(+'~4321aaaa'))
|
316
316
|
end
|
317
317
|
|
318
318
|
[
|