defmastership 1.0.17 → 1.0.19

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.gitlab-ci.yml +37 -11
  4. data/Gemfile +71 -1
  5. data/Guardfile +44 -0
  6. data/Rakefile +16 -61
  7. data/bin/defmastership +9 -6
  8. data/config/cucumber.yml +3 -0
  9. data/config/mutant.yml +27 -3
  10. data/config/reek.yml +129 -105
  11. data/config/rubocop.yml +72 -28
  12. data/defmastership.gemspec +5 -13
  13. data/features/changeref.feature +0 -8
  14. data/features/definition_checksum.feature +30 -10
  15. data/features/definition_version.feature +168 -10
  16. data/features/export.feature +64 -17
  17. data/features/modify.feature +1 -5
  18. data/features/rename_included_files.feature +27 -4
  19. data/features/step_definitions/git_steps.rb +19 -0
  20. data/lib/defmastership/batch_modifier.rb +17 -12
  21. data/lib/defmastership/change_ref_modifier.rb +88 -6
  22. data/lib/defmastership/comment_filter.rb +1 -1
  23. data/lib/defmastership/constants.rb +10 -7
  24. data/lib/defmastership/csv_formatter.rb +16 -12
  25. data/lib/defmastership/csv_formatter_body.rb +18 -15
  26. data/lib/defmastership/csv_formatter_header.rb +1 -1
  27. data/lib/defmastership/definition.rb +59 -20
  28. data/lib/defmastership/document.rb +101 -74
  29. data/lib/defmastership/matching_line.rb +17 -0
  30. data/lib/defmastership/modifier.rb +42 -0
  31. data/lib/defmastership/modifier_factory.rb +12 -0
  32. data/lib/defmastership/parsing_state.rb +15 -9
  33. data/lib/defmastership/rename_included_files_modifier.rb +172 -5
  34. data/lib/defmastership/set_join_hack.rb +11 -0
  35. data/lib/defmastership/update_def_checksum_modifier.rb +8 -13
  36. data/lib/defmastership/update_def_modifier.rb +49 -0
  37. data/lib/defmastership/update_def_version_modifier.rb +81 -15
  38. data/lib/defmastership/version.rb +1 -1
  39. data/lib/defmastership.rb +1 -6
  40. data/spec/spec_helper.rb +3 -1
  41. data/spec/unit/def_mastership/batch_modifier_spec.rb +40 -36
  42. data/spec/unit/def_mastership/change_ref_modifier_spec.rb +196 -51
  43. data/spec/unit/def_mastership/csv_formatter_body_spec.rb +60 -31
  44. data/spec/unit/def_mastership/csv_formatter_header_spec.rb +1 -1
  45. data/spec/unit/def_mastership/csv_formatter_spec.rb +79 -87
  46. data/spec/unit/def_mastership/definition_parser_spec.rb +1 -1
  47. data/spec/unit/def_mastership/definition_spec.rb +16 -6
  48. data/spec/unit/def_mastership/document_spec.rb +81 -38
  49. data/spec/unit/def_mastership/matching_line_spec.rb +37 -0
  50. data/spec/unit/def_mastership/modifier_factory_spec.rb +38 -0
  51. data/spec/unit/def_mastership/modifier_spec.rb +85 -0
  52. data/spec/unit/def_mastership/parsing_state_spec.rb +1 -1
  53. data/spec/unit/def_mastership/rename_included_files_modifier_spec.rb +219 -47
  54. data/spec/unit/def_mastership/string_spec.rb +1 -1
  55. data/spec/unit/def_mastership/update_def_checksum_modifier_spec.rb +82 -50
  56. data/spec/unit/def_mastership/update_def_modifier_spec.rb +121 -0
  57. data/spec/unit/def_mastership/update_def_version_modifier_spec.rb +327 -56
  58. data/tasks/code_quality.rake +74 -0
  59. data/tasks/console.rake +8 -0
  60. data/tasks/package.task +9 -0
  61. data/tasks/test.rake +30 -0
  62. metadata +33 -145
  63. data/.rubocop.yml +0 -76
  64. data/config/devtools.yml +0 -2
  65. data/config/flay.yml +0 -3
  66. data/config/flog.yml +0 -2
  67. data/config/yardstick.yml +0 -2
  68. data/cucumber.yml +0 -2
  69. data/lib/defmastership/change_ref_line_modifier.rb +0 -85
  70. data/lib/defmastership/line_modifier_base.rb +0 -29
  71. data/lib/defmastership/modifier_base.rb +0 -36
  72. data/lib/defmastership/rename_included_files_line_modifier.rb +0 -126
  73. data/lib/defmastership/update_def_checksum_line_modifier.rb +0 -38
  74. data/lib/defmastership/update_def_version_line_modifier.rb +0 -58
  75. data/spec/unit/def_mastership/change_ref_line_modifier_spec.rb +0 -250
  76. data/spec/unit/def_mastership/rename_included_files_line_modifier_spec.rb +0 -207
  77. data/spec/unit/def_mastership/update_def_checksum_line_modifier_spec.rb +0 -82
  78. data/spec/unit/def_mastership/update_def_version_line_modifier_spec.rb +0 -131
  79. /data/{.rspec → config/rspec} +0 -0
