defmastership 1.0.2 → 1.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/.gitlab-ci.yml +20 -0
  4. data/.rubocop.yml +6 -8
  5. data/Gemfile +1 -0
  6. data/LICENSE +22 -0
  7. data/Rakefile +2 -2
  8. data/bin/defmastership +37 -24
  9. data/cucumber.yml +2 -0
  10. data/defmastership.gemspec +17 -10
  11. data/features/changeref.feature +82 -129
  12. data/features/checksum.feature +244 -0
  13. data/features/export.feature +49 -31
  14. data/features/modify.feature +143 -0
  15. data/features/rename_included_files.feature +121 -0
  16. data/features/step_definitions/defmastership_steps.rb +1 -0
  17. data/features/support/env.rb +1 -0
  18. data/lib/defmastership.rb +15 -3
  19. data/lib/defmastership/batch_modifier.rb +33 -0
  20. data/lib/defmastership/{ref_changer.rb → change_ref_line_modifier.rb} +19 -35
  21. data/lib/defmastership/change_ref_modifier.rb +15 -0
  22. data/lib/defmastership/comment_filter.rb +1 -0
  23. data/lib/defmastership/constants.rb +15 -1
  24. data/lib/defmastership/csv_formatter.rb +19 -18
  25. data/lib/defmastership/csv_formatter_body.rb +12 -6
  26. data/lib/defmastership/csv_formatter_header.rb +12 -10
  27. data/lib/defmastership/definition.rb +12 -0
  28. data/lib/defmastership/definition_parser.rb +46 -0
  29. data/lib/defmastership/document.rb +54 -75
  30. data/lib/defmastership/filters.rb +30 -0
  31. data/lib/defmastership/line_modifier_base.rb +29 -0
  32. data/lib/defmastership/modifier_base.rb +29 -0
  33. data/lib/defmastership/rename_included_files_line_modifier.rb +126 -0
  34. data/lib/defmastership/rename_included_files_modifier.rb +15 -0
  35. data/lib/defmastership/update_def_checksum_line_modifier.rb +39 -0
  36. data/lib/defmastership/update_def_checksum_modifier.rb +21 -0
  37. data/lib/defmastership/version.rb +2 -1
  38. data/spec/spec_helper.rb +2 -0
  39. data/spec/unit/defmastership/batch_modifier_spec.rb +115 -0
  40. data/spec/unit/defmastership/{ref_changer_spec.rb → change_ref_line_modifier_spec.rb} +49 -26
  41. data/spec/unit/defmastership/change_ref_modifier_spec.rb +76 -0
  42. data/spec/unit/defmastership/comment_filter_spec.rb +9 -4
  43. data/spec/unit/defmastership/csv_formatter_body_spec.rb +62 -37
  44. data/spec/unit/defmastership/csv_formatter_header_spec.rb +47 -22
  45. data/spec/unit/defmastership/csv_formatter_spec.rb +67 -105
  46. data/spec/unit/defmastership/definition_parser_spec.rb +63 -0
  47. data/spec/unit/defmastership/definition_spec.rb +31 -4
  48. data/spec/unit/defmastership/document_spec.rb +170 -35
  49. data/spec/unit/defmastership/rename_included_files_line_modifier_spec.rb +203 -0
  50. data/spec/unit/defmastership/rename_included_files_modifier_spec.rb +67 -0
  51. data/spec/unit/defmastership/update_def_checksum_line_modifier_spec.rb +68 -0
  52. data/spec/unit/defmastership/update_def_checksum_modifier_spec.rb +75 -0
  53. data/spec/unit/defmastership_spec.rb +1 -0
  54. metadata +50 -18
  55. data/Gemfile.lock +0 -137
  56. data/lib/defmastership/batch_changer.rb +0 -40
  57. data/lib/defmastership/project_ref_changer.rb +0 -27
  58. data/spec/unit/defmastership/batch_changer_spec.rb +0 -108
  59. data/spec/unit/defmastership/project_ref_changer_spec.rb +0 -79
