defmastership 1.0.5 → 1.0.6

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 (44) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -1
  3. data/bin/defmastership +21 -15
  4. data/cucumber.yml +1 -1
  5. data/defmastership.gemspec +12 -6
  6. data/features/changeref.feature +82 -129
  7. data/features/export.feature +88 -34
  8. data/features/modify.feature +143 -0
  9. data/features/rename_included_files.feature +121 -0
  10. data/lib/defmastership.rb +11 -3
  11. data/lib/defmastership/batch_modifier.rb +33 -0
  12. data/lib/defmastership/{ref_changer.rb → change_ref_line_modifier.rb} +18 -35
  13. data/lib/defmastership/change_ref_modifier.rb +15 -0
  14. data/lib/defmastership/constants.rb +14 -1
  15. data/lib/defmastership/csv_formatter.rb +15 -16
  16. data/lib/defmastership/csv_formatter_body.rb +11 -6
  17. data/lib/defmastership/csv_formatter_header.rb +11 -10
  18. data/lib/defmastership/definition.rb +11 -0
  19. data/lib/defmastership/definition_parser.rb +46 -0
  20. data/lib/defmastership/document.rb +43 -75
  21. data/lib/defmastership/filters.rb +30 -0
  22. data/lib/defmastership/line_modifier_base.rb +29 -0
  23. data/lib/defmastership/modifier_base.rb +29 -0
  24. data/lib/defmastership/rename_included_files_line_modifier.rb +126 -0
  25. data/lib/defmastership/rename_included_files_modifier.rb +30 -0
  26. data/lib/defmastership/version.rb +1 -1
  27. data/spec/spec_helper.rb +1 -0
  28. data/spec/unit/defmastership/batch_modifier_spec.rb +115 -0
  29. data/spec/unit/defmastership/{ref_changer_spec.rb → change_ref_line_modifier_spec.rb} +48 -26
  30. data/spec/unit/defmastership/change_ref_modifier_spec.rb +76 -0
  31. data/spec/unit/defmastership/comment_filter_spec.rb +8 -4
  32. data/spec/unit/defmastership/csv_formatter_body_spec.rb +61 -37
  33. data/spec/unit/defmastership/csv_formatter_header_spec.rb +46 -22
  34. data/spec/unit/defmastership/csv_formatter_spec.rb +65 -104
  35. data/spec/unit/defmastership/definition_parser_spec.rb +63 -0
  36. data/spec/unit/defmastership/definition_spec.rb +30 -4
  37. data/spec/unit/defmastership/document_spec.rb +112 -35
  38. data/spec/unit/defmastership/rename_included_files_line_modifier_spec.rb +203 -0
  39. data/spec/unit/defmastership/rename_included_files_modifier_spec.rb +67 -0
  40. metadata +34 -9
  41. data/lib/defmastership/batch_changer.rb +0 -41
  42. data/lib/defmastership/project_ref_changer.rb +0 -28
  43. data/spec/unit/defmastership/batch_changer_spec.rb +0 -109
  44. data/spec/unit/defmastership/project_ref_changer_spec.rb +0 -80