@@ -1,80 +1,351 @@
1
1
  # Copyright (c) 2020 Jerome Arbez-Gindre
2
2
  # frozen_string_literal: true
3
3
 
4
- require('defmastership')
4
+ require('defmastership/update_def_version_modifier')
5
+ require('git')
5
6
 
6
7
  RSpec.describe(DefMastership::UpdateDefVersionModifier) do
7
- subject(:modifier) do
8
- described_class.new(
9
- ref_document: 'ref.adoc'
10
- )
11
- end
12
-
13
- let(:adoc_texts) do
14
- {
15
- 'file1.adoc' => "file1 line1\nfile1 line2",
16
- 'file2.adoc' => "file2 line1\nfile2 line2"
17
- }
18
- end
8
+ subject(:modifier) { described_class.new({}) }
19
9
 
20
10
  describe '.new' do
11
+ it { expect(described_class.ancestors).to(include(DefMastership::Modifier)) }
21
12
  it { is_expected.not_to(be_nil) }
22
- it { is_expected.to(have_attributes(config: { ref_document: 'ref.adoc' })) }
23
- it { is_expected.to(have_attributes(changes: [])) }
13
+ it { is_expected.to(have_attributes(def_type: '')) }
14
+ it { is_expected.to(have_attributes(ref_document: [])) }
15
+ it { is_expected.to(have_attributes(first_version: '')) }
16
+ end
17
+
18
+ describe '.replacement_methods' do
19
+ it { expect(described_class.replacement_methods).to(eq(%i[replace_reference])) }
24
20
  end
25
21
 
26
22
  describe '#do_modifications' do
27
- let(:line_modifier) { instance_double(DefMastership::UpdateDefVersionLineModifier, 'lineModifier') }
28
- let(:document) { instance_double(DefMastership::Document, 'document') }
29
- let(:ref_document) { instance_double(DefMastership::Document, 'ref_document') }
23
+ context 'when only one ref document' do
24
+ subject(:modifier) do
25
+ described_class.new(
26
+ ref_document: 'ref_doc.adoc',
27
+ def_type: 'req',
28
+ first_version: 'a'
29
+ )
30
+ end
30
31
 