@@ -1,3 +1,4 @@
1
+ # Copyright (c) 2020 Jerome Arbez-Gindre
1
2
  # frozen_string_literal: true
2
3
 
3
4
  require('defmastership')
@@ -74,8 +75,10 @@ RSpec.describe(DefMastership::CommentFilter) do
74
75
  end
75
76
 
76
77
  before do
77
- allow(DefMastership).to(receive(:comment_filter)
78
- .and_return(comment_filter))
78
+ allow(DefMastership).to(
79
+ receive(:comment_filter)
80
+ .and_return(comment_filter)
81
+ )
79
82
  end
80
83
 
81
84
  context 'when not .commented?' do
@@ -93,8 +96,10 @@ RSpec.describe(DefMastership::CommentFilter) do
93
96
 
94
97
  context 'when .commented?' do
95
98
  before do
96
- allow(comment_filter).to(receive(:accept?)
97
- .with('blabla').and_return(false))
99
+ allow(comment_filter).to(
100
+ receive(:accept?)
101
+ .with('blabla').and_return(false)
102
+ )
98
103
  end
99
104
 
100
105
  it do
@@ -1,3 +1,4 @@
1
+ # Copyright (c) 2020 Jerome Arbez-Gindre
1
2
  # frozen_string_literal: true
2
3
 
3
4
  require('defmastership')
@@ -12,12 +13,13 @@ RSpec.describe(DefMastership::CSVFormatterBody) do
12
13
  it { is_expected.not_to(be(nil)) }
13
14
  end
14
15
 
15
- describe '#fixed_body' do
16
+ describe '#fixed' do
16
17
  before do
17
18
  allow(definition).to(receive(:type).with(no_args).and_return('a'))
18
19
  allow(definition).to(receive(:reference).with(no_args).and_return('b'))
19
20
  allow(definition).to(receive(:value).with(no_args).and_return('c'))
20
- formatter.fixed_body(definition)
21
+ allow(definition).to(receive(:sha256).with(no_args).and_return('d'))
22
+ formatter.fixed(definition)
21
23
  end
22
24
 
23
25
  it { expect(definition).to(have_received(:type).with(no_args)) }
@@ -26,19 +28,43 @@ RSpec.describe(DefMastership::CSVFormatterBody) do
26
28
 
27
29
  it { expect(definition).to(have_received(:value).with(no_args)) }
28
30
 
29
- it { expect(formatter.fixed_body(definition)).to(eq(%w[a b c])) }
31
+ it { expect(definition).to(have_received(:sha256).with(no_args)) }
32
+
33
+ it { expect(formatter.fixed(definition)).to(eq(%w[a b c d])) }
34
+ end
35
+
36
+ describe '#wrong_explicit_checksum' do
37
+ context 'when no wrong_explicit checksum' do
38
+ before do
39
+ allow(definition).to(receive(:wrong_explicit_checksum).with(no_args).and_return(nil))
40
+ formatter.wrong_explicit_checksum(definition)
41
+ end
42
+
43
+ it { expect(definition).to(have_received(:wrong_explicit_checksum).with(no_args)) }
44
+
45
+ it { expect(formatter.wrong_explicit_checksum(definition)).to(eq([''])) }
46
+ end
47
+
48
+ context 'when explicit checksum' do
49
+ before do
50
+ allow(definition).to(receive(:wrong_explicit_checksum).with(no_args).and_return('ab12'))
51
+ formatter.wrong_explicit_checksum(definition)
52
+ end
53
+
54
+ it { expect(formatter.wrong_explicit_checksum(definition)).to(eq(['ab12'])) }
55
+ end
30
56
  end
31
57
 
32
- describe '#labels_body' do
58
+ describe '#labels' do
33
59
  context 'when no labels on document' do
34
60
  before do
