defmastership 1.0.4 → 1.0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/.gitlab-ci.yml +0 -1
  4. data/.rubocop.yml +1 -1
  5. data/Rakefile +1 -2
  6. data/bin/defmastership +36 -24
  7. data/cucumber.yml +2 -0
  8. data/defmastership.gemspec +14 -8
  9. data/features/changeref.feature +82 -129
  10. data/features/definition_checksum.feature +298 -0
  11. data/features/definition_version.feature +24 -0
  12. data/features/export.feature +49 -31
  13. data/features/modify.feature +165 -0
  14. data/features/rename_included_files.feature +121 -0
  15. data/lib/defmastership.rb +14 -3
  16. data/lib/defmastership/batch_modifier.rb +35 -0
  17. data/lib/defmastership/{ref_changer.rb → change_ref_line_modifier.rb} +18 -35
  18. data/lib/defmastership/change_ref_modifier.rb +15 -0
  19. data/lib/defmastership/constants.rb +14 -1
  20. data/lib/defmastership/csv_formatter.rb +25 -19
  21. data/lib/defmastership/csv_formatter_body.rb +19 -11
  22. data/lib/defmastership/csv_formatter_header.rb +15 -10
  23. data/lib/defmastership/definition.rb +14 -3
  24. data/lib/defmastership/definition_parser.rb +46 -0
  25. data/lib/defmastership/document.rb +59 -85
  26. data/lib/defmastership/filters.rb +30 -0
  27. data/lib/defmastership/line_modifier_base.rb +29 -0
  28. data/lib/defmastership/modifier_base.rb +29 -0
  29. data/lib/defmastership/rename_included_files_line_modifier.rb +126 -0
  30. data/lib/defmastership/rename_included_files_modifier.rb +15 -0
  31. data/lib/defmastership/update_def_checksum_line_modifier.rb +38 -0
  32. data/lib/defmastership/update_def_checksum_modifier.rb +21 -0
  33. data/lib/defmastership/version.rb +1 -1
  34. data/spec/spec_helper.rb +1 -0
  35. data/spec/unit/defmastership/batch_modifier_spec.rb +123 -0
  36. data/spec/unit/defmastership/{ref_changer_spec.rb → change_ref_line_modifier_spec.rb} +48 -26
  37. data/spec/unit/defmastership/change_ref_modifier_spec.rb +76 -0
  38. data/spec/unit/defmastership/comment_filter_spec.rb +8 -4
  39. data/spec/unit/defmastership/csv_formatter_body_spec.rb +88 -82
  40. data/spec/unit/defmastership/csv_formatter_header_spec.rb +68 -22
  41. data/spec/unit/defmastership/csv_formatter_spec.rb +208 -110
  42. data/spec/unit/defmastership/definition_parser_spec.rb +63 -0
  43. data/spec/unit/defmastership/definition_spec.rb +45 -4
  44. data/spec/unit/defmastership/document_spec.rb +236 -35
  45. data/spec/unit/defmastership/rename_included_files_line_modifier_spec.rb +203 -0
  46. data/spec/unit/defmastership/rename_included_files_modifier_spec.rb +67 -0
  47. data/spec/unit/defmastership/update_def_checksum_line_modifier_spec.rb +78 -0
  48. data/spec/unit/defmastership/update_def_checksum_modifier_spec.rb +75 -0
  49. metadata +47 -16
  50. data/Gemfile.lock +0 -140
  51. data/lib/defmastership/batch_changer.rb +0 -41
  52. data/lib/defmastership/project_ref_changer.rb +0 -28
  53. data/spec/unit/defmastership/batch_changer_spec.rb +0 -109
  54. data/spec/unit/defmastership/project_ref_changer_spec.rb +0 -80
@@ -3,9 +3,10 @@
3
3
 
4
4
  require('defmastership')
5
5
  require('ostruct')
6
+ require('csv')
6
7
 
7
8
  RSpec.describe(DefMastership::CSVFormatter) do
8
- subject(:formatter) { described_class.new(document) }
9
+ subject(:formatter) { described_class.new(document, ';') }
9
10
 
10
11
  let(:document) { instance_double(DefMastership::Document, 'document') }
11
12
 
@@ -13,160 +14,257 @@ RSpec.describe(DefMastership::CSVFormatter) do
13
14
  it { is_expected.not_to(be(nil)) }
