defmastership 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +4 -0
  3. data/.rspec +4 -0
  4. data/.rubocop.yml +63 -0
  5. data/Gemfile +4 -0
  6. data/Gemfile.lock +140 -0
  7. data/README.rdoc +6 -0
  8. data/Rakefile +53 -0
  9. data/bin/defmastership +99 -0
  10. data/config/devtools.yml +2 -0
  11. data/config/flay.yml +3 -0
  12. data/config/flog.yml +2 -0
  13. data/config/mutant.yml +6 -0
  14. data/config/reek.yml +106 -0
  15. data/config/rubocop.yml +44 -0
  16. data/config/yardstick.yml +2 -0
  17. data/defmastership.gemspec +37 -0
  18. data/defmastership.rdoc +5 -0
  19. data/features/changeref.feature +296 -0
  20. data/features/defmastership.feature +8 -0
  21. data/features/export.feature +275 -0
  22. data/features/step_definitions/defmastership_steps.rb +8 -0
  23. data/features/support/env.rb +18 -0
  24. data/lib/defmastership.rb +15 -0
  25. data/lib/defmastership/batch_changer.rb +40 -0
  26. data/lib/defmastership/comment_filter.rb +42 -0
  27. data/lib/defmastership/constants.rb +77 -0
  28. data/lib/defmastership/csv_formatter.rb +42 -0
  29. data/lib/defmastership/csv_formatter_body.rb +34 -0
  30. data/lib/defmastership/csv_formatter_header.rb +35 -0
  31. data/lib/defmastership/definition.rb +41 -0
  32. data/lib/defmastership/document.rb +153 -0
  33. data/lib/defmastership/project_ref_changer.rb +27 -0
  34. data/lib/defmastership/ref_changer.rb +102 -0
  35. data/lib/defmastership/version.rb +6 -0
  36. data/spec/spec_helper.rb +35 -0
  37. data/spec/unit/defmastership/batch_changer_spec.rb +108 -0
  38. data/spec/unit/defmastership/comment_filter_spec.rb +121 -0
  39. data/spec/unit/defmastership/csv_formatter_body_spec.rb +167 -0
  40. data/spec/unit/defmastership/csv_formatter_header_spec.rb +100 -0
  41. data/spec/unit/defmastership/csv_formatter_spec.rb +171 -0
  42. data/spec/unit/defmastership/definition_spec.rb +110 -0
  43. data/spec/unit/defmastership/document_spec.rb +398 -0
  44. data/spec/unit/defmastership/project_ref_changer_spec.rb +79 -0
  45. data/spec/unit/defmastership/ref_changer_spec.rb +205 -0
  46. data/spec/unit/defmastership_spec.rb +7 -0
  47. metadata +234 -0
