defmastership 1.0.16 → 1.0.18

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 (68) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.gitlab-ci.yml +50 -7
  4. data/.rubocop.yml +14 -6
  5. data/Gemfile +51 -1
  6. data/Rakefile +16 -47
  7. data/bin/defmastership +12 -9
  8. data/config/mutant.yml +23 -3
  9. data/defmastership.gemspec +22 -27
  10. data/features/definition_checksum.feature +31 -1
  11. data/features/export.feature +43 -1
  12. data/features/rename_included_files.feature +28 -0
  13. data/lib/defmastership/batch_modifier.rb +17 -12
  14. data/lib/defmastership/change_ref_modifier.rb +89 -5
  15. data/lib/defmastership/comment_filter.rb +1 -1
  16. data/lib/defmastership/constants.rb +5 -4
  17. data/lib/defmastership/csv_formatter.rb +20 -16
  18. data/lib/defmastership/csv_formatter_body.rb +18 -15
  19. data/lib/defmastership/csv_formatter_header.rb +1 -1
  20. data/lib/defmastership/definition.rb +58 -19
  21. data/lib/defmastership/document.rb +109 -74
  22. data/lib/defmastership/matching_line.rb +17 -0
  23. data/lib/defmastership/modifier.rb +42 -0
  24. data/lib/defmastership/modifier_factory.rb +12 -0
  25. data/lib/defmastership/parsing_state.rb +15 -9
  26. data/lib/defmastership/rename_included_files_modifier.rb +172 -5
  27. data/lib/defmastership/set_join_hack.rb +11 -0
  28. data/lib/defmastership/update_def_checksum_modifier.rb +8 -13
  29. data/lib/defmastership/update_def_modifier.rb +49 -0
  30. data/lib/defmastership/update_def_version_modifier.rb +56 -15
  31. data/lib/defmastership/version.rb +1 -1
  32. data/lib/defmastership.rb +7 -17
  33. data/spec/spec_helper.rb +4 -2
  34. data/spec/unit/{defmastership → def_mastership}/batch_modifier_spec.rb +42 -39
  35. data/spec/unit/{defmastership/change_ref_line_modifier_spec.rb → def_mastership/change_ref_modifier_spec.rb} +44 -66
  36. data/spec/unit/{defmastership → def_mastership}/csv_formatter_body_spec.rb +61 -32
  37. data/spec/unit/{defmastership → def_mastership}/csv_formatter_header_spec.rb +2 -2
  38. data/spec/unit/{defmastership → def_mastership}/csv_formatter_spec.rb +81 -86
  39. data/spec/unit/{defmastership → def_mastership}/definition_parser_spec.rb +2 -2
  40. data/spec/unit/{defmastership → def_mastership}/definition_spec.rb +17 -7
  41. data/spec/unit/{defmastership → def_mastership}/document_spec.rb +108 -53
  42. data/spec/unit/def_mastership/matching_line_spec.rb +37 -0
  43. data/spec/unit/def_mastership/modifier_factory_spec.rb +37 -0
  44. data/spec/unit/def_mastership/modifier_spec.rb +83 -0
  45. data/spec/unit/{defmastership → def_mastership}/parsing_state_spec.rb +16 -16
  46. data/spec/unit/{defmastership/rename_included_files_line_modifier_spec.rb → def_mastership/rename_included_files_modifier_spec.rb} +72 -36
  47. data/spec/unit/{defmastership/comment_filter_spec.rb → def_mastership/string_spec.rb} +1 -1
  48. data/spec/unit/def_mastership/update_def_checksum_modifier_spec.rb +107 -0
  49. data/spec/unit/def_mastership/update_def_modifier_spec.rb +119 -0
  50. data/spec/unit/def_mastership/update_def_version_modifier_spec.rb +159 -0
  51. data/spec/unit/{defmastership_spec.rb → def_mastership_spec.rb} +1 -1
  52. data/tasks/console.rake +8 -0
  53. data/tasks/package.task +9 -0
  54. data/tasks/smelling_code.rake +38 -0
  55. data/tasks/test.rake +45 -0
  56. metadata +37 -145
  57. data/lib/defmastership/change_ref_line_modifier.rb +0 -82
  58. data/lib/defmastership/line_modifier_base.rb +0 -29
  59. data/lib/defmastership/modifier_base.rb +0 -29
  60. data/lib/defmastership/rename_included_files_line_modifier.rb +0 -126
  61. data/lib/defmastership/update_def_checksum_line_modifier.rb +0 -38
  62. data/lib/defmastership/update_def_version_line_modifier.rb +0 -58
  63. data/spec/unit/defmastership/change_ref_modifier_spec.rb +0 -76
  64. data/spec/unit/defmastership/rename_included_files_modifier_spec.rb +0 -67
  65. data/spec/unit/defmastership/update_def_checksum_line_modifier_spec.rb +0 -78
  66. data/spec/unit/defmastership/update_def_checksum_modifier_spec.rb +0 -75
  67. data/spec/unit/defmastership/update_def_version_line_modifier_spec.rb +0 -127
  68. data/spec/unit/defmastership/update_def_version_modifier_spec.rb +0 -80
