defmastership 1.0.18 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +4 -0
  3. data/.gitlab-ci.yml +42 -1
  4. data/Gemfile +49 -18
  5. data/Guardfile +44 -0
  6. data/LICENSE +1 -1
  7. data/README.adoc +24 -0
  8. data/Rakefile +0 -1
  9. data/bin/defmastership +5 -5
  10. data/config/cucumber.yml +3 -0
  11. data/config/mutant.yml +22 -16
  12. data/config/reek.yml +129 -105
  13. data/config/rubocop.yml +67 -28
  14. data/defmastership.gemspec +8 -6
  15. data/features/changeref.feature +0 -8
  16. data/features/definition_checksum.feature +0 -10
  17. data/features/definition_version.feature +168 -10
  18. data/features/export.feature +23 -18
  19. data/features/modify.feature +1 -5
  20. data/features/rename_included_files.feature +0 -5
  21. data/features/step_definitions/git_steps.rb +19 -0
  22. data/lib/defmastership/batch_modifier.rb +23 -5
  23. data/lib/defmastership/comment_filter.rb +2 -1
  24. data/lib/defmastership/definition.rb +26 -6
  25. data/lib/defmastership/definition_parser.rb +2 -2
  26. data/lib/defmastership/document.rb +45 -33
  27. data/lib/defmastership/export/body_formatter.rb +55 -0
  28. data/lib/defmastership/export/csv/formatter.rb +64 -0
  29. data/lib/defmastership/export/header_formatter.rb +51 -0
  30. data/lib/defmastership/filters.rb +15 -12
  31. data/lib/defmastership/matching_line.rb +3 -2
  32. data/lib/defmastership/modifier/change_ref.rb +117 -0
  33. data/lib/defmastership/modifier/factory.rb +17 -0
  34. data/lib/defmastership/modifier/modifier_common.rb +71 -0
  35. data/lib/defmastership/modifier/rename_included_files.rb +223 -0
  36. data/lib/defmastership/modifier/update_def.rb +72 -0
  37. data/lib/defmastership/modifier/update_def_checksum.rb +17 -0
  38. data/lib/defmastership/modifier/update_def_version.rb +110 -0
  39. data/lib/defmastership/set_join_hack.rb +2 -0
  40. data/lib/defmastership/version.rb +3 -2
  41. data/lib/defmastership.rb +6 -8
  42. data/spec/unit/{def_mastership → defmastership}/batch_modifier_spec.rb +15 -13
  43. data/spec/unit/{def_mastership → defmastership}/definition_parser_spec.rb +1 -1
  44. data/spec/unit/{def_mastership → defmastership}/definition_spec.rb +1 -1
  45. data/spec/unit/{def_mastership → defmastership}/document_spec.rb +57 -57
  46. data/spec/unit/{def_mastership/csv_formatter_body_spec.rb → defmastership/export/body_formatter_spec.rb} +4 -4
  47. data/spec/unit/{def_mastership/csv_formatter_spec.rb → defmastership/export/csv/formatter_spec.rb} +13 -8
  48. data/spec/unit/{def_mastership/csv_formatter_header_spec.rb → defmastership/export/header_formatter_spec.rb} +3 -3
  49. data/spec/unit/{def_mastership → defmastership}/matching_line_spec.rb +1 -1
  50. data/spec/unit/{def_mastership/change_ref_modifier_spec.rb → defmastership/modifier/change_ref_spec.rb} +19 -44
  51. data/spec/unit/defmastership/modifier/factory_spec.rb +45 -0
  52. data/spec/unit/{def_mastership/modifier_spec.rb → defmastership/modifier/modifier_common_spec.rb} +11 -18
  53. data/spec/unit/{def_mastership/rename_included_files_modifier_spec.rb → defmastership/modifier/rename_included_files_spec.rb} +3 -3
  54. data/spec/unit/{def_mastership/update_def_checksum_modifier_spec.rb → defmastership/modifier/update_def_checksum_spec.rb} +10 -10
  55. data/spec/unit/{def_mastership/update_def_modifier_spec.rb → defmastership/modifier/update_def_spec.rb} +22 -18
  56. data/spec/unit/defmastership/modifier/update_def_version_spec.rb +351 -0
  57. data/spec/unit/{def_mastership_spec.rb → defmastership_spec.rb} +2 -2
  58. data/tasks/code_quality.rake +74 -0
  59. data/tasks/documentation.rake +19 -0
  60. data/tasks/package.rake +4 -0
  61. data/tasks/test.rake +6 -21
  62. metadata +96 -51
  63. data/.rubocop.yml +0 -76
  64. data/README.rdoc +0 -6
  65. data/config/devtools.yml +0 -2
  66. data/config/flay.yml +0 -3
  67. data/config/flog.yml +0 -2
  68. data/config/yardstick.yml +0 -2
  69. data/cucumber.yml +0 -2
  70. data/defmastership.rdoc +0 -5
  71. data/lib/defmastership/change_ref_modifier.rb +0 -99
  72. data/lib/defmastership/constants.rb +0 -89
  73. data/lib/defmastership/csv_formatter.rb +0 -53
  74. data/lib/defmastership/csv_formatter_body.rb +0 -46
  75. data/lib/defmastership/csv_formatter_header.rb +0 -41
  76. data/lib/defmastership/modifier.rb +0 -42
  77. data/lib/defmastership/modifier_factory.rb +0 -12
  78. data/lib/defmastership/parsing_state.rb +0 -31
  79. data/lib/defmastership/rename_included_files_modifier.rb +0 -182
  80. data/lib/defmastership/update_def_checksum_modifier.rb +0 -16
  81. data/lib/defmastership/update_def_modifier.rb +0 -49
  82. data/lib/defmastership/update_def_version_modifier.rb +0 -66
  83. data/spec/unit/def_mastership/modifier_factory_spec.rb +0 -37
  84. data/spec/unit/def_mastership/parsing_state_spec.rb +0 -62
  85. data/spec/unit/def_mastership/update_def_version_modifier_spec.rb +0 -159
  86. data/tasks/package.task +0 -9
  87. data/tasks/smelling_code.rake +0 -38
  88. /data/{.rspec → config/rspec} +0 -0
  89. /data/spec/unit/{def_mastership → defmastership}/string_spec.rb +0 -0
