defmastership 1.0.3 → 1.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.gitlab-ci.yml +0 -1
- data/.rubocop.yml +3 -2
- data/Gemfile +1 -0
- data/LICENSE +22 -0
- data/Rakefile +2 -2
- data/bin/defmastership +37 -24
- data/cucumber.yml +2 -0
- data/defmastership.gemspec +16 -9
- data/features/changeref.feature +82 -129
- data/features/definition_checksum.feature +244 -0
- data/features/definition_version.feature +24 -0
- data/features/export.feature +49 -31
- data/features/modify.feature +165 -0
- data/features/rename_included_files.feature +121 -0
- data/features/step_definitions/defmastership_steps.rb +1 -0
- data/features/support/env.rb +1 -0
- data/lib/defmastership.rb +15 -3
- data/lib/defmastership/batch_modifier.rb +35 -0
- data/lib/defmastership/{ref_changer.rb → change_ref_line_modifier.rb} +19 -35
- data/lib/defmastership/change_ref_modifier.rb +15 -0
- data/lib/defmastership/comment_filter.rb +1 -0
- data/lib/defmastership/constants.rb +15 -1
- data/lib/defmastership/csv_formatter.rb +26 -19
- data/lib/defmastership/csv_formatter_body.rb +20 -11
- data/lib/defmastership/csv_formatter_header.rb +16 -10
- data/lib/defmastership/definition.rb +15 -3
- data/lib/defmastership/definition_parser.rb +46 -0
- data/lib/defmastership/document.rb +60 -85
- data/lib/defmastership/filters.rb +30 -0
- data/lib/defmastership/line_modifier_base.rb +29 -0
- data/lib/defmastership/modifier_base.rb +29 -0
- data/lib/defmastership/rename_included_files_line_modifier.rb +126 -0
- data/lib/defmastership/rename_included_files_modifier.rb +15 -0
- data/lib/defmastership/update_def_checksum_line_modifier.rb +39 -0
- data/lib/defmastership/update_def_checksum_modifier.rb +21 -0
- data/lib/defmastership/version.rb +2 -1
- data/spec/spec_helper.rb +2 -0
- data/spec/unit/defmastership/batch_modifier_spec.rb +123 -0
- data/spec/unit/defmastership/{ref_changer_spec.rb → change_ref_line_modifier_spec.rb} +49 -26
- data/spec/unit/defmastership/change_ref_modifier_spec.rb +76 -0
- data/spec/unit/defmastership/comment_filter_spec.rb +9 -4
- data/spec/unit/defmastership/csv_formatter_body_spec.rb +89 -82
- data/spec/unit/defmastership/csv_formatter_header_spec.rb +69 -22
- data/spec/unit/defmastership/csv_formatter_spec.rb +209 -110
- data/spec/unit/defmastership/definition_parser_spec.rb +63 -0
- data/spec/unit/defmastership/definition_spec.rb +46 -4
- data/spec/unit/defmastership/document_spec.rb +237 -35
- data/spec/unit/defmastership/rename_included_files_line_modifier_spec.rb +203 -0
- data/spec/unit/defmastership/rename_included_files_modifier_spec.rb +67 -0
- data/spec/unit/defmastership/update_def_checksum_line_modifier_spec.rb +68 -0
- data/spec/unit/defmastership/update_def_checksum_modifier_spec.rb +75 -0
- data/spec/unit/defmastership_spec.rb +1 -0
- metadata +49 -17
- data/Gemfile.lock +0 -140
- data/lib/defmastership/batch_changer.rb +0 -40
- data/lib/defmastership/project_ref_changer.rb +0 -27
- data/spec/unit/defmastership/batch_changer_spec.rb +0 -108
- 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 '#
|
16
|
-
|
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
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
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(
|
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
|
-
|
59
|
+
context 'when wrong_explicit_checksum' do
|
60
|
+
methods = %i[fixed wrong_explicit_checksum]
|
28
61
|
|
29
|
-
|
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
|
-
|
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(
|
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
|
83
|
+
context 'when explicit_version' do
|
84
|
+
methods = %i[fixed explicit_version]
|
85
|
+
|
37
86
|
before do
|
38
|
-
|
39
|
-
.with(no_args)
|
40
|
-
.and_return([
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
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
|
-
|
52
|
-
expect(
|
53
|
-
|
54
|
-
|
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
|
-
|
60
|
-
|
107
|
+
context 'when labels' do
|
108
|
+
methods = %i[fixed labels]
|
61
109
|
|
62
|
-
context 'when minimal' do
|
63
110
|
before do
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
allow(
|
70
|
-
|
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
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
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(
|
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
|
-
|
131
|
+
context 'when eref' do
|
132
|
+
methods = %i[fixed eref]
|
83
133
|
|
84
|
-
|
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
|
-
|
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(
|
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
|
155
|
+
context 'when iref' do
|
156
|
+
methods = %i[fixed iref]
|
157
|
+
|
92
158
|
before do
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
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
|
-
|
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
|
-
|
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(
|
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
|
-
|
179
|
+
context 'when attributes' do
|
180
|
+
methods = %i[fixed attributes]
|
120
181
|
|
121
|
-
|
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
|
-
|
124
|
-
expect(
|
125
|
-
|
126
|
-
|
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
|
-
|
133
|
-
|
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
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
allow(document).to(receive(:
|
149
|
-
|
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
|
-
|
153
|
-
|
154
|
-
|
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(
|
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
|
-
|
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
|
-
|
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
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
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 '
|
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
|
-
|
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 '
|
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 '
|
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
|