defmastership 1.0.5 → 1.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/bin/defmastership +33 -22
- data/cucumber.yml +1 -1
- data/defmastership.gemspec +12 -6
- data/features/changeref.feature +82 -129
- data/features/definition_checksum.feature +298 -0
- data/features/definition_version.feature +204 -0
- data/features/export.feature +35 -34
- data/features/modify.feature +165 -0
- data/features/rename_included_files.feature +121 -0
- data/lib/defmastership.rb +17 -3
- data/lib/defmastership/batch_modifier.rb +35 -0
- data/lib/defmastership/{ref_changer.rb → change_ref_line_modifier.rb} +18 -35
- data/lib/defmastership/change_ref_modifier.rb +15 -0
- data/lib/defmastership/constants.rb +14 -1
- data/lib/defmastership/csv_formatter.rb +22 -17
- data/lib/defmastership/csv_formatter_body.rb +19 -11
- data/lib/defmastership/csv_formatter_header.rb +15 -10
- data/lib/defmastership/definition.rb +14 -3
- data/lib/defmastership/definition_parser.rb +46 -0
- data/lib/defmastership/document.rb +59 -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 +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/spec_helper.rb +1 -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} +48 -26
- data/spec/unit/defmastership/change_ref_modifier_spec.rb +76 -0
- data/spec/unit/defmastership/comment_filter_spec.rb +8 -4
- data/spec/unit/defmastership/csv_formatter_body_spec.rb +88 -82
- data/spec/unit/defmastership/csv_formatter_header_spec.rb +68 -22
- data/spec/unit/defmastership/csv_formatter_spec.rb +207 -109
- data/spec/unit/defmastership/definition_parser_spec.rb +63 -0
- data/spec/unit/defmastership/definition_spec.rb +45 -4
- data/spec/unit/defmastership/document_spec.rb +236 -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 +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 +44 -9
- data/lib/defmastership/batch_changer.rb +0 -41
- data/lib/defmastership/project_ref_changer.rb +0 -28
- data/spec/unit/defmastership/batch_changer_spec.rb +0 -109
- data/spec/unit/defmastership/project_ref_changer_spec.rb +0 -80
@@ -13,88 +13,134 @@ RSpec.describe(DefMastership::CSVFormatterHeader) do
|
|
13
13
|
end
|
14
14
|
|
15
15
|
describe '#header' do
|
16
|
-
describe '#
|
17
|
-
it { expect(formatter.
|
16
|
+
describe '#fixed' do
|
17
|
+
it { expect(formatter.fixed).to(eq(%w[Type Reference Value Checksum])) }
|
18
18
|
end
|
19
19
|
|
20
|
-
describe '#
|
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
|
40
|
+
end
|
41
|
+
|
42
|
+
describe '#wrong_explicit_checksum' do
|
43
|
+
context 'when no wrong explicit checksum' do
|
44
|
+
before do
|
45
|
+
allow(document).to(receive(:wrong_explicit_checksum?).and_return(false))
|
46
|
+
formatter.wrong_explicit_checksum
|
47
|
+
end
|
48
|
+
|
49
|
+
it { expect(document).to(have_received(:wrong_explicit_checksum?)) }
|
50
|
+
|
51
|
+
it { expect(formatter.wrong_explicit_checksum).to(eq([])) }
|
52
|
+
end
|
53
|
+
|
54
|
+
context 'when wrong explicit checksum' do
|
55
|
+
before do
|
56
|
+
allow(document).to(receive(:wrong_explicit_checksum?).and_return(true))
|
57
|
+
formatter.wrong_explicit_checksum
|
58
|
+
end
|
59
|
+
|
60
|
+
it { expect(formatter.wrong_explicit_checksum).to(eq(['Wrong explicit checksum'])) }
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe '#labels' do
|
21
65
|
context 'when no labels' do
|
22
66
|
before do
|
23
67
|
allow(document).to(receive(:labels).and_return([]))
|
24
|
-
formatter.
|
68
|
+
formatter.labels
|
25
69
|
end
|
26
70
|
|
27
71
|
it { expect(document).to(have_received(:labels)) }
|
28
72
|
|
29
|
-
it { expect(formatter.
|
73
|
+
it { expect(formatter.labels).to(eq([])) }
|
30
74
|
end
|
31
75
|
|
32
76
|
context 'when there is labels' do
|
33
77
|
before { allow(document).to(receive(:labels).and_return(['Whatever'])) }
|
34
78
|
|
35
|
-
it { expect(formatter.
|
79
|
+
it { expect(formatter.labels).to(eq(['Labels'])) }
|
36
80
|
end
|
37
81
|
end
|
38
82
|
|
39
|
-
describe '#
|
83
|
+
describe '#eref' do
|
40
84
|
context 'when no eref' do
|
41
85
|
before do
|
42
86
|
allow(document).to(receive(:eref).and_return({}))
|
43
|
-
formatter.
|
87
|
+
formatter.eref
|
44
88
|
end
|
45
89
|
|
46
90
|
it { expect(document).to(have_received(:eref)) }
|
47
91
|
|
48
|
-
it { expect(formatter.
|
92
|
+
it { expect(formatter.eref).to(eq([])) }
|
49
93
|
end
|
50
94
|
|
51
95
|
context 'when eref' do
|
52
96
|
before do
|
53
|
-
allow(document).to(
|
54
|
-
|
55
|
-
|
56
|
-
|
97
|
+
allow(document).to(
|
98
|
+
receive(:eref).and_return(
|
99
|
+
whatever: { prefix: 'A' },
|
100
|
+
other: { prefix: 'C', url: 'D' }
|
101
|
+
)
|
102
|
+
)
|
57
103
|
end
|
58
104
|
|
59
|
-
it { expect(formatter.
|
105
|
+
it { expect(formatter.eref).to(eq(%w[A C])) }
|
60
106
|
end
|
61
107
|
end
|
62
108
|
|
63
|
-
describe '#
|
109
|
+
describe '#iref' do
|
64
110
|
context 'when no iref' do
|
65
111
|
before do
|
66
112
|
allow(document).to(receive(:iref).and_return(false))
|
67
|
-
formatter.
|
113
|
+
formatter.iref
|
68
114
|
end
|
69
115
|
|
70
116
|
it { expect(document).to(have_received(:iref)) }
|
71
117
|
|
72
|
-
it { expect(formatter.
|
118
|
+
it { expect(formatter.iref).to(eq([])) }
|
73
119
|
end
|
74
120
|
|
75
121
|
context 'when iref' do
|
76
122
|
before { allow(document).to(receive(:iref).and_return(true)) }
|
77
123
|
|
78
|
-
it { expect(formatter.
|
124
|
+
it { expect(formatter.iref).to(eq(['Internal links'])) }
|
79
125
|
end
|
80
126
|
end
|
81
127
|
|
82
|
-
describe '#
|
128
|
+
describe '#attributes' do
|
83
129
|
context 'when no attributes' do
|
84
130
|
before do
|
85
131
|
allow(document).to(receive(:attributes).and_return({}))
|
86
|
-
formatter.
|
132
|
+
formatter.attributes
|
87
133
|
end
|
88
134
|
|
89
135
|
it { expect(document).to(have_received(:attributes)) }
|
90
136
|
|
91
|
-
it { expect(formatter.
|
137
|
+
it { expect(formatter.attributes).to(eq([])) }
|
92
138
|
end
|
93
139
|
|
94
140
|
context 'when attributes' do
|
95
141
|
before { allow(document).to(receive(:attributes).and_return(whatever: 'A', other: 'B')) }
|
96
142
|
|
97
|
-
it { expect(formatter.
|
143
|
+
it { expect(formatter.attributes).to(eq(%w[A B])) }
|
98
144
|
end
|
99
145
|
end
|
100
146
|
end
|
@@ -3,6 +3,7 @@
|
|
3
3
|
|
4
4
|
require('defmastership')
|
5
5
|
require('ostruct')
|
6
|
+
require('csv')
|
6
7
|
|
7
8
|
RSpec.describe(DefMastership::CSVFormatter) do
|
8
9
|
subject(:formatter) { described_class.new(document, ';') }
|
@@ -13,160 +14,257 @@ RSpec.describe(DefMastership::CSVFormatter) do
|
|
13
14
|
it { is_expected.not_to(be(nil)) }
|
14
15
|
end
|
15
16
|
|
16
|
-
describe '#
|
17
|
-
|
17
|
+
describe '#export_to' do
|
18
|
+
let(:header) { instance_double(DefMastership::CSVFormatterHeader, 'header') }
|
19
|
+
let(:body) { instance_double(DefMastership::CSVFormatterBody, 'body') }
|
20
|
+
let(:csv) { instance_double(CSV, 'csv') }
|
21
|
+
|
22
|
+
before do
|
23
|
+
allow(CSV).to(receive(:open).and_yield(csv))
|
24
|
+
allow(csv).to(receive(:<<))
|
25
|
+
allow(DefMastership::CSVFormatterHeader).to(receive(:new).with(document).and_return(header))
|
26
|
+
allow(DefMastership::CSVFormatterBody).to(receive(:new).with(document).and_return(body))
|
27
|
+
allow(document).to(receive(:definitions).and_return(%i[def1 def2]))
|
28
|
+
allow(document).to(receive(:wrong_explicit_checksum?).with(no_args).and_return(false))
|
29
|
+
allow(document).to(receive(:explicit_version?).with(no_args).and_return(false))
|
30
|
+
allow(document).to(receive(:labels).with(no_args).and_return([]))
|
31
|
+
allow(document).to(receive(:eref).with(no_args).and_return([]))
|
32
|
+
allow(document).to(receive(:iref).with(no_args).and_return(false))
|
33
|
+
allow(document).to(receive(:attributes).with(no_args).and_return([]))
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'when no variable columns' do
|
37
|
+
methods = %i[fixed]
|
38
|
+
|
18
39
|
before do
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
40
|
+
methods.each do |method|
|
41
|
+
allow(header).to(receive(method).with(no_args).and_return(["#{method} header"]))
|
42
|
+
allow(body).to(receive(method).with(:def1).and_return(["#{method} def1 body"]))
|
43
|
+
allow(body).to(receive(method).with(:def2).and_return(["#{method} def2 body"]))
|
44
|
+
end
|
45
|
+
formatter.export_to('whatever')
|
46
|
+
end
|
47
|
+
|
48
|
+
methods.each do |method|
|
49
|
+
it { expect(header).to(have_received(method).with(no_args)) }
|
50
|
+
it { expect(body).to(have_received(method).with(:def1)) }
|
51
|
+
it { expect(body).to(have_received(method).with(:def2)) }
|
24
52
|
end
|
25
53
|
|
26
|
-
it { expect(
|
54
|
+
it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} header" })) }
|
55
|
+
it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} def1 body" })) }
|
56
|
+
it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} def2 body" })) }
|
57
|
+
end
|
27
58
|
|
28
|
-
|
59
|
+
context 'when wrong_explicit_checksum' do
|
60
|
+
methods = %i[fixed wrong_explicit_checksum]
|
29
61
|
|
30
|
-
|
62
|
+
before do
|
63
|
+
methods.each do |method|
|
64
|
+
allow(header).to(receive(method).with(no_args).and_return(["#{method} header"]))
|
65
|
+
allow(body).to(receive(method).with(:def1).and_return(["#{method} def1 body"]))
|
66
|
+
allow(body).to(receive(method).with(:def2).and_return(["#{method} def2 body"]))
|
67
|
+
end
|
68
|
+
allow(document).to(receive(:wrong_explicit_checksum?).with(no_args).and_return(true))
|
69
|
+
formatter.export_to('whatever')
|
70
|
+
end
|
31
71
|
|
32
|
-
|
72
|
+
methods.each do |method|
|
73
|
+
it { expect(header).to(have_received(method).with(no_args)) }
|
74
|
+
it { expect(body).to(have_received(method).with(:def1)) }
|
75
|
+
it { expect(body).to(have_received(method).with(:def2)) }
|
76
|
+
end
|
33
77
|
|
34
|
-
it { expect(
|
78
|
+
it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} header" })) }
|
79
|
+
it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} def1 body" })) }
|
80
|
+
it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} def2 body" })) }
|
35
81
|
end
|
36
82
|
|
37
|
-
context 'when
|
83
|
+
context 'when explicit_version' do
|
84
|
+
methods = %i[fixed explicit_version]
|
85
|
+
|
38
86
|
before do
|
39
|
-
|
40
|
-
.with(no_args)
|
41
|
-
.and_return([
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
allow(document).to(receive(:iref).with(no_args).and_return(true))
|
47
|
-
allow(document).to(receive(:attributes)
|
48
|
-
.with(no_args)
|
49
|
-
.and_return(whatever: 'E', other: 'F'))
|
87
|
+
methods.each do |method|
|
88
|
+
allow(header).to(receive(method).with(no_args).and_return(["#{method} header"]))
|
89
|
+
allow(body).to(receive(method).with(:def1).and_return(["#{method} def1 body"]))
|
90
|
+
allow(body).to(receive(method).with(:def2).and_return(["#{method} def2 body"]))
|
91
|
+
end
|
92
|
+
allow(document).to(receive(:explicit_version?).with(no_args).and_return(true))
|
93
|
+
formatter.export_to('whatever')
|
50
94
|
end
|
51
95
|
|
52
|
-
|
53
|
-
expect(
|
54
|
-
|
55
|
-
|
96
|
+
methods.each do |method|
|
97
|
+
it { expect(header).to(have_received(method).with(no_args)) }
|
98
|
+
it { expect(body).to(have_received(method).with(:def1)) }
|
99
|
+
it { expect(body).to(have_received(method).with(:def2)) }
|
56
100
|
end
|
101
|
+
|
102
|
+
it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} header" })) }
|
103
|
+
it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} def1 body" })) }
|
104
|
+
it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} def2 body" })) }
|
57
105
|
end
|
58
|
-
end
|
59
106
|
|
60
|
-
|
61
|
-
|
107
|
+
context 'when labels' do
|
108
|
+
methods = %i[fixed labels]
|
62
109
|
|
63
|
-
context 'when minimal' do
|
64
110
|
before do
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
allow(
|
71
|
-
|
72
|
-
formatter.body(definition)
|
111
|
+
methods.each do |method|
|
112
|
+
allow(header).to(receive(method).with(no_args).and_return(["#{method} header"]))
|
113
|
+
allow(body).to(receive(method).with(:def1).and_return(["#{method} def1 body"]))
|
114
|
+
allow(body).to(receive(method).with(:def2).and_return(["#{method} def2 body"]))
|
115
|
+
end
|
116
|
+
allow(document).to(receive(:labels).with(no_args).and_return([:whatever]))
|
117
|
+
formatter.export_to('whatever')
|
73
118
|
end
|
74
119
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
120
|
+
methods.each do |method|
|
121
|
+
it { expect(header).to(have_received(method).with(no_args)) }
|
122
|
+
it { expect(body).to(have_received(method).with(:def1)) }
|
123
|
+
it { expect(body).to(have_received(method).with(:def2)) }
|
124
|
+
end
|
80
125
|
|
81
|
-
it { expect(
|
126
|
+
it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} header" })) }
|
127
|
+
it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} def1 body" })) }
|
128
|
+
it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} def2 body" })) }
|
129
|
+
end
|
82
130
|
|
83
|
-
|
131
|
+
context 'when eref' do
|
132
|
+
methods = %i[fixed eref]
|
84
133
|
|
85
|
-
|
134
|
+
before do
|
135
|
+
methods.each do |method|
|
136
|
+
allow(header).to(receive(method).with(no_args).and_return(["#{method} header"]))
|
137
|
+
allow(body).to(receive(method).with(:def1).and_return(["#{method} def1 body"]))
|
138
|
+
allow(body).to(receive(method).with(:def2).and_return(["#{method} def2 body"]))
|
139
|
+
end
|
140
|
+
allow(document).to(receive(:eref).with(no_args).and_return([:whatever]))
|
141
|
+
formatter.export_to('whatever')
|
142
|
+
end
|
86
143
|
|
87
|
-
|
144
|
+
methods.each do |method|
|
145
|
+
it { expect(header).to(have_received(method).with(no_args)) }
|
146
|
+
it { expect(body).to(have_received(method).with(:def1)) }
|
147
|
+
it { expect(body).to(have_received(method).with(:def2)) }
|
148
|
+
end
|
88
149
|
|
89
|
-
it { expect(
|
150
|
+
it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} header" })) }
|
151
|
+
it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} def1 body" })) }
|
152
|
+
it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} def2 body" })) }
|
90
153
|
end
|
91
154
|
|
92
|
-
context 'when
|
155
|
+
context 'when iref' do
|
156
|
+
methods = %i[fixed iref]
|
157
|
+
|
93
158
|
before do
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
))
|
159
|
+
methods.each do |method|
|
160
|
+
allow(header).to(receive(method).with(no_args).and_return(["#{method} header"]))
|
161
|
+
allow(body).to(receive(method).with(:def1).and_return(["#{method} def1 body"]))
|
162
|
+
allow(body).to(receive(method).with(:def2).and_return(["#{method} def2 body"]))
|
163
|
+
end
|
100
164
|
allow(document).to(receive(:iref).with(no_args).and_return(true))
|
101
|
-
|
102
|
-
a: 'whatever',
|
103
|
-
b: 'whatever',
|
104
|
-
c: 'whatever'
|
105
|
-
))
|
106
|
-
allow(definition).to(receive(:type).with(no_args).and_return('a'))
|
107
|
-
allow(definition).to(receive(:reference).with(no_args).and_return('b'))
|
108
|
-
allow(definition).to(receive(:value).with(no_args).and_return('c'))
|
109
|
-
allow(definition).to(receive(:labels).with(no_args).and_return(%w[toto tutu]))
|
110
|
-
allow(definition).to(receive(:eref).with(no_args).and_return(a: %w[A B], b: [], c: ['C']))
|
111
|
-
allow(definition).to(receive(:iref).with(no_args).and_return(%w[E F]))
|
112
|
-
allow(definition).to(receive(:attributes).with(no_args).and_return(a: 'X', b: '', c: 'Y'))
|
113
|
-
formatter.body(definition)
|
165
|
+
formatter.export_to('whatever')
|
114
166
|
end
|
115
167
|
|
116
|
-
|
168
|
+
methods.each do |method|
|
169
|
+
it { expect(header).to(have_received(method).with(no_args)) }
|
170
|
+
it { expect(body).to(have_received(method).with(:def1)) }
|
171
|
+
it { expect(body).to(have_received(method).with(:def2)) }
|
172
|
+
end
|
117
173
|
|
118
|
-
it { expect(
|
174
|
+
it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} header" })) }
|
175
|
+
it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} def1 body" })) }
|
176
|
+
it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} def2 body" })) }
|
177
|
+
end
|
119
178
|
|
120
|
-
|
179
|
+
context 'when attributes' do
|
180
|
+
methods = %i[fixed attributes]
|
121
181
|
|
122
|
-
|
182
|
+
before do
|
183
|
+
methods.each do |method|
|
184
|
+
allow(header).to(receive(method).with(no_args).and_return(["#{method} header"]))
|
185
|
+
allow(body).to(receive(method).with(:def1).and_return(["#{method} def1 body"]))
|
186
|
+
allow(body).to(receive(method).with(:def2).and_return(["#{method} def2 body"]))
|
187
|
+
end
|
188
|
+
allow(document).to(receive(:attributes).with(no_args).and_return([:whatever]))
|
189
|
+
formatter.export_to('whatever')
|
190
|
+
end
|
123
191
|
|
124
|
-
|
125
|
-
expect(
|
126
|
-
|
127
|
-
|
128
|
-
['X', '', 'Y']))
|
192
|
+
methods.each do |method|
|
193
|
+
it { expect(header).to(have_received(method).with(no_args)) }
|
194
|
+
it { expect(body).to(have_received(method).with(:def1)) }
|
195
|
+
it { expect(body).to(have_received(method).with(:def2)) }
|
129
196
|
end
|
197
|
+
|
198
|
+
it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} header" })) }
|
199
|
+
it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} def1 body" })) }
|
200
|
+
it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} def2 body" })) }
|
130
201
|
end
|
131
|
-
end
|
132
202
|
|
133
|
-
|
134
|
-
|
135
|
-
let(:target_file) { 'export.csv' }
|
136
|
-
let(:definitions) do
|
137
|
-
[
|
138
|
-
OpenStruct.new(type: 'a', reference: 'b', value: 'c'),
|
139
|
-
OpenStruct.new(type: 'd', reference: 'e', value: 'f')
|
140
|
-
]
|
141
|
-
end
|
203
|
+
context 'when every colums' do
|
204
|
+
methods = %i[fixed wrong_explicit_checksum explicit_version labels eref iref attributes]
|
142
205
|
|
143
206
|
before do
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
allow(document).to(receive(:
|
150
|
-
|
207
|
+
methods.each do |method|
|
208
|
+
allow(header).to(receive(method).with(no_args).and_return(["#{method} header"]))
|
209
|
+
allow(body).to(receive(method).with(:def1).and_return(["#{method} def1 body"]))
|
210
|
+
allow(body).to(receive(method).with(:def2).and_return(["#{method} def2 body"]))
|
211
|
+
end
|
212
|
+
allow(document).to(receive(:wrong_explicit_checksum?).with(no_args).and_return(true))
|
213
|
+
allow(document).to(receive(:explicit_version?).with(no_args).and_return(true))
|
214
|
+
allow(document).to(receive(:labels).with(no_args).and_return([:whatever]))
|
215
|
+
allow(document).to(receive(:eref).with(no_args).and_return([:whatever]))
|
216
|
+
allow(document).to(receive(:iref).with(no_args).and_return(true))
|
217
|
+
allow(document).to(receive(:attributes).with(no_args).and_return([:whatever]))
|
218
|
+
formatter.export_to('whatever')
|
151
219
|
end
|
152
220
|
|
153
|
-
|
154
|
-
|
155
|
-
|
221
|
+
methods.each do |method|
|
222
|
+
it { expect(header).to(have_received(method).with(no_args)) }
|
223
|
+
it { expect(body).to(have_received(method).with(:def1)) }
|
224
|
+
it { expect(body).to(have_received(method).with(:def2)) }
|
225
|
+
end
|
156
226
|
|
157
|
-
it { expect(
|
227
|
+
it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} header" })) }
|
228
|
+
it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} def1 body" })) }
|
229
|
+
it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} def2 body" })) }
|
230
|
+
end
|
231
|
+
end
|
158
232
|
|
159
|
-
|
233
|
+
context 'when #export_to csv file' do
|
234
|
+
let(:target_file) { 'export.csv' }
|
235
|
+
let(:definitions) do
|
236
|
+
[
|
237
|
+
OpenStruct.new(type: 'a', reference: 'b', value: 'c', sha256: 'd'),
|
238
|
+
OpenStruct.new(type: 'd', reference: 'e', value: 'f', sha256: 'g')
|
239
|
+
]
|
240
|
+
end
|
160
241
|
|
161
|
-
|
242
|
+
before do
|
243
|
+
setup_aruba
|
244
|
+
allow(document).to(receive(:labels).with(no_args).and_return([]))
|
245
|
+
allow(document).to(receive(:eref).with(no_args).and_return({}))
|
246
|
+
allow(document).to(receive(:iref).with(no_args).and_return(false))
|
247
|
+
allow(document).to(receive(:attributes).with(no_args).and_return({}))
|
248
|
+
allow(document).to(receive(:definitions).with(no_args).and_return(definitions))
|
249
|
+
allow(document).to(receive(:wrong_explicit_checksum?).with(no_args).and_return(false))
|
250
|
+
allow(document).to(receive(:explicit_version?).with(no_args).and_return(false))
|
251
|
+
formatter.export_to("#{aruba.current_directory}/#{target_file}")
|
252
|
+
end
|
162
253
|
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
254
|
+
it { expect(document).to(have_received(:labels).with(no_args)) }
|
255
|
+
it { expect(document).to(have_received(:eref).with(no_args)) }
|
256
|
+
it { expect(document).to(have_received(:iref).with(no_args)) }
|
257
|
+
it { expect(document).to(have_received(:attributes).with(no_args)) }
|
258
|
+
it { expect(document).to(have_received(:definitions).with(no_args)) }
|
259
|
+
it { expect(document).to(have_received(:wrong_explicit_checksum?).with(no_args)) }
|
260
|
+
it { expect(document).to(have_received(:explicit_version?).with(no_args)) }
|
261
|
+
|
262
|
+
it do
|
263
|
+
expect(target_file).to(have_file_content(<<~CSV_FILE))
|
264
|
+
Type;Reference;Value;Checksum
|
265
|
+
a;b;c;d
|
266
|
+
d;e;f;g
|
267
|
+
CSV_FILE
|
170
268
|
end
|
171
269
|
end
|
172
270
|
end
|