defmastership 1.0.17 → 1.0.19

Sign up to get free protection for your applications and to get access to all the features.
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,75 +1,107 @@
1
1
  # Copyright (c) 2020 Jerome Arbez-Gindre
2
2
  # frozen_string_literal: true
3
3
 
4
- require('defmastership')
4
+ require('defmastership/update_def_checksum_modifier')
5
5
 
6
6
  RSpec.describe(DefMastership::UpdateDefChecksumModifier) do
7
- subject(:modifier) do
8
- described_class.new(
9
- 'fake config'
10
- )
11
- end
12
-
13
- let(:adoc_texts) do
14
- {
15
- 'file1.adoc' => "file1 line1\nfile1 line2",
16
- 'file2.adoc' => "file2 line1\nfile2 line2"
17
- }
18
- end
7
+ subject(:modifier) { described_class.new({}) }
19
8
 
20
9
  describe '.new' do
10
+ it { expect(described_class.ancestors).to(include(DefMastership::Modifier)) }
21
11
  it { is_expected.not_to(be_nil) }
22
- it { is_expected.to(have_attributes(config: 'fake config')) }
23
- it { is_expected.to(have_attributes(changes: [])) }
12
+ it { is_expected.to(have_attributes(def_type: '')) }
13
+ end
14
+
15
+ describe '.replacement_methods' do
16
+ it { expect(described_class.replacement_methods).to(eq(%i[replace_reference])) }
24
17
  end
25
18
 
26
19
  describe '#do_modifications' do
27
- let(:line_modifier) { instance_double(DefMastership::UpdateDefChecksumLineModifier, 'lineModifier') }
28
- let(:document) { instance_double(DefMastership::Document, 'document') }
20
+ subject(:modifier) { described_class.new({ def_type: 'req' }) }
21
+
22
+ let(:document) { instance_double(DefMastership::Document, 'document') }
23
+ let(:definition) { instance_double(DefMastership::Definition, 'definition') }
24
+ let(:definitions) { { 'REFERENCE' => definition } }
25
+ let(:adoc_sources) do
26
+ {
27
+ 'file1.adoc' => "[define,req,REFERENCE]\nfile1 line2",
28
+ 'file2.adoc' => "file2 line1\nfile2 line2"
29
+ }
30
+ end
31
+ let(:new_adoc_sources) { nil }
29
32
 
30
33
  before do
31
- allow(DefMastership::UpdateDefChecksumLineModifier).to(
32
- receive(:from_config).with('fake config').and_return(line_modifier)
33
- )
34
34
  allow(DefMastership::Document).to(receive(:new).and_return(document))
35
35
  allow(document).to(receive(:parse_file_with_preprocessor))
36
- allow(line_modifier).to(receive(:'document=').with(document))
37
- allow(line_modifier).to(receive(:replace).with("file1 line1\n").and_return("new file1 line1\n"))
38
- allow(line_modifier).to(receive(:replace).with('file1 line2').and_return('new file1 line2'))
39
- allow(line_modifier).to(receive(:replace).with("file2 line1\n").and_return("new file2 line1\n"))
40
- allow(line_modifier).to(receive(:replace).with('file2 line2').and_return('new file2 line2'))
41
- allow(line_modifier).to(receive(:config).and_return('new fake config'))
42
- allow(line_modifier).to(receive(:changes).and_return([%w[from1 to1], %w[from2 to2]]))
36
+ allow(document).to(receive(:ref_to_def).with('REFERENCE').and_return(definition))
37
+ allow(definition).to(receive(:sha256_short).and_return('~abcd1234'))
38
+
39
+ modifier.do_modifications(adoc_sources)
43
40
  end
44
41
 
45
- context 'when detailed expectations' do
46
- before { modifier.do_modifications(adoc_texts) }
42
+ it { expect(DefMastership::Document).to(have_received(:new)) }
43
+
44
+ it do
45
+ expect(document).to(
46
+ have_received(:parse_file_with_preprocessor)
47
+ .once.with('file1.adoc')
48
+ .once.with('file2.adoc')
49
+ )
50
+ end
51
+
52
+ it do
53
+ expect(modifier.do_modifications(adoc_sources).fetch('file1.adoc')).to(include('abcd1234'))
54
+ end
55
+ end
56
+
57
+ describe '#replace' do
58
+ subject(:modifier) do
59
+ described_class.new(
60
+ def_type: 'requirement'
61
+ )
62
+ end
47
63
 