@@ -1,13 +1,13 @@
1
1
  # Copyright (c) 2020 Jerome Arbez-Gindre
2
2
  # frozen_string_literal: true
3
3
 
4
- require('defmastership/change_ref_modifier')
4
+ require('defmastership/modifier/change_ref')
5
5
 
6
- RSpec.describe(DefMastership::ChangeRefModifier) do
6
+ RSpec.describe(Defmastership::Modifier::ChangeRef) do
7
7
  subject(:refchanger) { described_class.new({}) }
8
8
 
9
9
  describe '.new' do
10
- it { expect(described_class.ancestors).to(include(DefMastership::Modifier)) }
10
+ it { expect(described_class.ancestors).to(include(Defmastership::Modifier::ModifierCommon)) }
11
11
  it { is_expected.not_to(be_nil) }
12
12
  it { is_expected.to(have_attributes(from_regexp: '')) }
13
13
  it { is_expected.to(have_attributes(to_template: '')) }
@@ -28,7 +28,7 @@ RSpec.describe(DefMastership::ChangeRefModifier) do
28
28
  end
29
29
  end
30
30
 
31
- describe '#replace_def' do
31
+ describe '#replace_refdef' do
32
32
  context 'when really simple rule' do
33
33
  subject(:refchanger) do
34
34
  described_class.new(
@@ -42,6 +42,21 @@ RSpec.describe(DefMastership::ChangeRefModifier) do
42
42
  expect(refchanger.replace_refdef('[define, whatever, TEMP]'))
43
43
  .to(eq('[define, whatever, TUTU]'))
44
44
  end
45
+
46
+ it do
47
+ expect(refchanger.replace_refdef('[define, whatever, TEMP(a~12345678)]'))
48
+ .to(eq('[define, whatever, TUTU(a~12345678)]'))
49
+ end
50
+
51
+ it do
52
+ expect(refchanger.replace_refdef('[define, whatever, TEMP(~12345678)]'))
53
+ .to(eq('[define, whatever, TUTU(~12345678)]'))
54
+ end
55
+
56
+ it do
57
+ expect(refchanger.replace_refdef('[define, whatever, TEMP(a)]'))
58
+ .to(eq('[define, whatever, TUTU(a)]'))
59
+ end
45
60
  end
46
61
 
47
62
  context 'when no valid definition' do
@@ -178,44 +193,4 @@ RSpec.describe(DefMastership::ChangeRefModifier) do
178
193
  ).to(eq('defs:iref[TOTO-0132] defs:iref[TOTO-0132] bla'))
