defmastership 1.0.3 → 1.0.8

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.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/.gitlab-ci.yml +0 -1
  4. data/.rubocop.yml +3 -2
  5. data/Gemfile +1 -0
  6. data/LICENSE +22 -0
  7. data/Rakefile +2 -2
  8. data/bin/defmastership +37 -24
  9. data/cucumber.yml +2 -0
  10. data/defmastership.gemspec +16 -9
  11. data/features/changeref.feature +82 -129
  12. data/features/definition_checksum.feature +244 -0
  13. data/features/definition_version.feature +24 -0
  14. data/features/export.feature +49 -31
  15. data/features/modify.feature +165 -0
  16. data/features/rename_included_files.feature +121 -0
  17. data/features/step_definitions/defmastership_steps.rb +1 -0
  18. data/features/support/env.rb +1 -0
  19. data/lib/defmastership.rb +15 -3
  20. data/lib/defmastership/batch_modifier.rb +35 -0
  21. data/lib/defmastership/{ref_changer.rb → change_ref_line_modifier.rb} +19 -35
  22. data/lib/defmastership/change_ref_modifier.rb +15 -0
  23. data/lib/defmastership/comment_filter.rb +1 -0
  24. data/lib/defmastership/constants.rb +15 -1
  25. data/lib/defmastership/csv_formatter.rb +26 -19
  26. data/lib/defmastership/csv_formatter_body.rb +20 -11
  27. data/lib/defmastership/csv_formatter_header.rb +16 -10
  28. data/lib/defmastership/definition.rb +15 -3
  29. data/lib/defmastership/definition_parser.rb +46 -0
  30. data/lib/defmastership/document.rb +60 -85
  31. data/lib/defmastership/filters.rb +30 -0
  32. data/lib/defmastership/line_modifier_base.rb +29 -0
  33. data/lib/defmastership/modifier_base.rb +29 -0
  34. data/lib/defmastership/rename_included_files_line_modifier.rb +126 -0
  35. data/lib/defmastership/rename_included_files_modifier.rb +15 -0
  36. data/lib/defmastership/update_def_checksum_line_modifier.rb +39 -0
  37. data/lib/defmastership/update_def_checksum_modifier.rb +21 -0
  38. data/lib/defmastership/version.rb +2 -1
  39. data/spec/spec_helper.rb +2 -0
  40. data/spec/unit/defmastership/batch_modifier_spec.rb +123 -0
  41. data/spec/unit/defmastership/{ref_changer_spec.rb → change_ref_line_modifier_spec.rb} +49 -26
  42. data/spec/unit/defmastership/change_ref_modifier_spec.rb +76 -0
  43. data/spec/unit/defmastership/comment_filter_spec.rb +9 -4
  44. data/spec/unit/defmastership/csv_formatter_body_spec.rb +89 -82
  45. data/spec/unit/defmastership/csv_formatter_header_spec.rb +69 -22
  46. data/spec/unit/defmastership/csv_formatter_spec.rb +209 -110
  47. data/spec/unit/defmastership/definition_parser_spec.rb +63 -0
  48. data/spec/unit/defmastership/definition_spec.rb +46 -4
  49. data/spec/unit/defmastership/document_spec.rb +237 -35
  50. data/spec/unit/defmastership/rename_included_files_line_modifier_spec.rb +203 -0
  51. data/spec/unit/defmastership/rename_included_files_modifier_spec.rb +67 -0
  52. data/spec/unit/defmastership/update_def_checksum_line_modifier_spec.rb +68 -0
  53. data/spec/unit/defmastership/update_def_checksum_modifier_spec.rb +75 -0
  54. data/spec/unit/defmastership_spec.rb +1 -0
  55. metadata +49 -17
  56. data/Gemfile.lock +0 -140
  57. data/lib/defmastership/batch_changer.rb +0 -40
  58. data/lib/defmastership/project_ref_changer.rb +0 -27
  59. data/spec/unit/defmastership/batch_changer_spec.rb +0 -108
  60. data/spec/unit/defmastership/project_ref_changer_spec.rb +0 -79
@@ -1,10 +1,12 @@
1
+ # Copyright (c) 2020 Jerome Arbez-Gindre
1
2
  # frozen_string_literal: true