35
61
  allow(document).to(receive(:labels).with(no_args).and_return([]))
36
- formatter.labels_body(definition)
62
+ formatter.labels(definition)
37
63
  end
38
64
 
39
65
  it { expect(document).to(have_received(:labels).once.with(no_args)) }
40
66
 
41
- it { expect(formatter.labels_body(definition)).to(eq([])) }
67
+ it { expect(formatter.labels(definition)).to(eq([])) }
42
68
  end
43
69
 
44
70
  context 'when labels on document' do
@@ -47,66 +73,66 @@ RSpec.describe(DefMastership::CSVFormatterBody) do
47
73
  context 'when no labels on definition' do
48
74
  before do
49
75
  allow(definition).to(receive(:labels).with(no_args).and_return([]))
50
- formatter.labels_body(definition)
76
+ formatter.labels(definition)
51
77
  end
52
78
 
53
79
  it { expect(definition).to(have_received(:labels).once.with(no_args)) }
54
80
 
55
- it { expect(formatter.labels_body(definition)).to(eq([''])) }
81
+ it { expect(formatter.labels(definition)).to(eq([''])) }
56
82
  end
57
83
 
58
84
  context 'when labels on definition' do
59
85
  before do
60
86
  allow(definition).to(receive(:labels).with(no_args).and_return(%w[toto tutu]))
61
- formatter.labels_body(definition)
87
+ formatter.labels(definition)
62
88
  end
63
89
 
64
90
  it { expect(definition).to(have_received(:labels).once.with(no_args)) }
65
91
 
66
- it { expect(formatter.labels_body(definition)).to(eq(["toto\ntutu"])) }
92
+ it { expect(formatter.labels(definition)).to(eq(["toto\ntutu"])) }
67
93
  end
68
94
  end
69
95
  end
70
96
 
71
- describe '#eref_body' do
97
+ describe '#eref' do
72
98
  context 'when no eref on the document' do
73
99
  before do
74
100
  allow(document).to(receive(:eref).with(no_args).and_return({}))
75
- formatter.eref_body(definition)
101
+ formatter.eref(definition)
76
102
  end
77
103
 
78
104
  it { expect(document).to(have_received(:eref).with(no_args)) }
79
105
 
80
- it { expect(formatter.eref_body(nil)).to(eq([])) }
106
+ it { expect(formatter.eref(nil)).to(eq([])) }
81
107
  end
82
108
 
83
109
  context 'when eref on the document' do
84
110
  before do
85
- allow(document).to(receive(:eref).with(no_args).and_return(
86
- a: 'whatever',
87
- b: 'whatever',
88
- c: 'whatever'
89
- ))
111
+ allow(document).to(
112
+ receive(:eref).with(no_args).and_return(
113
+ a: 'whatever', b: 'whatever', c: 'whatever'
114
+ )
115
+ )
90
116
  allow(definition).to(receive(:eref).with(no_args).and_return(a: %w[A B], b: [], c: ['C']))
91
- formatter.eref_body(definition)
117
+ formatter.eref(definition)
92
118
  end
93
119
 
94
120
  it { expect(definition).to(have_received(:eref).exactly(3).times.with(no_args)) }
95
121
 
96
- it { expect(formatter.eref_body(definition)).to(eq(["A\nB", '', 'C'])) }
122
+ it { expect(formatter.eref(definition)).to(eq(["A\nB", '', 'C'])) }
97
123
  end
98
124
  end
99
125
 
100
- describe '#iref_body' do
126
+ describe '#iref' do
101
127
  context 'when no iref on the document' do
102
128
  before do
103
129
  allow(document).to(receive(:iref).with(no_args).and_return(false))
104
- formatter.iref_body(definition)
130
+ formatter.iref(definition)
105
131
  end
106
132
 
107
133
  it { expect(document).to(have_received(:iref).with(no_args)) }
108
134
 
