defmastership 1.0.17 → 1.0.19

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.
Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.gitlab-ci.yml +37 -11
  4. data/Gemfile +71 -1
  5. data/Guardfile +44 -0
  6. data/Rakefile +16 -61
  7. data/bin/defmastership +9 -6
  8. data/config/cucumber.yml +3 -0
  9. data/config/mutant.yml +27 -3
  10. data/config/reek.yml +129 -105
  11. data/config/rubocop.yml +72 -28
  12. data/defmastership.gemspec +5 -13
  13. data/features/changeref.feature +0 -8
  14. data/features/definition_checksum.feature +30 -10
  15. data/features/definition_version.feature +168 -10
  16. data/features/export.feature +64 -17
  17. data/features/modify.feature +1 -5
  18. data/features/rename_included_files.feature +27 -4
  19. data/features/step_definitions/git_steps.rb +19 -0
  20. data/lib/defmastership/batch_modifier.rb +17 -12
  21. data/lib/defmastership/change_ref_modifier.rb +88 -6
  22. data/lib/defmastership/comment_filter.rb +1 -1
  23. data/lib/defmastership/constants.rb +10 -7
  24. data/lib/defmastership/csv_formatter.rb +16 -12
  25. data/lib/defmastership/csv_formatter_body.rb +18 -15
  26. data/lib/defmastership/csv_formatter_header.rb +1 -1
  27. data/lib/defmastership/definition.rb +59 -20
  28. data/lib/defmastership/document.rb +101 -74
  29. data/lib/defmastership/matching_line.rb +17 -0
  30. data/lib/defmastership/modifier.rb +42 -0
  31. data/lib/defmastership/modifier_factory.rb +12 -0
  32. data/lib/defmastership/parsing_state.rb +15 -9
  33. data/lib/defmastership/rename_included_files_modifier.rb +172 -5
  34. data/lib/defmastership/set_join_hack.rb +11 -0
  35. data/lib/defmastership/update_def_checksum_modifier.rb +8 -13
  36. data/lib/defmastership/update_def_modifier.rb +49 -0
  37. data/lib/defmastership/update_def_version_modifier.rb +81 -15
  38. data/lib/defmastership/version.rb +1 -1
  39. data/lib/defmastership.rb +1 -6
  40. data/spec/spec_helper.rb +3 -1
  41. data/spec/unit/def_mastership/batch_modifier_spec.rb +40 -36
  42. data/spec/unit/def_mastership/change_ref_modifier_spec.rb +196 -51
  43. data/spec/unit/def_mastership/csv_formatter_body_spec.rb +60 -31
  44. data/spec/unit/def_mastership/csv_formatter_header_spec.rb +1 -1
  45. data/spec/unit/def_mastership/csv_formatter_spec.rb +79 -87
  46. data/spec/unit/def_mastership/definition_parser_spec.rb +1 -1
  47. data/spec/unit/def_mastership/definition_spec.rb +16 -6
  48. data/spec/unit/def_mastership/document_spec.rb +81 -38
  49. data/spec/unit/def_mastership/matching_line_spec.rb +37 -0
  50. data/spec/unit/def_mastership/modifier_factory_spec.rb +38 -0
  51. data/spec/unit/def_mastership/modifier_spec.rb +85 -0
  52. data/spec/unit/def_mastership/parsing_state_spec.rb +1 -1
  53. data/spec/unit/def_mastership/rename_included_files_modifier_spec.rb +219 -47
  54. data/spec/unit/def_mastership/string_spec.rb +1 -1
  55. data/spec/unit/def_mastership/update_def_checksum_modifier_spec.rb +82 -50
  56. data/spec/unit/def_mastership/update_def_modifier_spec.rb +121 -0
  57. data/spec/unit/def_mastership/update_def_version_modifier_spec.rb +327 -56
  58. data/tasks/code_quality.rake +74 -0
  59. data/tasks/console.rake +8 -0
  60. data/tasks/package.task +9 -0
  61. data/tasks/test.rake +30 -0
  62. metadata +33 -145
  63. data/.rubocop.yml +0 -76
  64. data/config/devtools.yml +0 -2
  65. data/config/flay.yml +0 -3
  66. data/config/flog.yml +0 -2
  67. data/config/yardstick.yml +0 -2
  68. data/cucumber.yml +0 -2
  69. data/lib/defmastership/change_ref_line_modifier.rb +0 -85
  70. data/lib/defmastership/line_modifier_base.rb +0 -29
  71. data/lib/defmastership/modifier_base.rb +0 -36
  72. data/lib/defmastership/rename_included_files_line_modifier.rb +0 -126
  73. data/lib/defmastership/update_def_checksum_line_modifier.rb +0 -38
  74. data/lib/defmastership/update_def_version_line_modifier.rb +0 -58
  75. data/spec/unit/def_mastership/change_ref_line_modifier_spec.rb +0 -250
  76. data/spec/unit/def_mastership/rename_included_files_line_modifier_spec.rb +0 -207
  77. data/spec/unit/def_mastership/update_def_checksum_line_modifier_spec.rb +0 -82
  78. data/spec/unit/def_mastership/update_def_version_line_modifier_spec.rb +0 -131
  79. /data/{.rspec → config/rspec} +0 -0