2
3
 
3
4
  require('defmastership')
4
5
  require('ostruct')
6
+ require('csv')
5
7
 
6
8
  RSpec.describe(DefMastership::CSVFormatter) do
7
- subject(:formatter) { described_class.new(document) }
9
+ subject(:formatter) { described_class.new(document, ';') }
8
10
 
9
11
  let(:document) { instance_double(DefMastership::Document, 'document') }
10
12
 
@@ -12,160 +14,257 @@ RSpec.describe(DefMastership::CSVFormatter) do
12
14
  it { is_expected.not_to(be(nil)) }
13
15
  end
14
16
 
15
- describe '#header' do
16
- context 'when minimal' do
17
+ describe '#export_to' do
18
+ let(:header) { instance_double(DefMastership::CSVFormatterHeader, 'header') }
19
+ let(:body) { instance_double(DefMastership::CSVFormatterBody, 'body') }
20
+ let(:csv) { instance_double(CSV, 'csv') }
21
+
22
+ before do
23
+ allow(CSV).to(receive(:open).and_yield(csv))
24
+ allow(csv).to(receive(:<<))
25
+ allow(DefMastership::CSVFormatterHeader).to(receive(:new).with(document).and_return(header))
26
+ allow(DefMastership::CSVFormatterBody).to(receive(:new).with(document).and_return(body))
27
+ allow(document).to(receive(:definitions).and_return(%i[def1 def2]))
28
+ allow(document).to(receive(:wrong_explicit_checksum?).with(no_args).and_return(false))
29
+ allow(document).to(receive(:explicit_version?).with(no_args).and_return(false))
30
+ allow(document).to(receive(:labels).with(no_args).and_return([]))
31
+ allow(document).to(receive(:eref).with(no_args).and_return([]))
32
+ allow(document).to(receive(:iref).with(no_args).and_return(false))
33
+ allow(document).to(receive(:attributes).with(no_args).and_return([]))
34
+ end
35
+
36
+ context 'when no variable columns' do
37
+ methods = %i[fixed]
38
+
17
39
  before do
18
- allow(document).to(receive(:labels).with(no_args).and_return([]))
19
- allow(document).to(receive(:eref).with(no_args).and_return({}))
20
- allow(document).to(receive(:iref).with(no_args).and_return(false))
21
- allow(document).to(receive(:attributes).with(no_args).and_return({}))
22
- formatter.header
40
+ methods.each do |method|
41
+ allow(header).to(receive(method).with(no_args).and_return(["#{method} header"]))
42
+ allow(body).to(receive(method).with(:def1).and_return(["#{method} def1 body"]))
43
+ allow(body).to(receive(method).with(:def2).and_return(["#{method} def2 body"]))
44
+ end
45
+ formatter.export_to('whatever')
46
+ end
47
+
48
+ methods.each do |method|
49
+ it { expect(header).to(have_received(method).with(no_args)) }
50
+ it { expect(body).to(have_received(method).with(:def1)) }
51
+ it { expect(body).to(have_received(method).with(:def2)) }
23
52
  end
24
53
 
25
- it { expect(document).to(have_received(:labels).with(no_args)) }
54
+ it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} header" })) }
55
+ 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
+ end
26
58
 
27
- it { expect(document).to(have_received(:eref).with(no_args)) }
59
+ context 'when wrong_explicit_checksum' do
60
+ methods = %i[fixed wrong_explicit_checksum]
28
61
 
29
- it { expect(document).to(have_received(:iref).with(no_args)) }
62
+ before do
63
+ methods.each do |method|
64
+ allow(header).to(receive(method).with(no_args).and_return(["#{method} header"]))
65
+ allow(body).to(receive(method).with(:def1).and_return(["#{method} def1 body"]))
66
+ allow(body).to(receive(method).with(:def2).and_return(["#{method} def2 body"]))
67
+ end
68
+ allow(document).to(receive(:wrong_explicit_checksum?).with(no_args).and_return(true))
69
+ formatter.export_to('whatever')
70
+ end
30
71
 
31
- it { expect(document).to(have_received(:attributes).with(no_args)) }
72
+ methods.each do |method|
73
+ it { expect(header).to(have_received(method).with(no_args)) }
74
+ it { expect(body).to(have_received(method).with(:def1)) }
75
+ it { expect(body).to(have_received(method).with(:def2)) }
76
+ end
32
77
 