@@ -1,29 +1,31 @@
1
1
  # Copyright (c) 2020 Jerome Arbez-Gindre
2
2
  # frozen_string_literal: true
3
3
 
4
- require('defmastership')
4
+ require('defmastership/batch_modifier')
5
5
 
6
6
  module DefMastership
7
- class TotoClassModifier < ModifierBase
7
+ class TotoModifier
8
+ include Modifier
8
9
  end
9
10
 
10
- class TutuClassModifier < ModifierBase
11
+ class TuTuModifier
12
+ include Modifier
11
13
  end
12
14
  end
13
15
 
14
16
  RSpec.describe(DefMastership::BatchModifier) do
15
17
  subject(:batchmodifier) do
16
- described_class.new(config, adoc_texts)
18
+ described_class.new(config, adoc_sources)
17
19
  end
18
20
 
19
21
  let(:config) do
20
22
  {
21
- modifier1: { type: 'toto_class', config: { p: 1 } },
22
- modifier2: { type: 'toto_class', config: { p: 'whatever1' } },
23
- modifier3: { type: 'tutu_class', config: { p1: 'whatever2', p2: 'whatever3' } }
23
+ modifier1: { type: 'toto', config: { p: 1 } },
24
+ modifier2: { type: 'toto', config: { p: 'whatever1' } },
25
+ modifier3: { type: 'tu_tu', config: { p1: 'whatever2', p2: 'whatever3' } }
24
26
  }
25
27
  end