@@ -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(:sha256).with(no_args).and_return('d'))
22
- formatter.fixed(definition)
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(:sha256).with(no_args)) }
29
- it { expect(formatter.fixed(definition)).to(eq(%w[a b c d])) }
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(definition)
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(definition)).to(eq([''])) }
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(definition)
46
+ formatter.wrong_explicit_checksum
47
47
  end
48
48
 
49
- it { expect(formatter.wrong_explicit_checksum(definition)).to(eq(['ab12'])) }
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(definition)
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(definition)).to(eq([''])) }
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(definition)
67
+ formatter.explicit_version
68
68
  end
69
69
 
70
- it { expect(formatter.explicit_version(definition)).to(eq(['ab12'])) }
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(definition)
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(definition)).to(eq([''])) }
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(definition)
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(definition)).to(eq(["toto\ntutu"])) }
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(definition)
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(nil)).to(eq([])) }
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(definition)
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(definition)).to(eq(["A\nB", '', 'C'])) }
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(definition)
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(definition)).to(eq([''])) }
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(definition)
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(definition)).to(eq(["A\nB"])) }
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(definition)
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(nil)).to(eq([])) }
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(definition)
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(definition)).to(eq(['X', '', 'Y'])) }
200
+ it { expect(formatter.attributes).to(eq(['X', '', ''])) }
172
201
  end
173
202
  end
174
203
  end
@@ -1,7 +1,7 @@
1
1
  # Copyright (c) 2020 Jerome Arbez-Gindre
2
2
  # frozen_string_literal: true
3
3
 
4
- require('defmastership')
4
+ require('defmastership/csv_formatter_header')
5
5
 
6
6
  RSpec.describe(DefMastership::CSVFormatterHeader) do
7
7
  subject(:formatter) { described_class.new(document) }
@@ -2,7 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require('csv')
5
- require('defmastership')
5
+ require('defmastership/csv_formatter')
6
6
  require('ostruct')
7
7
 
8
8
  RSpec.describe(DefMastership::CSVFormatter) do
@@ -16,15 +16,22 @@ RSpec.describe(DefMastership::CSVFormatter) do
16
16
 
17
17
  describe '#export_to' do
18
18
  let(:header) { instance_double(DefMastership::CSVFormatterHeader, 'header') }
19
- let(:body) { instance_double(DefMastership::CSVFormatterBody, 'body') }
20
- let(:csv) { instance_double(CSV, 'csv') }
19
+ let(:bodies) do
20
+ [
21
+ instance_double(DefMastership::CSVFormatterBody, 'bodies[0]'),
22
+ instance_double(DefMastership::CSVFormatterBody, 'bodies[1]')
23
+ ]
24
+ end
25
+ let(:csv) { instance_double(CSV, 'csv') }
21
26
 
22
27
  before do
23
- allow(CSV).to(receive(:open).and_yield(csv))
28
+ allow(CSV).to(receive(:open).with('whatever', 'w:ISO-8859-1', col_sep: ';').and_yield(csv))
24
29
  allow(csv).to(receive(:<<))
25
30
  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]))
31
+ bodies.each_with_index do |body, index|
32
+ allow(DefMastership::CSVFormatterBody).to(receive(:new).with(document, :"def#{index}").and_return(body))
33
+ end
34
+ allow(document).to(receive(:definitions).and_return(%i[def0 def1]))
28
35
  allow(document).to(receive(:wrong_explicit_checksum?).with(no_args).and_return(false))