33
- it { expect(formatter.header).to(eq(%w[Type Reference Value])) }
78
+ it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} header" })) }
79
+ 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" })) }
34
81
  end
35
82
 
36
- context 'when has everything' do
83
+ context 'when explicit_version' do
84
+ methods = %i[fixed explicit_version]
85
+
37
86
  before do
38
- allow(document).to(receive(:labels)
39
- .with(no_args)
40
- .and_return(['Whatever']))
41
- allow(document).to(receive(:eref)
42
- .with(no_args)
43
- .and_return(whatever: { prefix: 'A' },
44
- other: { prefix: 'C', url: 'D' }))
45
- allow(document).to(receive(:iref).with(no_args).and_return(true))
46
- allow(document).to(receive(:attributes)
47
- .with(no_args)
48
- .and_return(whatever: 'E', other: 'F'))
87
+ methods.each do |method|
88
+ allow(header).to(receive(method).with(no_args).and_return(["#{method} header"]))
89
+ allow(body).to(receive(method).with(:def1).and_return(["#{method} def1 body"]))
90
+ allow(body).to(receive(method).with(:def2).and_return(["#{method} def2 body"]))
91
+ end
92
+ allow(document).to(receive(:explicit_version?).with(no_args).and_return(true))
93
+ formatter.export_to('whatever')
49
94
  end
50
95
 
51
- it do
52
- expect(formatter.header).to(eq(%w[Type Reference Value Labels] +
53
- ['A', 'C D', 'Internal links'] +
54
- %w[E F]))
96
+ methods.each do |method|
97
+ it { expect(header).to(have_received(method).with(no_args)) }
98
+ it { expect(body).to(have_received(method).with(:def1)) }
99
+ it { expect(body).to(have_received(method).with(:def2)) }
55
100
  end
101
+
102
+ it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} header" })) }
103
+ 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" })) }
56
105
  end
57
- end
58
106
 
59
- describe '#body' do
60
- let(:definition) { instance_double(DefMastership::Definition, 'definition') }
107
+ context 'when labels' do
108
+ methods = %i[fixed labels]
61
109
 
62
- context 'when minimal' do
63
110
  before do
64
- allow(document).to(receive(:labels).with(no_args).and_return([]))
65
- allow(document).to(receive(:eref).with(no_args).and_return({}))
66
- allow(document).to(receive(:iref).with(no_args).and_return(false))
67
- allow(document).to(receive(:attributes).with(no_args).and_return({}))
68
- allow(definition).to(receive(:type).with(no_args).and_return('a'))
69
- allow(definition).to(receive(:reference).with(no_args).and_return('b'))
70
- allow(definition).to(receive(:value).with(no_args).and_return('c'))
71
- formatter.body(definition)
111
+ methods.each do |method|
112
+ allow(header).to(receive(method).with(no_args).and_return(["#{method} header"]))
113
+ allow(body).to(receive(method).with(:def1).and_return(["#{method} def1 body"]))
114
+ allow(body).to(receive(method).with(:def2).and_return(["#{method} def2 body"]))
115
+ end
116
+ allow(document).to(receive(:labels).with(no_args).and_return([:whatever]))
117
+ formatter.export_to('whatever')
72
118
  end
73
119
 
74
- it { expect(document).to(have_received(:labels).with(no_args)) }
75
-
76
- it { expect(document).to(have_received(:eref).with(no_args)) }
77
-
78
- it { expect(document).to(have_received(:iref).with(no_args)) }
120
+ methods.each do |method|
121
+ it { expect(header).to(have_received(method).with(no_args)) }
122
+ it { expect(body).to(have_received(method).with(:def1)) }
123
+ it { expect(body).to(have_received(method).with(:def2)) }
124
+ end
79
125
 
80
- it { expect(document).to(have_received(:attributes).with(no_args)) }
126
+ it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} header" })) }
127
+ 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
+ end
81
130
 
82
- it { expect(definition).to(have_received(:type).with(no_args)) }
131
+ context 'when eref' do
132
+ methods = %i[fixed eref]
83
133
 