@@ -0,0 +1,79 @@
1
+ # frozen_string_literal: true
2
+
3
+ require('defmastership')
4
+ require('yaml')
5
+
6
+ RSpec.describe(DefMastership::ProjectRefChanger) do
7
+ subject(:projectrefchanger) do
8
+ described_class.new(
9
+ 'fake yaml config',
10
+ {
11
+ 'file1.adoc' => "file1 line1\nfile1 line2",
12
+ 'file2.adoc' => "file2 line1\nfile2 line2"
13
+ }
14
+ )
15
+ end
16
+
17
+ describe '.new' do
18
+ it { is_expected.not_to(be(nil)) }
19
+ it { is_expected.to(have_attributes(yaml_config: 'fake yaml config')) }
20
+
21
+ it do
22
+ expect(projectrefchanger).to(have_attributes(adoc_texts:
23
+ {
24
+ 'file1.adoc' => "file1 line1\nfile1 line2",
25
+ 'file2.adoc' => "file2 line1\nfile2 line2"
26
+ }))
27
+ end
28
+
29
+ it { is_expected.to(have_attributes(changes: nil)) }
30
+ end
31
+
32
+ describe '#replace_all' do
33
+ let(:batch_changer) { instance_double(DefMastership::BatchChanger, 'batch_changer') }
34
+ let(:config_hash) { instance_double(Hash, 'config_hash') }
35
+
36
+ before do
37
+ allow(DefMastership::BatchChanger).to(receive(:from_h).with('fake yaml config').and_return(batch_changer))
38
+ allow(batch_changer).to(receive(:replace).with(:refdef, "file1 line1\n").and_return("new file1 line1\n"))
39
+ allow(batch_changer).to(receive(:replace).with(:refdef, 'file1 line2').and_return('new file1 line2'))
40
+ allow(batch_changer).to(receive(:replace).with(:refdef, "file2 line1\n").and_return("new file2 line1\n"))
41
+ allow(batch_changer).to(receive(:replace).with(:refdef, 'file2 line2').and_return('new file2 line2'))
42
+ allow(batch_changer).to(receive(:replace).with(:irefs, "new file1 line1\n").and_return("new2 file1 line1\n"))
43
+ allow(batch_changer).to(receive(:replace).with(:irefs, 'new file1 line2').and_return('new2 file1 line2'))
44
+ allow(batch_changer).to(receive(:replace).with(:irefs, "new file2 line1\n").and_return("new2 file2 line1\n"))
45
+ allow(batch_changer).to(receive(:replace).with(:irefs, 'new file2 line2').and_return('new2 file2 line2'))
46
+ allow(batch_changer).to(receive(:to_h).and_return(config_hash))
47
+ allow(batch_changer).to(receive(:changes).and_return('pouet'))
48
+ allow(config_hash).to(receive(:to_yaml).with(no_args).and_return('new fake yaml config'))
49
+ projectrefchanger.replace_all
50
+ end
51
+
52
+ it { expect(DefMastership::BatchChanger).to(have_received(:from_h).with('fake yaml config')) }
53
+
54
+ it { expect(batch_changer).to(have_received(:replace).with(:refdef, "file1 line1\n")) }
55
+ it { expect(batch_changer).to(have_received(:replace).with(:refdef, 'file1 line2')) }
56
+ it { expect(batch_changer).to(have_received(:replace).with(:refdef, "file2 line1\n")) }
57
+ it { expect(batch_changer).to(have_received(:replace).with(:refdef, 'file2 line2')) }
58
+ it { expect(batch_changer).to(have_received(:replace).with(:irefs, "new file1 line1\n")) }
59
+ it { expect(batch_changer).to(have_received(:replace).with(:irefs, 'new file1 line2')) }
60
+ it { expect(batch_changer).to(have_received(:replace).with(:irefs, "new file2 line1\n")) }
61
+ it { expect(batch_changer).to(have_received(:replace).with(:irefs, 'new file2 line2')) }
62
+
63
+ it { expect(batch_changer).to(have_received(:to_h)) }
64
+
65
+ it { expect(config_hash).to(have_received(:to_yaml).with(no_args)) }
66
+
67
+ it { expect(projectrefchanger).to(have_attributes(yaml_config: 'new fake yaml config')) }
68
+
69
+ it do
70
+ expect(projectrefchanger).to(have_attributes(adoc_texts: {
71
+ 'file1.adoc' => "new2 file1 line1\nnew2 file1 line2",
72
+ 'file2.adoc' => "new2 file2 line1\nnew2 file2 line2"
73
+ }))
74
+ end
75
+
76
+ it { expect(batch_changer).to(have_received(:changes)) }
77
+ it { expect(projectrefchanger).to(have_attributes(changes: 'pouet')) }
78
+ end
79
+ end
@@ -0,0 +1,205 @@
1
+ # frozen_string_literal: true
2
+
3
+ require('defmastership')
4
+
5
+ RSpec.describe(DefMastership::RefChanger) do
6
+ subject(:refchanger) { described_class.new }
7
+
8
+ describe '.new' do
9
+ it { is_expected.not_to(be(nil)) }
10
+ it { is_expected.to(have_attributes(from_regexp: '')) }
11
+ it { is_expected.to(have_attributes(to_template: '')) }
12
+ it { is_expected.to(have_attributes(next_ref: 0)) }
13
+ it { is_expected.to(have_attributes(changes: [])) }
14
+ it { expect { refchanger.user_defined_attribute }.to(raise_error(NoMethodError)) }
15
+ end
16
+
17
+ describe '.from_h' do
18
+ subject(:refchanger) do
19
+ described_class.from_h(
20
+ from_regexp: 'Whatever.+',
21
+ to_template: 'Whatever',
22
+ next_ref: 17
23
+ )
24
+ end
25
+
26
+ it { is_expected.not_to(be(nil)) }
27
+ it { is_expected.to(have_attributes(from_regexp: 'Whatever.+')) }
28
+ it { is_expected.to(have_attributes(to_template: 'Whatever')) }
29
+ it { is_expected.to(have_attributes(next_ref: 17)) }
30
+ end
31
+
32
+ describe '#from_h' do
33
+ before do
34
+ refchanger.from_h(
35
+ from_regexp: 'Whatever.+',
36
+ to_template: 'Whatever',
37
+ next_ref: 17,
38
+ user_defined_attribute: 'Tadaam'
39
+ )
40
+ end
41
+
42
+ it { is_expected.to(have_attributes(from_regexp: 'Whatever.+')) }
43
+ it { is_expected.to(have_attributes(to_template: 'Whatever')) }
44
+ it { is_expected.to(have_attributes(next_ref: 17)) }
45
+ it { is_expected.to(have_attributes(user_defined_attribute: 'Tadaam')) }
46
+ end
47
+
48
+ describe '#to_h' do
49
+ context 'when not initalized' do
50
+ it do
51
+ expect(refchanger.to_h).to(include(
52
+ from_regexp: '',
53
+ to_template: '',
54
+ next_ref: 0
55
+ ))
56
+ end
57
+ end
58
+
59
+ context 'when initalized with additionnal keys' do
60
+ before do
61
+ refchanger.from_h(
62
+ next_ref: 1256,
63
+ user_defined_attribute: 'Tadaam'
64
+ )
65
+ end
66
+
67
+ it { expect(refchanger.to_h).to(include(from_regexp: '')) }
68
+ it { expect(refchanger.to_h).to(include(to_template: '')) }
69
+ it { expect(refchanger.to_h).to(include(next_ref: 1256)) }
70
+ it { expect(refchanger.to_h).to(include(user_defined_attribute: 'Tadaam')) }
71
+ end
72
+ end
73
+
74
+ describe '#replace_definitions' do
75
+ context 'when really simple rule' do
76
+ before do
77
+ refchanger.from_h(
78
+ from_regexp: 'TEMP',
79
+ to_template: 'TUTU'
80
+ )
81
+ end
82
+
83
+ context 'when valid definition' do
84
+ it do
85
+ expect(refchanger.replace_refdef('[define, whatever, TEMP]'))
86
+ .to(eq('[define, whatever, TUTU]'))
87
+ end
88
+ end
89
+
90
+ context 'when no valid definition' do
91
+ it do
92
+ expect(refchanger.replace_refdef('[pouet, whatever, TEMP]'))
93
+ .to(eq('[pouet, whatever, TEMP]'))
94
+ end
95
+ end
96
+ end
97
+
98
+ context 'when template is variable' do
99
+ before do
100
+ refchanger.from_h(
101
+ from_regexp: 'TEMP',
102
+ to_template: 'TOTO-%<next_ref>04d',
103
+ next_ref: 124
104
+ )
105
+ end
106
+
107
+ it do
108
+ expect(refchanger.replace_refdef('[define, whatever, TEMP]'))
109
+ .to(eq('[define, whatever, TOTO-0124]'))
110
+ end
111
+
112
+ it do
113
+ refchanger.replace_refdef('[define, whatever, TEMP]')
114
+ expect(refchanger).to(have_attributes(next_ref: 125))
115
+ end
116
+ end
117
+
118
+ context 'when capture group in regexp' do
119
+ before do
120
+ refchanger.from_h(
121
+ from_regexp: '(?<cg>TOTO|TITI)-TEMP[\d]*',
122
+ to_template: '%<cg>s-%<next_ref>04d',
123
+ next_ref: 132
124
+ )
125
+ end
126
+
127
+ it do
128
+ expect(refchanger.replace_refdef('[define, whatever, TOTO-TEMP]'))
129
+ .to(eq('[define, whatever, TOTO-0132]'))
130
+ end
131
+
132
+ it do
133
+ refchanger.replace_refdef('[define, whatever, TOTO-TEMP]')
134
+ expect(refchanger.replace_refdef('[define, whatever, TITI-TEMP]'))
135
+ .to(eq('[define, whatever, TITI-0133]'))
136
+ end
137
+
138
+ it do
139
+ refchanger.replace_refdef('[define, whatever, TOTO-TEMP1]')
140
+ refchanger.replace_refdef('[define, whatever, TITI-TEMP2]')
141
+ expect(refchanger).to(have_attributes(changes: [%w[TOTO-TEMP1 TOTO-0132], %w[TITI-TEMP2 TITI-0133]]))
142
+ end
143
+ end
144
+
145
+ context 'when definition is in literal block' do
146
+ before do
147
+ refchanger.from_h(
148
+ from_regexp: 'TEMP',
149
+ to_template: 'TUTU'
150
+ )
151
+ refchanger.replace_refdef('....')
152
+ end
153
+
154
+ it do
155
+ expect(refchanger.replace_refdef('[define, whatever, TEMP]'))
156
+ .to(eq('[define, whatever, TEMP]'))
157
+ end
158
+ end
159
+
160
+ context 'when defintion is after literal block' do
161
+ before do
162
+ refchanger.from_h(
163
+ from_regexp: 'TEMP',
164
+ to_template: 'TUTU'
165
+ )
166
+ refchanger.replace_refdef("....\n")
167
+ refchanger.replace_refdef('[define, whatever, TEMP]')
168
+ refchanger.replace_refdef("....\n")
169
+ end
170
+
171
+ it do
172
+ expect(refchanger.replace_refdef('[define, whatever, TEMP]'))
173
+ .to(eq('[define, whatever, TUTU]'))
174
+ end
175
+ end
176
+ end
177
+
178
+ describe '#replace_irefs' do
179
+ before do
180
+ refchanger.from_h(
181
+ from_regexp: '(?<cg>TOTO|TITI)-TEMP[\d]*',
182
+ to_template: '%<cg>s-%<next_ref>04d',
183
+ next_ref: 132
184
+ )
185
+ refchanger.replace_refdef('[define, whatever, TOTO-TEMP123]')
186
+ refchanger.replace_refdef('[define, whatever, TITI-TEMP421]')
187
+ end
188
+
189
+ it do
190
+ expect(refchanger.replace_irefs('defs:iref[TOTO-TEMP1234]'))
191
+ .to(eq('defs:iref[TOTO-TEMP1234]'))
192
+ end
193
+
194
+ it do
195
+ expect(refchanger.replace_irefs('defs:iref[TOTO-TEMP123]'))
196
+ .to(eq('defs:iref[TOTO-0132]'))
197
+ end
198
+
199
+ it do
200
+ expect(refchanger.replace_irefs('defs:iref[TOTO-TEMP123] ' \
201
+ 'defs:iref[TITI-TEMP421] bla'))
202
+ .to(eq('defs:iref[TOTO-0132] defs:iref[TITI-0133] bla'))
203
+ end
204
+ end
205
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe(DefMastership) do
4
+ it 'has a version number' do
5
+ expect(DefMastership::VERSION).not_to(be(nil))
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,234 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: defmastership
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jérôme Arbez-Gindre
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-09-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: aruba
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '13'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '13'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rdoc
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '6'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '6'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop-rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1'
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: aasm
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '5'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '5'
125
+ - !ruby/object:Gem::Dependency
126
+ name: asciidoctor
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '2'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '2'
139
+ - !ruby/object:Gem::Dependency
140
+ name: gli
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '2'
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '2'
153
+ description:
154
+ email: jeromearbezgindre@gmail.com
155
+ executables:
156
+ - defmastership
157
+ extensions: []
158
+ extra_rdoc_files:
159
+ - README.rdoc
160
+ - defmastership.rdoc
161
+ files:
162
+ - ".gitignore"
163
+ - ".rspec"
164
+ - ".rubocop.yml"
165
+ - Gemfile
166
+ - Gemfile.lock
167
+ - README.rdoc
168
+ - Rakefile
169
+ - bin/defmastership
170
+ - config/devtools.yml
171
+ - config/flay.yml
172
+ - config/flog.yml
173
+ - config/mutant.yml
174
+ - config/reek.yml
175
+ - config/rubocop.yml
176
+ - config/yardstick.yml
177
+ - defmastership.gemspec
178
+ - defmastership.rdoc
179
+ - features/changeref.feature
180
+ - features/defmastership.feature
181
+ - features/export.feature
182
+ - features/step_definitions/defmastership_steps.rb
183
+ - features/support/env.rb
184
+ - lib/defmastership.rb
185
+ - lib/defmastership/batch_changer.rb
186
+ - lib/defmastership/comment_filter.rb
187
+ - lib/defmastership/constants.rb
188
+ - lib/defmastership/csv_formatter.rb
189
+ - lib/defmastership/csv_formatter_body.rb
190
+ - lib/defmastership/csv_formatter_header.rb
191
+ - lib/defmastership/definition.rb
192
+ - lib/defmastership/document.rb
193
+ - lib/defmastership/project_ref_changer.rb
194
+ - lib/defmastership/ref_changer.rb
195
+ - lib/defmastership/version.rb
196
+ - spec/spec_helper.rb
197
+ - spec/unit/defmastership/batch_changer_spec.rb
198
+ - spec/unit/defmastership/comment_filter_spec.rb
199
+ - spec/unit/defmastership/csv_formatter_body_spec.rb
200
+ - spec/unit/defmastership/csv_formatter_header_spec.rb
201
+ - spec/unit/defmastership/csv_formatter_spec.rb
202
+ - spec/unit/defmastership/definition_spec.rb
203
+ - spec/unit/defmastership/document_spec.rb
204
+ - spec/unit/defmastership/project_ref_changer_spec.rb
205
+ - spec/unit/defmastership/ref_changer_spec.rb
206
+ - spec/unit/defmastership_spec.rb
207
+ homepage: http://your.website.com
208
+ licenses:
209
+ - Nonstandard
210
+ metadata: {}
211
+ post_install_message:
212
+ rdoc_options:
213
+ - "--title defmastership"
214
+ - "--main README.rdoc"
215
+ - "-ri"
216
+ require_paths:
217
+ - lib
218
+ - lib
219
+ required_ruby_version: !ruby/object:Gem::Requirement
220
+ requirements:
221
+ - - ">="
222
+ - !ruby/object:Gem::Version
223
+ version: '2.6'
224
+ required_rubygems_version: !ruby/object:Gem::Requirement
225
+ requirements:
226
+ - - ">="
227
+ - !ruby/object:Gem::Version
228
+ version: '0'
229
+ requirements: []
230
+ rubygems_version: 3.1.2
231
+ signing_key:
232
+ specification_version: 4
233
+ summary: Handling of references and definitions with asciidoctor
234
+ test_files: []