defmastership 1.0.6 → 1.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/defmastership +12 -7
- data/features/changeref.feature +33 -0
- data/features/definition_checksum.feature +298 -0
- data/features/definition_version.feature +204 -0
- data/features/export.feature +21 -74
- data/features/modify.feature +23 -1
- data/lib/defmastership.rb +6 -0
- data/lib/defmastership/batch_modifier.rb +2 -0
- data/lib/defmastership/change_ref_line_modifier.rb +2 -1
- data/lib/defmastership/change_ref_modifier.rb +2 -2
- data/lib/defmastership/constants.rb +4 -2
- data/lib/defmastership/csv_formatter.rb +12 -6
- data/lib/defmastership/csv_formatter_body.rb +8 -5
- data/lib/defmastership/csv_formatter_header.rb +5 -1
- data/lib/defmastership/definition.rb +4 -4
- data/lib/defmastership/document.rb +33 -27
- data/lib/defmastership/modifier_base.rb +1 -1
- data/lib/defmastership/rename_included_files_modifier.rb +2 -17
- data/lib/defmastership/update_def_checksum_line_modifier.rb +38 -0
- data/lib/defmastership/update_def_checksum_modifier.rb +21 -0
- data/lib/defmastership/update_def_version_line_modifier.rb +58 -0
- data/lib/defmastership/update_def_version_modifier.rb +25 -0
- data/lib/defmastership/version.rb +1 -1
- data/spec/unit/defmastership/batch_modifier_spec.rb +8 -0
- data/spec/unit/defmastership/change_ref_line_modifier_spec.rb +15 -0
- data/spec/unit/defmastership/csv_formatter_body_spec.rb +42 -60
- data/spec/unit/defmastership/csv_formatter_header_spec.rb +23 -1
- data/spec/unit/defmastership/csv_formatter_spec.rb +204 -67
- data/spec/unit/defmastership/definition_spec.rb +19 -4
- data/spec/unit/defmastership/document_spec.rb +129 -5
- data/spec/unit/defmastership/update_def_checksum_line_modifier_spec.rb +78 -0
- data/spec/unit/defmastership/update_def_checksum_modifier_spec.rb +75 -0
- data/spec/unit/defmastership/update_def_version_line_modifier_spec.rb +127 -0
- data/spec/unit/defmastership/update_def_version_modifier_spec.rb +80 -0
- metadata +12 -2
@@ -4,27 +4,12 @@
|
|
4
4
|
module DefMastership
|
5
5
|
# Change included filenames
|
6
6
|
class RenameIncludedFilesModifier < ModifierBase
|
7
|
-
def do_modifications(adoc_texts)
|
8
|
-
line_modifier = line_modifier_class.from_config(@config)
|
9
|
-
|
10
|
-
adoc_texts =
|
11
|
-
replacements.reduce(adoc_texts) do |texts, method|
|
12
|
-
texts.transform_values do |text|
|
13
|
-
text.lines.map { |line| line_modifier.public_send(method, line) }.join
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
@config = line_modifier.config
|
18
|
-
@changes = line_modifier.changes
|
19
|
-
adoc_texts
|
20
|
-
end
|
21
|
-
|
22
7
|
def replacements
|
23
8
|
%i[replace]
|
24
9
|
end
|
25
10
|
|
26
|
-
def
|
27
|
-
RenameIncludedFilesLineModifier
|
11
|
+
def new_line_modifier(config, _adoc_texts)
|
12
|
+
RenameIncludedFilesLineModifier.from_config(config)
|
28
13
|
end
|
29
14
|
end
|
30
15
|
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# Copyright (c) 2020 Jerome Arbez-Gindre
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module DefMastership
|
5
|
+
# modify one line after another
|
6
|
+
class UpdateDefChecksumLineModifier < LineModifierBase
|
7
|
+
attr_accessor :document
|
8
|
+
|
9
|
+
def self.from_config(hash)
|
10
|
+
new.from_config(hash)
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize
|
14
|
+
super
|
15
|
+
@config = {
|
16
|
+
def_type: ''
|
17
|
+
}
|
18
|
+
end
|
19
|
+
|
20
|
+
def replace(line)
|
21
|
+
match = matched?(line)
|
22
|
+
|
23
|
+
return line unless match
|
24
|
+
return line unless match[:type] == def_type
|
25
|
+
|
26
|
+
line.gsub(Regexp.new("#{match[:reference]}#{DMRegexp::DEF_VERSION_AND_CHECKSUM}")) do
|
27
|
+
"#{match[:reference]}(#{match[:explicit_version]}#{@document.ref_to_def(match[:reference]).sha256})"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def matched?(line)
|
32
|
+
return if line.commented?
|
33
|
+
return unless line =~ DMRegexp::DEFINITION
|
34
|
+
|
35
|
+
Regexp.last_match
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# Copyright (c) 2020 Jerome Arbez-Gindre
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module DefMastership
|
5
|
+
# Update definition checksum with calculated one
|
6
|
+
class UpdateDefChecksumModifier < ModifierBase
|
7
|
+
def replacements
|
8
|
+
%i[replace]
|
9
|
+
end
|
10
|
+
|
11
|
+
def new_line_modifier(config, adoc_texts)
|
12
|
+
document = Document.new
|
13
|
+
adoc_texts.each do |adoc_file, _|
|
14
|
+
document.parse_file_with_preprocessor(adoc_file)
|
15
|
+
end
|
16
|
+
line_modifier = UpdateDefChecksumLineModifier.from_config(config)
|
17
|
+
line_modifier.document = document
|
18
|
+
line_modifier
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# Copyright (c) 2020 Jerome Arbez-Gindre
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module DefMastership
|
5
|
+
# modify one line after another
|
6
|
+
class UpdateDefVersionLineModifier < LineModifierBase
|
7
|
+
attr_accessor :document, :ref_document
|
8
|
+
|
9
|
+
def self.from_config(hash)
|
10
|
+
new.from_config(hash)
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize
|
14
|
+
super
|
15
|
+
@config = {
|
16
|
+
def_type: '',
|
17
|
+
ref_document: '',
|
18
|
+
first_version: ''
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
def replace(line)
|
23
|
+
match = matched?(line)
|
24
|
+
|
25
|
+
return line unless match
|
26
|
+
return line unless match[:type] == def_type
|
27
|
+
|
28
|
+
version_and_checksum = ''
|
29
|
+
if match[:explicit_checksum] || version_string(match)
|
30
|
+
version_and_checksum = "(#{version_string(match)}#{match[:explicit_checksum]})"
|
31
|
+
end
|
32
|
+
|
33
|
+
line.gsub(Regexp.new("#{match[:reference]}#{DMRegexp::DEF_VERSION_AND_CHECKSUM}")) do
|
34
|
+
"#{match[:reference]}#{version_and_checksum}"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def matched?(line)
|
41
|
+
return if line.commented?
|
42
|
+
return unless line =~ DMRegexp::DEFINITION
|
43
|
+
|
44
|
+
Regexp.last_match
|
45
|
+
end
|
46
|
+
|
47
|
+
def version_string(match)
|
48
|
+
ref_definition = @ref_document.ref_to_def(match[:reference])
|
49
|
+
definition = @document.ref_to_def(match[:reference])
|
50
|
+
|
51
|
+
return if ref_definition.nil?
|
52
|
+
return ref_definition.explicit_version if definition.sha256 == ref_definition.sha256
|
53
|
+
|
54
|
+
ref_version = @ref_document.ref_to_def(match[:reference]).explicit_version
|
55
|
+
ref_version.nil? ? @config[:first_version] : ref_version.next
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# Copyright (c) 2020 Jerome Arbez-Gindre
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module DefMastership
|
5
|
+
# Update definition version if the definition has change since
|
6
|
+
# reference document
|
7
|
+
class UpdateDefVersionModifier < ModifierBase
|
8
|
+
def replacements
|
9
|
+
%i[replace]
|
10
|
+
end
|
11
|
+
|
12
|
+
def new_line_modifier(config, adoc_texts)
|
13
|
+
document = Document.new
|
14
|
+
adoc_texts.each do |adoc_file, _|
|
15
|
+
document.parse_file_with_preprocessor(adoc_file)
|
16
|
+
end
|
17
|
+
ref_document = Document.new
|
18
|
+
ref_document.parse_file_with_preprocessor(config[:ref_document])
|
19
|
+
line_modifier = UpdateDefVersionLineModifier.from_config(config)
|
20
|
+
line_modifier.document = document
|
21
|
+
line_modifier.ref_document = ref_document
|
22
|
+
line_modifier
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -111,5 +111,13 @@ RSpec.describe(DefMastership::BatchModifier) do
|
|
111
111
|
it { is_expected.to(have_attributes(config: config_modified)) }
|
112
112
|
it { is_expected.to(have_attributes(changes: [%w[modifier2 from1 to1], %w[modifier3 from2 to2]])) }
|
113
113
|
end
|
114
|
+
|
115
|
+
context 'with wrong modification' do
|
116
|
+
it do
|
117
|
+
expect { batchmodifier.apply('wrong-modification') }.to(
|
118
|
+
raise_error(ArgumentError, 'wrong-modification is not a known modification')
|
119
|
+
)
|
120
|
+
end
|
121
|
+
end
|
114
122
|
end
|
115
123
|
end
|
@@ -217,6 +217,21 @@ RSpec.describe(DefMastership::ChangeRefLineModifier) do
|
|
217
217
|
.to(eq('[define, whatever, TUTU]'))
|
218
218
|
end
|
219
219
|
|
220
|
+
it do
|
221
|
+
expect(refchanger.replace(:refdef, '[define, whatever, TEMP(a~12345678)]'))
|
222
|
+
.to(eq('[define, whatever, TUTU(a~12345678)]'))
|
223
|
+
end
|
224
|
+
|
225
|
+
it do
|
226
|
+
expect(refchanger.replace(:refdef, '[define, whatever, TEMP(~12345678)]'))
|
227
|
+
.to(eq('[define, whatever, TUTU(~12345678)]'))
|
228
|
+
end
|
229
|
+
|
230
|
+
it do
|
231
|
+
expect(refchanger.replace(:refdef, '[define, whatever, TEMP(a)]'))
|
232
|
+
.to(eq('[define, whatever, TUTU(a)]'))
|
233
|
+
end
|
234
|
+
|
220
235
|
it do
|
221
236
|
refchanger.replace(:refdef, '[define, whatever, TEMP]')
|
222
237
|
expect(refchanger.replace(:irefs, 'defs:iref[TEMP]'))
|
@@ -23,13 +23,9 @@ RSpec.describe(DefMastership::CSVFormatterBody) do
|
|
23
23
|
end
|
24
24
|
|
25
25
|
it { expect(definition).to(have_received(:type).with(no_args)) }
|
26
|
-
|
27
26
|
it { expect(definition).to(have_received(:reference).with(no_args)) }
|
28
|
-
|
29
27
|
it { expect(definition).to(have_received(:value).with(no_args)) }
|
30
|
-
|
31
28
|
it { expect(definition).to(have_received(:sha256).with(no_args)) }
|
32
|
-
|
33
29
|
it { expect(formatter.fixed(definition)).to(eq(%w[a b c d])) }
|
34
30
|
end
|
35
31
|
|
@@ -41,7 +37,6 @@ RSpec.describe(DefMastership::CSVFormatterBody) do
|
|
41
37
|
end
|
42
38
|
|
43
39
|
it { expect(definition).to(have_received(:wrong_explicit_checksum).with(no_args)) }
|
44
|
-
|
45
40
|
it { expect(formatter.wrong_explicit_checksum(definition)).to(eq([''])) }
|
46
41
|
end
|
47
42
|
|
@@ -55,42 +50,48 @@ RSpec.describe(DefMastership::CSVFormatterBody) do
|
|
55
50
|
end
|
56
51
|
end
|
57
52
|
|
58
|
-
describe '#
|
59
|
-
context 'when no
|
53
|
+
describe '#explicit_version' do
|
54
|
+
context 'when no explicit_version' do
|
60
55
|
before do
|
61
|
-
allow(
|
62
|
-
formatter.
|
56
|
+
allow(definition).to(receive(:explicit_version).with(no_args).and_return(nil))
|
57
|
+
formatter.explicit_version(definition)
|
63
58
|
end
|
64
59
|
|
65
|
-
it { expect(
|
66
|
-
|
67
|
-
it { expect(formatter.labels(definition)).to(eq([])) }
|
60
|
+
it { expect(definition).to(have_received(:explicit_version).with(no_args)) }
|
61
|
+
it { expect(formatter.explicit_version(definition)).to(eq([''])) }
|
68
62
|
end
|
69
63
|
|
70
|
-
context 'when
|
71
|
-
before
|
64
|
+
context 'when explicit_version' do
|
65
|
+
before do
|
66
|
+
allow(definition).to(receive(:explicit_version).with(no_args).and_return('ab12'))
|
67
|
+
formatter.explicit_version(definition)
|
68
|
+
end
|
72
69
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
formatter.labels(definition)
|
77
|
-
end
|
70
|
+
it { expect(formatter.explicit_version(definition)).to(eq(['ab12'])) }
|
71
|
+
end
|
72
|
+
end
|
78
73
|
|
79
|
-
|
74
|
+
describe '#labels' do
|
75
|
+
before { allow(document).to(receive(:labels).with(no_args).and_return(['whatever'])) }
|
80
76
|
|
81
|
-
|
77
|
+
context 'when no labels on definition' do
|
78
|
+
before do
|
79
|
+
allow(definition).to(receive(:labels).with(no_args).and_return([]))
|
80
|
+
formatter.labels(definition)
|
82
81
|
end
|
83
82
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
formatter.labels(definition)
|
88
|
-
end
|
89
|
-
|
90
|
-
it { expect(definition).to(have_received(:labels).once.with(no_args)) }
|
83
|
+
it { expect(definition).to(have_received(:labels).once.with(no_args)) }
|
84
|
+
it { expect(formatter.labels(definition)).to(eq([''])) }
|
85
|
+
end
|
91
86
|
|
92
|
-
|
87
|
+
context 'when labels on definition' do
|
88
|
+
before do
|
89
|
+
allow(definition).to(receive(:labels).with(no_args).and_return(%w[toto tutu]))
|
90
|
+
formatter.labels(definition)
|
93
91
|
end
|
92
|
+
|
93
|
+
it { expect(definition).to(have_received(:labels).once.with(no_args)) }
|
94
|
+
it { expect(formatter.labels(definition)).to(eq(["toto\ntutu"])) }
|
94
95
|
end
|
95
96
|
end
|
96
97
|
|
@@ -102,7 +103,6 @@ RSpec.describe(DefMastership::CSVFormatterBody) do
|
|
102
103
|
end
|
103
104
|
|
104
105
|
it { expect(document).to(have_received(:eref).with(no_args)) }
|
105
|
-
|
106
106
|
it { expect(formatter.eref(nil)).to(eq([])) }
|
107
107
|
end
|
108
108
|
|
@@ -118,47 +118,31 @@ RSpec.describe(DefMastership::CSVFormatterBody) do
|
|
118
118
|
end
|
119
119
|
|
120
120
|
it { expect(definition).to(have_received(:eref).exactly(3).times.with(no_args)) }
|
121
|
-
|
122
121
|
it { expect(formatter.eref(definition)).to(eq(["A\nB", '', 'C'])) }
|
123
122
|
end
|
124
123
|
end
|
125
124
|
|
126
125
|
describe '#iref' do
|
127
|
-
|
126
|
+
before { allow(document).to(receive(:iref).with(no_args).and_return(true)) }
|
127
|
+
|
128
|
+
context 'when no iref on the definition' do
|
128
129
|
before do
|
129
|
-
allow(
|
130
|
+
allow(definition).to(receive(:iref).with(no_args).and_return([]))
|
130
131
|
formatter.iref(definition)
|
131
132
|
end
|
132
133
|
|
133
|
-
it { expect(
|
134
|
-
|
135
|
-
it { expect(formatter.iref(definition)).to(eq([])) }
|
134
|
+
it { expect(definition).to(have_received(:iref).with(no_args)) }
|
135
|
+
it { expect(formatter.iref(definition)).to(eq([''])) }
|
136
136
|
end
|
137
137
|
|
138
|
-
context 'when iref on the
|
139
|
-
before
|
140
|
-
|
141
|
-
|
142
|
-
before do
|
143
|
-
allow(definition).to(receive(:iref).with(no_args).and_return([]))
|
144
|
-
formatter.iref(definition)
|
145
|
-
end
|
146
|
-
|
147
|
-
it { expect(definition).to(have_received(:iref).with(no_args)) }
|
148
|
-
|
149
|
-
it { expect(formatter.iref(definition)).to(eq([''])) }
|
138
|
+
context 'when iref on the definition' do
|
139
|
+
before do
|
140
|
+
allow(definition).to(receive(:iref).with(no_args).and_return(%w[A B]))
|
141
|
+
formatter.iref(definition)
|
150
142
|
end
|
151
143
|
|
152
|
-
|
153
|
-
|
154
|
-
allow(definition).to(receive(:iref).with(no_args).and_return(%w[A B]))
|
155
|
-
formatter.iref(definition)
|
156
|
-
end
|
157
|
-
|
158
|
-
it { expect(definition).to(have_received(:iref).with(no_args)) }
|
159
|
-
|
160
|
-
it { expect(formatter.iref(definition)).to(eq(["A\nB"])) }
|
161
|
-
end
|
144
|
+
it { expect(definition).to(have_received(:iref).with(no_args)) }
|
145
|
+
it { expect(formatter.iref(definition)).to(eq(["A\nB"])) }
|
162
146
|
end
|
163
147
|
end
|
164
148
|
|
@@ -170,7 +154,6 @@ RSpec.describe(DefMastership::CSVFormatterBody) do
|
|
170
154
|
end
|
171
155
|
|
172
156
|
it { expect(document).to(have_received(:attributes).with(no_args)) }
|
173
|
-
|
174
157
|
it { expect(formatter.attributes(nil)).to(eq([])) }
|
175
158
|
end
|
176
159
|
|
@@ -185,7 +168,6 @@ RSpec.describe(DefMastership::CSVFormatterBody) do
|
|
185
168
|
end
|
186
169
|
|
187
170
|
it { expect(definition).to(have_received(:attributes).exactly(3).times) }
|
188
|
-
|
189
171
|
it { expect(formatter.attributes(definition)).to(eq(['X', '', 'Y'])) }
|
190
172
|
end
|
191
173
|
end
|
@@ -14,7 +14,29 @@ RSpec.describe(DefMastership::CSVFormatterHeader) do
|
|
14
14
|
|
15
15
|
describe '#header' do
|
16
16
|
describe '#fixed' do
|
17
|
-
it { expect(formatter.fixed).to(eq(%w[Type Reference Value
|
17
|
+
it { expect(formatter.fixed).to(eq(%w[Type Reference Value Checksum])) }
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#explicit_version' do
|
21
|
+
context 'when no explicit version' do
|
22
|
+
before do
|
23
|
+
allow(document).to(receive(:explicit_version?).and_return(false))
|
24
|
+
formatter.explicit_version
|
25
|
+
end
|
26
|
+
|
27
|
+
it { expect(document).to(have_received(:explicit_version?)) }
|
28
|
+
|
29
|
+
it { expect(formatter.explicit_version).to(eq([])) }
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'when explicit version' do
|
33
|
+
before do
|
34
|
+
allow(document).to(receive(:explicit_version?).and_return(true))
|
35
|
+
formatter.explicit_version
|
36
|
+
end
|
37
|
+
|
38
|
+
it { expect(formatter.explicit_version).to(eq(['Version'])) }
|
39
|
+
end
|
18
40
|
end
|
19
41
|
|
20
42
|
describe '#wrong_explicit_checksum' do
|
@@ -15,20 +15,29 @@ RSpec.describe(DefMastership::CSVFormatter) do
|
|
15
15
|
end
|
16
16
|
|
17
17
|
describe '#export_to' do
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
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]
|
22
38
|
|
23
|
-
methods1 = %i[fixed wrong_explicit_checksum labels eref iref attributes]
|
24
39
|
before do
|
25
|
-
|
26
|
-
allow(csv).to(receive(:<<))
|
27
|
-
allow(DefMastership::CSVFormatterHeader).to(receive(:new).with(document).and_return(header))
|
28
|
-
allow(DefMastership::CSVFormatterBody).to(receive(:new).with(document).and_return(body))
|
29
|
-
allow(document).to(receive(:definitions).and_return(%i[def1 def2]))
|
30
|
-
allow(document).to(receive(:wrong_explicit_checksum?).with(no_args).and_return(true))
|
31
|
-
methods1.each do |method|
|
40
|
+
methods.each do |method|
|
32
41
|
allow(header).to(receive(method).with(no_args).and_return(["#{method} header"]))
|
33
42
|
allow(body).to(receive(method).with(:def1).and_return(["#{method} def1 body"]))
|
34
43
|
allow(body).to(receive(method).with(:def2).and_return(["#{method} def2 body"]))
|
@@ -36,98 +45,226 @@ RSpec.describe(DefMastership::CSVFormatter) do
|
|
36
45
|
formatter.export_to('whatever')
|
37
46
|
end
|
38
47
|
|
39
|
-
|
48
|
+
methods.each do |method|
|
40
49
|
it { expect(header).to(have_received(method).with(no_args)) }
|
41
50
|
it { expect(body).to(have_received(method).with(:def1)) }
|
42
51
|
it { expect(body).to(have_received(method).with(:def2)) }
|
43
52
|
end
|
44
53
|
|
45
|
-
it
|
46
|
-
|
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
|
58
|
+
|
59
|
+
context 'when wrong_explicit_checksum' do
|
60
|
+
methods = %i[fixed wrong_explicit_checksum]
|
61
|
+
|
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')
|
47
70
|
end
|
48
71
|
|
49
|
-
|
50
|
-
expect(
|
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)) }
|
51
76
|
end
|
52
77
|
|
53
|
-
it
|
54
|
-
|
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" })) }
|
81
|
+
end
|
82
|
+
|
83
|
+
context 'when explicit_version' do
|
84
|
+
methods = %i[fixed explicit_version]
|
85
|
+
|
86
|
+
before do
|
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')
|
94
|
+
end
|
95
|
+
|
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
106
|
|
58
|
-
context 'when
|
59
|
-
|
60
|
-
let(:body) { instance_double(DefMastership::CSVFormatterBody, 'body') }
|
61
|
-
let(:csv) { instance_double(CSV, 'csv') }
|
107
|
+
context 'when labels' do
|
108
|
+
methods = %i[fixed labels]
|
62
109
|
|
63
|
-
methods2 = %i[fixed labels eref iref attributes]
|
64
110
|
before do
|
65
|
-
|
66
|
-
allow(csv).to(receive(:<<))
|
67
|
-
allow(DefMastership::CSVFormatterHeader).to(receive(:new).with(document).and_return(header))
|
68
|
-
allow(DefMastership::CSVFormatterBody).to(receive(:new).with(document).and_return(body))
|
69
|
-
allow(document).to(receive(:definitions).and_return(%i[def1 def2]))
|
70
|
-
allow(document).to(receive(:wrong_explicit_checksum?).with(no_args).and_return(false))
|
71
|
-
methods2.each do |method|
|
111
|
+
methods.each do |method|
|
72
112
|
allow(header).to(receive(method).with(no_args).and_return(["#{method} header"]))
|
73
113
|
allow(body).to(receive(method).with(:def1).and_return(["#{method} def1 body"]))
|
74
114
|
allow(body).to(receive(method).with(:def2).and_return(["#{method} def2 body"]))
|
75
115
|
end
|
116
|
+
allow(document).to(receive(:labels).with(no_args).and_return([:whatever]))
|
76
117
|
formatter.export_to('whatever')
|
77
118
|
end
|
78
119
|
|
79
|
-
|
120
|
+
methods.each do |method|
|
80
121
|
it { expect(header).to(have_received(method).with(no_args)) }
|
81
122
|
it { expect(body).to(have_received(method).with(:def1)) }
|
82
123
|
it { expect(body).to(have_received(method).with(:def2)) }
|
83
124
|
end
|
84
125
|
|
85
|
-
it
|
86
|
-
|
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
|
130
|
+
|
131
|
+
context 'when eref' do
|
132
|
+
methods = %i[fixed eref]
|
133
|
+
|
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')
|
87
142
|
end
|
88
143
|
|
89
|
-
|
90
|
-
expect(
|
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
|
149
|
+
|
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" })) }
|
153
|
+
end
|
154
|
+
|
155
|
+
context 'when iref' do
|
156
|
+
methods = %i[fixed iref]
|
157
|
+
|
158
|
+
before do
|
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
|
164
|
+
allow(document).to(receive(:iref).with(no_args).and_return(true))
|
165
|
+
formatter.export_to('whatever')
|
91
166
|
end
|
92
167
|
|
93
|
-
|
94
|
-
expect(
|
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)) }
|
95
172
|
end
|
173
|
+
|
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" })) }
|
96
177
|
end
|
97
178
|
|
98
|
-
context 'when
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
179
|
+
context 'when attributes' do
|
180
|
+
methods = %i[fixed attributes]
|
181
|
+
|
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
|
191
|
+
|
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)) }
|
105
196
|
end
|
106
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" })) }
|
201
|
+
end
|
202
|
+
|
203
|
+
context 'when every colums' do
|
204
|
+
methods = %i[fixed wrong_explicit_checksum explicit_version labels eref iref attributes]
|
205
|
+
|
107
206
|
before do
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
allow(document).to(receive(:
|
114
|
-
allow(document).to(receive(:
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
it { expect(document).to(have_received(:iref).exactly(3).times.with(no_args)) }
|
121
|
-
it { expect(document).to(have_received(:attributes).exactly(3).times.with(no_args)) }
|
122
|
-
it { expect(document).to(have_received(:definitions).with(no_args)) }
|
123
|
-
|
124
|
-
it do
|
125
|
-
expect(target_file).to(have_file_content(<<~CSV_FILE))
|
126
|
-
Type;Reference;Value;sha256
|
127
|
-
a;b;c;d
|
128
|
-
d;e;f;g
|
129
|
-
CSV_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')
|
130
219
|
end
|
220
|
+
|
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
|
226
|
+
|
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
|
232
|
+
|
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
|
241
|
+
|
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
|
253
|
+
|
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
|
131
268
|
end
|
132
269
|
end
|
133
270
|
end
|