84
- it { expect(definition).to(have_received(:reference).with(no_args)) }
134
+ before do
135
+ methods.each do |method|
136
+ allow(header).to(receive(method).with(no_args).and_return(["#{method} header"]))
137
+ allow(body).to(receive(method).with(:def1).and_return(["#{method} def1 body"]))
138
+ allow(body).to(receive(method).with(:def2).and_return(["#{method} def2 body"]))
139
+ end
140
+ allow(document).to(receive(:eref).with(no_args).and_return([:whatever]))
141
+ formatter.export_to('whatever')
142
+ end
85
143
 
86
- it { expect(definition).to(have_received(:value).with(no_args)) }
144
+ methods.each do |method|
145
+ it { expect(header).to(have_received(method).with(no_args)) }
146
+ it { expect(body).to(have_received(method).with(:def1)) }
147
+ it { expect(body).to(have_received(method).with(:def2)) }
148
+ end
87
149
 
88
- it { expect(formatter.body(definition)).to(eq(%w[a b c])) }
150
+ it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} header" })) }
151
+ 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" })) }
89
153
  end
90
154
 
91
- context 'when has everything' do
155
+ context 'when iref' do
156
+ methods = %i[fixed iref]
157
+
92
158
  before do
93
- allow(document).to(receive(:labels).with(no_args).and_return(['Whatever']))
94
- allow(document).to(receive(:eref).with(no_args).and_return(
95
- a: 'whatever',
96
- b: 'whatever',
97
- c: 'whatever'
98
- ))
159
+ methods.each do |method|
160
+ allow(header).to(receive(method).with(no_args).and_return(["#{method} header"]))
161
+ allow(body).to(receive(method).with(:def1).and_return(["#{method} def1 body"]))
162
+ allow(body).to(receive(method).with(:def2).and_return(["#{method} def2 body"]))
163
+ end
99
164
  allow(document).to(receive(:iref).with(no_args).and_return(true))
100
- allow(document).to(receive(:attributes).with(no_args).and_return(
101
- a: 'whatever',
102
- b: 'whatever',
103
- c: 'whatever'
104
- ))
105
- allow(definition).to(receive(:type).with(no_args).and_return('a'))
106
- allow(definition).to(receive(:reference).with(no_args).and_return('b'))
107
- allow(definition).to(receive(:value).with(no_args).and_return('c'))
108
- allow(definition).to(receive(:labels).with(no_args).and_return(%w[toto tutu]))
109
- allow(definition).to(receive(:eref).with(no_args).and_return(a: %w[A B], b: [], c: ['C']))
110
- allow(definition).to(receive(:iref).with(no_args).and_return(%w[E F]))
111
- allow(definition).to(receive(:attributes).with(no_args).and_return(a: 'X', b: '', c: 'Y'))
112
- formatter.body(definition)
165
+ formatter.export_to('whatever')
113
166
  end
114
167
 
115
- it { expect(definition).to(have_received(:labels).with(no_args)) }
168
+ methods.each do |method|
169
+ it { expect(header).to(have_received(method).with(no_args)) }
170
+ it { expect(body).to(have_received(method).with(:def1)) }
171
+ it { expect(body).to(have_received(method).with(:def2)) }
172
+ end
116
173
 
117
- it { expect(definition).to(have_received(:eref).exactly(3).times.with(no_args)) }
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} def1 body" })) }
176
+ it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} def2 body" })) }
177
+ end
118
178
 
119
- it { expect(definition).to(have_received(:iref).with(no_args)) }
179
+ context 'when attributes' do
180
+ methods = %i[fixed attributes]
120
181
 
121
- it { expect(definition).to(have_received(:attributes).exactly(3).times.with(no_args)) }
182
+ before do
183
+ methods.each do |method|
184
+ allow(header).to(receive(method).with(no_args).and_return(["#{method} header"]))
185
+ allow(body).to(receive(method).with(:def1).and_return(["#{method} def1 body"]))
186
+ allow(body).to(receive(method).with(:def2).and_return(["#{method} def2 body"]))
187
+ end
188
+ allow(document).to(receive(:attributes).with(no_args).and_return([:whatever]))
189
+ formatter.export_to('whatever')
190
+ end
122
191
 