29
36
  allow(document).to(receive(:explicit_version?).with(no_args).and_return(false))
30
37
  allow(document).to(receive(:labels).with(no_args).and_return([]))
@@ -39,21 +46,26 @@ RSpec.describe(DefMastership::CSVFormatter) do
39
46
  before do
40
47
  methods.each do |method|
41
48
  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"]))
49
+ bodies.each_with_index do |body, index|
50
+ allow(body).to(receive(method).with(no_args).and_return(["#{method} def#{index} body"]))
51
+ end
44
52
  end
45
53
  formatter.export_to('whatever')
46
54
  end
47
55
 
56
+ it { expect(CSV).to(have_received(:open).with('whatever', 'w:ISO-8859-1', col_sep: ';')) }
57
+
48
58
  methods.each do |method|
49
59
  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)) }
60
+
61
+ 2.times do |index|
62
+ it { expect(bodies[index]).to(have_received(method).with(no_args)) }
63
+ end
52
64
  end
53
65
 
54
66
  it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} header" })) }
67
+ it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} def0 body" })) }
55
68
  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
69
  end
58
70
 
59
71
  context 'when wrong_explicit_checksum' do
@@ -62,8 +74,9 @@ RSpec.describe(DefMastership::CSVFormatter) do
62
74
  before do
63
75
  methods.each do |method|
64
76
  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"]))
77
+ bodies.each_with_index do |body, index|
78
+ allow(body).to(receive(method).with(no_args).and_return(["#{method} def#{index} body"]))
79
+ end
67
80
  end
68
81
  allow(document).to(receive(:wrong_explicit_checksum?).with(no_args).and_return(true))
69
82
  formatter.export_to('whatever')
@@ -71,13 +84,15 @@ RSpec.describe(DefMastership::CSVFormatter) do
71
84
 
72
85
  methods.each do |method|
73
86
  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)) }
87
+
88
+ 2.times do |index|
89
+ it { expect(bodies[index]).to(have_received(method).with(no_args)) }
90
+ end
76
91
  end
77
92
 
78
93
  it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} header" })) }
94
+ it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} def0 body" })) }
79
95
  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
96
  end
82
97
 
83
98
  context 'when explicit_version' do
@@ -86,8 +101,9 @@ RSpec.describe(DefMastership::CSVFormatter) do
86
101
  before do
87
102
  methods.each do |method|
88
103
  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"]))
104
+ bodies.each_with_index do |body, index|
105
+ allow(body).to(receive(method).with(no_args).and_return(["#{method} def#{index} body"]))
106
+ end
91
107
  end
92
108
  allow(document).to(receive(:explicit_version?).with(no_args).and_return(true))
93
109
  formatter.export_to('whatever')
@@ -95,13 +111,15 @@ RSpec.describe(DefMastership::CSVFormatter) do
95
111
 
96
112
  methods.each do |method|
97
113
  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)) }
114
+
115
+ 2.times do |index|
116
+ it { expect(bodies[index]).to(have_received(method).with(no_args)) }
117
+ end
100
118
  end
101
119
 
102
120
  it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} header" })) }
121
+ it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} def0 body" })) }
103
122
  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" })) }
105
123
  end
106
124
 
107
125
  context 'when labels' do
@@ -110,8 +128,9 @@ RSpec.describe(DefMastership::CSVFormatter) do
110
128
  before do
111
129
  methods.each do |method|
112
130
  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"]))
131
+ bodies.each_with_index do |body, index|
132
+ allow(body).to(receive(method).with(no_args).and_return(["#{method} def#{index} body"]))
133
+ end
115
134
  end
116
135
  allow(document).to(receive(:labels).with(no_args).and_return([:whatever]))
117
136
  formatter.export_to('whatever')
@@ -119,13 +138,15 @@ RSpec.describe(DefMastership::CSVFormatter) do
119
138
 
120
139
  methods.each do |method|
121
140
  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)) }
141
+
142
+ 2.times do |index|
143
+ it { expect(bodies[index]).to(have_received(method).with(no_args)) }
144
+ end
124
145
  end
125
146
 
126
147
  it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} header" })) }