109
- it { expect(formatter.iref_body(definition)).to(eq([])) }
135
+ it { expect(formatter.iref(definition)).to(eq([])) }
110
136
  end
111
137
 
112
138
  context 'when iref on the document' do
@@ -115,53 +141,52 @@ RSpec.describe(DefMastership::CSVFormatterBody) do
115
141
  context 'when no iref on the definition' do
116
142
  before do
117
143
  allow(definition).to(receive(:iref).with(no_args).and_return([]))
118
- formatter.iref_body(definition)
144
+ formatter.iref(definition)
119
145
  end
120
146
 
121
147
  it { expect(definition).to(have_received(:iref).with(no_args)) }
122
148
 
123
- it { expect(formatter.iref_body(definition)).to(eq([''])) }
149
+ it { expect(formatter.iref(definition)).to(eq([''])) }
124
150
  end
125
151
 
126
152
  context 'when iref on the definition' do
127
153
  before do
128
154
  allow(definition).to(receive(:iref).with(no_args).and_return(%w[A B]))
129
- formatter.iref_body(definition)
155
+ formatter.iref(definition)
130
156
  end
131
157
 
132
158
  it { expect(definition).to(have_received(:iref).with(no_args)) }
133
159
 
134
- it { expect(formatter.iref_body(definition)).to(eq(["A\nB"])) }
160
+ it { expect(formatter.iref(definition)).to(eq(["A\nB"])) }
135
161
  end
136
162
  end
137
163
  end
138
164
 
139
- describe '#attributes_body' do
165
+ describe '#attributes' do
140
166
  context 'when no attributes on the document' do
141
167
  before do
142
168
  allow(document).to(receive(:attributes).with(no_args).and_return({}))
143
- formatter.attributes_body(definition)
169
+ formatter.attributes(definition)
144
170
  end
145
171
 
146
172
  it { expect(document).to(have_received(:attributes).with(no_args)) }
147
173
 
148
- it { expect(formatter.attributes_body(nil)).to(eq([])) }
174
+ it { expect(formatter.attributes(nil)).to(eq([])) }
149
175
  end
150
176
 
151
177
  context 'when attributes on the document' do
152
178
  before do
153
- allow(document).to(receive(:attributes).with(no_args).and_return(
154
- a: 'whatever',
155
- b: 'whatever',
156
- c: 'whatever'
157
- ))
179
+ allow(document).to(
180
+ receive(:attributes).with(no_args)
181
+ .and_return(a: 'whatever', b: 'whatever', c: 'whatever')
182
+ )
158
183
  allow(definition).to(receive(:attributes).and_return(a: 'X', b: '', c: 'Y'))
159
- formatter.attributes_body(definition)
184
+ formatter.attributes(definition)
160
185
  end
161
186
 
162
187
  it { expect(definition).to(have_received(:attributes).exactly(3).times) }
163
188
 
164
- it { expect(formatter.attributes_body(definition)).to(eq(['X', '', 'Y'])) }
189
+ it { expect(formatter.attributes(definition)).to(eq(['X', '', 'Y'])) }
165
190
  end
166
191
  end
167
192
  end
@@ -1,3 +1,4 @@
1
+ # Copyright (c) 2020 Jerome Arbez-Gindre
1
2
  # frozen_string_literal: true
2
3
 
3
4
  require('defmastership')
@@ -12,88 +13,112 @@ RSpec.describe(DefMastership::CSVFormatterHeader) do
12
13
  end
13
14
 
14
15
  describe '#header' do
15
- describe '#fixed_header' do
16
- it { expect(formatter.fixed_header).to(eq(%w[Type Reference Value])) }
16
+ describe '#fixed' do
17
+ it { expect(formatter.fixed).to(eq(%w[Type Reference Value sha256])) }
17
18
  end
18
19
 