64
+ let(:definition) { instance_double(DefMastership::Definition, 'definition') }
65
+ let(:document) { instance_double(DefMastership::Document, 'document') }
66
+ let(:definitions) { { 'REFERENCE' => definition } }
67
+
68
+ before do
69
+ allow(File).to(receive(:rename))
70
+ end
71
+
72
+ context 'when definition has not the good type' do
48
73
  it do
49
- expect(DefMastership::UpdateDefChecksumLineModifier).to(
50
- have_received(:from_config).with('fake config')
51
- )
74
+ expect(modifier.replace_reference('[define,req,REFERENCE]'))
75
+ .to(eq('[define,req,REFERENCE]'))
52
76
  end
53
-
54
- it { expect(document).to(have_received(:parse_file_with_preprocessor).with('file1.adoc')) }
55
- it { expect(document).to(have_received(:parse_file_with_preprocessor).with('file2.adoc')) }
56
- it { expect(line_modifier).to(have_received(:'document=').with(document)) }
57
- it { expect(line_modifier).to(have_received(:replace).with("file1 line1\n")) }
58
- it { expect(line_modifier).to(have_received(:replace).with('file1 line2')) }
59
- it { expect(line_modifier).to(have_received(:replace).with("file2 line1\n")) }
60
- it { expect(line_modifier).to(have_received(:replace).with('file2 line2')) }
61
- it { expect(line_modifier).to(have_received(:config)) }
62
- it { expect(line_modifier).to(have_received(:changes)) }
63
- it { is_expected.to(have_attributes(config: 'new fake config')) }
64
- it { is_expected.to(have_attributes(changes: [%w[from1 to1], %w[from2 to2]])) }
65
77
  end
66
78
 
67
- it do
68
- expected_adoc = {
69
- 'file1.adoc' => "new file1 line1\nnew file1 line2",
70
- 'file2.adoc' => "new file2 line1\nnew file2 line2"
71
- }
72
- expect(modifier.do_modifications(adoc_texts)).to(eq(expected_adoc))
79
+ context 'when definition has the good type' do
80
+ before do
81
+ allow(DefMastership::Document).to(receive(:new).and_return(document))
82
+ allow(document).to(receive(:ref_to_def).with('REFERENCE').and_return(definition))
83
+ allow(definition).to(receive(:sha256_short).and_return('~abcd1234'))
84
+ end
85
+
86
+ it do
87
+ expect(modifier.replace_reference('[define,requirement,REFERENCE]'))
88
+ .to(eq('[define,requirement,REFERENCE(~abcd1234)]'))
89
+ end
90
+
91
+ it do
92
+ expect(modifier.replace_reference('[define,requirement,REFERENCE(~bad)]'))
93
+ .to(eq('[define,requirement,REFERENCE(~abcd1234)]'))
94
+ end
95
+
96
+ it do
97
+ expect(modifier.replace_reference('[define,requirement,REFERENCE(toto~bad)]'))
98
+ .to(eq('[define,requirement,REFERENCE(toto~abcd1234)]'))
99
+ end
100
+
101
+ it do
102
+ expect(modifier.replace_reference('[define,requirement,REFERENCE(toto)]'))
103
+ .to(eq('[define,requirement,REFERENCE(toto~abcd1234)]'))
104
+ end
73
105
  end
74
106
  end
75
107
  end