148
+ it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} def0 body" })) }
127
149
  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
150
  end
130
151
 
131
152
  context 'when eref' do
@@ -134,8 +155,9 @@ RSpec.describe(DefMastership::CSVFormatter) do
134
155
  before do
135
156
  methods.each do |method|
136
157
  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"]))
158
+ bodies.each_with_index do |body, index|
159
+ allow(body).to(receive(method).with(no_args).and_return(["#{method} def#{index} body"]))
160
+ end
139
161
  end
140
162
  allow(document).to(receive(:eref).with(no_args).and_return([:whatever]))
141
163
  formatter.export_to('whatever')
@@ -143,13 +165,15 @@ RSpec.describe(DefMastership::CSVFormatter) do
143
165
 
144
166
  methods.each do |method|
145
167
  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)) }
168
+
169
+ 2.times do |index|
170
+ it { expect(bodies[index]).to(have_received(method).with(no_args)) }
171
+ end
148
172
  end
149
173
 
150
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} def0 body" })) }
151
176
  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
177
  end
154
178
 
155
179
  context 'when iref' do
@@ -158,8 +182,9 @@ RSpec.describe(DefMastership::CSVFormatter) do
158
182
  before do
159
183
  methods.each do |method|
160
184
  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"]))
185
+ bodies.each_with_index do |body, index|
186
+ allow(body).to(receive(method).with(no_args).and_return(["#{method} def#{index} body"]))
187
+ end
163
188
  end
164
189
  allow(document).to(receive(:iref).with(no_args).and_return(true))
165
190
  formatter.export_to('whatever')
@@ -167,13 +192,15 @@ RSpec.describe(DefMastership::CSVFormatter) do
167
192
 
168
193
  methods.each do |method|
169
194
  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)) }
195
+
196
+ 2.times do |index|
197
+ it { expect(bodies[index]).to(have_received(method).with(no_args)) }
198
+ end
172
199
  end
173
200
 
174
201
  it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} header" })) }
202
+ it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} def0 body" })) }
175
203
  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
204
  end
178
205
 
179
206
  context 'when attributes' do
@@ -182,8 +209,9 @@ RSpec.describe(DefMastership::CSVFormatter) do
182
209
  before do
183
210
  methods.each do |method|
184
211
  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"]))
212
+ bodies.each_with_index do |body, index|
213
+ allow(body).to(receive(method).with(no_args).and_return(["#{method} def#{index} body"]))
214
+ end
187
215
  end
188
216
  allow(document).to(receive(:attributes).with(no_args).and_return([:whatever]))
189
217
  formatter.export_to('whatever')
@@ -191,13 +219,15 @@ RSpec.describe(DefMastership::CSVFormatter) do
191
219
 
192
220
  methods.each do |method|
193
221
  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)) }
222
+
223
+ 2.times do |index|
224
+ it { expect(bodies[index]).to(have_received(method).with(no_args)) }
225
+ end
196
226
  end
197
227
 
198
228
  it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} header" })) }
229
+ it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} def0 body" })) }
199
230
  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
231
  end
202
232
 
203
233
  context 'when every colums' do
@@ -206,8 +236,9 @@ RSpec.describe(DefMastership::CSVFormatter) do
206
236
  before do
207
237
  methods.each do |method|
208
238
  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"]))
239
+ bodies.each_with_index do |body, index|
240
+ allow(body).to(receive(method).with(no_args).and_return(["#{method} def#{index} body"]))
241
+ end
211
242
  end
212
243
  allow(document).to(receive(:wrong_explicit_checksum?).with(no_args).and_return(true))
213
244
  allow(document).to(receive(:explicit_version?).with(no_args).and_return(true))
@@ -220,54 +251,15 @@ RSpec.describe(DefMastership::CSVFormatter) do
220
251
 
221
252
  methods.each do |method|
222
253
  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)) }
254
+
255
+ 2.times do |index|
256
+ it { expect(bodies[index]).to(have_received(method).with(no_args)) }
257
+ end
225
258
  end
226
259
 
227
260
  it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} header" })) }
261
+ it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} def0 body" })) }
228
262
  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) { [double, double] }