19
- describe '#labels_header' do
20
+ describe '#wrong_explicit_checksum' do
21
+ context 'when no wrong explicit checksum' do
22
+ before do
23
+ allow(document).to(receive(:wrong_explicit_checksum?).and_return(false))
24
+ formatter.wrong_explicit_checksum
25
+ end
26
+
27
+ it { expect(document).to(have_received(:wrong_explicit_checksum?)) }
28
+
29
+ it { expect(formatter.wrong_explicit_checksum).to(eq([])) }
30
+ end
31
+
32
+ context 'when wrong explicit checksum' do
33
+ before do
34
+ allow(document).to(receive(:wrong_explicit_checksum?).and_return(true))
35
+ formatter.wrong_explicit_checksum
36
+ end
37
+
38
+ it { expect(formatter.wrong_explicit_checksum).to(eq(['Wrong explicit checksum'])) }
39
+ end
40
+ end
41
+
42
+ describe '#labels' do
20
43
  context 'when no labels' do
21
44
  before do
22
45
  allow(document).to(receive(:labels).and_return([]))
23
- formatter.labels_header
46
+ formatter.labels
24
47
  end
25
48
 
26
49
  it { expect(document).to(have_received(:labels)) }
27
50
 
28
- it { expect(formatter.labels_header).to(eq([])) }
51
+ it { expect(formatter.labels).to(eq([])) }
29
52
  end
30
53
 
31
54
  context 'when there is labels' do
32
55
  before { allow(document).to(receive(:labels).and_return(['Whatever'])) }
33
56
 
34
- it { expect(formatter.labels_header).to(eq(['Labels'])) }
57
+ it { expect(formatter.labels).to(eq(['Labels'])) }
35
58
  end
36
59
  end
37
60
 
38
- describe '#eref_header' do
61
+ describe '#eref' do
39
62
  context 'when no eref' do
40
63
  before do
41
64
  allow(document).to(receive(:eref).and_return({}))
42
- formatter.eref_header
65
+ formatter.eref
43
66
  end
44
67
 
45
68
  it { expect(document).to(have_received(:eref)) }
46
69
 
47
- it { expect(formatter.eref_header).to(eq([])) }
70
+ it { expect(formatter.eref).to(eq([])) }
48
71
  end
49
72
 
50
73
  context 'when eref' do
51
74
  before do
52
- allow(document).to(receive(:eref).and_return(
53
- whatever: { prefix: 'A' },
54
- other: { prefix: 'C', url: 'D' }
55
- ))
75
+ allow(document).to(
76
+ receive(:eref).and_return(
77
+ whatever: { prefix: 'A' },
78
+ other: { prefix: 'C', url: 'D' }
79
+ )
80
+ )
56
81
  end
57
82
 
58
- it { expect(formatter.eref_header).to(eq(['A', 'C D'])) }
83
+ it { expect(formatter.eref).to(eq(%w[A C])) }
59
84
  end
60
85
  end
61
86
 
62
- describe '#iref_header' do
87
+ describe '#iref' do
63
88
  context 'when no iref' do
64
89
  before do
65
90
  allow(document).to(receive(:iref).and_return(false))
66
- formatter.iref_header
91
+ formatter.iref
67
92
  end
68
93
 
69
94
  it { expect(document).to(have_received(:iref)) }
70
95
 
71
- it { expect(formatter.iref_header).to(eq([])) }
96
+ it { expect(formatter.iref).to(eq([])) }
72
97
  end
73
98
 
74
99
  context 'when iref' do
75
100
  before { allow(document).to(receive(:iref).and_return(true)) }
76
101
 
77
- it { expect(formatter.iref_header).to(eq(['Internal links'])) }
102
+ it { expect(formatter.iref).to(eq(['Internal links'])) }
78
103
  end
79
104
  end
80
105
 
81
- describe '#attributes_header' do
106
+ describe '#attributes' do
82
107
  context 'when no attributes' do
83
108
  before do
84
109
  allow(document).to(receive(:attributes).and_return({}))
85
- formatter.attributes_header
110
+ formatter.attributes
86
111
  end