179
194
  end
180
195
  end
181
-
182
- describe '#replace' do
183
- subject(:refchanger) do
184
- described_class.new(
185
- from_regexp: 'TEMP',
186
- to_template: 'TUTU'
187
- )
188
- end
189
-
190
- it do
191
- expect(refchanger.replace(:refdef, '[define, whatever, TEMP]'))
192
- .to(eq('[define, whatever, TUTU]'))
193
- end
194
-
195
- it do
196
- expect(refchanger.replace(:refdef, '[define, whatever, TEMP(a~12345678)]'))
197
- .to(eq('[define, whatever, TUTU(a~12345678)]'))
198
- end
199
-
200
- it do
201
- expect(refchanger.replace(:refdef, '[define, whatever, TEMP(~12345678)]'))
202
- .to(eq('[define, whatever, TUTU(~12345678)]'))
203
- end
204
-
205
- it do
206
- expect(refchanger.replace(:refdef, '[define, whatever, TEMP(a)]'))
207
- .to(eq('[define, whatever, TUTU(a)]'))
208
- end
209
-
210
- it do
211
- refchanger.replace(:refdef, '[define, whatever, TEMP]')
212
- expect(refchanger.replace(:irefs, 'defs:iref[TEMP] defs:iref[TEMP]'))
213
- .to(eq('defs:iref[TUTU] defs:iref[TUTU]'))
214
- end
215
-
216
- it do
217
- expect { refchanger.replace(:pouet, 'whatever') }
218
- .to(raise_error(NoMethodError))
219
- end
220
- end
221
196
  end
@@ -0,0 +1,45 @@
1
+ # Copyright (c) 2023 Jerome Arbez-Gindre
2
+ # frozen_string_literal: true
3
+
4
+ require('defmastership/modifier/factory')
5
+
6
+ module Defmastership
7
+ module Modifier
8
+ # Modifier example
9
+ class Toto
10
+ include ModifierCommon
11
+ end
12
+
13
+ # Modifier example
14
+ class TuTu
15
+ include ModifierCommon
16
+ end
17
+ end
18
+ end
19
+
20
+ RSpec.describe(Defmastership::Modifier::Factory) do
21
+ describe('.from_config') do
22
+ let(:toto) { instance_double(Defmastership::Modifier::Toto, 'toto') }
23
+ let(:toto_config) { { type: 'toto', config: { p: 'whatever' } } }
24
+ let(:tutu) { instance_double(Defmastership::Modifier::TuTu, 'tutu') }
25
+ let(:tutu_config) { { type: 'tu_tu', config: { p: 'whatever' } } }
26
+
27
+ before do
28
+ allow(Defmastership::Modifier::Toto).to(receive(:new).with(toto_config[:config]).and_return(toto))
29
+ allow(Defmastership::Modifier::TuTu).to(receive(:new).with(tutu_config[:config]).and_return(tutu))
30
+ end
31
+
32
+ it { expect(described_class.from_config(toto_config)).to(be(toto)) }
33
+ it { expect(described_class.from_config(tutu_config)).to(be(tutu)) }
34
+
35
+ it do
36
+ described_class.from_config(toto_config)
37
+ expect(Defmastership::Modifier::Toto).to(have_received(:new).with(toto_config[:config]))
38
+ end
39
+
40
+ it do
41
+ described_class.from_config(tutu_config)
42
+ expect(Defmastership::Modifier::TuTu).to(have_received(:new).with(tutu_config[:config]))
43
+ end
44
+ end
45
+ end
@@ -1,9 +1,12 @@
1
1
  # Copyright (c) 2023 Jerome Arbez-Gindre