@@ -0,0 +1,121 @@
1
+ # Copyright (c) 2020 Jerome Arbez-Gindre
2
+ # frozen_string_literal: true
3
+
4
+ require('defmastership/update_def_modifier')
5
+
6
+ module DefMastership
7
+ # Just a class for tests
8
+ class ConcreteRefModifier < UpdateDefModifier
9
+ private
10
+
11
+ # This method smells of :reek:UtilityFunction
12
+ def reference_replacement(reference, match)
13
+ "#{reference}_something_#{match[:explicit_version]}"
14
+ end
15
+ end
16
+ end
17
+
18
+ RSpec.describe(DefMastership::UpdateDefModifier) do
19
+ subject(:modifier) { DefMastership::ConcreteRefModifier.new({}) }
20
+
21
+ describe '.new' do
22
+ it { expect(described_class.ancestors).to(include(DefMastership::Modifier)) }
23
+ it { is_expected.not_to(be_nil) }
24
+ it { is_expected.to(have_attributes(def_type: '')) }
25
+ end
26
+
27
+ describe '.replacement_methods' do
28
+ it { expect(described_class.replacement_methods).to(eq(%i[replace_reference])) }
29
+ end
30
+
31
+ describe '#do_modifications' do
32
+ subject(:modifier) { DefMastership::ConcreteRefModifier.new({ def_type: 'req' }) }
33
+
34
+ let(:document) { instance_double(DefMastership::Document, 'document') }
35
+ let(:definition) { instance_double(DefMastership::Definition, 'definition') }
36
+ let(:definitions) { { 'REFERENCE' => definition } }
37
+ let(:adoc_sources) do
38
+ {
39
+ 'file1.adoc' => "[define,req,REFERENCE]\nfile1 line2",
40
+ 'file2.adoc' => "file2 line1\nfile2 line2"
41
+ }
42
+ end
43
+ let(:new_adoc_sources) { nil }
44
+
45
+ before do
46
+ allow(DefMastership::Document).to(receive(:new).and_return(document))
47
+ allow(document).to(receive(:parse_file_with_preprocessor).with('file1.adoc'))
48
+ allow(document).to(receive(:parse_file_with_preprocessor).with('file2.adoc'))
49
+
50
+ modifier.do_modifications(adoc_sources)
51
+ end
52
+
53
+ it { expect(DefMastership::Document).to(have_received(:new)) }
54
+
55
+ it do
56
+ expect(document).to(
57
+ have_received(:parse_file_with_preprocessor)
58
+ .once.with('file1.adoc')
59
+ .once.with('file2.adoc')
60
+ )
61
+ end
62
+
63
+ it do
64
+ expect(modifier.do_modifications(adoc_sources).fetch('file1.adoc'))
65
+ .to(include('REFERENCE_something_'))
66
+ end
67
+ end
68
+
69
+ describe '#replace_reference' do
70
+ subject(:modifier) do
71
+ DefMastership::ConcreteRefModifier.new(
72
+ def_type: 'requirement'
73
+ )
74
+ end
75
+
76
+ let(:definition) { instance_double(DefMastership::Definition, 'definition') }
77
+ let(:document) { instance_double(DefMastership::Document, 'document') }
78
+ let(:definitions) { { 'REFERENCE' => definition } }
79
+
80
+ before do
81
+ allow(File).to(receive(:rename))
82
+ end
83
+
84
+ context 'when line do not match' do
85
+ it do
86
+ expect(modifier.replace_reference('[define---,req,REFERENCE(abcd)]'))
87
+ .to(eq('[define---,req,REFERENCE(abcd)]'))
88
+ end
89
+ end
90
+
91
+ context 'when definition has not the good type' do
92
+ it do
93
+ expect(modifier.replace_reference('[define,req,REFERENCE(abcd)]'))
94
+ .to(eq('[define,req,REFERENCE(abcd)]'))
95
+ end
96
+ end
97
+
98
+ context 'when definition has the good type' do
99
+ before do
100
+ allow(DefMastership::Document).to(receive(:new).and_return(document))
101
+ allow(document).to(receive(:ref_to_def).with('REFERENCE').and_return(definition))
102
+ allow(definition).to(receive(:sha256_short).and_return('~abcd1234'))
103
+ end
104
+
105
+ it do
106
+ expect(modifier.replace_reference('[define,requirement,REFERENCE(abcd)]'))
107
+ .to(eq('[define,requirement,REFERENCE_something_abcd]'))
108
+ end
109
+
110
+ it do
111
+ expect(modifier.replace_reference('[define,requirement,REFERENCE(abcd~bad)]'))
112
+ .to(eq('[define,requirement,REFERENCE_something_abcd]'))
113
+ end
114
+
115
+ it do
116
+ expect(modifier.replace_reference('// [define,requirement,REFERENCE(abcd~bad)]'))
117
+ .to(eq('// [define,requirement,REFERENCE(abcd~bad)]'))
118
+ end
119
+ end
120
+ end
121
+ end