87
112
 
88
113
  it { expect(document).to(have_received(:attributes)) }
89
114
 
90
- it { expect(formatter.attributes_header).to(eq([])) }
115
+ it { expect(formatter.attributes).to(eq([])) }
91
116
  end
92
117
 
93
118
  context 'when attributes' do
94
119
  before { allow(document).to(receive(:attributes).and_return(whatever: 'A', other: 'B')) }
95
120
 
96
- it { expect(formatter.attributes_header).to(eq(%w[A B])) }
121
+ it { expect(formatter.attributes).to(eq(%w[A B])) }
97
122
  end
98
123
  end
99
124
  end
@@ -1,10 +1,12 @@
1
+ # Copyright (c) 2020 Jerome Arbez-Gindre
1
2
  # frozen_string_literal: true
2
3
 
3
4
  require('defmastership')
4
5
  require('ostruct')
6
+ require('csv')
5
7
 
6
8
  RSpec.describe(DefMastership::CSVFormatter) do
7
- subject(:formatter) { described_class.new(document) }
9
+ subject(:formatter) { described_class.new(document, ';') }
8
10
 
9
11
  let(:document) { instance_double(DefMastership::Document, 'document') }
10
12
 
@@ -12,130 +14,93 @@ RSpec.describe(DefMastership::CSVFormatter) do
12
14
  it { is_expected.not_to(be(nil)) }
13
15
  end
14
16
 
15
- describe '#header' do
16
- context 'when minimal' do
17
+ describe '#export_to' do
18
+ context 'when wrong explicit checksum' do
19
+ let(:header) { instance_double(DefMastership::CSVFormatterHeader, 'header') }
20
+ let(:body) { instance_double(DefMastership::CSVFormatterBody, 'body') }
21
+ let(:csv) { instance_double(CSV, 'csv') }
22
+
23
+ methods1 = %i[fixed wrong_explicit_checksum labels eref iref attributes]
17
24
  before do
18
- allow(document).to(receive(:labels).with(no_args).and_return([]))
19
- allow(document).to(receive(:eref).with(no_args).and_return({}))
20
- allow(document).to(receive(:iref).with(no_args).and_return(false))
21
- allow(document).to(receive(:attributes).with(no_args).and_return({}))
22
- formatter.header
25
+ allow(CSV).to(receive(:open).and_yield(csv))
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|
32
+ allow(header).to(receive(method).with(no_args).and_return(["#{method} header"]))
33
+ allow(body).to(receive(method).with(:def1).and_return(["#{method} def1 body"]))
34
+ allow(body).to(receive(method).with(:def2).and_return(["#{method} def2 body"]))
35
+ end
36
+ formatter.export_to('whatever')
23
37
  end
24
38
 
25
- it { expect(document).to(have_received(:labels).with(no_args)) }
26
-
27
- it { expect(document).to(have_received(:eref).with(no_args)) }
28
-
29
- it { expect(document).to(have_received(:iref).with(no_args)) }
30
-
31
- it { expect(document).to(have_received(:attributes).with(no_args)) }
39
+ methods1.each do |method|
40
+ it { expect(header).to(have_received(method).with(no_args)) }
41
+ it { expect(body).to(have_received(method).with(:def1)) }
42
+ it { expect(body).to(have_received(method).with(:def2)) }
43
+ end
32
44
 
33
- it { expect(formatter.header).to(eq(%w[Type Reference Value])) }
34
- end
45
+ it do
46
+ expect(csv).to(have_received(:<<).with(methods1.map { |method| "#{method} header" }))
47
+ end
35
48
 