2
2
  # frozen_string_literal: true
3
3
 
4
- require('defmastership/modifier')
4
+ require('defmastership/modifier/modifier_common')
5
5
 
6
- class DummyclassParrent
6
+ # just a class for test
7
+ class DummyClassParent
8
+ # This method smells of :reek:ControlParameter
9
+ # This method smells of :reek:UtilityFunction
7
10
  def respond_to_missing?(method_name, *_)
8
11
  return true if method_name == :ploup
9
12
 
@@ -11,8 +14,9 @@ class DummyclassParrent
11
14
  end
12
15
  end
13
16
 
14
- class DummyClass < DummyclassParrent
15
- include DefMastership::Modifier
17
+ # just a class for test
18
+ class DummyClass < DummyClassParent
19
+ include Defmastership::Modifier::ModifierCommon
16
20
 
17
21
  def self.replacement_methods
18
22
  %i[replace_pouet_by_foo replace_foo_by_zoo]
@@ -27,20 +31,18 @@ class DummyClass < DummyclassParrent
27
31
  super()
28
32
  end
29
33
 
34
+ # This method smells of :reek:UtilityFunction
30
35
  def replace_pouet_by_foo(line)
31
36
  line.gsub('pouet', 'foo')
32
37
  end
33
38
 
39
+ # This method smells of :reek:UtilityFunction
34
40
  def replace_foo_by_zoo(line)
35
41
  line.gsub('foo', 'zoo')
36
42
  end
37
43
  end
38
44
 
39
- class BadDummyClass < DummyclassParrent
40
- include DefMastership::Modifier
41
- end
42
-
43
- RSpec.describe(DefMastership::Modifier) do
45
+ RSpec.describe(Defmastership::Modifier::ModifierCommon) do
44
46
  subject(:modifier) { DummyClass.new({}) }
45
47
 
46
48
  describe '.new' do
@@ -63,15 +65,6 @@ RSpec.describe(DefMastership::Modifier) do
63
65
  end
64
66
  end
65
67
 
66
- describe '#apply_to_all' do
67
- it do
68
- texts = { first: "pouet\ntoto\npouet", second: "toto\npouet\ntoto" }
69
-
70
- expect(modifier.apply_to_all(texts, :replace_pouet_by_foo))
71
- .to(eq({ first: "foo\ntoto\nfoo", second: "toto\nfoo\ntoto" }))
72
- end
73
- end
74
-
75
68
  describe '#do_modifications' do
76
69
  it do
77
70
  adoc_sources = { first: "pouet\ntoto\npouet", second: "toto\npouet\ntoto" }
@@ -1,13 +1,13 @@
1
1
  # Copyright (c) 2021 Jerome Arbez-Gindre
2
2
  # frozen_string_literal: true
3
3
 
4
- require('defmastership/rename_included_files_modifier')
4
+ require('defmastership/modifier/rename_included_files')
5
5
 
6
- RSpec.describe(DefMastership::RenameIncludedFilesModifier) do
6
+ RSpec.describe(Defmastership::Modifier::RenameIncludedFiles) do
7
7
  subject(:includeschanger) { described_class.new({}) }
8
8
 
9
9
  describe '.new' do
10
- it { expect(described_class.ancestors).to(include(DefMastership::Modifier)) }
10
+ it { expect(described_class.ancestors).to(include(Defmastership::Modifier::ModifierCommon)) }
11
11
  it { is_expected.not_to(be_nil) }
12
12
  it { is_expected.to(have_attributes(from_regexp: '')) }
13
13
  it { is_expected.to(have_attributes(to_template: '')) }
@@ -1,13 +1,13 @@
1
1
  # Copyright (c) 2020 Jerome Arbez-Gindre
2
2
  # frozen_string_literal: true
3
3
 
4
- require('defmastership/update_def_checksum_modifier')
4
+ require('defmastership/modifier/update_def_checksum')
5
5
 