123
- it do
124
- expect(formatter.body(definition)).to(eq(%w[a b c] + ["toto\ntutu"] +
125
- ["A\nB", '', 'C'] +
126
- ["E\nF"] +
127
- ['X', '', 'Y']))
192
+ methods.each do |method|
193
+ it { expect(header).to(have_received(method).with(no_args)) }
194
+ it { expect(body).to(have_received(method).with(:def1)) }
195
+ it { expect(body).to(have_received(method).with(:def2)) }
128
196
  end
197
+
198
+ it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} header" })) }
199
+ 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" })) }
129
201
  end
130
- end
131
202
 
132
- describe '#export_to' do
133
- context 'when #export_to csv file' do
134
- let(:target_file) { 'export.csv' }
135
- let(:definitions) do
136
- [
137
- OpenStruct.new(type: 'a', reference: 'b', value: 'c'),
138
- OpenStruct.new(type: 'd', reference: 'e', value: 'f')
139
- ]
140
- end
203
+ context 'when every colums' do
204
+ methods = %i[fixed wrong_explicit_checksum explicit_version labels eref iref attributes]
141
205
 
142
206
  before do
143
- setup_aruba
144
- allow(document).to(receive(:labels).exactly(3).times.with(no_args).and_return([]))
145
- allow(document).to(receive(:eref).exactly(3).times.with(no_args).and_return({}))
146
- allow(document).to(receive(:iref).exactly(3).times.with(no_args).and_return(false))
147
- allow(document).to(receive(:attributes).exactly(3).times.with(no_args).and_return({}))
148
- allow(document).to(receive(:definitions).with(no_args).and_return(definitions))
149
- formatter.export_to("#{aruba.current_directory}/#{target_file}")
207
+ methods.each do |method|
208
+ allow(header).to(receive(method).with(no_args).and_return(["#{method} header"]))
209
+ allow(body).to(receive(method).with(:def1).and_return(["#{method} def1 body"]))
210
+ allow(body).to(receive(method).with(:def2).and_return(["#{method} def2 body"]))
211
+ end
212
+ allow(document).to(receive(:wrong_explicit_checksum?).with(no_args).and_return(true))
213
+ allow(document).to(receive(:explicit_version?).with(no_args).and_return(true))
214
+ allow(document).to(receive(:labels).with(no_args).and_return([:whatever]))
215
+ allow(document).to(receive(:eref).with(no_args).and_return([:whatever]))
216
+ allow(document).to(receive(:iref).with(no_args).and_return(true))
217
+ allow(document).to(receive(:attributes).with(no_args).and_return([:whatever]))
218
+ formatter.export_to('whatever')
150
219
  end
151
220
 
152
- it { expect(document).to(have_received(:labels).exactly(3).times.with(no_args)) }
153
-
154
- it { expect(document).to(have_received(:eref).exactly(3).times.with(no_args)) }
221
+ methods.each do |method|
222
+ it { expect(header).to(have_received(method).with(no_args)) }
223
+ it { expect(body).to(have_received(method).with(:def1)) }
224
+ it { expect(body).to(have_received(method).with(:def2)) }
225
+ end
155
226
 
156
- it { expect(document).to(have_received(:iref).exactly(3).times.with(no_args)) }
227
+ it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} header" })) }
228
+ 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
157
232
 
158
- it { expect(document).to(have_received(:attributes).exactly(3).times.with(no_args)) }
233
+ context 'when #export_to csv file' do
234
+ let(:target_file) { 'export.csv' }
235
+ let(:definitions) do
236
+ [
237
+ OpenStruct.new(type: 'a', reference: 'b', value: 'c', sha256: 'd'),
238
+ OpenStruct.new(type: 'd', reference: 'e', value: 'f', sha256: 'g')
239
+ ]
240
+ end
159
241
 
160
- it { expect(document).to(have_received(:definitions).with(no_args)) }
242
+ before do
243
+ setup_aruba
244
+ allow(document).to(receive(:labels).with(no_args).and_return([]))
245
+ allow(document).to(receive(:eref).with(no_args).and_return({}))
246
+ allow(document).to(receive(:iref).with(no_args).and_return(false))
247
+ allow(document).to(receive(:attributes).with(no_args).and_return({}))
248
+ allow(document).to(receive(:definitions).with(no_args).and_return(definitions))
249
+ allow(document).to(receive(:wrong_explicit_checksum?).with(no_args).and_return(false))
250
+ allow(document).to(receive(:explicit_version?).with(no_args).and_return(false))
251
+ formatter.export_to("#{aruba.current_directory}/#{target_file}")
252
+ end
161
253
 