36
- context 'when has everything' do
37
- before do
38
- allow(document).to(receive(:labels)
39
- .with(no_args)
40
- .and_return(['Whatever']))
41
- allow(document).to(receive(:eref)
42
- .with(no_args)
43
- .and_return(whatever: { prefix: 'A' },
44
- other: { prefix: 'C', url: 'D' }))
45
- allow(document).to(receive(:iref).with(no_args).and_return(true))
46
- allow(document).to(receive(:attributes)
47
- .with(no_args)
48
- .and_return(whatever: 'E', other: 'F'))
49
+ it do
50
+ expect(csv).to(have_received(:<<).with(methods1.map { |method| "#{method} def1 body" }))
49
51
  end
50
52
 
51
53
  it do
52
- expect(formatter.header).to(eq(%w[Type Reference Value Labels] +
53
- ['A', 'C D', 'Internal links'] +
54
- %w[E F]))
54
+ expect(csv).to(have_received(:<<).with(methods1.map { |method| "#{method} def2 body" }))
55
55
  end
56
56
  end
57
- end
58
57
 
59
- describe '#body' do
60
- let(:definition) { instance_double(DefMastership::Definition, 'definition') }
58
+ context 'when no wrong explicit checksum' do
59
+ let(:header) { instance_double(DefMastership::CSVFormatterHeader, 'header') }
60
+ let(:body) { instance_double(DefMastership::CSVFormatterBody, 'body') }
61
+ let(:csv) { instance_double(CSV, 'csv') }
61
62
 
62
- context 'when minimal' do
63
+ methods2 = %i[fixed labels eref iref attributes]
63
64
  before do
64
- allow(document).to(receive(:labels).with(no_args).and_return([]))
65
- allow(document).to(receive(:eref).with(no_args).and_return({}))
66
- allow(document).to(receive(:iref).with(no_args).and_return(false))
67
- allow(document).to(receive(:attributes).with(no_args).and_return({}))
68
- allow(definition).to(receive(:type).with(no_args).and_return('a'))
69
- allow(definition).to(receive(:reference).with(no_args).and_return('b'))
70
- allow(definition).to(receive(:value).with(no_args).and_return('c'))
71
- formatter.body(definition)
65
+ allow(CSV).to(receive(:open).and_yield(csv))
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|
72
+ allow(header).to(receive(method).with(no_args).and_return(["#{method} header"]))
73
+ allow(body).to(receive(method).with(:def1).and_return(["#{method} def1 body"]))
74
+ allow(body).to(receive(method).with(:def2).and_return(["#{method} def2 body"]))
75
+ end
76
+ formatter.export_to('whatever')
72
77
  end
73
78
 
74
- it { expect(document).to(have_received(:labels).with(no_args)) }
75
-
76
- it { expect(document).to(have_received(:eref).with(no_args)) }
77
-
78
- it { expect(document).to(have_received(:iref).with(no_args)) }
79
-
80
- it { expect(document).to(have_received(:attributes).with(no_args)) }
81
-
82
- it { expect(definition).to(have_received(:type).with(no_args)) }
83
-
84
- it { expect(definition).to(have_received(:reference).with(no_args)) }
85
-
86
- it { expect(definition).to(have_received(:value).with(no_args)) }
87
-
88
- it { expect(formatter.body(definition)).to(eq(%w[a b c])) }
89
- end
90
-
91
- context 'when has everything' do
92
- before do
93
- allow(document).to(receive(:labels).with(no_args).and_return(['Whatever']))
94
- allow(document).to(receive(:eref).with(no_args).and_return(
95
- a: 'whatever',
96
- b: 'whatever',
97
- c: 'whatever'
98
- ))
99
- allow(document).to(receive(:iref).with(no_args).and_return(true))
100
- allow(document).to(receive(:attributes).with(no_args).and_return(
101
- a: 'whatever',
102
- b: 'whatever',
103
- c: 'whatever'
104
- ))
105
- allow(definition).to(receive(:type).with(no_args).and_return('a'))
106
- allow(definition).to(receive(:reference).with(no_args).and_return('b'))
107
- allow(definition).to(receive(:value).with(no_args).and_return('c'))
108
- allow(definition).to(receive(:labels).with(no_args).and_return(%w[toto tutu]))
109
- allow(definition).to(receive(:eref).with(no_args).and_return(a: %w[A B], b: [], c: ['C']))
110
- allow(definition).to(receive(:iref).with(no_args).and_return(%w[E F]))
111
- allow(definition).to(receive(:attributes).with(no_args).and_return(a: 'X', b: '', c: 'Y'))
112
- formatter.body(definition)
79
+ methods2.each do |method|
80
+ it { expect(header).to(have_received(method).with(no_args)) }
81
+ it { expect(body).to(have_received(method).with(:def1)) }
82
+ it { expect(body).to(have_received(method).with(:def2)) }
113
83
  end