6
- RSpec.describe(DefMastership::UpdateDefChecksumModifier) do
6
+ RSpec.describe(Defmastership::Modifier::UpdateDefChecksum) do
7
7
  subject(:modifier) { described_class.new({}) }
8
8
 
9
9
  describe '.new' do
10
- it { expect(described_class.ancestors).to(include(DefMastership::Modifier)) }
10
+ it { expect(described_class.ancestors).to(include(Defmastership::Modifier::ModifierCommon)) }
11
11
  it { is_expected.not_to(be_nil) }
12
12
  it { is_expected.to(have_attributes(def_type: '')) }
13
13
  end
@@ -19,8 +19,8 @@ RSpec.describe(DefMastership::UpdateDefChecksumModifier) do
19
19
  describe '#do_modifications' do
20
20
  subject(:modifier) { described_class.new({ def_type: 'req' }) }
21
21
 
22
- let(:document) { instance_double(DefMastership::Document, 'document') }
23
- let(:definition) { instance_double(DefMastership::Definition, 'definition') }
22
+ let(:document) { instance_double(Defmastership::Document, 'document') }
23
+ let(:definition) { instance_double(Defmastership::Definition, 'definition') }
24
24
  let(:definitions) { { 'REFERENCE' => definition } }
25
25
  let(:adoc_sources) do