162
- it do
163
- expect(target_file).to(have_file_content(<<~CSV_FILE))
164
- Type,Reference,Value
165
- a,b,c
166
- d,e,f
167
- CSV_FILE
168
- end
254
+ it { expect(document).to(have_received(:labels).with(no_args)) }
255
+ it { expect(document).to(have_received(:eref).with(no_args)) }
256
+ it { expect(document).to(have_received(:iref).with(no_args)) }
257
+ it { expect(document).to(have_received(:attributes).with(no_args)) }
258
+ it { expect(document).to(have_received(:definitions).with(no_args)) }
259
+ it { expect(document).to(have_received(:wrong_explicit_checksum?).with(no_args)) }
260
+ it { expect(document).to(have_received(:explicit_version?).with(no_args)) }
261
+
262
+ it do
263
+ expect(target_file).to(have_file_content(<<~CSV_FILE))
264
+ Type;Reference;Value;Checksum
265
+ a;b;c;d
266
+ d;e;f;g
267
+ CSV_FILE
169
268
  end
170
269
  end
171
270
  end
@@ -0,0 +1,63 @@
1
+ # Copyright (c) 2020 Jerome Arbez-Gindre
2
+ # frozen_string_literal: true
3
+
4
+ require('defmastership')
5
+
6
+ RSpec.describe(DefMastership::DefinitionParser) do
7
+ subject(:parser) { described_class.new(callback_object) }
8
+
9
+ let(:callback_object) { instance_double('callback_object') }
10
+
11
+ before do
12
+ allow(callback_object).to(receive(:add_new_definition).with(any_args))
13
+ allow(callback_object).to(receive(:add_line).with(any_args))
14
+ end
15
+
16
+ describe 'transitions' do
17
+ it { is_expected.to(have_state(:idle)) }
18
+
19
+ it { is_expected.to(transition_from(:idle).to(:wait_content).on_event(:new_definition, :whatever)) }
20
+
21
+ it { is_expected.to(transition_from(:wait_content).to(:in_block).on_event(:block_delimiter, :whatever)) }
22
+ it { is_expected.to(transition_from(:in_block).to(:idle).on_event(:block_delimiter, :whatever)) }
23
+ it { is_expected.to(transition_from(:idle).to(:idle).on_event(:block_delimiter, :whatever)) }
24
+ it { is_expected.to(transition_from(:single_para).to(:idle).on_event(:block_delimiter, :whatever)) }
25
+
26
+ it { is_expected.to(transition_from(:wait_content).to(:single_para).on_event(:new_line, :whatever)) }
27
+ it { is_expected.to(transition_from(:single_para).to(:single_para).on_event(:new_line, :whatever)) }
28
+ it { is_expected.to(transition_from(:in_block).to(:in_block).on_event(:new_line, :whatever)) }
29
+ it { is_expected.to(transition_from(:idle).to(:idle).on_event(:new_line, :whatever)) }
30
+
31
+ it { is_expected.to(transition_from(:wait_content).to(:idle).on_event(:empty_line, :whatever)) }
32
+ it { is_expected.to(transition_from(:single_para).to(:idle).on_event(:empty_line, :whatever)) }
33
+ it { is_expected.to(transition_from(:idle).to(:idle).on_event(:empty_line, :whatever)) }
34
+ it { is_expected.to(transition_from(:in_block).to(:in_block).on_event(:empty_line, :whatever)) }
35
+ end
36
+
37
+ describe 'actions' do
38
+ it do
39
+ parser.new_definition(:whatever)
40
+ expect(callback_object).to(have_received(:add_new_definition).with(:whatever))
41
+ end
42
+
43
+ it do
44
+ parser.new_definition(:whatever)
45
+ parser.new_line(:other_whatever)
46
+ expect(callback_object).to(have_received(:add_line).with(:other_whatever))
47
+ end
48
+
49
+ it do
50
+ parser.new_definition(:whatever)
51
+ parser.new_line(:other_whatever)
52
+ parser.new_line(:other_whatever2)
53
+ expect(callback_object).to(have_received(:add_line).with(:other_whatever2))
54
+ end
55
+
56
+ it do
57
+ parser.new_definition(:whatever)
58
+ parser.block_delimiter(:other_whatever)
59
+ parser.new_line(:other_whatever2)
60
+ expect(callback_object).to(have_received(:add_line).with(:other_whatever2))
61
+ end
62
+ end
63
+ end
@@ -1,10 +1,11 @@
1
+ # Copyright (c) 2020 Jerome Arbez-Gindre
1
2
  # frozen_string_literal: true