14
15
  end
15
16
 
16
- describe '#header' do
17
- 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
+
18
39
  before do
19
- allow(document).to(receive(:labels).with(no_args).and_return([]))
20
- allow(document).to(receive(:eref).with(no_args).and_return({}))
21
- allow(document).to(receive(:iref).with(no_args).and_return(false))
22
- allow(document).to(receive(:attributes).with(no_args).and_return({}))
23
- 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)) }
24
52
  end
25
53
 
26
- 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
27
58
 
28
- it { expect(document).to(have_received(:eref).with(no_args)) }
59
+ context 'when wrong_explicit_checksum' do
60
+ methods = %i[fixed wrong_explicit_checksum]
29
61
 
30
- 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
31
71
 
32
- 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
33
77
 
34
- 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" })) }
35
81
  end
36
82
 
37
- context 'when has everything' do
83
+ context 'when explicit_version' do
84
+ methods = %i[fixed explicit_version]
85
+
38
86
  before do
39
- allow(document).to(receive(:labels)
40
- .with(no_args)
41
- .and_return(['Whatever']))
42
- allow(document).to(receive(:eref)
43
- .with(no_args)
44
- .and_return(whatever: { prefix: 'A' },
45
- other: { prefix: 'C', url: 'D' }))
46
- allow(document).to(receive(:iref).with(no_args).and_return(true))
47
- allow(document).to(receive(:attributes)
48
- .with(no_args)
49
- .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')
50
94
  end
51
95
 
52
- it do
53
- expect(formatter.header).to(eq(%w[Type Reference Value Labels] +
54
- ['A', 'C D', 'Internal links'] +
55
- %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)) }
56
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" })) }
57
105
  end
58
- end
59
106
 
60
- describe '#body' do
61
- let(:definition) { instance_double(DefMastership::Definition, 'definition') }
107
+ context 'when labels' do
108
+ methods = %i[fixed labels]
62
109
 
63
- context 'when minimal' do
64
110
  before do
65
- allow(document).to(receive(:labels).with(no_args).and_return([]))
66
- allow(document).to(receive(:eref).with(no_args).and_return({}))
67
- allow(document).to(receive(:iref).with(no_args).and_return(false))
68
- allow(document).to(receive(:attributes).with(no_args).and_return({}))
69
- allow(definition).to(receive(:type).with(no_args).and_return('a'))
70
- allow(definition).to(receive(:reference).with(no_args).and_return('b'))
71
- allow(definition).to(receive(:value).with(no_args).and_return('c'))
72
- 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')
73
118
  end
74
119
 
75
- it { expect(document).to(have_received(:labels).with(no_args)) }
76
-
77
- it { expect(document).to(have_received(:eref).with(no_args)) }
78
-
79
- 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
80
125
 
81
- 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
82
130
 
83
- it { expect(definition).to(have_received(:type).with(no_args)) }
131
+ context 'when eref' do
132
+ methods = %i[fixed eref]
84
133
 
85
- 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
86
143
 
87
- 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
88
149
 
89
- 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" })) }
90
153
  end
91
154
 
92
- context 'when has everything' do
155
+ context 'when iref' do
156
+ methods = %i[fixed iref]
157
+
93
158
  before do
94
- allow(document).to(receive(:labels).with(no_args).and_return(['Whatever']))
95
- allow(document).to(receive(:eref).with(no_args).and_return(
96
- a: 'whatever',
97
- b: 'whatever',
98
- c: 'whatever'
99
- ))
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
100
164
  allow(document).to(receive(:iref).with(no_args).and_return(true))
101
- allow(document).to(receive(:attributes).with(no_args).and_return(
102
- a: 'whatever',
103
- b: 'whatever',
104
- c: 'whatever'
105
- ))
106
- allow(definition).to(receive(:type).with(no_args).and_return('a'))
107
- allow(definition).to(receive(:reference).with(no_args).and_return('b'))
108
- allow(definition).to(receive(:value).with(no_args).and_return('c'))
109
- allow(definition).to(receive(:labels).with(no_args).and_return(%w[toto tutu]))
110
- allow(definition).to(receive(:eref).with(no_args).and_return(a: %w[A B], b: [], c: ['C']))
111
- allow(definition).to(receive(:iref).with(no_args).and_return(%w[E F]))
112
- allow(definition).to(receive(:attributes).with(no_args).and_return(a: 'X', b: '', c: 'Y'))
113
- formatter.body(definition)
165
+ formatter.export_to('whatever')
114
166
  end
