defmastership 1.0.17 → 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/.gitlab-ci.yml +22 -10
- data/Gemfile +51 -1
- data/Rakefile +16 -61
- data/bin/defmastership +9 -6
- data/config/mutant.yml +23 -3
- data/defmastership.gemspec +0 -10
- 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 +88 -6
- data/lib/defmastership/comment_filter.rb +1 -1
- data/lib/defmastership/constants.rb +5 -4
- data/lib/defmastership/csv_formatter.rb +16 -12
- 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 +1 -6
- data/spec/spec_helper.rb +3 -1
- data/spec/unit/def_mastership/batch_modifier_spec.rb +38 -36
- data/spec/unit/def_mastership/change_ref_modifier_spec.rb +196 -51
- data/spec/unit/def_mastership/csv_formatter_body_spec.rb +60 -31
- data/spec/unit/def_mastership/csv_formatter_header_spec.rb +1 -1
- data/spec/unit/def_mastership/csv_formatter_spec.rb +79 -87
- data/spec/unit/def_mastership/definition_parser_spec.rb +1 -1
- data/spec/unit/def_mastership/definition_spec.rb +16 -6
- data/spec/unit/def_mastership/document_spec.rb +81 -38
- 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/def_mastership/parsing_state_spec.rb +1 -1
- data/spec/unit/def_mastership/rename_included_files_modifier_spec.rb +219 -47
- data/spec/unit/def_mastership/string_spec.rb +1 -1
- data/spec/unit/def_mastership/update_def_checksum_modifier_spec.rb +82 -50
- data/spec/unit/def_mastership/update_def_modifier_spec.rb +119 -0
- data/spec/unit/def_mastership/update_def_version_modifier_spec.rb +135 -56
- 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 +16 -153
- data/lib/defmastership/change_ref_line_modifier.rb +0 -85
- data/lib/defmastership/line_modifier_base.rb +0 -29
- data/lib/defmastership/modifier_base.rb +0 -36
- 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/def_mastership/change_ref_line_modifier_spec.rb +0 -250
- data/spec/unit/def_mastership/rename_included_files_line_modifier_spec.rb +0 -207
- data/spec/unit/def_mastership/update_def_checksum_line_modifier_spec.rb +0 -82
- data/spec/unit/def_mastership/update_def_version_line_modifier_spec.rb +0 -131
@@ -1,76 +1,221 @@
|
|
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
6
|
RSpec.describe(DefMastership::ChangeRefModifier) do
|
7
|
-
subject(:
|
8
|
-
|
9
|
-
|
10
|
-
)
|
7
|
+
subject(:refchanger) { described_class.new({}) }
|
8
|
+
|
9
|
+
describe '.new' do
|
10
|
+
it { expect(described_class.ancestors).to(include(DefMastership::Modifier)) }
|
11
|
+
it { is_expected.not_to(be_nil) }
|
12
|
+
it { is_expected.to(have_attributes(from_regexp: '')) }
|
13
|
+
it { is_expected.to(have_attributes(to_template: '')) }
|
14
|
+
it { is_expected.to(have_attributes(next_ref: 0)) }
|
11
15
|
end
|
12
16
|
|
13
|
-
|
14
|
-
{
|
15
|
-
'file1.adoc' => "file1 line1\nfile1 line2",
|
16
|
-
'file2.adoc' => "file2 line1\nfile2 line2"
|
17
|
-
}
|
17
|
+
describe '.replacement_methods' do
|
18
|
+
it { expect(described_class.replacement_methods).to(eq(%i[replace_refdef replace_irefs])) }
|
18
19
|
end
|
19
20
|
|
20
|
-
describe '
|
21
|
-
|
22
|
-
|
23
|
-
|
21
|
+
describe '#config' do
|
22
|
+
context 'when not initalized' do
|
23
|
+
it do
|
24
|
+
expect(refchanger.config).to(
|
25
|
+
include(from_regexp: '', to_template: '', next_ref: 0)
|
26
|
+
)
|
27
|
+
end
|
28
|
+
end
|
24
29
|
end
|
25
30
|
|
26
|
-
describe '#
|
27
|
-
|
31
|
+
describe '#replace_def' do
|
32
|
+
context 'when really simple rule' do
|
33
|
+
subject(:refchanger) do
|
34
|
+
described_class.new(
|
35
|
+
from_regexp: 'TEMP',
|
36
|
+
to_template: 'TUTU'
|
37
|
+
)
|
38
|
+
end
|
28
39
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
allow(line_modifier).to(receive(:changes).and_return([%w[from1 to1], %w[from2 to2]]))
|
40
|
+
context 'when valid definition' do
|
41
|
+
it do
|
42
|
+
expect(refchanger.replace_refdef('[define, whatever, TEMP]'))
|
43
|
+
.to(eq('[define, whatever, TUTU]'))
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context 'when no valid definition' do
|
48
|
+
it do
|
49
|
+
expect(refchanger.replace_refdef('[pouet, whatever, TEMP]'))
|
50
|
+
.to(eq('[pouet, whatever, TEMP]'))
|
51
|
+
end
|
52
|
+
end
|
43
53
|
end
|
44
54
|
|
45
|
-
context 'when
|
46
|
-
|
55
|
+
context 'when template is variable' do
|
56
|
+
subject(:refchanger) do
|
57
|
+
described_class.new(
|
58
|
+
from_regexp: 'TEMP',
|
59
|
+
to_template: 'TOTO-%<next_ref>04d',
|
60
|
+
next_ref: 124
|
61
|
+
)
|
62
|
+
end
|
47
63
|
|
48
64
|
it do
|
49
|
-
expect(
|
50
|
-
|
65
|
+
expect(refchanger.replace_refdef('[define, whatever, TEMP]'))
|
66
|
+
.to(eq('[define, whatever, TOTO-0124]'))
|
67
|
+
end
|
68
|
+
|
69
|
+
it do
|
70
|
+
refchanger.replace_refdef('[define, whatever, TEMP]')
|
71
|
+
expect(refchanger).to(have_attributes(next_ref: 125))
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
context 'when capture group in regexp' do
|
76
|
+
subject(:refchanger) do
|
77
|
+
described_class.new(
|
78
|
+
from_regexp: '(?<cg>TOTO|TITI)-TEMP[\d]*',
|
79
|
+
to_template: '%<cg>s-%<next_ref>04d',
|
80
|
+
next_ref: 132
|
81
|
+
)
|
82
|
+
end
|
83
|
+
|
84
|
+
it do
|
85
|
+
expect(refchanger.replace_refdef('[define, whatever, TOTO-TEMP]'))
|
86
|
+
.to(eq('[define, whatever, TOTO-0132]'))
|
87
|
+
end
|
88
|
+
|
89
|
+
it do
|
90
|
+
refchanger.replace_refdef('[define, whatever, TOTO-TEMP]')
|
91
|
+
expect(refchanger.replace_refdef('[define, whatever, TITI-TEMP]'))
|
92
|
+
.to(eq('[define, whatever, TITI-0133]'))
|
93
|
+
end
|
94
|
+
|
95
|
+
it do
|
96
|
+
refchanger.replace_refdef('[define, whatever, TOTO-TEMP1]')
|
97
|
+
refchanger.replace_refdef('[define, whatever, TITI-TEMP2]')
|
98
|
+
expect(refchanger).to(have_attributes(changes: [%w[TOTO-TEMP1 TOTO-0132], %w[TITI-TEMP2 TITI-0133]]))
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
context 'when definition is in literal block' do
|
103
|
+
subject(:refchanger) do
|
104
|
+
described_class.new(
|
105
|
+
from_regexp: 'TEMP',
|
106
|
+
to_template: 'TUTU'
|
107
|
+
)
|
108
|
+
end
|
109
|
+
|
110
|
+
before do
|
111
|
+
refchanger.replace_refdef('....')
|
112
|
+
end
|
113
|
+
|
114
|
+
it do
|
115
|
+
expect(refchanger.replace_refdef('[define, whatever, TEMP]'))
|
116
|
+
.to(eq('[define, whatever, TEMP]'))
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
context 'when defintion is after literal block' do
|
121
|
+
subject(:refchanger) do
|
122
|
+
described_class.new(
|
123
|
+
from_regexp: 'TEMP',
|
124
|
+
to_template: 'TUTU'
|
51
125
|
)
|
52
126
|
end
|
53
127
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
it
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
128
|
+
before do
|
129
|
+
refchanger.replace_refdef("....\n")
|
130
|
+
refchanger.replace_refdef('[define, whatever, TEMP]')
|
131
|
+
refchanger.replace_refdef("....\n")
|
132
|
+
end
|
133
|
+
|
134
|
+
it do
|
135
|
+
expect(refchanger.replace_refdef('[define, whatever, TEMP]'))
|
136
|
+
.to(eq('[define, whatever, TUTU]'))
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
describe '#replace_irefs' do
|
142
|
+
subject(:refchanger) do
|
143
|
+
described_class.new(
|
144
|
+
from_regexp: '(?<cg>TOTO|TITI)-TEMP[\d]*',
|
145
|
+
to_template: '%<cg>s-%<next_ref>04d',
|
146
|
+
next_ref: 132
|
147
|
+
)
|
148
|
+
end
|
149
|
+
|
150
|
+
before do
|
151
|
+
refchanger.replace_refdef('[define, whatever, TOTO-TEMP123]')
|
152
|
+
refchanger.replace_refdef('[define, whatever, TITI-TEMP421]')
|
153
|
+
end
|
154
|
+
|
155
|
+
it do
|
156
|
+
expect(refchanger.replace_irefs('defs:iref[TOTO-TEMP1234]'))
|
157
|
+
.to(eq('defs:iref[TOTO-TEMP1234]'))
|
158
|
+
end
|
159
|
+
|
160
|
+
it do
|
161
|
+
expect(refchanger.replace_irefs('defs:iref[TOTO-TEMP123]'))
|
162
|
+
.to(eq('defs:iref[TOTO-0132]'))
|
163
|
+
end
|
164
|
+
|
165
|
+
it do
|
166
|
+
expect(
|
167
|
+
refchanger.replace_irefs(
|
168
|
+
'defs:iref[TOTO-TEMP123] defs:iref[TITI-TEMP421] bla'
|
169
|
+
)
|
170
|
+
).to(eq('defs:iref[TOTO-0132] defs:iref[TITI-0133] bla'))
|
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
|
180
|
+
end
|
181
|
+
|
182
|
+
describe '#replace' do
|
183
|
+
subject(:refchanger) do
|
184
|
+
described_class.new(
|
185
|
+
from_regexp: 'TEMP',
|
186
|
+
to_template: 'TUTU'
|
187
|
+
)
|
188
|
+
end
|
189
|
+
|
190
|
+
it do
|
191
|
+
expect(refchanger.replace(:refdef, '[define, whatever, TEMP]'))
|
192
|
+
.to(eq('[define, whatever, TUTU]'))
|
193
|
+
end
|
194
|
+
|
195
|
+
it do
|
196
|
+
expect(refchanger.replace(:refdef, '[define, whatever, TEMP(a~12345678)]'))
|
197
|
+
.to(eq('[define, whatever, TUTU(a~12345678)]'))
|
198
|
+
end
|
199
|
+
|
200
|
+
it do
|
201
|
+
expect(refchanger.replace(:refdef, '[define, whatever, TEMP(~12345678)]'))
|
202
|
+
.to(eq('[define, whatever, TUTU(~12345678)]'))
|
203
|
+
end
|
204
|
+
|
205
|
+
it do
|
206
|
+
expect(refchanger.replace(:refdef, '[define, whatever, TEMP(a)]'))
|
207
|
+
.to(eq('[define, whatever, TUTU(a)]'))
|
208
|
+
end
|
209
|
+
|
210
|
+
it do
|
211
|
+
refchanger.replace(:refdef, '[define, whatever, TEMP]')
|
212
|
+
expect(refchanger.replace(:irefs, 'defs:iref[TEMP] defs:iref[TEMP]'))
|
213
|
+
.to(eq('defs:iref[TUTU] defs:iref[TUTU]'))
|
66
214
|
end
|
67
215
|
|
68
216
|
it do
|
69
|
-
|
70
|
-
|
71
|
-
'file2.adoc' => "new2 file2 line1\nnew2 file2 line2"
|
72
|
-
}
|
73
|
-
expect(modifier.do_modifications(adoc_texts)).to(eq(expected_adoc))
|
217
|
+
expect { refchanger.replace(:pouet, 'whatever') }
|
218
|
+
.to(raise_error(NoMethodError))
|
74
219
|
end
|
75
220
|
end
|
76
221
|
end
|
@@ -1,10 +1,10 @@
|
|
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') }
|
@@ -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
|