2
3
 
3
4
  require('defmastership')
4
5
 
5
6
  RSpec.describe(DefMastership::Definition) do
6
7
  describe '.new' do
7
- context 'without labels' do
8
+ context 'when minimal' do
8
9
  subject do
9
10
  described_class.new(
10
11
  type: 'req',
@@ -21,12 +22,14 @@ RSpec.describe(DefMastership::Definition) do
21
22
  it { is_expected.to(have_attributes(iref: [])) }
22
23
  it { is_expected.to(have_attributes(attributes: {})) }
23
24
  it { is_expected.to(have_attributes(labels: Set.new)) }
25
+ it { is_expected.to(have_attributes(wrong_explicit_checksum: nil)) }
26
+ it { is_expected.to(have_attributes(explicit_version: nil)) }
24
27
  end
25
28
 
26
29
  context 'with labels' do
27
30
  subject do
28
31
  described_class.new(
29
- gtype: 'req',
32
+ type: 'req',
30
33
  reference: 'TUTU-001',
31
34
  labels: 'something'
32
35
  )
@@ -34,6 +37,40 @@ RSpec.describe(DefMastership::Definition) do
34
37
 
35
38
  it { is_expected.to(have_attributes(labels: Set['something'])) }
36
39
  end
40
+
41
+ context 'with explicit_checksum' do
42
+ subject(:definition) do
43
+ described_class.new(
44
+ type: 'req',
45
+ reference: 'TUTU-001',
46
+ explicit_checksum: '~8cc259e6'
47
+ )
48
+ end
49
+
50
+ it do
51
+ definition << 'def value with a checksum != ~8cc259e6'
52
+ expect(definition).to(have_attributes(wrong_explicit_checksum: '~8cc259e6'))
53
+ end
54
+
55
+ it do
56
+ definition << 'def value with a good checksum'
57
+ expect(definition).to(have_attributes(wrong_explicit_checksum: nil))
58
+ end
59
+ end
60
+
61
+ context 'with explicit_version' do
62
+ subject(:definition) do
63
+ described_class.new(
64
+ type: 'req',
65
+ reference: 'TUTU-001',
66
+ explicit_version: 'pouet'
67
+ )
68
+ end
69
+
70
+ it do
71
+ expect(definition).to(have_attributes(explicit_version: 'pouet'))
72
+ end
73
+ end
37
74
  end
38
75
 
39
76
  describe '#<<' do
@@ -49,7 +86,7 @@ RSpec.describe(DefMastership::Definition) do
49
86
  expect(definition.value).to(eq('first line'))
50
87
  end
51
88
 
52
- it 'store line when added' do
89
+ it 'stores line when added' do
53
90
  definition << 'first line'
54
91
  expect(definition.lines).to(eq(['first line']))
55
92
  end
@@ -59,10 +96,15 @@ RSpec.describe(DefMastership::Definition) do
59
96
  expect(definition.value).to(eq("first line\nsecond line"))
60
97
  end
61
98
 
62
- it 'store each line when added' do
99
+ it 'stores each line when added' do
63
100
  definition << 'first line' << 'second line'
64
101
  expect(definition.lines).to(eq(['first line', 'second line']))
65
102
  end
103
+
104
+ it 'calculates sha256 of value' do
105
+ definition << 'first line' << 'second line'
106
+ expect(definition.sha256).to(eq('~beb0535a'))
107
+ end
66
108
  end
67
109
 
68
110
  describe '#add_eref' do