26
26
  {
@@ -31,7 +31,7 @@ RSpec.describe(DefMastership::UpdateDefChecksumModifier) do
31
31
  let(:new_adoc_sources) { nil }
32
32
 
33
33
  before do
34
- allow(DefMastership::Document).to(receive(:new).and_return(document))
34
+ allow(Defmastership::Document).to(receive(:new).and_return(document))
35
35
  allow(document).to(receive(:parse_file_with_preprocessor))
36
36
  allow(document).to(receive(:ref_to_def).with('REFERENCE').and_return(definition))
37
37
  allow(definition).to(receive(:sha256_short).and_return('~abcd1234'))
@@ -39,7 +39,7 @@ RSpec.describe(DefMastership::UpdateDefChecksumModifier) do
39
39
  modifier.do_modifications(adoc_sources)
40
40
  end
41
41
 
42
- it { expect(DefMastership::Document).to(have_received(:new)) }
42
+ it { expect(Defmastership::Document).to(have_received(:new)) }
43
43
 
44
44
  it do
45
45
  expect(document).to(
@@ -61,8 +61,8 @@ RSpec.describe(DefMastership::UpdateDefChecksumModifier) do
61
61
  )
62
62
  end
63
63
 
64
- let(:definition) { instance_double(DefMastership::Definition, 'definition') }
65
- let(:document) { instance_double(DefMastership::Document, 'document') }
64
+ let(:definition) { instance_double(Defmastership::Definition, 'definition') }
65
+ let(:document) { instance_double(Defmastership::Document, 'document') }
66
66
  let(:definitions) { { 'REFERENCE' => definition } }
67
67
 
68
68
  before do
@@ -78,7 +78,7 @@ RSpec.describe(DefMastership::UpdateDefChecksumModifier) do
78
78
 
79
79
  context 'when definition has the good type' do
80
80
  before do
81
- allow(DefMastership::Document).to(receive(:new).and_return(document))
81
+ allow(Defmastership::Document).to(receive(:new).and_return(document))
82
82
  allow(document).to(receive(:ref_to_def).with('REFERENCE').and_return(definition))
83
83
  allow(definition).to(receive(:sha256_short).and_return('~abcd1234'))
84
84
  end
@@ -1,23 +1,27 @@
1
1
  # Copyright (c) 2020 Jerome Arbez-Gindre
2
2
  # frozen_string_literal: true
3
3
 
4
- require('defmastership/update_def_modifier')
4
+ require('defmastership/modifier/update_def')
5
5
 
6
- module DefMastership
7
- class ConcreteRefModifier < UpdateDefModifier
8
- private
6
+ module Defmastership
7
+ module Modifier
8
+ # Just a class for tests
9
+ class ConcreteRef < UpdateDef
10
+ private
9
11
 
10
- def reference_replacement(reference, match)
11
- "#{reference}_something_#{match[:explicit_version]}"
12
+ # This method smells of :reek:UtilityFunction
13
+ def reference_replacement(reference, match)
14
+ "#{reference}_something_#{match[:explicit_version]}"
15
+ end
12
16
  end
13
17
  end
14
18
  end
15
19
 
16
- RSpec.describe(DefMastership::UpdateDefModifier) do
17
- subject(:modifier) { DefMastership::ConcreteRefModifier.new({}) }
20
+ RSpec.describe(Defmastership::Modifier::UpdateDef) do
21
+ subject(:modifier) { Defmastership::Modifier::ConcreteRef.new({}) }
18
22
 
19
23
  describe '.new' do
20
- it { expect(described_class.ancestors).to(include(DefMastership::Modifier)) }
24
+ it { expect(described_class.ancestors).to(include(Defmastership::Modifier::ModifierCommon)) }
21
25
  it { is_expected.not_to(be_nil) }
22
26
  it { is_expected.to(have_attributes(def_type: '')) }
23
27
  end
@@ -27,10 +31,10 @@ RSpec.describe(DefMastership::UpdateDefModifier) do
27
31
  end
28
32
 
29
33
  describe '#do_modifications' do
30
- subject(:modifier) { DefMastership::ConcreteRefModifier.new({ def_type: 'req' }) }
34
+ subject(:modifier) { Defmastership::Modifier::ConcreteRef.new({ def_type: 'req' }) }
31
35
 
32
- let(:document) { instance_double(DefMastership::Document, 'document') }
33
- let(:definition) { instance_double(DefMastership::Definition, 'definition') }
36
+ let(:document) { instance_double(Defmastership::Document, 'document') }
37
+ let(:definition) { instance_double(Defmastership::Definition, 'definition') }
34
38
  let(:definitions) { { 'REFERENCE' => definition } }
35
39
  let(:adoc_sources) do
36
40
  {
@@ -41,14 +45,14 @@ RSpec.describe(DefMastership::UpdateDefModifier) do
41
45
  let(:new_adoc_sources) { nil }
42
46
 
43
47
  before do
44
- allow(DefMastership::Document).to(receive(:new).and_return(document))
48
+ allow(Defmastership::Document).to(receive(:new).and_return(document))
45
49
  allow(document).to(receive(:parse_file_with_preprocessor).with('file1.adoc'))
46
50
  allow(document).to(receive(:parse_file_with_preprocessor).with('file2.adoc'))
47
51
 
48
52
  modifier.do_modifications(adoc_sources)
49
53
  end
50
54
 
51
- it { expect(DefMastership::Document).to(have_received(:new)) }
55
+ it { expect(Defmastership::Document).to(have_received(:new)) }
52
56
 
53
57
  it do
54
58
  expect(document).to(
@@ -66,13 +70,13 @@ RSpec.describe(DefMastership::UpdateDefModifier) do
66
70
 
67
71
  describe '#replace_reference' do
68
72
  subject(:modifier) do
69
- DefMastership::ConcreteRefModifier.new(
73
+ Defmastership::Modifier::ConcreteRef.new(
70
74
  def_type: 'requirement'
71
75
  )
72
76
  end
73
77
 
74
- let(:definition) { instance_double(DefMastership::Definition, 'definition') }
75
- let(:document) { instance_double(DefMastership::Document, 'document') }
78
+ let(:definition) { instance_double(Defmastership::Definition, 'definition') }
79
+ let(:document) { instance_double(Defmastership::Document, 'document') }
76
80
  let(:definitions) { { 'REFERENCE' => definition } }
77
81
 
78
82
  before do
@@ -95,7 +99,7 @@ RSpec.describe(DefMastership::UpdateDefModifier) do
95
99
 
96
100
  context 'when definition has the good type' do
97
101
  before do
98
- allow(DefMastership::Document).to(receive(:new).and_return(document))
102
+ allow(Defmastership::Document).to(receive(:new).and_return(document))
99
103
  allow(document).to(receive(:ref_to_def).with('REFERENCE').and_return(definition))
100
104
  allow(definition).to(receive(:sha256_short).and_return('~abcd1234'))
101
105
  end