defmastership 1.0.16 → 1.0.18
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.gitlab-ci.yml +50 -7
- data/.rubocop.yml +14 -6
- data/Gemfile +51 -1
- data/Rakefile +16 -47
- data/bin/defmastership +12 -9
- data/config/mutant.yml +23 -3
- data/defmastership.gemspec +22 -27
- data/features/definition_checksum.feature +31 -1
- data/features/export.feature +43 -1
- data/features/rename_included_files.feature +28 -0
- data/lib/defmastership/batch_modifier.rb +17 -12
- data/lib/defmastership/change_ref_modifier.rb +89 -5
- data/lib/defmastership/comment_filter.rb +1 -1
- data/lib/defmastership/constants.rb +5 -4
- data/lib/defmastership/csv_formatter.rb +20 -16
- data/lib/defmastership/csv_formatter_body.rb +18 -15
- data/lib/defmastership/csv_formatter_header.rb +1 -1
- data/lib/defmastership/definition.rb +58 -19
- data/lib/defmastership/document.rb +109 -74
- data/lib/defmastership/matching_line.rb +17 -0
- data/lib/defmastership/modifier.rb +42 -0
- data/lib/defmastership/modifier_factory.rb +12 -0
- data/lib/defmastership/parsing_state.rb +15 -9
- data/lib/defmastership/rename_included_files_modifier.rb +172 -5
- data/lib/defmastership/set_join_hack.rb +11 -0
- data/lib/defmastership/update_def_checksum_modifier.rb +8 -13
- data/lib/defmastership/update_def_modifier.rb +49 -0
- data/lib/defmastership/update_def_version_modifier.rb +56 -15
- data/lib/defmastership/version.rb +1 -1
- data/lib/defmastership.rb +7 -17
- data/spec/spec_helper.rb +4 -2
- data/spec/unit/{defmastership → def_mastership}/batch_modifier_spec.rb +42 -39
- data/spec/unit/{defmastership/change_ref_line_modifier_spec.rb → def_mastership/change_ref_modifier_spec.rb} +44 -66
- data/spec/unit/{defmastership → def_mastership}/csv_formatter_body_spec.rb +61 -32
- data/spec/unit/{defmastership → def_mastership}/csv_formatter_header_spec.rb +2 -2
- data/spec/unit/{defmastership → def_mastership}/csv_formatter_spec.rb +81 -86
- data/spec/unit/{defmastership → def_mastership}/definition_parser_spec.rb +2 -2
- data/spec/unit/{defmastership → def_mastership}/definition_spec.rb +17 -7
- data/spec/unit/{defmastership → def_mastership}/document_spec.rb +108 -53
- data/spec/unit/def_mastership/matching_line_spec.rb +37 -0
- data/spec/unit/def_mastership/modifier_factory_spec.rb +37 -0
- data/spec/unit/def_mastership/modifier_spec.rb +83 -0
- data/spec/unit/{defmastership → def_mastership}/parsing_state_spec.rb +16 -16
- data/spec/unit/{defmastership/rename_included_files_line_modifier_spec.rb → def_mastership/rename_included_files_modifier_spec.rb} +72 -36
- data/spec/unit/{defmastership/comment_filter_spec.rb → def_mastership/string_spec.rb} +1 -1
- data/spec/unit/def_mastership/update_def_checksum_modifier_spec.rb +107 -0
- data/spec/unit/def_mastership/update_def_modifier_spec.rb +119 -0
- data/spec/unit/def_mastership/update_def_version_modifier_spec.rb +159 -0
- data/spec/unit/{defmastership_spec.rb → def_mastership_spec.rb} +1 -1
- data/tasks/console.rake +8 -0
- data/tasks/package.task +9 -0
- data/tasks/smelling_code.rake +38 -0
- data/tasks/test.rake +45 -0
- metadata +37 -145
- data/lib/defmastership/change_ref_line_modifier.rb +0 -82
- data/lib/defmastership/line_modifier_base.rb +0 -29
- data/lib/defmastership/modifier_base.rb +0 -29
- data/lib/defmastership/rename_included_files_line_modifier.rb +0 -126
- data/lib/defmastership/update_def_checksum_line_modifier.rb +0 -38
- data/lib/defmastership/update_def_version_line_modifier.rb +0 -58
- data/spec/unit/defmastership/change_ref_modifier_spec.rb +0 -76
- data/spec/unit/defmastership/rename_included_files_modifier_spec.rb +0 -67
- data/spec/unit/defmastership/update_def_checksum_line_modifier_spec.rb +0 -78
- data/spec/unit/defmastership/update_def_checksum_modifier_spec.rb +0 -75
- data/spec/unit/defmastership/update_def_version_line_modifier_spec.rb +0 -127
- data/spec/unit/defmastership/update_def_version_modifier_spec.rb +0 -80
@@ -1,29 +1,31 @@
|
|
1
1
|
# Copyright (c) 2020 Jerome Arbez-Gindre
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
require('defmastership')
|
4
|
+
require('defmastership/batch_modifier')
|
5
5
|
|
6
6
|
module DefMastership
|
7
|
-
class
|
7
|
+
class TotoModifier
|
8
|
+
include Modifier
|
8
9
|
end
|
9
10
|
|
10
|
-
class
|
11
|
+
class TuTuModifier
|
12
|
+
include Modifier
|
11
13
|
end
|
12
14
|
end
|
13
15
|
|
14
16
|
RSpec.describe(DefMastership::BatchModifier) do
|
15
17
|
subject(:batchmodifier) do
|
16
|
-
described_class.new(config,
|
18
|
+
described_class.new(config, adoc_sources)
|
17
19
|
end
|
18
20
|
|
19
21
|
let(:config) do
|
20
22
|
{
|
21
|
-
modifier1: { type: '
|
22
|
-
modifier2: { type: '
|
23
|
-
modifier3: { type: '
|
23
|
+
modifier1: { type: 'toto', config: { p: 1 } },
|
24
|
+
modifier2: { type: 'toto', config: { p: 'whatever1' } },
|
25
|
+
modifier3: { type: 'tu_tu', config: { p1: 'whatever2', p2: 'whatever3' } }
|
24
26
|
}
|
25
27
|
end
|
26
|
-
let(:
|
28
|
+
let(:adoc_sources) do
|
27
29
|
{
|
28
30
|
'file1.adoc' => 'some text',
|
29
31
|
'file2.adoc' => 'another text'
|
@@ -31,18 +33,18 @@ RSpec.describe(DefMastership::BatchModifier) do
|
|
31
33
|
end
|
32
34
|
|
33
35
|
describe '.new' do
|
34
|
-
it { is_expected.not_to(
|
36
|
+
it { is_expected.not_to(be_nil) }
|
35
37
|
it { is_expected.to(have_attributes(config: config)) }
|
36
38
|
|
37
39
|
it do
|
38
|
-
expect(batchmodifier).to(have_attributes(
|
40
|
+
expect(batchmodifier).to(have_attributes(adoc_sources: adoc_sources))
|
39
41
|
end
|
40
42
|
end
|
41
43
|
|
42
44
|
describe '#apply' do
|
43
45
|
context 'with only one modification' do
|
44
|
-
let(:toto1) { instance_double(DefMastership::
|
45
|
-
let(:
|
46
|
+
let(:toto1) { instance_double(DefMastership::TotoModifier, 'toto1') }
|
47
|
+
let(:adoc_sources_modified) do
|
46
48
|
{
|
47
49
|
'file1.adoc' => 'some text modified',
|
48
50
|
'file2.adoc' => 'another text'
|
@@ -51,26 +53,26 @@ RSpec.describe(DefMastership::BatchModifier) do
|
|
51
53
|
|
52
54
|
let(:config_modified) do
|
53
55
|
{
|
54
|
-
modifier1: { type: '
|
55
|
-
modifier2: { type: '
|
56
|
-
modifier3: { type: '
|
56
|
+
modifier1: { type: 'toto', config: { p: 'modified_param' } },
|
57
|
+
modifier2: { type: 'toto', config: { p: 'whatever1' } },
|
58
|
+
modifier3: { type: 'tu_tu', config: { p1: 'whatever2', p2: 'whatever3' } }
|
57
59
|
}
|
58
60
|
end
|
59
61
|
|
60
62
|
before do
|
61
|
-
allow(DefMastership::
|
62
|
-
allow(toto1).to(receive(:do_modifications).once.and_return(
|
63
|
+
allow(DefMastership::TotoModifier).to(receive(:new).once.and_return(toto1))
|
64
|
+
allow(toto1).to(receive(:do_modifications).once.and_return(adoc_sources_modified))
|
63
65
|
allow(toto1).to(receive(:config).once.and_return(p: 'modified_param'))
|
64
66
|
allow(toto1).to(receive(:changes).once.and_return([%w[from1 to1], %w[from2 to2]]))
|
65
|
-
batchmodifier.apply(
|
67
|
+
batchmodifier.apply(%i[modifier1])
|
66
68
|
end
|
67
69
|
|
68
70
|
it do
|
69
|
-
expect(DefMastership::
|
71
|
+
expect(DefMastership::TotoModifier).to(have_received(:new).with(p: 1))
|
70
72
|
end
|
71
73
|
|
72
|
-
it { expect(toto1).to(have_received(:do_modifications).with(
|
73
|
-
it { is_expected.to(have_attributes(
|
74
|
+
it { expect(toto1).to(have_received(:do_modifications).with(adoc_sources)) }
|
75
|
+
it { is_expected.to(have_attributes(adoc_sources: adoc_sources_modified)) }
|
74
76
|
it { expect(toto1).to(have_received(:config).with(no_args)) }
|
75
77
|
|
76
78
|
it { is_expected.to(have_attributes(config: config_modified)) }
|
@@ -78,45 +80,46 @@ RSpec.describe(DefMastership::BatchModifier) do
|
|
78
80
|
end
|
79
81
|
|
80
82
|
context 'with two modifications' do
|
81
|
-
let(:toto2) { instance_double(DefMastership::
|
82
|
-
let(:tutu3) { instance_double(DefMastership::
|
83
|
+
let(:toto2) { instance_double(DefMastership::TotoModifier, 'toto2') }
|
84
|
+
let(:tutu3) { instance_double(DefMastership::TuTuModifier, 'tutu3') }
|
83
85
|
|
84
86
|
let(:config_modified) do
|
85
87
|
{
|
86
|
-
modifier1: { type: '
|
87
|
-
modifier2: { type: '
|
88
|
-
modifier3: { type: '
|
88
|
+
modifier1: { type: 'toto', config: { p: 1 } },
|
89
|
+
modifier2: { type: 'toto', config: :whatever },
|
90
|
+
modifier3: { type: 'tu_tu', config: :pouet }
|
89
91
|
}
|
90
92
|
end
|
91
93
|
|
92
94
|
before do
|
93
|
-
allow(DefMastership::
|
94
|
-
allow(toto2).to(receive(:do_modifications).once.and_return(:
|
95
|
+
allow(DefMastership::TotoModifier).to(receive(:new).once.and_return(toto2))
|
96
|
+
allow(toto2).to(receive(:do_modifications).once.and_return(:adoc_sources_modified_mod2))
|
95
97
|
allow(toto2).to(receive(:config).once.and_return(:whatever))
|
96
|
-
allow(DefMastership::
|
97
|
-
allow(tutu3).to(receive(:do_modifications).once.and_return(:
|
98
|
+
allow(DefMastership::TuTuModifier).to(receive(:new).once.and_return(tutu3))
|
99
|
+
allow(tutu3).to(receive(:do_modifications).once.and_return(:adoc_sources_modified_mod3))
|
98
100
|
allow(tutu3).to(receive(:config).once.and_return(:pouet))
|
99
101
|
allow(toto2).to(receive(:changes).once.and_return([%w[from1 to1]]))
|
100
102
|
allow(tutu3).to(receive(:changes).once.and_return([%w[from2 to2]]))
|
101
|
-
batchmodifier.apply(
|
103
|
+
batchmodifier.apply(%i[modifier2 modifier3])
|
102
104
|
end
|
103
105
|
|
104
|
-
it { expect(DefMastership::
|
105
|
-
it { expect(DefMastership::
|
106
|
-
it { expect(toto2).to(have_received(:do_modifications).with(
|
106
|
+
it { expect(DefMastership::TotoModifier).to(have_received(:new).with(p: 'whatever1')) }
|
107
|
+
it { expect(DefMastership::TuTuModifier).to(have_received(:new).with(p1: 'whatever2', p2: 'whatever3')) }
|
108
|
+
it { expect(toto2).to(have_received(:do_modifications).with(adoc_sources)) }
|
107
109
|
it { expect(toto2).to(have_received(:config).with(no_args)) }
|
108
|
-
it { expect(tutu3).to(have_received(:do_modifications).with(:
|
110
|
+
it { expect(tutu3).to(have_received(:do_modifications).with(:adoc_sources_modified_mod2)) }
|
109
111
|
it { expect(tutu3).to(have_received(:config).with(no_args)) }
|
110
|
-
it { is_expected.to(have_attributes(
|
112
|
+
it { is_expected.to(have_attributes(adoc_sources: :adoc_sources_modified_mod3)) }
|
111
113
|
it { is_expected.to(have_attributes(config: config_modified)) }
|
112
114
|
it { is_expected.to(have_attributes(changes: [%w[modifier2 from1 to1], %w[modifier3 from2 to2]])) }
|
113
115
|
end
|
114
116
|
|
115
117
|
context 'with wrong modification' do
|
116
118
|
it do
|
117
|
-
expect { batchmodifier.apply(
|
118
|
-
|
119
|
-
|
119
|
+
expect { batchmodifier.apply(%i[wrong-modification]) }
|
120
|
+
.to(
|
121
|
+
raise_error(ArgumentError, 'wrong-modification is not a known modification')
|
122
|
+
)
|
120
123
|
end
|
121
124
|
end
|
122
125
|
end
|
@@ -1,49 +1,21 @@
|
|
1
1
|
# Copyright (c) 2020 Jerome Arbez-Gindre
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
require('defmastership')
|
4
|
+
require('defmastership/change_ref_modifier')
|
5
5
|
|
6
|
-
RSpec.describe(DefMastership::
|
7
|
-
subject(:refchanger) { described_class.new }
|
6
|
+
RSpec.describe(DefMastership::ChangeRefModifier) do
|
7
|
+
subject(:refchanger) { described_class.new({}) }
|
8
8
|
|
9
9
|
describe '.new' do
|
10
|
-
it {
|
10
|
+
it { expect(described_class.ancestors).to(include(DefMastership::Modifier)) }
|
11
|
+
it { is_expected.not_to(be_nil) }
|
11
12
|
it { is_expected.to(have_attributes(from_regexp: '')) }
|
12
13
|
it { is_expected.to(have_attributes(to_template: '')) }
|
13
14
|
it { is_expected.to(have_attributes(next_ref: 0)) }
|
14
|
-
it { is_expected.to(have_attributes(changes: [])) }
|
15
|
-
it { expect { refchanger.user_defined_attribute }.to(raise_error(NoMethodError)) }
|
16
15
|
end
|
17
16
|
|
18
|
-
describe '.
|
19
|
-
|
20
|
-
described_class.from_config(
|
21
|
-
from_regexp: 'Whatever.+',
|
22
|
-
to_template: 'Whatever',
|
23
|
-
next_ref: 17
|
24
|
-
)
|
25
|
-
end
|
26
|
-
|
27
|
-
it { is_expected.not_to(be(nil)) }
|
28
|
-
it { is_expected.to(have_attributes(from_regexp: 'Whatever.+')) }
|
29
|
-
it { is_expected.to(have_attributes(to_template: 'Whatever')) }
|
30
|
-
it { is_expected.to(have_attributes(next_ref: 17)) }
|
31
|
-
end
|
32
|
-
|
33
|
-
describe '#from_config' do
|
34
|
-
before do
|
35
|
-
refchanger.from_config(
|
36
|
-
from_regexp: 'Whatever.+',
|
37
|
-
to_template: 'Whatever',
|
38
|
-
next_ref: 17,
|
39
|
-
user_defined_attribute: 'Tadaam'
|
40
|
-
)
|
41
|
-
end
|
42
|
-
|
43
|
-
it { is_expected.to(have_attributes(from_regexp: 'Whatever.+')) }
|
44
|
-
it { is_expected.to(have_attributes(to_template: 'Whatever')) }
|
45
|
-
it { is_expected.to(have_attributes(next_ref: 17)) }
|
46
|
-
it { is_expected.to(have_attributes(user_defined_attribute: 'Tadaam')) }
|
17
|
+
describe '.replacement_methods' do
|
18
|
+
it { expect(described_class.replacement_methods).to(eq(%i[replace_refdef replace_irefs])) }
|
47
19
|
end
|
48
20
|
|
49
21
|
describe '#config' do
|
@@ -54,26 +26,12 @@ RSpec.describe(DefMastership::ChangeRefLineModifier) do
|
|
54
26
|
)
|
55
27
|
end
|
56
28
|
end
|
57
|
-
|
58
|
-
context 'when initalized with additionnal keys' do
|
59
|
-
before do
|
60
|
-
refchanger.from_config(
|
61
|
-
next_ref: 1256,
|
62
|
-
user_defined_attribute: 'Tadaam'
|
63
|
-
)
|
64
|
-
end
|
65
|
-
|
66
|
-
it { expect(refchanger.config).to(include(from_regexp: '')) }
|
67
|
-
it { expect(refchanger.config).to(include(to_template: '')) }
|
68
|
-
it { expect(refchanger.config).to(include(next_ref: 1256)) }
|
69
|
-
it { expect(refchanger.config).to(include(user_defined_attribute: 'Tadaam')) }
|
70
|
-
end
|
71
29
|
end
|
72
30
|
|
73
31
|
describe '#replace_def' do
|
74
32
|
context 'when really simple rule' do
|
75
|
-
|
76
|
-
|
33
|
+
subject(:refchanger) do
|
34
|
+
described_class.new(
|
77
35
|
from_regexp: 'TEMP',
|
78
36
|
to_template: 'TUTU'
|
79
37
|
)
|
@@ -95,8 +53,8 @@ RSpec.describe(DefMastership::ChangeRefLineModifier) do
|
|
95
53
|
end
|
96
54
|
|
97
55
|
context 'when template is variable' do
|
98
|
-
|
99
|
-
|
56
|
+
subject(:refchanger) do
|
57
|
+
described_class.new(
|
100
58
|
from_regexp: 'TEMP',
|
101
59
|
to_template: 'TOTO-%<next_ref>04d',
|
102
60
|
next_ref: 124
|
@@ -115,8 +73,8 @@ RSpec.describe(DefMastership::ChangeRefLineModifier) do
|
|
115
73
|
end
|
116
74
|
|
117
75
|
context 'when capture group in regexp' do
|
118
|
-
|
119
|
-
|
76
|
+
subject(:refchanger) do
|
77
|
+
described_class.new(
|
120
78
|
from_regexp: '(?<cg>TOTO|TITI)-TEMP[\d]*',
|
121
79
|
to_template: '%<cg>s-%<next_ref>04d',
|
122
80
|
next_ref: 132
|
@@ -142,11 +100,14 @@ RSpec.describe(DefMastership::ChangeRefLineModifier) do
|
|
142
100
|
end
|
143
101
|
|
144
102
|
context 'when definition is in literal block' do
|
145
|
-
|
146
|
-
|
103
|
+
subject(:refchanger) do
|
104
|
+
described_class.new(
|
147
105
|
from_regexp: 'TEMP',
|
148
106
|
to_template: 'TUTU'
|
149
107
|
)
|
108
|
+
end
|
109
|
+
|
110
|
+
before do
|
150
111
|
refchanger.replace_refdef('....')
|
151
112
|
end
|
152
113
|
|
@@ -157,11 +118,14 @@ RSpec.describe(DefMastership::ChangeRefLineModifier) do
|
|
157
118
|
end
|
158
119
|
|
159
120
|
context 'when defintion is after literal block' do
|
160
|
-
|
161
|
-
|
121
|
+
subject(:refchanger) do
|
122
|
+
described_class.new(
|
162
123
|
from_regexp: 'TEMP',
|
163
124
|
to_template: 'TUTU'
|
164
125
|
)
|
126
|
+
end
|
127
|
+
|
128
|
+
before do
|
165
129
|
refchanger.replace_refdef("....\n")
|
166
130
|
refchanger.replace_refdef('[define, whatever, TEMP]')
|
167
131
|
refchanger.replace_refdef("....\n")
|
@@ -175,12 +139,15 @@ RSpec.describe(DefMastership::ChangeRefLineModifier) do
|
|
175
139
|
end
|
176
140
|
|
177
141
|
describe '#replace_irefs' do
|
178
|
-
|
179
|
-
|
142
|
+
subject(:refchanger) do
|
143
|
+
described_class.new(
|
180
144
|
from_regexp: '(?<cg>TOTO|TITI)-TEMP[\d]*',
|
181
145
|
to_template: '%<cg>s-%<next_ref>04d',
|
182
146
|
next_ref: 132
|
183
147
|
)
|
148
|
+
end
|
149
|
+
|
150
|
+
before do
|
184
151
|
refchanger.replace_refdef('[define, whatever, TOTO-TEMP123]')
|
185
152
|
refchanger.replace_refdef('[define, whatever, TITI-TEMP421]')
|
186
153
|
end
|
@@ -202,11 +169,19 @@ RSpec.describe(DefMastership::ChangeRefLineModifier) do
|
|
202
169
|
)
|
203
170
|
).to(eq('defs:iref[TOTO-0132] defs:iref[TITI-0133] bla'))
|
204
171
|
end
|
172
|
+
|
173
|
+
it do
|
174
|
+
expect(
|
175
|
+
refchanger.replace_irefs(
|
176
|
+
'defs:iref[TOTO-TEMP123] defs:iref[TOTO-TEMP123] bla'
|
177
|
+
)
|
178
|
+
).to(eq('defs:iref[TOTO-0132] defs:iref[TOTO-0132] bla'))
|
179
|
+
end
|
205
180
|
end
|
206
181
|
|
207
182
|
describe '#replace' do
|
208
|
-
|
209
|
-
|
183
|
+
subject(:refchanger) do
|
184
|
+
described_class.new(
|
210
185
|
from_regexp: 'TEMP',
|
211
186
|
to_template: 'TUTU'
|
212
187
|
)
|
@@ -234,10 +209,13 @@ RSpec.describe(DefMastership::ChangeRefLineModifier) do
|
|
234
209
|
|
235
210
|
it do
|
236
211
|
refchanger.replace(:refdef, '[define, whatever, TEMP]')
|
237
|
-
expect(refchanger.replace(:irefs, 'defs:iref[TEMP]'))
|
238
|
-
.to(eq('defs:iref[TUTU]'))
|
212
|
+
expect(refchanger.replace(:irefs, 'defs:iref[TEMP] defs:iref[TEMP]'))
|
213
|
+
.to(eq('defs:iref[TUTU] defs:iref[TUTU]'))
|
239
214
|
end
|
240
215
|
|
241
|
-
it
|
216
|
+
it do
|
217
|
+
expect { refchanger.replace(:pouet, 'whatever') }
|
218
|
+
.to(raise_error(NoMethodError))
|
219
|
+
end
|
242
220
|
end
|
243
221
|
end
|
@@ -1,16 +1,16 @@
|
|
1
1
|
# Copyright (c) 2020 Jerome Arbez-Gindre
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
require('defmastership')
|
4
|
+
require('defmastership/csv_formatter_body')
|
5
5
|
|
6
6
|
RSpec.describe(DefMastership::CSVFormatterBody) do
|
7
|
-
subject(:formatter) { described_class.new(document) }
|
7
|
+
subject(:formatter) { described_class.new(document, definition) }
|
8
8
|
|
9
9
|
let(:document) { instance_double(DefMastership::Document, 'document') }
|
10
10
|
let(:definition) { instance_double(DefMastership::Definition, 'definition') }
|
11
11
|
|
12
12
|
describe '.new' do
|
13
|
-
it { is_expected.not_to(
|
13
|
+
it { is_expected.not_to(be_nil) }
|
14
14
|
end
|
15
15
|
|
16
16
|
describe '#fixed' do
|
@@ -18,35 +18,35 @@ RSpec.describe(DefMastership::CSVFormatterBody) do
|
|
18
18
|
allow(definition).to(receive(:type).with(no_args).and_return('a'))
|
19
19
|
allow(definition).to(receive(:reference).with(no_args).and_return('b'))
|
20
20
|
allow(definition).to(receive(:value).with(no_args).and_return('c'))
|
21
|
-
allow(definition).to(receive(:
|
22
|
-
formatter.fixed
|
21
|
+
allow(definition).to(receive(:sha256_short).with(no_args).and_return('d'))
|
22
|
+
formatter.fixed
|
23
23
|
end
|
24
24
|
|
25
25
|
it { expect(definition).to(have_received(:type).with(no_args)) }
|
26
26
|
it { expect(definition).to(have_received(:reference).with(no_args)) }
|
27
27
|
it { expect(definition).to(have_received(:value).with(no_args)) }
|
28
|
-
it { expect(definition).to(have_received(:
|
29
|
-
it { expect(formatter.fixed
|
28
|
+
it { expect(definition).to(have_received(:sha256_short).with(no_args)) }
|
29
|
+
it { expect(formatter.fixed).to(eq(%w[a b c d])) }
|
30
30
|
end
|
31
31
|
|
32
32
|
describe '#wrong_explicit_checksum' do
|
33
33
|
context 'when no wrong_explicit checksum' do
|
34
34
|
before do
|
35
35
|
allow(definition).to(receive(:wrong_explicit_checksum).with(no_args).and_return(nil))
|
36
|
-
formatter.wrong_explicit_checksum
|
36
|
+
formatter.wrong_explicit_checksum
|
37
37
|
end
|
38
38
|
|
39
39
|
it { expect(definition).to(have_received(:wrong_explicit_checksum).with(no_args)) }
|
40
|
-
it { expect(formatter.wrong_explicit_checksum
|
40
|
+
it { expect(formatter.wrong_explicit_checksum).to(eq([''])) }
|
41
41
|
end
|
42
42
|
|
43
43
|
context 'when explicit checksum' do
|
44
44
|
before do
|
45
45
|
allow(definition).to(receive(:wrong_explicit_checksum).with(no_args).and_return('ab12'))
|
46
|
-
formatter.wrong_explicit_checksum
|
46
|
+
formatter.wrong_explicit_checksum
|
47
47
|
end
|
48
48
|
|
49
|
-
it { expect(formatter.wrong_explicit_checksum
|
49
|
+
it { expect(formatter.wrong_explicit_checksum).to(eq(['ab12'])) }
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
@@ -54,20 +54,20 @@ RSpec.describe(DefMastership::CSVFormatterBody) do
|
|
54
54
|
context 'when no explicit_version' do
|
55
55
|
before do
|
56
56
|
allow(definition).to(receive(:explicit_version).with(no_args).and_return(nil))
|
57
|
-
formatter.explicit_version
|
57
|
+
formatter.explicit_version
|
58
58
|
end
|
59
59
|
|
60
60
|
it { expect(definition).to(have_received(:explicit_version).with(no_args)) }
|
61
|
-
it { expect(formatter.explicit_version
|
61
|
+
it { expect(formatter.explicit_version).to(eq([''])) }
|
62
62
|
end
|
63
63
|
|
64
64
|
context 'when explicit_version' do
|
65
65
|
before do
|
66
66
|
allow(definition).to(receive(:explicit_version).with(no_args).and_return('ab12'))
|
67
|
-
formatter.explicit_version
|
67
|
+
formatter.explicit_version
|
68
68
|
end
|
69
69
|
|
70
|
-
it { expect(formatter.explicit_version
|
70
|
+
it { expect(formatter.explicit_version).to(eq(['ab12'])) }
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
@@ -77,21 +77,21 @@ RSpec.describe(DefMastership::CSVFormatterBody) do
|
|
77
77
|
context 'when no labels on definition' do
|
78
78
|
before do
|
79
79
|
allow(definition).to(receive(:labels).with(no_args).and_return([]))
|
80
|
-
formatter.labels
|
80
|
+
formatter.labels
|
81
81
|
end
|
82
82
|
|
83
83
|
it { expect(definition).to(have_received(:labels).once.with(no_args)) }
|
84
|
-
it { expect(formatter.labels
|
84
|
+
it { expect(formatter.labels).to(eq([''])) }
|
85
85
|
end
|
86
86
|
|
87
87
|
context 'when labels on definition' do
|
88
88
|
before do
|
89
|
-
allow(definition).to(receive(:labels).with(no_args).and_return(%w[toto tutu]))
|
90
|
-
formatter.labels
|
89
|
+
allow(definition).to(receive(:labels).with(no_args).and_return(%w[toto tutu].to_set))
|
90
|
+
formatter.labels
|
91
91
|
end
|
92
92
|
|
93
93
|
it { expect(definition).to(have_received(:labels).once.with(no_args)) }
|
94
|
-
it { expect(formatter.labels
|
94
|
+
it { expect(formatter.labels).to(eq(["toto\ntutu"])) }
|
95
95
|
end
|
96
96
|
end
|
97
97
|
|
@@ -99,11 +99,11 @@ RSpec.describe(DefMastership::CSVFormatterBody) do
|
|
99
99
|
context 'when no eref on the document' do
|
100
100
|
before do
|
101
101
|
allow(document).to(receive(:eref).with(no_args).and_return({}))
|
102
|
-
formatter.eref
|
102
|
+
formatter.eref
|
103
103
|
end
|
104
104
|
|
105
105
|
it { expect(document).to(have_received(:eref).with(no_args)) }
|
106
|
-
it { expect(formatter.eref
|
106
|
+
it { expect(formatter.eref).to(eq([])) }
|
107
107
|
end
|
108
108
|
|
109
109
|
context 'when eref on the document' do
|
@@ -114,11 +114,26 @@ RSpec.describe(DefMastership::CSVFormatterBody) do
|
|
114
114
|
)
|
115
115
|
)
|
116
116
|
allow(definition).to(receive(:eref).with(no_args).and_return(a: %w[A B], b: [], c: ['C']))
|
117
|
-
formatter.eref
|
117
|
+
formatter.eref
|
118
118
|
end
|
119
119
|
|
120
120
|
it { expect(definition).to(have_received(:eref).exactly(3).times.with(no_args)) }
|
121
|
-
it { expect(formatter.eref
|
121
|
+
it { expect(formatter.eref).to(eq(["A\nB", '', 'C'])) }
|
122
|
+
end
|
123
|
+
|
124
|
+
context 'when missing eref on the definition' do
|
125
|
+
before do
|
126
|
+
allow(document).to(
|
127
|
+
receive(:eref).with(no_args).and_return(
|
128
|
+
a: 'whatever', b: 'whatever'
|
129
|
+
)
|
130
|
+
)
|
131
|
+
allow(definition).to(receive(:eref).with(no_args).and_return(b: ['B']))
|
132
|
+
formatter.eref
|
133
|
+
end
|
134
|
+
|
135
|
+
it { expect(definition).to(have_received(:eref).exactly(2).times.with(no_args)) }
|
136
|
+
it { expect(formatter.eref).to(eq(['', 'B'])) }
|
122
137
|
end
|
123
138
|
end
|
124
139
|
|
@@ -128,21 +143,21 @@ RSpec.describe(DefMastership::CSVFormatterBody) do
|
|
128
143
|
context 'when no iref on the definition' do
|
129
144
|
before do
|
130
145
|
allow(definition).to(receive(:iref).with(no_args).and_return([]))
|
131
|
-
formatter.iref
|
146
|
+
formatter.iref
|
132
147
|
end
|
133
148
|
|
134
149
|
it { expect(definition).to(have_received(:iref).with(no_args)) }
|
135
|
-
it { expect(formatter.iref
|
150
|
+
it { expect(formatter.iref).to(eq([''])) }
|
136
151
|
end
|
137
152
|
|
138
153
|
context 'when iref on the definition' do
|
139
154
|
before do
|
140
155
|
allow(definition).to(receive(:iref).with(no_args).and_return(%w[A B]))
|
141
|
-
formatter.iref
|
156
|
+
formatter.iref
|
142
157
|
end
|
143
158
|
|
144
159
|
it { expect(definition).to(have_received(:iref).with(no_args)) }
|
145
|
-
it { expect(formatter.iref
|
160
|
+
it { expect(formatter.iref).to(eq(["A\nB"])) }
|
146
161
|
end
|
147
162
|
end
|
148
163
|
|
@@ -150,11 +165,11 @@ RSpec.describe(DefMastership::CSVFormatterBody) do
|
|
150
165
|
context 'when no attributes on the document' do
|
151
166
|
before do
|
152
167
|
allow(document).to(receive(:attributes).with(no_args).and_return({}))
|
153
|
-
formatter.attributes
|
168
|
+
formatter.attributes
|
154
169
|
end
|
155
170
|
|
156
171
|
it { expect(document).to(have_received(:attributes).with(no_args)) }
|
157
|
-
it { expect(formatter.attributes
|
172
|
+
it { expect(formatter.attributes).to(eq([])) }
|
158
173
|
end
|
159
174
|
|
160
175
|
context 'when attributes on the document' do
|
@@ -164,11 +179,25 @@ RSpec.describe(DefMastership::CSVFormatterBody) do
|
|
164
179
|
.and_return(a: 'whatever', b: 'whatever', c: 'whatever')
|
165
180
|
)
|
166
181
|
allow(definition).to(receive(:attributes).and_return(a: 'X', b: '', c: 'Y'))
|
167
|
-
formatter.attributes
|
182
|
+
formatter.attributes
|
183
|
+
end
|
184
|
+
|
185
|
+
it { expect(definition).to(have_received(:attributes).exactly(3).times) }
|
186
|
+
it { expect(formatter.attributes).to(eq(['X', '', 'Y'])) }
|
187
|
+
end
|
188
|
+
|
189
|
+
context 'when miing attribute on the definition' do
|
190
|
+
before do
|
191
|
+
allow(document).to(
|
192
|
+
receive(:attributes).with(no_args)
|
193
|
+
.and_return(a: 'whatever', b: 'whatever', c: 'whatever')
|
194
|
+
)
|
195
|
+
allow(definition).to(receive(:attributes).and_return(a: 'X', b: ''))
|
196
|
+
formatter.attributes
|
168
197
|
end
|
169
198
|
|
170
199
|
it { expect(definition).to(have_received(:attributes).exactly(3).times) }
|
171
|
-
it { expect(formatter.attributes
|
200
|
+
it { expect(formatter.attributes).to(eq(['X', '', ''])) }
|
172
201
|
end
|
173
202
|
end
|
174
203
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# Copyright (c) 2020 Jerome Arbez-Gindre
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
require('defmastership')
|
4
|
+
require('defmastership/csv_formatter_header')
|
5
5
|
|
6
6
|
RSpec.describe(DefMastership::CSVFormatterHeader) do
|
7
7
|
subject(:formatter) { described_class.new(document) }
|
@@ -9,7 +9,7 @@ RSpec.describe(DefMastership::CSVFormatterHeader) do
|
|
9
9
|
let(:document) { instance_double(DefMastership::Document, 'document') }
|
10
10
|
|
11
11
|
describe '.new' do
|
12
|
-
it { is_expected.not_to(
|
12
|
+
it { is_expected.not_to(be_nil) }
|
13
13
|
end
|
14
14
|
|
15
15
|
describe '#header' do
|