31
- before do
32
- allow(DefMastership::UpdateDefVersionLineModifier).to(
33
- receive(:from_config).with({ ref_document: 'ref.adoc' }).and_return(line_modifier)
34
- )
35
- allow(DefMastership::Document).to(receive(:new).and_return(document, ref_document))
36
- allow(document).to(receive(:parse_file_with_preprocessor))
37
- allow(ref_document).to(receive(:parse_file_with_preprocessor))
38
- allow(line_modifier).to(receive(:'document=').with(document))
39
- allow(line_modifier).to(receive(:'ref_document=').with(ref_document))
40
- allow(line_modifier).to(receive(:replace).with("file1 line1\n").and_return("new file1 line1\n"))
41
- allow(line_modifier).to(receive(:replace).with('file1 line2').and_return('new file1 line2'))
42
- allow(line_modifier).to(receive(:replace).with("file2 line1\n").and_return("new file2 line1\n"))
43
- allow(line_modifier).to(receive(:replace).with('file2 line2').and_return('new file2 line2'))
44
- allow(line_modifier).to(receive(:config).and_return(ref_document: 'ref.adoc'))
45
- allow(line_modifier).to(receive(:changes).and_return([%w[from1 to1], %w[from2 to2]]))
32
+ let(:document) { instance_double(DefMastership::Document, 'document') }
33
+ let(:ref_document) { instance_double(DefMastership::Document, 'ref_document') }
34
+ let(:definition) { instance_double(DefMastership::Definition, 'definition') }
35
+ let(:ref_definition) { instance_double(DefMastership::Definition, 'ref_definitions') }
36
+ let(:adoc_sources) do
37
+ {
38
+ 'file1.adoc' => "[define,req,REFERENCE]\nfile1 line2",
39
+ 'file2.adoc' => "file2 line1\nfile2 line2"
40
+ }
41
+ end
42
+
43
+ before do
44
+ allow(DefMastership::Document).to(receive(:new).twice.and_return(ref_document, 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
+ allow(ref_document).to(receive(:parse_file_with_preprocessor).with('ref_doc.adoc'))
48
+ allow(document).to(receive(:ref_to_def).with('REFERENCE').and_return(definition))
49
+ allow(ref_document).to(receive(:ref_to_def).with('REFERENCE').and_return(ref_definition))
50
+ allow(ref_definition).to(receive(:explicit_version).with(no_args).and_return(nil))
51
+ allow(definition).to(receive(:sha256_short).with(no_args).and_return('something'))
52
+ allow(ref_definition).to(receive(:sha256_short).with(no_args).and_return('something_else'))
53
+
54
+ modifier.do_modifications(adoc_sources)
55
+ end
56
+
57
+ it { is_expected.to(have_attributes(ref_document: ['ref_doc.adoc'])) }
58
+ it { expect(DefMastership::Document).to(have_received(:new).twice) }
59
+ it { expect(document).to(have_received(:parse_file_with_preprocessor).twice) }
60
+ it { expect(ref_document).to(have_received(:parse_file_with_preprocessor).with('ref_doc.adoc')) }
61
+
62
+ it do
63
+ expect(modifier.do_modifications(adoc_sources).fetch('file1.adoc')).to(include('REFERENCE(a)'))
64
+ end
65
+ end
66
+
67
+ context 'when more ref document' do
68
+ subject(:modifier) do
69
+ described_class.new(
70
+ ref_document: ['ref_doc1.adoc', 'ref_doc2.adoc'],
71
+ def_type: 'req',
72
+ first_version: 'a'
73
+ )
74
+ end
75
+
76
+ let(:document) { instance_double(DefMastership::Document, 'document') }
77
+ let(:ref_document) { instance_double(DefMastership::Document, 'ref_document') }
78
+ let(:definition) { instance_double(DefMastership::Definition, 'definition') }
79
+ let(:ref_definition) { instance_double(DefMastership::Definition, 'ref_definitions') }
80
+ let(:adoc_sources) do
81
+ {
82
+ 'file1.adoc' => "[define,req,REFERENCE]\nfile1 line2",
83
+ 'file2.adoc' => "file2 line1\nfile2 line2"
84
+ }
85
+ end
86
+
87
+ before do
88
+ allow(DefMastership::Document).to(receive(:new).twice.and_return(ref_document, document))
89
+ allow(document).to(receive(:parse_file_with_preprocessor).with('file1.adoc'))
90
+ allow(document).to(receive(:parse_file_with_preprocessor).with('file2.adoc'))
91
+ allow(ref_document).to(receive(:parse_file_with_preprocessor).with('ref_doc1.adoc'))
92
+ allow(ref_document).to(receive(:parse_file_with_preprocessor).with('ref_doc2.adoc'))
93
+ allow(document).to(receive(:ref_to_def).with('REFERENCE').and_return(definition))
94
+ allow(ref_document).to(receive(:ref_to_def).with('REFERENCE').and_return(ref_definition))
95
+ allow(ref_definition).to(receive(:explicit_version).with(no_args).and_return(nil))
96
+ allow(definition).to(receive(:sha256_short).with(no_args).and_return('something'))
97
+ allow(ref_definition).to(receive(:sha256_short).with(no_args).and_return('something_else'))
98
+
99
+ modifier.do_modifications(adoc_sources)
100
+ end
101
+
102
+ it { expect(DefMastership::Document).to(have_received(:new).twice) }
103
+ it { expect(document).to(have_received(:parse_file_with_preprocessor).twice) }
104
+ it { expect(ref_document).to(have_received(:parse_file_with_preprocessor).with('ref_doc1.adoc')) }
105
+ it { expect(ref_document).to(have_received(:parse_file_with_preprocessor).with('ref_doc2.adoc')) }
46
106
  end
47
107
 
48
- context 'when detailed expectations' do
49
- before { modifier.do_modifications(adoc_texts) }
108
+ context 'when ref_tag is provided' do
109
+ subject(:modifier) do
110
+ described_class.new(
111
+ ref_tag: 'THE_TAG',
112
+ def_type: 'req',
113
+ first_version: 'a'
114
+ )
115
+ end
116
+
117
+ let(:document) { instance_double(DefMastership::Document, 'document') }
118
+ let(:ref_document) { instance_double(DefMastership::Document, 'ref_document') }
119
+ let(:definition) { instance_double(DefMastership::Definition, 'definition') }
120
+ let(:ref_definition) { instance_double(DefMastership::Definition, 'ref_definitions') }
121
+ let(:adoc_sources) do
122
+ {
123
+ 'file1.adoc' => "[define,req,REFERENCE]\nfile1 line2",
124
+ 'file2.adoc' => "file2 line1\nfile2 line2"
125
+ }
126
+ end
127
+
128
+ before do
129
+ allow(Dir).to(receive(:mktmpdir).and_yield('tmp'))
130
+ allow(Git).to(receive(:clone))
131
+ allow(DefMastership::Document).to(receive(:new).twice.and_return(ref_document, document))
132
+ allow(document).to(receive(:parse_file_with_preprocessor).with('file1.adoc'))
133
+ allow(document).to(receive(:parse_file_with_preprocessor).with('file2.adoc'))
134
+ allow(ref_document).to(receive(:parse_file_with_preprocessor).with('tmp/file1.adoc'))
135
+ allow(ref_document).to(receive(:parse_file_with_preprocessor).with('tmp/file2.adoc'))
136
+ allow(document).to(receive(:ref_to_def).with('REFERENCE').and_return(definition))
137
+ allow(ref_document).to(receive(:ref_to_def).with('REFERENCE').and_return(ref_definition))
138
+ allow(ref_definition).to(receive(:explicit_version).with(no_args).and_return(nil))
139
+ allow(definition).to(receive(:sha256_short).with(no_args).and_return('something'))
140
+ allow(ref_definition).to(receive(:sha256_short).with(no_args).and_return('something_else'))
141
+
142
+ modifier.do_modifications(adoc_sources)
143
+ end
144
+
145
+ it { expect(Dir).to(have_received(:mktmpdir).with('defmastership')) }
146
+ it { expect(Git).to(have_received(:clone).with('.', 'tmp', branch: 'THE_TAG')) }
147
+ it { expect(DefMastership::Document).to(have_received(:new).twice) }
148
+ it { expect(ref_document).to(have_received(:parse_file_with_preprocessor).with('tmp/file1.adoc')) }
149
+ it { expect(ref_document).to(have_received(:parse_file_with_preprocessor).with('tmp/file2.adoc')) }
150
+ it { expect(ref_document).to(have_received(:parse_file_with_preprocessor).twice) }
151
+
152
+ it do
153
+ expect(modifier.do_modifications(adoc_sources).fetch('file1.adoc')).to(include('REFERENCE(a)'))
154
+ end
155
+ end
156
+
157
+ context 'when ref_tag and ref_repo is provided' do
158
+ subject(:modifier) do
159
+ described_class.new(
160
+ ref_tag: 'THE_TAG',
161
+ ref_repo: 'not dot',
162
+ def_type: 'req',
163
+ first_version: 'a'
164
+ )
165
+ end
166
+
167
+ let(:document) { instance_double(DefMastership::Document, 'document') }
168
+ let(:ref_document) { instance_double(DefMastership::Document, 'ref_document') }
169
+ let(:definition) { instance_double(DefMastership::Definition, 'definition') }
170
+ let(:ref_definition) { instance_double(DefMastership::Definition, 'ref_definitions') }
171
+ let(:adoc_sources) do
172
+ {
173
+ 'file1.adoc' => "[define,req,REFERENCE]\nfile1 line2",
174
+ 'file2.adoc' => "file2 line1\nfile2 line2"
175
+ }
176
+ end
177
+
178
+ before do
179
+ allow(Dir).to(receive(:mktmpdir).and_yield('tmp'))
180
+ allow(Git).to(receive(:clone))
181
+ allow(DefMastership::Document).to(receive(:new).twice.and_return(ref_document, document))
182
+ allow(document).to(receive(:parse_file_with_preprocessor).with('file1.adoc'))
183
+ allow(document).to(receive(:parse_file_with_preprocessor).with('file2.adoc'))
184
+ allow(ref_document).to(receive(:parse_file_with_preprocessor).with('tmp/file1.adoc'))
185
+ allow(ref_document).to(receive(:parse_file_with_preprocessor).with('tmp/file2.adoc'))
186
+ allow(document).to(receive(:ref_to_def).with('REFERENCE').and_return(definition))
187
+ allow(ref_document).to(receive(:ref_to_def).with('REFERENCE').and_return(ref_definition))
188
+ allow(ref_definition).to(receive(:explicit_version).with(no_args).and_return(nil))
189
+ allow(definition).to(receive(:sha256_short).with(no_args).and_return('something'))
190
+ allow(ref_definition).to(receive(:sha256_short).with(no_args).and_return('something_else'))
191
+
192
+ modifier.do_modifications(adoc_sources)
193
+ end
194
+
195
+ it { expect(Dir).to(have_received(:mktmpdir).with('defmastership')) }
196
+ it { expect(Git).to(have_received(:clone).with('not dot', 'tmp', branch: 'THE_TAG')) }
197
+ it { expect(DefMastership::Document).to(have_received(:new).twice) }
198
+ it { expect(ref_document).to(have_received(:parse_file_with_preprocessor).with('tmp/file1.adoc')) }
199
+ it { expect(ref_document).to(have_received(:parse_file_with_preprocessor).with('tmp/file2.adoc')) }
200
+ it { expect(ref_document).to(have_received(:parse_file_with_preprocessor).twice) }
50
201
 
51
202
  it do
52
- expect(DefMastership::UpdateDefVersionLineModifier).to(
53
- have_received(:from_config).with({ ref_document: 'ref.adoc' })
203
+ expect(modifier.do_modifications(adoc_sources).fetch('file1.adoc')).to(include('REFERENCE(a)'))
204
+ end
205
+ end
206
+
207
+ context 'when both ref_tag and ref_document are provided' do
208
+ subject(:modifier) do
209
+ described_class.new(
210
+ ref_tag: 'THE_TAG',
211
+ ref_document: './another/doc.adoc',
212
+ def_type: 'req',
213
+ first_version: 'a'
54
214
  )
55
215
  end
56
216
 
57
- it { expect(document).to(have_received(:parse_file_with_preprocessor).with('file1.adoc')) }
58
- it { expect(document).to(have_received(:parse_file_with_preprocessor).with('file2.adoc')) }
59
- it { expect(ref_document).to(have_received(:parse_file_with_preprocessor).with('ref.adoc')) }
60
- it { expect(line_modifier).to(have_received(:'document=').with(document)) }
61
- it { expect(line_modifier).to(have_received(:'ref_document=').with(ref_document)) }
62
- it { expect(line_modifier).to(have_received(:replace).with("file1 line1\n")) }
63
- it { expect(line_modifier).to(have_received(:replace).with('file1 line2')) }
64
- it { expect(line_modifier).to(have_received(:replace).with("file2 line1\n")) }
65
- it { expect(line_modifier).to(have_received(:replace).with('file2 line2')) }
66
- it { expect(line_modifier).to(have_received(:config)) }
67
- it { expect(line_modifier).to(have_received(:changes)) }
68
- it { is_expected.to(have_attributes(config: { ref_document: 'ref.adoc' })) }
69
- it { is_expected.to(have_attributes(changes: [%w[from1 to1], %w[from2 to2]])) }
217
+ let(:document) { instance_double(DefMastership::Document, 'document') }
218
+ let(:ref_document) { instance_double(DefMastership::Document, 'ref_document') }
219
+ let(:definition) { instance_double(DefMastership::Definition, 'definition') }
220
+ let(:ref_definition) { instance_double(DefMastership::Definition, 'ref_definitions') }
221
+ let(:adoc_sources) do
222
+ {
223
+ 'file1.adoc' => "[define,req,REFERENCE]\nfile1 line2",
224
+ 'file2.adoc' => "file2 line1\nfile2 line2"
225
+ }
226
+ end
227
+
228
+ before do
229
+ allow(Dir).to(receive(:mktmpdir).and_yield('tmp'))
230
+ allow(Git).to(receive(:clone))
231
+ allow(DefMastership::Document).to(receive(:new).twice.and_return(ref_document, document))
232
+ allow(document).to(receive(:parse_file_with_preprocessor).with('file1.adoc'))
233
+ allow(document).to(receive(:parse_file_with_preprocessor).with('file2.adoc'))
234
+ allow(ref_document).to(receive(:parse_file_with_preprocessor))
235
+ allow(document).to(receive(:ref_to_def).with('REFERENCE').and_return(definition))
236
+ allow(ref_document).to(receive(:ref_to_def).with('REFERENCE').and_return(ref_definition))
237
+ allow(ref_definition).to(receive(:explicit_version).with(no_args).and_return(nil))
238
+ allow(definition).to(receive(:sha256_short).with(no_args).and_return('something'))
239
+ allow(ref_definition).to(receive(:sha256_short).with(no_args).and_return('something_else'))
240
+
241
+ modifier.do_modifications(adoc_sources)
242
+ end
243
+
244
+ it { expect(Dir).to(have_received(:mktmpdir).with('defmastership')) }
245
+ it { expect(Git).to(have_received(:clone).with('.', 'tmp', branch: 'THE_TAG')) }
246
+ it { expect(DefMastership::Document).to(have_received(:new).twice) }
247
+ it { expect(ref_document).to(have_received(:parse_file_with_preprocessor).with('tmp/./another/doc.adoc')) }
248
+ it { expect(ref_document).to(have_received(:parse_file_with_preprocessor).once) }
249
+
250
+ it do
251
+ expect(modifier.do_modifications(adoc_sources).fetch('file1.adoc')).to(include('REFERENCE(a)'))
252
+ end
253
+ end
254
+ end
255
+
256
+ describe '#replace_reference' do
257
+ subject(:modifier) do
258
+ described_class.new(
259
+ def_type: 'requirement',
260
+ first_version: 'a'
261
+ )
262
+ end
263
+
264
+ let(:document) { instance_double(DefMastership::Document, 'document') }
265
+ let(:ref_document) { instance_double(DefMastership::Document, 'ref_document') }
266
+ let(:definition) { instance_double(DefMastership::Definition, 'definition') }
267
+ let(:ref_definition) { instance_double(DefMastership::Definition, 'ref_definitions') }
268
+
269
+ before do
270
+ allow(File).to(receive(:rename))
271
+ allow(DefMastership::Document).to(receive(:new).with(no_args).and_return(ref_document, document))
70
272
  end
71
273
 
72
- it do
73
- expected_adoc = {
74
- 'file1.adoc' => "new file1 line1\nnew file1 line2",
75
- 'file2.adoc' => "new file2 line1\nnew file2 line2"
76
- }
77
- expect(modifier.do_modifications(adoc_texts)).to(eq(expected_adoc))
274
+ context 'when definition has not the good type' do
275
+ it do
276
+ expect(modifier.replace_reference('[define,req,REFERENCE]'))
277
+ .to(eq('[define,req,REFERENCE]'))
278
+ end
279
+ end
280
+
281
+ context 'when definition has the good type' do
282
+ before do
283
+ allow(document).to(receive(:ref_to_def).with('REFERENCE').and_return(definition))
284
+ allow(definition).to(receive(:sha256_short).and_return('~abcd1234'))
285
+ end
286
+
287
+ context 'when definition has NOT changed' do
288
+ before do
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'))
291
+ end
292
+
293
+ it do
294
+ allow(ref_definition).to(receive(:explicit_version).and_return(nil))
295
+ expect(modifier.replace_reference('[define,requirement,REFERENCE]'))
296
+ .to(eq('[define,requirement,REFERENCE]'))
297
+ end
298
+
299
+ it do
300
+ allow(ref_definition).to(receive(:explicit_version).and_return('c'))
301
+ expect(modifier.replace_reference('[define,requirement,REFERENCE]'))
302
+ .to(eq('[define,requirement,REFERENCE(c)]'))
303
+ end
304
+
305
+ it do
306
+ allow(ref_definition).to(receive(:explicit_version).and_return('c'))
307
+ expect(modifier.replace_reference('[define,requirement,REFERENCE(tyty~1234)]'))
308
+ .to(eq('[define,requirement,REFERENCE(c~1234)]'))
309
+ end
310
+ end
311
+
312
+ context 'when definition has changed' do
313
+ before do
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'))
316
+ end
317
+
318
+ [
319
+ [nil, '', '(a)'],
320
+ ['c', '', '(d)'],
321
+ ['c', '(tyty~1234)', '(d~1234)'],
322
+ ['2', '', '(3)'],
323
+ ['1222', '', '(1223)'],
324
+ ['abb', '', '(abc)']
325
+ ].each do |ref, from, to|
326
+ it do
327
+ allow(ref_definition).to(receive(:explicit_version).and_return(ref))
328
+ expect(modifier.replace_reference("[define,requirement,REFERENCE#{from}]"))
329
+ .to(eq("[define,requirement,REFERENCE#{to}]"))
330
+ end
331
+ end
332
+ end
333
+
334
+ context 'when definition is new' do
335
+ before do
336
+ allow(ref_document).to(receive(:ref_to_def).with('REFERENCE').and_return(nil))
337
+ end
338
+
339
+ it do
340
+ expect(modifier.replace_reference('[define,requirement,REFERENCE(whatever)]'))
341
+ .to(eq('[define,requirement,REFERENCE]'))
342
+ end
343
+
344
+ it do
345
+ expect(modifier.replace_reference('[define,requirement,REFERENCE(~1234)]'))
346
+ .to(eq('[define,requirement,REFERENCE(~1234)]'))
347
+ end
348
+ end
78
349
  end
79
350
  end
80
351
  end
@@ -0,0 +1,74 @@
1
+ # Copyright (c) 2023 Jerome Arbez-Gindre
2
+ # frozen_string_literal: true
3
+
4
+ # rubocop:disable Metrics/BlockLength
5
+ namespace 'quality' do
6
+ begin
7
+ require('rubocop/rake_task')
8
+
9
+ RuboCop::RakeTask.new do |task|
10
+ task.options << '--display-cop-names'
11
+ task.options << '--config=config/rubocop.yml'
12
+ end
13
+ rescue LoadError
14
+ task(:rubocop) do
15
+ puts('Install rubocop to run its rake tasks')
16
+ end
17
+ end
18
+
19
+ begin
20
+ require('reek/rake/task')
21
+
22
+ Reek::Rake::Task.new do |task|
23
+ task.fail_on_error = true
24
+ task.source_files = '{lib,spec}/**/*.rb'
25
+ task.reek_opts = '--config config/reek.yml --single-line'
26
+ end
27
+ rescue LoadError
28
+ task(:reek) do
29
+ puts('Install reek to run its rake tasks')
30
+ end
31
+ end
32
+
33
+ begin
34
+ require('flay_task')
35
+
36
+ FlayTask.new(:flay, 200, %w[bin lib]) do |task|
37
+ task.verbose = true
38
+ end
39
+ rescue LoadError
40
+ task(:flay) do
41
+ puts('Install flay to run its rake tasks')
42
+ end
43
+ end
44
+
45
+ begin
46
+ require('rubycritic/rake_task')
47
+
48
+ RubyCritic::RakeTask.new do |task|
49
+ task.verbose = true
50
+ task.options = '--no-browser'
51
+ end
52
+ rescue LoadError
53
+ task(:rubycritic) do
54
+ puts('Install rubycritic to run its rake tasks')
55
+ end
56
+ end
57
+
58
+ desc 'Runs all quality code check'
59
+ task(
60
+ all: [
61
+ 'quality:rubocop',
62
+ 'quality:reek',
63
+ 'quality:flay',
64
+ 'quality:rubycritic'
65
+ ]
66
+ )
67
+ end
68
+ # rubocop:enable Metrics/BlockLength
69
+
70
+ desc 'Synonym for quality:rubocop'
71
+ task(rubocop: 'quality:rubocop')
72
+
73
+ desc 'Synonym for quality:reek'
74
+ task(reek: 'quality:reek')
@@ -0,0 +1,8 @@
1
+ # Copyright (c) 2023 Jerome Arbez-Gindre
2
+ # frozen_string_literal: true
3
+
4
+ desc 'Starts the interactive console'
5
+ task :console do
6
+ require 'pry'
7
+ Pry.start
8
+ end
@@ -0,0 +1,9 @@
1
+ # Copyright (c) 2023 Jerome Arbez-Gindre
2
+ # frozen_string_literal: true
3
+
4
+ require('rubygems')
5
+ require('rubygems/package_task')
6
+
7
+ spec = eval(File.read('defmastership.gemspec'))
8
+
9
+ Gem::PackageTask.new(spec)
data/tasks/test.rake ADDED
@@ -0,0 +1,30 @@
1
+ # Copyright (c) 2023 Jerome Arbez-Gindre
2
+ # frozen_string_literal: true
3
+
4
+ require('cucumber/rake/task')
5
+ require('rspec/core/rake_task')
6
+
7
+ namespace 'test' do
8
+ RSpec::Core::RakeTask.new(:spec) do |t|
9
+ t.rspec_opts = ['--options config/rspec']
10
+ end
11
+
12
+ CLEAN << 'features_results.html'
13
+
14
+ Cucumber::Rake::Task.new(:features)
15
+ Cucumber::Rake::Task.new('features:wip') do |t|
16
+ t.cucumber_opts = ['--profile wip']
17
+ end
18
+
19
+ desc 'Runs all unit tests and acceptance tests'
20
+ task(all: ['test:spec', 'test:features'])
21
+ end
22
+
23
+ desc 'Synonym for test:spec'
24
+ task(spec: 'test:spec')
25
+
26
+ desc 'Synonym for test:all'
27
+ task(test: 'test:all')
28
+
29
+ desc('Test all features')
30
+ task(cucumber: 'test:features')