236
-
237
- before do
238
- setup_aruba
239
- allow(document).to(receive(:labels).with(no_args).and_return([]))
240
- allow(document).to(receive(:eref).with(no_args).and_return({}))
241
- allow(document).to(receive(:iref).with(no_args).and_return(false))
242
- allow(document).to(receive(:attributes).with(no_args).and_return({}))
243
- allow(document).to(receive(:definitions).with(no_args).and_return(definitions))
244
- allow(definitions[0]).to(receive(:type).and_return('a'))
245
- allow(definitions[0]).to(receive(:reference).and_return('b'))
246
- allow(definitions[0]).to(receive(:value).and_return('c'))
247
- allow(definitions[0]).to(receive(:sha256).and_return('d'))
248
- allow(definitions[1]).to(receive(:type).and_return('d'))
249
- allow(definitions[1]).to(receive(:reference).and_return('e'))
250
- allow(definitions[1]).to(receive(:value).and_return('f'))
251
- allow(definitions[1]).to(receive(:sha256).and_return('g'))
252
- allow(document).to(receive(:wrong_explicit_checksum?).with(no_args).and_return(false))
253
- allow(document).to(receive(:explicit_version?).with(no_args).and_return(false))
254
- formatter.export_to("#{aruba.current_directory}/#{target_file}")
255
- end
256
-
257
- it { expect(document).to(have_received(:labels).with(no_args)) }
258
- it { expect(document).to(have_received(:eref).with(no_args)) }
259
- it { expect(document).to(have_received(:iref).with(no_args)) }
260
- it { expect(document).to(have_received(:attributes).with(no_args)) }
261
- it { expect(document).to(have_received(:definitions).with(no_args)) }
262
- it { expect(document).to(have_received(:wrong_explicit_checksum?).with(no_args)) }
263
- it { expect(document).to(have_received(:explicit_version?).with(no_args)) }
264
-
265
- it do
266
- expect(target_file).to(have_file_content(<<~CSV_FILE))
267
- Type;Reference;Value;Checksum
268
- a;b;c;d
269
- d;e;f;g
270
- CSV_FILE
271
263
  end
272
264
  end
273
265
  end
@@ -1,7 +1,7 @@
1
1
  # Copyright (c) 2020 Jerome Arbez-Gindre
2
2
  # frozen_string_literal: true
3
3
 
4
- require('defmastership')
4
+ require('defmastership/definition_parser')
5
5
 
6
6
  RSpec.describe(DefMastership::DefinitionParser) do
7
7
  subject(:parser) { described_class.new(callback_object) }
@@ -1,7 +1,7 @@
1
1
  # Copyright (c) 2020 Jerome Arbez-Gindre
2
2
  # frozen_string_literal: true
3
3
 
4
- require('defmastership')
4
+ require('defmastership/definition')
5
5
 
6
6
  RSpec.describe(DefMastership::Definition) do
7
7
  describe '.new' do
@@ -101,9 +101,14 @@ RSpec.describe(DefMastership::Definition) do
101
101
  expect(definition.lines).to(eq(['first line', 'second line']))
102
102
  end
103
103
 
104
- it 'calculates sha256 of value' do
104
+ it 'calculates sha256_short of value' do
105
105
  definition << 'first line' << 'second line'
106
- expect(definition.sha256).to(eq('~beb0535a'))
106
+ expect(definition.sha256_short).to(eq('~beb0535a'))
107
+ end
108
+
109
+ it 'returns the definition and not the "line"' do
110
+ expect { (definition << 'first line').sha256_short }
111
+ .not_to(raise_error)
107
112
  end
108
113
  end
109
114
 
@@ -115,9 +120,14 @@ RSpec.describe(DefMastership::Definition) do
115
120
  )
116
121
  end
117
122
 
118
- it 'shall accept to add one eref' do
119
- definition.add_eref(:foo, ' tutu, titi , pouet')
120
- expect(definition.eref[:foo]).to(eq(%w[tutu titi pouet]))
123
+ [
124
+ 'tutu,titi,pouet',
125
+ ' tutu , titi , pouet '
126
+ ].each do |erefs_cs|
127
+ it 'shall accept to add comma separated erefs' do
128
+ definition.add_eref(:foo, erefs_cs)
129
+ expect(definition.eref[:foo]).to(eq(%w[tutu titi pouet]))
130
+ end
121
131
  end
122
132
  end
123
133