115
167
 
116
- 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
117
173
 
118
- 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
119
178
 
120
- it { expect(definition).to(have_received(:iref).with(no_args)) }
179
+ context 'when attributes' do
180
+ methods = %i[fixed attributes]
121
181
 
122
- 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
123
191
 
124
- it do
125
- expect(formatter.body(definition)).to(eq(%w[a b c] + ["toto\ntutu"] +
126
- ["A\nB", '', 'C'] +
127
- ["E\nF"] +
128
- ['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)) }
129
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" })) }
130
201
  end
131
- end
132
202
 
133
- describe '#export_to' do
134
- context 'when #export_to csv file' do
135
- let(:target_file) { 'export.csv' }
136
- let(:definitions) do
137
- [
138
- OpenStruct.new(type: 'a', reference: 'b', value: 'c'),
139
- OpenStruct.new(type: 'd', reference: 'e', value: 'f')
140
- ]
141
- end
203
+ context 'when every colums' do
204
+ methods = %i[fixed wrong_explicit_checksum explicit_version labels eref iref attributes]
142
205
 
143
206
  before do
144
- setup_aruba
145
- allow(document).to(receive(:labels).exactly(3).times.with(no_args).and_return([]))
146
- allow(document).to(receive(:eref).exactly(3).times.with(no_args).and_return({}))
147
- allow(document).to(receive(:iref).exactly(3).times.with(no_args).and_return(false))
148
- allow(document).to(receive(:attributes).exactly(3).times.with(no_args).and_return({}))
149
- allow(document).to(receive(:definitions).with(no_args).and_return(definitions))
150
- 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')
151
219
  end
152
220
 
153
- it { expect(document).to(have_received(:labels).exactly(3).times.with(no_args)) }
154
-
155
- 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
156
226
 
157
- 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
158
232
 
159
- 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
160
241
 
161
- 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
162
253
 
163
- it do
164
- expect(target_file).to(have_file_content(<<~CSV_FILE))
165
- Type,Reference,Value
166
- a,b,c
167
- d,e,f
168
- CSV_FILE
169
- 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
170
268
  end
171
269
  end
172
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
@@ -5,7 +5,7 @@ require('defmastership')
5
5
 
6
6
  RSpec.describe(DefMastership::Definition) do
7
7
  describe '.new' do
8
- context 'without labels' do
8
+ context 'when minimal' do
9
9
  subject do
10
10
  described_class.new(
11
11
  type: 'req',
@@ -22,12 +22,14 @@ RSpec.describe(DefMastership::Definition) do
22
22
  it { is_expected.to(have_attributes(iref: [])) }
23
23
  it { is_expected.to(have_attributes(attributes: {})) }
24
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)) }
25
27
  end
26
28
 
27
29
  context 'with labels' do
28
30
  subject do
29
31
  described_class.new(
30
- gtype: 'req',
32
+ type: 'req',
31
33
  reference: 'TUTU-001',
32
34
  labels: 'something'
33
35
  )
@@ -35,6 +37,40 @@ RSpec.describe(DefMastership::Definition) do
35
37
 
36
38
  it { is_expected.to(have_attributes(labels: Set['something'])) }
37
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
38
74
  end
39
75
 
40
76
  describe '#<<' do
@@ -50,7 +86,7 @@ RSpec.describe(DefMastership::Definition) do
50
86
  expect(definition.value).to(eq('first line'))
51
87
  end
52
88
 
53
- it 'store line when added' do
89
+ it 'stores line when added' do
54
90
  definition << 'first line'
55
91
  expect(definition.lines).to(eq(['first line']))
56
92
  end
@@ -60,10 +96,15 @@ RSpec.describe(DefMastership::Definition) do
60
96
  expect(definition.value).to(eq("first line\nsecond line"))
61
97
  end
62
98
 
63
- it 'store each line when added' do
99
+ it 'stores each line when added' do
64
100
  definition << 'first line' << 'second line'
65
101
  expect(definition.lines).to(eq(['first line', 'second line']))
66
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
67
108
  end
68
109
 
69
110
  describe '#add_eref' do