@@ -0,0 +1,76 @@
1
+ # Copyright (c) 2020 Jerome Arbez-Gindre
2
+ # frozen_string_literal: true
3
+
4
+ require('defmastership')
5
+
6
+ RSpec.describe(DefMastership::ChangeRefModifier) 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
19
+
20
+ describe '.new' do
21
+ 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: [])) }
24
+ end
25
+
26
+ describe '#do_modifications' do
27
+ let(:line_modifier) { instance_double(DefMastership::ChangeRefLineModifier, 'lineModifier') }
28
+
29
+ before do
30
+ allow(DefMastership::ChangeRefLineModifier).to(
31
+ receive(:from_config).with('fake config').and_return(line_modifier)
32
+ )
33
+ allow(line_modifier).to(receive(:replace_refdef).with("file1 line1\n").and_return("new file1 line1\n"))
34
+ allow(line_modifier).to(receive(:replace_refdef).with('file1 line2').and_return('new file1 line2'))
35
+ allow(line_modifier).to(receive(:replace_refdef).with("file2 line1\n").and_return("new file2 line1\n"))
36
+ allow(line_modifier).to(receive(:replace_refdef).with('file2 line2').and_return('new file2 line2'))
37
+ allow(line_modifier).to(receive(:replace_irefs).with("new file1 line1\n").and_return("new2 file1 line1\n"))
38
+ allow(line_modifier).to(receive(:replace_irefs).with('new file1 line2').and_return('new2 file1 line2'))
39
+ allow(line_modifier).to(receive(:replace_irefs).with("new file2 line1\n").and_return("new2 file2 line1\n"))
40
+ allow(line_modifier).to(receive(:replace_irefs).with('new file2 line2').and_return('new2 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]]))
43
+ end
44
+
45
+ context 'when detailed expectations' do
46
+ before { modifier.do_modifications(adoc_texts) }
47
+
48
+ it do
49
+ expect(DefMastership::ChangeRefLineModifier).to(
50
+ have_received(:from_config).with('fake config')
51
+ )
52
+ end
53
+
54
+ it { expect(line_modifier).to(have_received(:replace_refdef).with("file1 line1\n")) }
55
+ it { expect(line_modifier).to(have_received(:replace_refdef).with('file1 line2')) }
56
+ it { expect(line_modifier).to(have_received(:replace_refdef).with("file2 line1\n")) }
57
+ it { expect(line_modifier).to(have_received(:replace_refdef).with('file2 line2')) }
58
+ it { expect(line_modifier).to(have_received(:replace_irefs).with("new file1 line1\n")) }
59
+ it { expect(line_modifier).to(have_received(:replace_irefs).with('new file1 line2')) }
60
+ it { expect(line_modifier).to(have_received(:replace_irefs).with("new file2 line1\n")) }
61
+ it { expect(line_modifier).to(have_received(:replace_irefs).with('new file2 line2')) }
62
+ it { expect(line_modifier).to(have_received(:config)) }
63
+ it { expect(line_modifier).to(have_received(:changes)) }
64
+ it { is_expected.to(have_attributes(config: 'new fake config')) }
65
+ it { is_expected.to(have_attributes(changes: [%w[from1 to1], %w[from2 to2]])) }
66
+ end
67
+
68
+ it do
69
+ expected_adoc = {
70
+ 'file1.adoc' => "new2 file1 line1\nnew2 file1 line2",
71
+ 'file2.adoc' => "new2 file2 line1\nnew2 file2 line2"
72
+ }
73
+ expect(modifier.do_modifications(adoc_texts)).to(eq(expected_adoc))
74
+ end
75
+ end
76
+ end
@@ -75,8 +75,10 @@ RSpec.describe(DefMastership::CommentFilter) do
75
75
  end
76
76
 
77
77
  before do
78
- allow(DefMastership).to(receive(:comment_filter)
79
- .and_return(comment_filter))
78
+ allow(DefMastership).to(
79
+ receive(:comment_filter)
80
+ .and_return(comment_filter)
81
+ )
80
82
  end
81
83
 
82
84
  context 'when not .commented?' do
@@ -94,8 +96,10 @@ RSpec.describe(DefMastership::CommentFilter) do
94
96
 
95
97
  context 'when .commented?' do
96
98
  before do
97
- allow(comment_filter).to(receive(:accept?)
98
- .with('blabla').and_return(false))
99
+ allow(comment_filter).to(
100
+ receive(:accept?)
101
+ .with('blabla').and_return(false)
102
+ )
99
103
  end
100
104
 
101
105
  it do
@@ -13,12 +13,13 @@ RSpec.describe(DefMastership::CSVFormatterBody) do
13
13
  it { is_expected.not_to(be(nil)) }
14
14
  end
15
15
 
16
- describe '#fixed_body' do
16
+ describe '#fixed' do
17
17
  before 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
- formatter.fixed_body(definition)
21
+ allow(definition).to(receive(:sha256).with(no_args).and_return('d'))
22
+ formatter.fixed(definition)
22
23
  end
23
24
 
24
25
  it { expect(definition).to(have_received(:type).with(no_args)) }
@@ -27,19 +28,43 @@ RSpec.describe(DefMastership::CSVFormatterBody) do
27
28
 
28
29
  it { expect(definition).to(have_received(:value).with(no_args)) }
29
30
 
30
- it { expect(formatter.fixed_body(definition)).to(eq(%w[a b c])) }
31
+ it { expect(definition).to(have_received(:sha256).with(no_args)) }
32
+
33
+ it { expect(formatter.fixed(definition)).to(eq(%w[a b c d])) }
34
+ end
35
+
36
+ describe '#wrong_explicit_checksum' do
37
+ context 'when no wrong_explicit checksum' do
38
+ before do
39
+ allow(definition).to(receive(:wrong_explicit_checksum).with(no_args).and_return(nil))
40
+ formatter.wrong_explicit_checksum(definition)
41
+ end
42
+
43
+ it { expect(definition).to(have_received(:wrong_explicit_checksum).with(no_args)) }
44
+
45
+ it { expect(formatter.wrong_explicit_checksum(definition)).to(eq([''])) }
46
+ end
47
+
48
+ context 'when explicit checksum' do
49
+ before do
50
+ allow(definition).to(receive(:wrong_explicit_checksum).with(no_args).and_return('ab12'))
51
+ formatter.wrong_explicit_checksum(definition)
52
+ end
53
+
54
+ it { expect(formatter.wrong_explicit_checksum(definition)).to(eq(['ab12'])) }
55
+ end
31
56
  end
32
57
 
33
- describe '#labels_body' do
58
+ describe '#labels' do
34
59
  context 'when no labels on document' do
35
60
  before do
36
61
  allow(document).to(receive(:labels).with(no_args).and_return([]))
37
- formatter.labels_body(definition)
62
+ formatter.labels(definition)
38
63
  end
39
64
 
40
65
  it { expect(document).to(have_received(:labels).once.with(no_args)) }
41
66
 
42
- it { expect(formatter.labels_body(definition)).to(eq([])) }
67
+ it { expect(formatter.labels(definition)).to(eq([])) }
43
68
  end
44
69
 
45
70
  context 'when labels on document' do
@@ -48,66 +73,66 @@ RSpec.describe(DefMastership::CSVFormatterBody) do
48
73
  context 'when no labels on definition' do
49
74
  before do
50
75
  allow(definition).to(receive(:labels).with(no_args).and_return([]))
51
- formatter.labels_body(definition)
76
+ formatter.labels(definition)
52
77
  end
53
78
 
54
79
  it { expect(definition).to(have_received(:labels).once.with(no_args)) }
55
80
 
56
- it { expect(formatter.labels_body(definition)).to(eq([''])) }
81
+ it { expect(formatter.labels(definition)).to(eq([''])) }
57
82
  end
58
83
 
59
84
  context 'when labels on definition' do
60
85
  before do
61
86
  allow(definition).to(receive(:labels).with(no_args).and_return(%w[toto tutu]))
62
- formatter.labels_body(definition)
87
+ formatter.labels(definition)
63
88
  end
64
89
 
65
90
  it { expect(definition).to(have_received(:labels).once.with(no_args)) }
66
91
 
67
- it { expect(formatter.labels_body(definition)).to(eq(["toto\ntutu"])) }
92
+ it { expect(formatter.labels(definition)).to(eq(["toto\ntutu"])) }
68
93
  end
69
94
  end
70
95
  end
71
96
 
72
- describe '#eref_body' do
97
+ describe '#eref' do
73
98
  context 'when no eref on the document' do
74
99
  before do
75
100
  allow(document).to(receive(:eref).with(no_args).and_return({}))
76
- formatter.eref_body(definition)
101
+ formatter.eref(definition)
77
102
  end
78
103
 
79
104
  it { expect(document).to(have_received(:eref).with(no_args)) }
80
105
 
81
- it { expect(formatter.eref_body(nil)).to(eq([])) }
106
+ it { expect(formatter.eref(nil)).to(eq([])) }
82
107
  end
83
108
 
84
109
  context 'when eref on the document' do
85
110
  before do
86
- allow(document).to(receive(:eref).with(no_args).and_return(
87
- a: 'whatever',
88
- b: 'whatever',
89
- c: 'whatever'
90
- ))
111
+ allow(document).to(
112
+ receive(:eref).with(no_args).and_return(
113
+ a: 'whatever', b: 'whatever', c: 'whatever'
114
+ )
115
+ )
91
116
  allow(definition).to(receive(:eref).with(no_args).and_return(a: %w[A B], b: [], c: ['C']))
92
- formatter.eref_body(definition)
117
+ formatter.eref(definition)
93
118
  end
94
119
 
95
120
  it { expect(definition).to(have_received(:eref).exactly(3).times.with(no_args)) }
96
121
 
97
- it { expect(formatter.eref_body(definition)).to(eq(["A\nB", '', 'C'])) }
122
+ it { expect(formatter.eref(definition)).to(eq(["A\nB", '', 'C'])) }
98
123
  end
99
124
  end
100
125
 
101
- describe '#iref_body' do
126
+ describe '#iref' do
102
127
  context 'when no iref on the document' do
103
128
  before do
104
129
  allow(document).to(receive(:iref).with(no_args).and_return(false))
105
- formatter.iref_body(definition)
130
+ formatter.iref(definition)
106
131
  end
107
132
 
108
133
  it { expect(document).to(have_received(:iref).with(no_args)) }
109
134
 
110
- it { expect(formatter.iref_body(definition)).to(eq([])) }
135
+ it { expect(formatter.iref(definition)).to(eq([])) }
111
136
  end
112
137
 
113
138
  context 'when iref on the document' do
@@ -116,53 +141,52 @@ RSpec.describe(DefMastership::CSVFormatterBody) do
116
141
  context 'when no iref on the definition' do
117
142
  before do
118
143
  allow(definition).to(receive(:iref).with(no_args).and_return([]))
119
- formatter.iref_body(definition)
144
+ formatter.iref(definition)
120
145
  end
121
146
 
122
147
  it { expect(definition).to(have_received(:iref).with(no_args)) }
123
148
 
124
- it { expect(formatter.iref_body(definition)).to(eq([''])) }
149
+ it { expect(formatter.iref(definition)).to(eq([''])) }
125
150
  end
126
151
 
127
152
  context 'when iref on the definition' do
128
153
  before do
129
154
  allow(definition).to(receive(:iref).with(no_args).and_return(%w[A B]))
130
- formatter.iref_body(definition)
155
+ formatter.iref(definition)
131
156
  end
132
157
 
133
158
  it { expect(definition).to(have_received(:iref).with(no_args)) }
134
159
 
135
- it { expect(formatter.iref_body(definition)).to(eq(["A\nB"])) }
160
+ it { expect(formatter.iref(definition)).to(eq(["A\nB"])) }
136
161
  end
137
162
  end
138
163
  end
139
164
 
140
- describe '#attributes_body' do
165
+ describe '#attributes' do
141
166
  context 'when no attributes on the document' do
142
167
  before do
143
168
  allow(document).to(receive(:attributes).with(no_args).and_return({}))
144
- formatter.attributes_body(definition)
169
+ formatter.attributes(definition)
145
170
  end
146
171
 
147
172
  it { expect(document).to(have_received(:attributes).with(no_args)) }
148
173
 
149
- it { expect(formatter.attributes_body(nil)).to(eq([])) }
174
+ it { expect(formatter.attributes(nil)).to(eq([])) }
150
175
  end
151
176
 
152
177
  context 'when attributes on the document' do
153
178
  before do
154
- allow(document).to(receive(:attributes).with(no_args).and_return(
155
- a: 'whatever',
156
- b: 'whatever',
157
- c: 'whatever'
158
- ))
179
+ allow(document).to(
180
+ receive(:attributes).with(no_args)
181
+ .and_return(a: 'whatever', b: 'whatever', c: 'whatever')
182
+ )
159
183
  allow(definition).to(receive(:attributes).and_return(a: 'X', b: '', c: 'Y'))
160
- formatter.attributes_body(definition)
184
+ formatter.attributes(definition)
161
185
  end
162
186
 
163
187
  it { expect(definition).to(have_received(:attributes).exactly(3).times) }
164
188
 
165
- it { expect(formatter.attributes_body(definition)).to(eq(['X', '', 'Y'])) }
189
+ it { expect(formatter.attributes(definition)).to(eq(['X', '', 'Y'])) }
166
190
  end
167
191
  end
168
192
  end
@@ -13,88 +13,112 @@ RSpec.describe(DefMastership::CSVFormatterHeader) do
13
13
  end
14
14
 
15
15
  describe '#header' do
16
- describe '#fixed_header' do
17
- it { expect(formatter.fixed_header).to(eq(%w[Type Reference Value])) }
16
+ describe '#fixed' do
17
+ it { expect(formatter.fixed).to(eq(%w[Type Reference Value sha256])) }
18
18
  end
19
19
 
20
- describe '#labels_header' do
20
+ describe '#wrong_explicit_checksum' do
21
+ context 'when no wrong explicit checksum' do
22
+ before do
23
+ allow(document).to(receive(:wrong_explicit_checksum?).and_return(false))
24
+ formatter.wrong_explicit_checksum
25
+ end
26
+
27
+ it { expect(document).to(have_received(:wrong_explicit_checksum?)) }
28
+
29
+ it { expect(formatter.wrong_explicit_checksum).to(eq([])) }
30
+ end
31
+
32
+ context 'when wrong explicit checksum' do
33
+ before do
34
+ allow(document).to(receive(:wrong_explicit_checksum?).and_return(true))
35
+ formatter.wrong_explicit_checksum
36
+ end
37
+
38
+ it { expect(formatter.wrong_explicit_checksum).to(eq(['Wrong explicit checksum'])) }
39
+ end
40
+ end
41
+
42
+ describe '#labels' do
21
43
  context 'when no labels' do
22
44
  before do
23
45
  allow(document).to(receive(:labels).and_return([]))
24
- formatter.labels_header
46
+ formatter.labels
25
47
  end
26
48
 
27
49
  it { expect(document).to(have_received(:labels)) }
28
50
 
29
- it { expect(formatter.labels_header).to(eq([])) }
51
+ it { expect(formatter.labels).to(eq([])) }
30
52
  end
31
53
 
32
54
  context 'when there is labels' do
33
55
  before { allow(document).to(receive(:labels).and_return(['Whatever'])) }
34
56
 
35
- it { expect(formatter.labels_header).to(eq(['Labels'])) }
57
+ it { expect(formatter.labels).to(eq(['Labels'])) }
36
58
  end
37
59
  end
38
60
 
39
- describe '#eref_header' do
61
+ describe '#eref' do
40
62
  context 'when no eref' do
41
63
  before do
42
64
  allow(document).to(receive(:eref).and_return({}))
43
- formatter.eref_header
65
+ formatter.eref
44
66
  end
45
67
 
46
68
  it { expect(document).to(have_received(:eref)) }
47
69
 
48
- it { expect(formatter.eref_header).to(eq([])) }
70
+ it { expect(formatter.eref).to(eq([])) }
49
71
  end
50
72
 
51
73
  context 'when eref' do
52
74
  before do
53
- allow(document).to(receive(:eref).and_return(
54
- whatever: { prefix: 'A' },
55
- other: { prefix: 'C', url: 'D' }
56
- ))
75
+ allow(document).to(
76
+ receive(:eref).and_return(
77
+ whatever: { prefix: 'A' },
78
+ other: { prefix: 'C', url: 'D' }
79
+ )
80
+ )
57
81
  end
58
82
 
59
- it { expect(formatter.eref_header).to(eq(['A', 'C D'])) }
83
+ it { expect(formatter.eref).to(eq(%w[A C])) }
60
84
  end
61
85
  end
62
86
 
63
- describe '#iref_header' do
87
+ describe '#iref' do
64
88
  context 'when no iref' do
65
89
  before do
66
90
  allow(document).to(receive(:iref).and_return(false))
67
- formatter.iref_header
91
+ formatter.iref
68
92
  end
69
93
 
70
94
  it { expect(document).to(have_received(:iref)) }
71
95
 
72
- it { expect(formatter.iref_header).to(eq([])) }
96
+ it { expect(formatter.iref).to(eq([])) }
73
97
  end
74
98
 
75
99
  context 'when iref' do
76
100
  before { allow(document).to(receive(:iref).and_return(true)) }
77
101
 
78
- it { expect(formatter.iref_header).to(eq(['Internal links'])) }
102
+ it { expect(formatter.iref).to(eq(['Internal links'])) }
79
103
  end
80
104
  end
81
105
 
82
- describe '#attributes_header' do
106
+ describe '#attributes' do
83
107
  context 'when no attributes' do
84
108
  before do
85
109
  allow(document).to(receive(:attributes).and_return({}))
86
- formatter.attributes_header
110
+ formatter.attributes
87
111
  end
88
112
 
89
113
  it { expect(document).to(have_received(:attributes)) }
90
114
 
91
- it { expect(formatter.attributes_header).to(eq([])) }
115
+ it { expect(formatter.attributes).to(eq([])) }
92
116
  end
93
117
 
94
118
  context 'when attributes' do
95
119
  before { allow(document).to(receive(:attributes).and_return(whatever: 'A', other: 'B')) }
96
120
 
97
- it { expect(formatter.attributes_header).to(eq(%w[A B])) }
121
+ it { expect(formatter.attributes).to(eq(%w[A B])) }
98
122
  end
99
123
  end
100
124
  end