defmastership 1.0.17 → 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/.gitlab-ci.yml +22 -10
- data/Gemfile +51 -1
- data/Rakefile +16 -61
- data/bin/defmastership +9 -6
- data/config/mutant.yml +23 -3
- data/defmastership.gemspec +0 -10
- 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 +88 -6
- data/lib/defmastership/comment_filter.rb +1 -1
- data/lib/defmastership/constants.rb +5 -4
- data/lib/defmastership/csv_formatter.rb +16 -12
- 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 +1 -6
- data/spec/spec_helper.rb +3 -1
- data/spec/unit/def_mastership/batch_modifier_spec.rb +38 -36
- data/spec/unit/def_mastership/change_ref_modifier_spec.rb +196 -51
- data/spec/unit/def_mastership/csv_formatter_body_spec.rb +60 -31
- data/spec/unit/def_mastership/csv_formatter_header_spec.rb +1 -1
- data/spec/unit/def_mastership/csv_formatter_spec.rb +79 -87
- data/spec/unit/def_mastership/definition_parser_spec.rb +1 -1
- data/spec/unit/def_mastership/definition_spec.rb +16 -6
- data/spec/unit/def_mastership/document_spec.rb +81 -38
- 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/def_mastership/parsing_state_spec.rb +1 -1
- data/spec/unit/def_mastership/rename_included_files_modifier_spec.rb +219 -47
- data/spec/unit/def_mastership/string_spec.rb +1 -1
- data/spec/unit/def_mastership/update_def_checksum_modifier_spec.rb +82 -50
- data/spec/unit/def_mastership/update_def_modifier_spec.rb +119 -0
- data/spec/unit/def_mastership/update_def_version_modifier_spec.rb +135 -56
- 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 +16 -153
- data/lib/defmastership/change_ref_line_modifier.rb +0 -85
- data/lib/defmastership/line_modifier_base.rb +0 -29
- data/lib/defmastership/modifier_base.rb +0 -36
- 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/def_mastership/change_ref_line_modifier_spec.rb +0 -250
- data/spec/unit/def_mastership/rename_included_files_line_modifier_spec.rb +0 -207
- data/spec/unit/def_mastership/update_def_checksum_line_modifier_spec.rb +0 -82
- data/spec/unit/def_mastership/update_def_version_line_modifier_spec.rb +0 -131
@@ -2,7 +2,7 @@
|
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
require('csv')
|
5
|
-
require('defmastership')
|
5
|
+
require('defmastership/csv_formatter')
|
6
6
|
require('ostruct')
|
7
7
|
|
8
8
|
RSpec.describe(DefMastership::CSVFormatter) do
|
@@ -16,15 +16,22 @@ RSpec.describe(DefMastership::CSVFormatter) do
|
|
16
16
|
|
17
17
|
describe '#export_to' do
|
18
18
|
let(:header) { instance_double(DefMastership::CSVFormatterHeader, 'header') }
|
19
|
-
let(:
|
20
|
-
|
19
|
+
let(:bodies) do
|
20
|
+
[
|
21
|
+
instance_double(DefMastership::CSVFormatterBody, 'bodies[0]'),
|
22
|
+
instance_double(DefMastership::CSVFormatterBody, 'bodies[1]')
|
23
|
+
]
|
24
|
+
end
|
25
|
+
let(:csv) { instance_double(CSV, 'csv') }
|
21
26
|
|
22
27
|
before do
|
23
|
-
allow(CSV).to(receive(:open).and_yield(csv))
|
28
|
+
allow(CSV).to(receive(:open).with('whatever', 'w:ISO-8859-1', col_sep: ';').and_yield(csv))
|
24
29
|
allow(csv).to(receive(:<<))
|
25
30
|
allow(DefMastership::CSVFormatterHeader).to(receive(:new).with(document).and_return(header))
|
26
|
-
|
27
|
-
|
31
|
+
bodies.each_with_index do |body, index|
|
32
|
+
allow(DefMastership::CSVFormatterBody).to(receive(:new).with(document, :"def#{index}").and_return(body))
|
33
|
+
end
|
34
|
+
allow(document).to(receive(:definitions).and_return(%i[def0 def1]))
|
28
35
|
allow(document).to(receive(:wrong_explicit_checksum?).with(no_args).and_return(false))
|
29
36
|
allow(document).to(receive(:explicit_version?).with(no_args).and_return(false))
|
30
37
|
allow(document).to(receive(:labels).with(no_args).and_return([]))
|
@@ -39,21 +46,26 @@ RSpec.describe(DefMastership::CSVFormatter) do
|
|
39
46
|
before do
|
40
47
|
methods.each do |method|
|
41
48
|
allow(header).to(receive(method).with(no_args).and_return(["#{method} header"]))
|
42
|
-
|
43
|
-
|
49
|
+
bodies.each_with_index do |body, index|
|
50
|
+
allow(body).to(receive(method).with(no_args).and_return(["#{method} def#{index} body"]))
|
51
|
+
end
|
44
52
|
end
|
45
53
|
formatter.export_to('whatever')
|
46
54
|
end
|
47
55
|
|
56
|
+
it { expect(CSV).to(have_received(:open).with('whatever', 'w:ISO-8859-1', col_sep: ';')) }
|
57
|
+
|
48
58
|
methods.each do |method|
|
49
59
|
it { expect(header).to(have_received(method).with(no_args)) }
|
50
|
-
|
51
|
-
|
60
|
+
|
61
|
+
2.times do |index|
|
62
|
+
it { expect(bodies[index]).to(have_received(method).with(no_args)) }
|
63
|
+
end
|
52
64
|
end
|
53
65
|
|
54
66
|
it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} header" })) }
|
67
|
+
it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} def0 body" })) }
|
55
68
|
it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} def1 body" })) }
|
56
|
-
it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} def2 body" })) }
|
57
69
|
end
|
58
70
|
|
59
71
|
context 'when wrong_explicit_checksum' do
|
@@ -62,8 +74,9 @@ RSpec.describe(DefMastership::CSVFormatter) do
|
|
62
74
|
before do
|
63
75
|
methods.each do |method|
|
64
76
|
allow(header).to(receive(method).with(no_args).and_return(["#{method} header"]))
|
65
|
-
|
66
|
-
|
77
|
+
bodies.each_with_index do |body, index|
|
78
|
+
allow(body).to(receive(method).with(no_args).and_return(["#{method} def#{index} body"]))
|
79
|
+
end
|
67
80
|
end
|
68
81
|
allow(document).to(receive(:wrong_explicit_checksum?).with(no_args).and_return(true))
|
69
82
|
formatter.export_to('whatever')
|
@@ -71,13 +84,15 @@ RSpec.describe(DefMastership::CSVFormatter) do
|
|
71
84
|
|
72
85
|
methods.each do |method|
|
73
86
|
it { expect(header).to(have_received(method).with(no_args)) }
|
74
|
-
|
75
|
-
|
87
|
+
|
88
|
+
2.times do |index|
|
89
|
+
it { expect(bodies[index]).to(have_received(method).with(no_args)) }
|
90
|
+
end
|
76
91
|
end
|
77
92
|
|
78
93
|
it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} header" })) }
|
94
|
+
it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} def0 body" })) }
|
79
95
|
it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} def1 body" })) }
|
80
|
-
it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} def2 body" })) }
|
81
96
|
end
|
82
97
|
|
83
98
|
context 'when explicit_version' do
|
@@ -86,8 +101,9 @@ RSpec.describe(DefMastership::CSVFormatter) do
|
|
86
101
|
before do
|
87
102
|
methods.each do |method|
|
88
103
|
allow(header).to(receive(method).with(no_args).and_return(["#{method} header"]))
|
89
|
-
|
90
|
-
|
104
|
+
bodies.each_with_index do |body, index|
|
105
|
+
allow(body).to(receive(method).with(no_args).and_return(["#{method} def#{index} body"]))
|
106
|
+
end
|
91
107
|
end
|
92
108
|
allow(document).to(receive(:explicit_version?).with(no_args).and_return(true))
|
93
109
|
formatter.export_to('whatever')
|
@@ -95,13 +111,15 @@ RSpec.describe(DefMastership::CSVFormatter) do
|
|
95
111
|
|
96
112
|
methods.each do |method|
|
97
113
|
it { expect(header).to(have_received(method).with(no_args)) }
|
98
|
-
|
99
|
-
|
114
|
+
|
115
|
+
2.times do |index|
|
116
|
+
it { expect(bodies[index]).to(have_received(method).with(no_args)) }
|
117
|
+
end
|
100
118
|
end
|
101
119
|
|
102
120
|
it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} header" })) }
|
121
|
+
it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} def0 body" })) }
|
103
122
|
it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} def1 body" })) }
|
104
|
-
it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} def2 body" })) }
|
105
123
|
end
|
106
124
|
|
107
125
|
context 'when labels' do
|
@@ -110,8 +128,9 @@ RSpec.describe(DefMastership::CSVFormatter) do
|
|
110
128
|
before do
|
111
129
|
methods.each do |method|
|
112
130
|
allow(header).to(receive(method).with(no_args).and_return(["#{method} header"]))
|
113
|
-
|
114
|
-
|
131
|
+
bodies.each_with_index do |body, index|
|
132
|
+
allow(body).to(receive(method).with(no_args).and_return(["#{method} def#{index} body"]))
|
133
|
+
end
|
115
134
|
end
|
116
135
|
allow(document).to(receive(:labels).with(no_args).and_return([:whatever]))
|
117
136
|
formatter.export_to('whatever')
|
@@ -119,13 +138,15 @@ RSpec.describe(DefMastership::CSVFormatter) do
|
|
119
138
|
|
120
139
|
methods.each do |method|
|
121
140
|
it { expect(header).to(have_received(method).with(no_args)) }
|
122
|
-
|
123
|
-
|
141
|
+
|
142
|
+
2.times do |index|
|
143
|
+
it { expect(bodies[index]).to(have_received(method).with(no_args)) }
|
144
|
+
end
|
124
145
|
end
|
125
146
|
|
126
147
|
it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} header" })) }
|
148
|
+
it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} def0 body" })) }
|
127
149
|
it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} def1 body" })) }
|
128
|
-
it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} def2 body" })) }
|
129
150
|
end
|
130
151
|
|
131
152
|
context 'when eref' do
|
@@ -134,8 +155,9 @@ RSpec.describe(DefMastership::CSVFormatter) do
|
|
134
155
|
before do
|
135
156
|
methods.each do |method|
|
136
157
|
allow(header).to(receive(method).with(no_args).and_return(["#{method} header"]))
|
137
|
-
|
138
|
-
|
158
|
+
bodies.each_with_index do |body, index|
|
159
|
+
allow(body).to(receive(method).with(no_args).and_return(["#{method} def#{index} body"]))
|
160
|
+
end
|
139
161
|
end
|
140
162
|
allow(document).to(receive(:eref).with(no_args).and_return([:whatever]))
|
141
163
|
formatter.export_to('whatever')
|
@@ -143,13 +165,15 @@ RSpec.describe(DefMastership::CSVFormatter) do
|
|
143
165
|
|
144
166
|
methods.each do |method|
|
145
167
|
it { expect(header).to(have_received(method).with(no_args)) }
|
146
|
-
|
147
|
-
|
168
|
+
|
169
|
+
2.times do |index|
|
170
|
+
it { expect(bodies[index]).to(have_received(method).with(no_args)) }
|
171
|
+
end
|
148
172
|
end
|
149
173
|
|
150
174
|
it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} header" })) }
|
175
|
+
it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} def0 body" })) }
|
151
176
|
it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} def1 body" })) }
|
152
|
-
it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} def2 body" })) }
|
153
177
|
end
|
154
178
|
|
155
179
|
context 'when iref' do
|
@@ -158,8 +182,9 @@ RSpec.describe(DefMastership::CSVFormatter) do
|
|
158
182
|
before do
|
159
183
|
methods.each do |method|
|
160
184
|
allow(header).to(receive(method).with(no_args).and_return(["#{method} header"]))
|
161
|
-
|
162
|
-
|
185
|
+
bodies.each_with_index do |body, index|
|
186
|
+
allow(body).to(receive(method).with(no_args).and_return(["#{method} def#{index} body"]))
|
187
|
+
end
|
163
188
|
end
|
164
189
|
allow(document).to(receive(:iref).with(no_args).and_return(true))
|
165
190
|
formatter.export_to('whatever')
|
@@ -167,13 +192,15 @@ RSpec.describe(DefMastership::CSVFormatter) do
|
|
167
192
|
|
168
193
|
methods.each do |method|
|
169
194
|
it { expect(header).to(have_received(method).with(no_args)) }
|
170
|
-
|
171
|
-
|
195
|
+
|
196
|
+
2.times do |index|
|
197
|
+
it { expect(bodies[index]).to(have_received(method).with(no_args)) }
|
198
|
+
end
|
172
199
|
end
|
173
200
|
|
174
201
|
it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} header" })) }
|
202
|
+
it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} def0 body" })) }
|
175
203
|
it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} def1 body" })) }
|
176
|
-
it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} def2 body" })) }
|
177
204
|
end
|
178
205
|
|
179
206
|
context 'when attributes' do
|
@@ -182,8 +209,9 @@ RSpec.describe(DefMastership::CSVFormatter) do
|
|
182
209
|
before do
|
183
210
|
methods.each do |method|
|
184
211
|
allow(header).to(receive(method).with(no_args).and_return(["#{method} header"]))
|
185
|
-
|
186
|
-
|
212
|
+
bodies.each_with_index do |body, index|
|
213
|
+
allow(body).to(receive(method).with(no_args).and_return(["#{method} def#{index} body"]))
|
214
|
+
end
|
187
215
|
end
|
188
216
|
allow(document).to(receive(:attributes).with(no_args).and_return([:whatever]))
|
189
217
|
formatter.export_to('whatever')
|
@@ -191,13 +219,15 @@ RSpec.describe(DefMastership::CSVFormatter) do
|
|
191
219
|
|
192
220
|
methods.each do |method|
|
193
221
|
it { expect(header).to(have_received(method).with(no_args)) }
|
194
|
-
|
195
|
-
|
222
|
+
|
223
|
+
2.times do |index|
|
224
|
+
it { expect(bodies[index]).to(have_received(method).with(no_args)) }
|
225
|
+
end
|
196
226
|
end
|
197
227
|
|
198
228
|
it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} header" })) }
|
229
|
+
it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} def0 body" })) }
|
199
230
|
it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} def1 body" })) }
|
200
|
-
it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} def2 body" })) }
|
201
231
|
end
|
202
232
|
|
203
233
|
context 'when every colums' do
|
@@ -206,8 +236,9 @@ RSpec.describe(DefMastership::CSVFormatter) do
|
|
206
236
|
before do
|
207
237
|
methods.each do |method|
|
208
238
|
allow(header).to(receive(method).with(no_args).and_return(["#{method} header"]))
|
209
|
-
|
210
|
-
|
239
|
+
bodies.each_with_index do |body, index|
|
240
|
+
allow(body).to(receive(method).with(no_args).and_return(["#{method} def#{index} body"]))
|
241
|
+
end
|
211
242
|
end
|
212
243
|
allow(document).to(receive(:wrong_explicit_checksum?).with(no_args).and_return(true))
|
213
244
|
allow(document).to(receive(:explicit_version?).with(no_args).and_return(true))
|
@@ -220,54 +251,15 @@ RSpec.describe(DefMastership::CSVFormatter) do
|
|
220
251
|
|
221
252
|
methods.each do |method|
|
222
253
|
it { expect(header).to(have_received(method).with(no_args)) }
|
223
|
-
|
224
|
-
|
254
|
+
|
255
|
+
2.times do |index|
|
256
|
+
it { expect(bodies[index]).to(have_received(method).with(no_args)) }
|
257
|
+
end
|
225
258
|
end
|
226
259
|
|
227
260
|
it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} header" })) }
|
261
|
+
it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} def0 body" })) }
|
228
262
|
it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} def1 body" })) }
|
229
|
-
it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} def2 body" })) }
|
230
|
-
end
|
231
|
-
end
|
232
|
-
|
233
|
-
context 'when #export_to csv file' do
|
234
|
-
let(:target_file) { 'export.csv' }
|
235
|
-
let(:definitions) { [double, double] }
|
236
|
-
|
237
|
-
before do
|
238
|
-
setup_aruba
|
239
|
-
allow(document).to(receive(:labels).with(no_args).and_return([]))
|
240
|
-
allow(document).to(receive(:eref).with(no_args).and_return({}))
|
241
|
-
allow(document).to(receive(:iref).with(no_args).and_return(false))
|
242
|
-
allow(document).to(receive(:attributes).with(no_args).and_return({}))
|
243
|
-
allow(document).to(receive(:definitions).with(no_args).and_return(definitions))
|
244
|
-
allow(definitions[0]).to(receive(:type).and_return('a'))
|
245
|
-
allow(definitions[0]).to(receive(:reference).and_return('b'))
|
246
|
-
allow(definitions[0]).to(receive(:value).and_return('c'))
|
247
|
-
allow(definitions[0]).to(receive(:sha256).and_return('d'))
|
248
|
-
allow(definitions[1]).to(receive(:type).and_return('d'))
|
249
|
-
allow(definitions[1]).to(receive(:reference).and_return('e'))
|
250
|
-
allow(definitions[1]).to(receive(:value).and_return('f'))
|
251
|
-
allow(definitions[1]).to(receive(:sha256).and_return('g'))
|
252
|
-
allow(document).to(receive(:wrong_explicit_checksum?).with(no_args).and_return(false))
|
253
|
-
allow(document).to(receive(:explicit_version?).with(no_args).and_return(false))
|
254
|
-
formatter.export_to("#{aruba.current_directory}/#{target_file}")
|
255
|
-
end
|
256
|
-
|
257
|
-
it { expect(document).to(have_received(:labels).with(no_args)) }
|
258
|
-
it { expect(document).to(have_received(:eref).with(no_args)) }
|
259
|
-
it { expect(document).to(have_received(:iref).with(no_args)) }
|
260
|
-
it { expect(document).to(have_received(:attributes).with(no_args)) }
|
261
|
-
it { expect(document).to(have_received(:definitions).with(no_args)) }
|
262
|
-
it { expect(document).to(have_received(:wrong_explicit_checksum?).with(no_args)) }
|
263
|
-
it { expect(document).to(have_received(:explicit_version?).with(no_args)) }
|
264
|
-
|
265
|
-
it do
|
266
|
-
expect(target_file).to(have_file_content(<<~CSV_FILE))
|
267
|
-
Type;Reference;Value;Checksum
|
268
|
-
a;b;c;d
|
269
|
-
d;e;f;g
|
270
|
-
CSV_FILE
|
271
263
|
end
|
272
264
|
end
|
273
265
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# Copyright (c) 2020 Jerome Arbez-Gindre
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
require('defmastership')
|
4
|
+
require('defmastership/definition')
|
5
5
|
|
6
6
|
RSpec.describe(DefMastership::Definition) do
|
7
7
|
describe '.new' do
|
@@ -101,9 +101,14 @@ RSpec.describe(DefMastership::Definition) do
|
|
101
101
|
expect(definition.lines).to(eq(['first line', 'second line']))
|
102
102
|
end
|
103
103
|
|
104
|
-
it 'calculates
|
104
|
+
it 'calculates sha256_short of value' do
|
105
105
|
definition << 'first line' << 'second line'
|
106
|
-
expect(definition.
|
106
|
+
expect(definition.sha256_short).to(eq('~beb0535a'))
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'returns the definition and not the "line"' do
|
110
|
+
expect { (definition << 'first line').sha256_short }
|
111
|
+
.not_to(raise_error)
|
107
112
|
end
|
108
113
|
end
|
109
114
|
|
@@ -115,9 +120,14 @@ RSpec.describe(DefMastership::Definition) do
|
|
115
120
|
)
|
116
121
|
end
|
117
122
|
|
118
|
-
|
119
|
-
|
120
|
-
|
123
|
+
[
|
124
|
+
'tutu,titi,pouet',
|
125
|
+
' tutu , titi , pouet '
|
126
|
+
].each do |erefs_cs|
|
127
|
+
it 'shall accept to add comma separated erefs' do
|
128
|
+
definition.add_eref(:foo, erefs_cs)
|
129
|
+
expect(definition.eref[:foo]).to(eq(%w[tutu titi pouet]))
|
130
|
+
end
|
121
131
|
end
|
122
132
|
end
|
123
133
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# Copyright (c) 2020 Jerome Arbez-Gindre
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
require('defmastership')
|
4
|
+
require('defmastership/document')
|
5
5
|
|
6
6
|
RSpec.describe(DefMastership::Document) do
|
7
7
|
subject(:document) { described_class.new }
|
@@ -15,16 +15,32 @@ RSpec.describe(DefMastership::Document) do
|
|
15
15
|
it { is_expected.to(have_attributes(variables: {})) }
|
16
16
|
end
|
17
17
|
|
18
|
+
describe '.method_missing' do
|
19
|
+
it do
|
20
|
+
expect { document.not_implemented_random_method }
|
21
|
+
.to(raise_error(NoMethodError))
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe '.respond_to_missing?' do
|
26
|
+
it { expect(document.respond_to?(:add_new_definition)).to(be(true)) }
|
27
|
+
it { expect(document.respond_to?(:not_implemented_random_method)).to(be(false)) }
|
28
|
+
end
|
29
|
+
|
18
30
|
describe '#parse' do
|
19
31
|
context 'with valid definitions' do
|
20
32
|
let(:definition) { instance_double(DefMastership::Definition, 'definition') }
|
21
33
|
|
22
34
|
before do
|
23
35
|
allow(DefMastership::Definition).to(receive(:new).and_return(definition))
|
24
|
-
allow(definition).to(
|
25
|
-
|
26
|
-
|
27
|
-
|
36
|
+
allow(definition).to(
|
37
|
+
receive_messages(
|
38
|
+
labels: Set.new,
|
39
|
+
'<<': definition,
|
40
|
+
add_eref: definition,
|
41
|
+
add_iref: definition
|
42
|
+
)
|
43
|
+
)
|
28
44
|
end
|
29
45
|
|
30
46
|
context 'when simple definition line' do
|
@@ -401,8 +417,12 @@ RSpec.describe(DefMastership::Document) do
|
|
401
417
|
|
402
418
|
before do
|
403
419
|
allow(DefMastership::Definition).to(receive(:new).and_return(definition))
|
404
|
-
allow(definition).to(
|
405
|
-
|
420
|
+
allow(definition).to(
|
421
|
+
receive_messages(
|
422
|
+
labels: Set.new,
|
423
|
+
'<<': definition
|
424
|
+
)
|
425
|
+
)
|
406
426
|
document.parse(input_lines)
|
407
427
|
end
|
408
428
|
|
@@ -431,6 +451,18 @@ RSpec.describe(DefMastership::Document) do
|
|
431
451
|
it { expect(definition).to(have_received(:<<).with('bef {variable} aft')) }
|
432
452
|
end
|
433
453
|
|
454
|
+
context 'when badly defined variable' do
|
455
|
+
let(:input_lines) do
|
456
|
+
[
|
457
|
+
':variable:one value',
|
458
|
+
'[define, requirement, TOTO-0001]',
|
459
|
+
'bef {variable} aft'
|
460
|
+
]
|
461
|
+
end
|
462
|
+
|
463
|
+
it { expect(definition).to(have_received(:<<).with('bef {variable} aft')) }
|
464
|
+
end
|
465
|
+
|
434
466
|
context 'when multiple defined variables' do
|
435
467
|
let(:input_lines) do
|
436
468
|
[
|
@@ -503,8 +535,12 @@ RSpec.describe(DefMastership::Document) do
|
|
503
535
|
allow(adoc_doc).to(receive(:reader).and_return(adoc_reader))
|
504
536
|
allow(adoc_reader).to(receive(:read_lines).and_return(input_lines))
|
505
537
|
allow(DefMastership::Definition).to(receive(:new).and_return(definition))
|
506
|
-
allow(definition).to(
|
507
|
-
|
538
|
+
allow(definition).to(
|
539
|
+
receive_messages(
|
540
|
+
'<<': definition,
|
541
|
+
labels: Set.new
|
542
|
+
)
|
543
|
+
)
|
508
544
|
document.parse_file_with_preprocessor('the_file.adoc')
|
509
545
|
end
|
510
546
|
|
@@ -539,30 +575,29 @@ RSpec.describe(DefMastership::Document) do
|
|
539
575
|
end
|
540
576
|
|
541
577
|
before do
|
542
|
-
allow(DefMastership::Definition).to(receive(:new).twice.and_return(defs
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
578
|
+
allow(DefMastership::Definition).to(receive(:new).twice.and_return(defs.first, defs[1]))
|
579
|
+
defs.each do |definition|
|
580
|
+
allow(definition).to(receive(:labels)).and_return([])
|
581
|
+
allow(definition).to(receive(:<<)).and_return(definition)
|
582
|
+
end
|
547
583
|
end
|
548
584
|
|
549
585
|
context 'when no wrong explicit checksum' do
|
550
586
|
before do
|
551
|
-
allow(
|
552
|
-
allow(defs[1]).to(receive(:wrong_explicit_checksum)).and_return(nil)
|
587
|
+
defs.each { |definition| allow(definition).to(receive(:wrong_explicit_checksum)).and_return(nil) }
|
553
588
|
document.parse(input_lines)
|
554
589
|
document.wrong_explicit_checksum?
|
555
590
|
end
|
556
591
|
|
557
|
-
it { expect(defs
|
592
|
+
it { expect(defs.first).to(have_received(:wrong_explicit_checksum)) }
|
558
593
|
it { expect(defs[1]).to(have_received(:wrong_explicit_checksum)) }
|
559
594
|
it { expect(document.wrong_explicit_checksum?).to(be(false)) }
|
560
595
|
end
|
561
596
|
|
562
597
|
context 'when one req has wrong explicit checksum' do
|
563
598
|
before do
|
564
|
-
allow(defs
|
565
|
-
allow(defs[1]).to(receive(:wrong_explicit_checksum)).and_return(
|
599
|
+
allow(defs.first).to(receive(:wrong_explicit_checksum)).and_return('toto')
|
600
|
+
allow(defs[1]).to(receive(:wrong_explicit_checksum)).and_return(nil)
|
566
601
|
document.parse(input_lines)
|
567
602
|
document.wrong_explicit_checksum?
|
568
603
|
end
|
@@ -589,30 +624,30 @@ RSpec.describe(DefMastership::Document) do
|
|
589
624
|
end
|
590
625
|
|
591
626
|
before do
|
592
|
-
allow(DefMastership::Definition).to(receive(:new).twice.and_return(defs
|
593
|
-
allow(defs
|
627
|
+
allow(DefMastership::Definition).to(receive(:new).twice.and_return(defs.first, defs[1]))
|
628
|
+
allow(defs.first).to(receive(:labels)).and_return([])
|
594
629
|
allow(defs[1]).to(receive(:labels)).and_return([])
|
595
|
-
allow(defs
|
630
|
+
allow(defs.first).to(receive(:<<).and_return(defs.first))
|
596
631
|
allow(defs[1]).to(receive(:<<).and_return(defs[1]))
|
597
632
|
end
|
598
633
|
|
599
634
|
context 'when no explicit version' do
|
600
635
|
before do
|
601
|
-
allow(defs
|
636
|
+
allow(defs.first).to(receive(:explicit_version)).and_return(nil)
|
602
637
|
allow(defs[1]).to(receive(:explicit_version)).and_return(nil)
|
603
638
|
document.parse(input_lines)
|
604
639
|
document.explicit_version?
|
605
640
|
end
|
606
641
|
|
607
|
-
it { expect(defs
|
642
|
+
it { expect(defs.first).to(have_received(:explicit_version)) }
|
608
643
|
it { expect(defs[1]).to(have_received(:explicit_version)) }
|
609
644
|
it { expect(document.explicit_version?).to(be(false)) }
|
610
645
|
end
|
611
646
|
|
612
647
|
context 'when one req has explicit version' do
|
613
648
|
before do
|
614
|
-
allow(defs
|
615
|
-
allow(defs[1]).to(receive(:explicit_version)).and_return(
|
649
|
+
allow(defs.first).to(receive(:explicit_version)).and_return('toto')
|
650
|
+
allow(defs[1]).to(receive(:explicit_version)).and_return(nil)
|
616
651
|
document.parse(input_lines)
|
617
652
|
document.explicit_version?
|
618
653
|
end
|
@@ -622,10 +657,10 @@ RSpec.describe(DefMastership::Document) do
|
|
622
657
|
end
|
623
658
|
|
624
659
|
describe '#ref_to_def?' do
|
625
|
-
let(:
|
660
|
+
let(:definitions) do
|
626
661
|
[
|
627
|
-
instance_double(DefMastership::Definition, '
|
628
|
-
instance_double(DefMastership::Definition, '
|
662
|
+
instance_double(DefMastership::Definition, 'def1'),
|
663
|
+
instance_double(DefMastership::Definition, 'def2')
|
629
664
|
]
|
630
665
|
end
|
631
666
|
let(:input_lines) do
|
@@ -639,17 +674,25 @@ RSpec.describe(DefMastership::Document) do
|
|
639
674
|
end
|
640
675
|
|
641
676
|
before do
|
642
|
-
allow(DefMastership::Definition).to(receive(:new).twice.and_return(
|
643
|
-
allow(
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
677
|
+
allow(DefMastership::Definition).to(receive(:new).twice.and_return(definitions.first, definitions[1]))
|
678
|
+
allow(definitions.first).to(
|
679
|
+
receive_messages(
|
680
|
+
labels: [],
|
681
|
+
'<<': definitions.first,
|
682
|
+
reference: 'TOTO-0001'
|
683
|
+
)
|
684
|
+
)
|
685
|
+
allow(definitions[1]).to(
|
686
|
+
receive_messages(
|
687
|
+
labels: [],
|
688
|
+
'<<': definitions[1],
|
689
|
+
reference: 'TOTO-0002'
|
690
|
+
)
|
691
|
+
)
|
649
692
|
document.parse(input_lines)
|
650
693
|
end
|
651
694
|
|
652
|
-
it { expect(document.ref_to_def('TOTO-0001')).to(eq(
|
653
|
-
it { expect(document.ref_to_def('TOTO-0002')).to(eq(
|
695
|
+
it { expect(document.ref_to_def('TOTO-0001')).to(eq(definitions.first)) }
|
696
|
+
it { expect(document.ref_to_def('TOTO-0002')).to(eq(definitions[1])) }
|
654
697
|
end
|
655
698
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# Copyright (c) 2024 Jerome Arbez-Gindre
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require('defmastership/matching_line')
|
5
|
+
|
6
|
+
RSpec.describe(DefMastership::MatchingLine) do
|
7
|
+
describe '.new' do
|
8
|
+
subject(:matching_line) do
|
9
|
+
described_class.new(:a_match, :a_line)
|
10
|
+
end
|
11
|
+
|
12
|
+
it { is_expected.not_to(be_nil) }
|
13
|
+
it { is_expected.to(have_attributes(match: :a_match)) }
|
14
|
+
it { is_expected.to(have_attributes(line: :a_line)) }
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '#[]' do
|
18
|
+
subject(:matching_line) do
|
19
|
+
described_class.new(match, :a_line)
|
20
|
+
end
|
21
|
+
|
22
|
+
let(:match) { instance_double(Hash, 'match') }
|
23
|
+
|
24
|
+
before do
|
25
|
+
allow(match).to(receive(:[]).with(:whatever).and_return('Whatever'))
|
26
|
+
allow(match).to(receive(:[]).with(:line).and_return(nil))
|
27
|
+
end
|
28
|
+
|
29
|
+
it do
|
30
|
+
matching_line[:whatever]
|
31
|
+
expect(match).to(have_received(:[]).with(:whatever))
|
32
|
+
end
|
33
|
+
|
34
|
+
it { expect(matching_line[:whatever]).to(eq('Whatever')) }
|
35
|
+
it { expect(matching_line[:line]).to(eq(:a_line)) }
|
36
|
+
end
|
37
|
+
end
|