114
84
 
115
- it { expect(definition).to(have_received(:labels).with(no_args)) }
116
-
117
- it { expect(definition).to(have_received(:eref).exactly(3).times.with(no_args)) }
118
-
119
- it { expect(definition).to(have_received(:iref).with(no_args)) }
85
+ it do
86
+ expect(csv).to(have_received(:<<).with(methods2.map { |method| "#{method} header" }))
87
+ end
120
88
 
121
- it { expect(definition).to(have_received(:attributes).exactly(3).times.with(no_args)) }
89
+ it do
90
+ expect(csv).to(have_received(:<<).with(methods2.map { |method| "#{method} def1 body" }))
91
+ end
122
92
 
123
93
  it do
124
- expect(formatter.body(definition)).to(eq(%w[a b c] + ["toto\ntutu"] +
125
- ["A\nB", '', 'C'] +
126
- ["E\nF"] +
127
- ['X', '', 'Y']))
94
+ expect(csv).to(have_received(:<<).with(methods2.map { |method| "#{method} def2 body" }))
128
95
  end
129
96
  end
130
- end
131
97
 
132
- describe '#export_to' do
133
98
  context 'when #export_to csv file' do
134
99
  let(:target_file) { 'export.csv' }
135
100
  let(:definitions) do
136
101
  [
137
- OpenStruct.new(type: 'a', reference: 'b', value: 'c'),
138
- OpenStruct.new(type: 'd', reference: 'e', value: 'f')
102
+ OpenStruct.new(type: 'a', reference: 'b', value: 'c', sha256: 'd'),
103
+ OpenStruct.new(type: 'd', reference: 'e', value: 'f', sha256: 'g')
139
104
  ]
140
105
  end
141
106
 
@@ -146,24 +111,21 @@ RSpec.describe(DefMastership::CSVFormatter) do
146
111
  allow(document).to(receive(:iref).exactly(3).times.with(no_args).and_return(false))
147
112
  allow(document).to(receive(:attributes).exactly(3).times.with(no_args).and_return({}))
148
113
  allow(document).to(receive(:definitions).with(no_args).and_return(definitions))
114
+ allow(document).to(receive(:wrong_explicit_checksum?).with(no_args).and_return(false))
149
115
  formatter.export_to("#{aruba.current_directory}/#{target_file}")
150
116
  end
151
117
 
152
118
  it { expect(document).to(have_received(:labels).exactly(3).times.with(no_args)) }
153
-
154
119
  it { expect(document).to(have_received(:eref).exactly(3).times.with(no_args)) }
155
-
156
120
  it { expect(document).to(have_received(:iref).exactly(3).times.with(no_args)) }
157
-
158
121
  it { expect(document).to(have_received(:attributes).exactly(3).times.with(no_args)) }
159
-
160
122
  it { expect(document).to(have_received(:definitions).with(no_args)) }
161
123
 
162
124
  it do
163
125
  expect(target_file).to(have_file_content(<<~CSV_FILE))
164
- Type,Reference,Value
165
- a,b,c
166
- d,e,f
126
+ Type;Reference;Value;sha256
127
+ a;b;c;d
128
+ d;e;f;g
167
129
  CSV_FILE
168
130
  end
169
131
  end