defmastership 1.0.17 → 1.0.19
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.gitlab-ci.yml +37 -11
- data/Gemfile +71 -1
- data/Guardfile +44 -0
- data/Rakefile +16 -61
- data/bin/defmastership +9 -6
- data/config/cucumber.yml +3 -0
- data/config/mutant.yml +27 -3
- data/config/reek.yml +129 -105
- data/config/rubocop.yml +72 -28
- data/defmastership.gemspec +5 -13
- data/features/changeref.feature +0 -8
- data/features/definition_checksum.feature +30 -10
- data/features/definition_version.feature +168 -10
- data/features/export.feature +64 -17
- data/features/modify.feature +1 -5
- data/features/rename_included_files.feature +27 -4
- data/features/step_definitions/git_steps.rb +19 -0
- data/lib/defmastership/batch_modifier.rb +17 -12
- data/lib/defmastership/change_ref_modifier.rb +88 -6
- data/lib/defmastership/comment_filter.rb +1 -1
- data/lib/defmastership/constants.rb +10 -7
- data/lib/defmastership/csv_formatter.rb +16 -12
- data/lib/defmastership/csv_formatter_body.rb +18 -15
- data/lib/defmastership/csv_formatter_header.rb +1 -1
- data/lib/defmastership/definition.rb +59 -20
- data/lib/defmastership/document.rb +101 -74
- data/lib/defmastership/matching_line.rb +17 -0
- data/lib/defmastership/modifier.rb +42 -0
- data/lib/defmastership/modifier_factory.rb +12 -0
- data/lib/defmastership/parsing_state.rb +15 -9
- data/lib/defmastership/rename_included_files_modifier.rb +172 -5
- data/lib/defmastership/set_join_hack.rb +11 -0
- data/lib/defmastership/update_def_checksum_modifier.rb +8 -13
- data/lib/defmastership/update_def_modifier.rb +49 -0
- data/lib/defmastership/update_def_version_modifier.rb +81 -15
- data/lib/defmastership/version.rb +1 -1
- data/lib/defmastership.rb +1 -6
- data/spec/spec_helper.rb +3 -1
- data/spec/unit/def_mastership/batch_modifier_spec.rb +40 -36
- data/spec/unit/def_mastership/change_ref_modifier_spec.rb +196 -51
- data/spec/unit/def_mastership/csv_formatter_body_spec.rb +60 -31
- data/spec/unit/def_mastership/csv_formatter_header_spec.rb +1 -1
- data/spec/unit/def_mastership/csv_formatter_spec.rb +79 -87
- data/spec/unit/def_mastership/definition_parser_spec.rb +1 -1
- data/spec/unit/def_mastership/definition_spec.rb +16 -6
- data/spec/unit/def_mastership/document_spec.rb +81 -38
- data/spec/unit/def_mastership/matching_line_spec.rb +37 -0
- data/spec/unit/def_mastership/modifier_factory_spec.rb +38 -0
- data/spec/unit/def_mastership/modifier_spec.rb +85 -0
- data/spec/unit/def_mastership/parsing_state_spec.rb +1 -1
- data/spec/unit/def_mastership/rename_included_files_modifier_spec.rb +219 -47
- data/spec/unit/def_mastership/string_spec.rb +1 -1
- data/spec/unit/def_mastership/update_def_checksum_modifier_spec.rb +82 -50
- data/spec/unit/def_mastership/update_def_modifier_spec.rb +121 -0
- data/spec/unit/def_mastership/update_def_version_modifier_spec.rb +327 -56
- data/tasks/code_quality.rake +74 -0
- data/tasks/console.rake +8 -0
- data/tasks/package.task +9 -0
- data/tasks/test.rake +30 -0
- metadata +33 -145
- data/.rubocop.yml +0 -76
- data/config/devtools.yml +0 -2
- data/config/flay.yml +0 -3
- data/config/flog.yml +0 -2
- data/config/yardstick.yml +0 -2
- data/cucumber.yml +0 -2
- data/lib/defmastership/change_ref_line_modifier.rb +0 -85
- data/lib/defmastership/line_modifier_base.rb +0 -29
- data/lib/defmastership/modifier_base.rb +0 -36
- data/lib/defmastership/rename_included_files_line_modifier.rb +0 -126
- data/lib/defmastership/update_def_checksum_line_modifier.rb +0 -38
- data/lib/defmastership/update_def_version_line_modifier.rb +0 -58
- data/spec/unit/def_mastership/change_ref_line_modifier_spec.rb +0 -250
- data/spec/unit/def_mastership/rename_included_files_line_modifier_spec.rb +0 -207
- data/spec/unit/def_mastership/update_def_checksum_line_modifier_spec.rb +0 -82
- data/spec/unit/def_mastership/update_def_version_line_modifier_spec.rb +0 -131
- /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)
|
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(
|
23
|
-
|
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
|
-
|
28
|
-
|
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(
|
37
|
-
allow(
|
38
|
-
|
39
|
-
|
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
|
-
|
46
|
-
|
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(
|
50
|
-
|
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
|
-
|
68
|
-
|
69
|
-
|
70
|
-
'
|
71
|
-
|
72
|
-
|
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
|