26
- let(:adoc_texts) do
28
+ let(:adoc_sources) do
27
29
  {
28
30
  'file1.adoc' => 'some text',
29
31
  'file2.adoc' => 'another text'
@@ -31,18 +33,18 @@ RSpec.describe(DefMastership::BatchModifier) do
31
33
  end
32
34
 
33
35
  describe '.new' do
34
- it { is_expected.not_to(be(nil)) }
36
+ it { is_expected.not_to(be_nil) }
35
37
  it { is_expected.to(have_attributes(config: config)) }
36
38
 
37
39
  it do
38
- expect(batchmodifier).to(have_attributes(adoc_texts: adoc_texts))
40
+ expect(batchmodifier).to(have_attributes(adoc_sources: adoc_sources))
39
41
  end
40
42
  end
41
43
 
42
44
  describe '#apply' do
43
45
  context 'with only one modification' do
44
- let(:toto1) { instance_double(DefMastership::TotoClassModifier, 'toto1') }
45
- let(:adoc_texts_modified) do
46
+ let(:toto1) { instance_double(DefMastership::TotoModifier, 'toto1') }
47
+ let(:adoc_sources_modified) do
46
48
  {
47
49
  'file1.adoc' => 'some text modified',
48
50
  'file2.adoc' => 'another text'
@@ -51,26 +53,26 @@ RSpec.describe(DefMastership::BatchModifier) do
51
53
 
52
54
  let(:config_modified) do
53
55
  {
54
- modifier1: { type: 'toto_class', config: { p: 'modified_param' } },
55
- modifier2: { type: 'toto_class', config: { p: 'whatever1' } },
56
- modifier3: { type: 'tutu_class', config: { p1: 'whatever2', p2: 'whatever3' } }
56
+ modifier1: { type: 'toto', config: { p: 'modified_param' } },
57
+ modifier2: { type: 'toto', config: { p: 'whatever1' } },
58
+ modifier3: { type: 'tu_tu', config: { p1: 'whatever2', p2: 'whatever3' } }
57
59
  }
58
60
  end
59
61
 
60
62
  before do
61
- allow(DefMastership::TotoClassModifier).to(receive(:new).once.and_return(toto1))
62
- allow(toto1).to(receive(:do_modifications).once.and_return(adoc_texts_modified))
63
+ allow(DefMastership::TotoModifier).to(receive(:new).once.and_return(toto1))
64
+ allow(toto1).to(receive(:do_modifications).once.and_return(adoc_sources_modified))
63
65
  allow(toto1).to(receive(:config).once.and_return(p: 'modified_param'))
64
66
  allow(toto1).to(receive(:changes).once.and_return([%w[from1 to1], %w[from2 to2]]))
65
- batchmodifier.apply('modifier1')
67
+ batchmodifier.apply(%i[modifier1])
66
68
  end
67
69
 
68
70
  it do
69
- expect(DefMastership::TotoClassModifier).to(have_received(:new).with(p: 1))
71
+ expect(DefMastership::TotoModifier).to(have_received(:new).with(p: 1))
70
72
  end
71
73
 
72
- it { expect(toto1).to(have_received(:do_modifications).with(adoc_texts)) }
73
- it { is_expected.to(have_attributes(adoc_texts: adoc_texts_modified)) }
74
+ it { expect(toto1).to(have_received(:do_modifications).with(adoc_sources)) }
75
+ it { is_expected.to(have_attributes(adoc_sources: adoc_sources_modified)) }
74
76
  it { expect(toto1).to(have_received(:config).with(no_args)) }
75
77
 
76
78
  it { is_expected.to(have_attributes(config: config_modified)) }
@@ -78,45 +80,46 @@ RSpec.describe(DefMastership::BatchModifier) do
78
80
  end
79
81
 
80
82
  context 'with two modifications' do
81
- let(:toto2) { instance_double(DefMastership::TotoClassModifier, 'toto2') }
82
- let(:tutu3) { instance_double(DefMastership::TutuClassModifier, 'tutu3') }
83
+ let(:toto2) { instance_double(DefMastership::TotoModifier, 'toto2') }
84
+ let(:tutu3) { instance_double(DefMastership::TuTuModifier, 'tutu3') }
83
85
 
84
86
  let(:config_modified) do
85
87
  {
86
- modifier1: { type: 'toto_class', config: { p: 1 } },
87
- modifier2: { type: 'toto_class', config: :whatever },
88
- modifier3: { type: 'tutu_class', config: :pouet }
88
+ modifier1: { type: 'toto', config: { p: 1 } },
89
+ modifier2: { type: 'toto', config: :whatever },
90
+ modifier3: { type: 'tu_tu', config: :pouet }
89
91
  }
90
92
  end
91
93
 
92
94
  before do
93
- allow(DefMastership::TotoClassModifier).to(receive(:new).once.and_return(toto2))
94
- allow(toto2).to(receive(:do_modifications).once.and_return(:adoc_texts_modified_mod2))
95
+ allow(DefMastership::TotoModifier).to(receive(:new).once.and_return(toto2))
96
+ allow(toto2).to(receive(:do_modifications).once.and_return(:adoc_sources_modified_mod2))
95
97
  allow(toto2).to(receive(:config).once.and_return(:whatever))
96
- allow(DefMastership::TutuClassModifier).to(receive(:new).once.and_return(tutu3))
97
- allow(tutu3).to(receive(:do_modifications).once.and_return(:adoc_texts_modified_mod3))
98
+ allow(DefMastership::TuTuModifier).to(receive(:new).once.and_return(tutu3))
99
+ allow(tutu3).to(receive(:do_modifications).once.and_return(:adoc_sources_modified_mod3))
98
100
  allow(tutu3).to(receive(:config).once.and_return(:pouet))
99
101
  allow(toto2).to(receive(:changes).once.and_return([%w[from1 to1]]))
100
102
  allow(tutu3).to(receive(:changes).once.and_return([%w[from2 to2]]))
101
- batchmodifier.apply('modifier2, modifier3')
103
+ batchmodifier.apply(%i[modifier2 modifier3])
102
104
  end
103
105
 
104
- it { expect(DefMastership::TotoClassModifier).to(have_received(:new).with(p: 'whatever1')) }
105
- it { expect(DefMastership::TutuClassModifier).to(have_received(:new).with(p1: 'whatever2', p2: 'whatever3')) }
106
- it { expect(toto2).to(have_received(:do_modifications).with(adoc_texts)) }
106
+ it { expect(DefMastership::TotoModifier).to(have_received(:new).with(p: 'whatever1')) }
107
+ it { expect(DefMastership::TuTuModifier).to(have_received(:new).with(p1: 'whatever2', p2: 'whatever3')) }
108
+ it { expect(toto2).to(have_received(:do_modifications).with(adoc_sources)) }
107
109
  it { expect(toto2).to(have_received(:config).with(no_args)) }
108
- it { expect(tutu3).to(have_received(:do_modifications).with(:adoc_texts_modified_mod2)) }
110
+ it { expect(tutu3).to(have_received(:do_modifications).with(:adoc_sources_modified_mod2)) }
109
111
  it { expect(tutu3).to(have_received(:config).with(no_args)) }
110
- it { is_expected.to(have_attributes(adoc_texts: :adoc_texts_modified_mod3)) }
112
+ it { is_expected.to(have_attributes(adoc_sources: :adoc_sources_modified_mod3)) }
111
113
  it { is_expected.to(have_attributes(config: config_modified)) }
112
114
  it { is_expected.to(have_attributes(changes: [%w[modifier2 from1 to1], %w[modifier3 from2 to2]])) }
113
115
  end
114
116
 
115
117
  context 'with wrong modification' do
116
118
  it do
117
- expect { batchmodifier.apply('wrong-modification') }.to(
118
- raise_error(ArgumentError, 'wrong-modification is not a known modification')
119
- )
119
+ expect { batchmodifier.apply(%i[wrong-modification]) }
120
+ .to(
121
+ raise_error(ArgumentError, 'wrong-modification is not a known modification')
122
+ )
120
123
  end
121
124
  end
122
125
  end
@@ -1,49 +1,21 @@
1
1
  # Copyright (c) 2020 Jerome Arbez-Gindre
2
2
  # frozen_string_literal: true
3
3
 
4
- require('defmastership')
4
+ require('defmastership/change_ref_modifier')
5
5
 
6
- RSpec.describe(DefMastership::ChangeRefLineModifier) do
7
- subject(:refchanger) { described_class.new }
6
+ RSpec.describe(DefMastership::ChangeRefModifier) do
7
+ subject(:refchanger) { described_class.new({}) }
8
8
 
9
9
  describe '.new' do
10
- it { is_expected.not_to(be(nil)) }
10
+ it { expect(described_class.ancestors).to(include(DefMastership::Modifier)) }
11
+ it { is_expected.not_to(be_nil) }
11
12
  it { is_expected.to(have_attributes(from_regexp: '')) }
12
13
  it { is_expected.to(have_attributes(to_template: '')) }
13
14
  it { is_expected.to(have_attributes(next_ref: 0)) }
14
- it { is_expected.to(have_attributes(changes: [])) }
15
- it { expect { refchanger.user_defined_attribute }.to(raise_error(NoMethodError)) }
16
15
  end
17
16
 
18
- describe '.from_config' do
19
- subject(:refchanger) do
20
- described_class.from_config(
21
- from_regexp: 'Whatever.+',
22
- to_template: 'Whatever',
23
- next_ref: 17
24
- )
25
- end
26
-
27
- it { is_expected.not_to(be(nil)) }
28
- it { is_expected.to(have_attributes(from_regexp: 'Whatever.+')) }
29
- it { is_expected.to(have_attributes(to_template: 'Whatever')) }
30
- it { is_expected.to(have_attributes(next_ref: 17)) }
31
- end
32
-
33
- describe '#from_config' do
34
- before do
35
- refchanger.from_config(
36
- from_regexp: 'Whatever.+',
37
- to_template: 'Whatever',
38
- next_ref: 17,
39
- user_defined_attribute: 'Tadaam'
40
- )
41
- end
42
-
43
- it { is_expected.to(have_attributes(from_regexp: 'Whatever.+')) }
44
- it { is_expected.to(have_attributes(to_template: 'Whatever')) }
45
- it { is_expected.to(have_attributes(next_ref: 17)) }
46
- it { is_expected.to(have_attributes(user_defined_attribute: 'Tadaam')) }
17
+ describe '.replacement_methods' do
18
+ it { expect(described_class.replacement_methods).to(eq(%i[replace_refdef replace_irefs])) }
47
19
  end
48
20
 
49
21
  describe '#config' do
@@ -54,26 +26,12 @@ RSpec.describe(DefMastership::ChangeRefLineModifier) do
54
26
  )
55
27
  end
56
28
  end
57
-
58
- context 'when initalized with additionnal keys' do
59
- before do
60
- refchanger.from_config(
61
- next_ref: 1256,
62
- user_defined_attribute: 'Tadaam'
63
- )
64
- end
65
-
66
- it { expect(refchanger.config).to(include(from_regexp: '')) }
67
- it { expect(refchanger.config).to(include(to_template: '')) }
68
- it { expect(refchanger.config).to(include(next_ref: 1256)) }
69
- it { expect(refchanger.config).to(include(user_defined_attribute: 'Tadaam')) }
70
- end
71
29
  end
72
30
 
73
31
  describe '#replace_def' do
74
32
  context 'when really simple rule' do
75
- before do
76
- refchanger.from_config(
33
+ subject(:refchanger) do
34
+ described_class.new(
77
35
  from_regexp: 'TEMP',
78
36
  to_template: 'TUTU'
79
37
  )
@@ -95,8 +53,8 @@ RSpec.describe(DefMastership::ChangeRefLineModifier) do
95
53
  end
96
54
 
97
55
  context 'when template is variable' do
98
- before do
99
- refchanger.from_config(
56
+ subject(:refchanger) do
57
+ described_class.new(
100
58
  from_regexp: 'TEMP',
101
59
  to_template: 'TOTO-%<next_ref>04d',
102
60
  next_ref: 124
@@ -115,8 +73,8 @@ RSpec.describe(DefMastership::ChangeRefLineModifier) do
115
73
  end
116
74
 
117
75
  context 'when capture group in regexp' do
118
- before do
119
- refchanger.from_config(
76
+ subject(:refchanger) do
77
+ described_class.new(
120
78
  from_regexp: '(?<cg>TOTO|TITI)-TEMP[\d]*',
121
79
  to_template: '%<cg>s-%<next_ref>04d',
122
80
  next_ref: 132
@@ -142,11 +100,14 @@ RSpec.describe(DefMastership::ChangeRefLineModifier) do
142
100
  end
143
101
 
144
102
  context 'when definition is in literal block' do
145
- before do
146
- refchanger.from_config(
103
+ subject(:refchanger) do
104
+ described_class.new(
147
105
  from_regexp: 'TEMP',
148
106
  to_template: 'TUTU'
149
107
  )
108
+ end
109
+
110
+ before do
150
111
  refchanger.replace_refdef('....')
151
112
  end
152
113
 
@@ -157,11 +118,14 @@ RSpec.describe(DefMastership::ChangeRefLineModifier) do
157
118
  end
158
119
 
159
120
  context 'when defintion is after literal block' do
160
- before do
161
- refchanger.from_config(
121
+ subject(:refchanger) do
122
+ described_class.new(
162
123
  from_regexp: 'TEMP',
163
124
  to_template: 'TUTU'
164
125
  )
126
+ end
127
+
128
+ before do
165
129
  refchanger.replace_refdef("....\n")
166
130
  refchanger.replace_refdef('[define, whatever, TEMP]')
167
131
  refchanger.replace_refdef("....\n")
@@ -175,12 +139,15 @@ RSpec.describe(DefMastership::ChangeRefLineModifier) do
175
139
  end
176
140
 
177
141
  describe '#replace_irefs' do
178
- before do
179
- refchanger.from_config(
142
+ subject(:refchanger) do
143
+ described_class.new(
180
144
  from_regexp: '(?<cg>TOTO|TITI)-TEMP[\d]*',
181
145
  to_template: '%<cg>s-%<next_ref>04d',
182
146
  next_ref: 132
183
147
  )
148
+ end
149
+
150
+ before do
184
151
  refchanger.replace_refdef('[define, whatever, TOTO-TEMP123]')
185
152
  refchanger.replace_refdef('[define, whatever, TITI-TEMP421]')
186
153
  end
@@ -202,11 +169,19 @@ RSpec.describe(DefMastership::ChangeRefLineModifier) do
202
169
  )
203
170
  ).to(eq('defs:iref[TOTO-0132] defs:iref[TITI-0133] bla'))
204
171
  end
172
+
173
+ it do
174
+ expect(
175
+ refchanger.replace_irefs(
176
+ 'defs:iref[TOTO-TEMP123] defs:iref[TOTO-TEMP123] bla'
177
+ )
178
+ ).to(eq('defs:iref[TOTO-0132] defs:iref[TOTO-0132] bla'))
179
+ end
205
180
  end
206
181
 
207
182
  describe '#replace' do
208
- before do
209
- refchanger.from_config(
183
+ subject(:refchanger) do
184
+ described_class.new(
210
185
  from_regexp: 'TEMP',
211
186
  to_template: 'TUTU'
212
187
  )
@@ -234,10 +209,13 @@ RSpec.describe(DefMastership::ChangeRefLineModifier) do
234
209
 
235
210
  it do
236
211
  refchanger.replace(:refdef, '[define, whatever, TEMP]')
237
- expect(refchanger.replace(:irefs, 'defs:iref[TEMP]'))
238
- .to(eq('defs:iref[TUTU]'))
212
+ expect(refchanger.replace(:irefs, 'defs:iref[TEMP] defs:iref[TEMP]'))
213
+ .to(eq('defs:iref[TUTU] defs:iref[TUTU]'))
239
214
  end
240
215
 
241
- it { expect { refchanger.replace(:pouet, 'whatever') }.to(raise_error(NoMethodError)) }
216
+ it do
217
+ expect { refchanger.replace(:pouet, 'whatever') }
218
+ .to(raise_error(NoMethodError))
219
+ end
242
220
  end
243
221
  end
@@ -1,16 +1,16 @@
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') }
11
11
 
12
12
  describe '.new' do
13
- it { is_expected.not_to(be(nil)) }
13
+ it { is_expected.not_to(be_nil) }
14
14
  end
15
15
 
16
16
  describe '#fixed' do
@@ -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) }
@@ -9,7 +9,7 @@ RSpec.describe(DefMastership::CSVFormatterHeader) do
9
9
  let(:document) { instance_double(DefMastership::Document, 'document') }
10
10
 
11
11
  describe '.new' do
12
- it { is_expected.not_to(be(nil)) }
12
+ it { is_expected.not_to(be_nil) }
13
13
  end
14
14
 
15
15
  describe '#header' do