defmastership 1.0.9 → 1.0.10

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9dd61d32bacab380bbfc110df15fd6617b38540aa5bc8eb14bd5b2736e657b7c
4
- data.tar.gz: 1ec7bc921411173863b71ba0c3f4164829ac2efbe0689c321830f632a3333f64
3
+ metadata.gz: '0498ff0b39ccfc024d4988c4c1137726e827e841a1750b921bc4c8d3be06db62'
4
+ data.tar.gz: af1b86530d440a08417bac712f15e30db40aa01b07ea312b1d7d4f125dccef5c
5
5
  SHA512:
6
- metadata.gz: e8dcebcb309fd755a339ab702f7c07c65387e5a961400518661d70e9421911630652855a10ad647ac6155b9686665927fde8315a8efb71e3a2913a8db32fbcd5
7
- data.tar.gz: 83e28e54b372de48cc554b8f532e659817453e905f3c6634071b3e280f23fba2431119353af9bdd6b23b97a6d6bf8a2b9a261b39e70591f27be45a3b04dce19b
6
+ metadata.gz: ec47e5182f9586be6102eed5be90c459db84e54e334cbe867bee2be4bf34645f8a91d7e08aea0b89a4733e3ca6089c90f96e1a6969d8f6b329034cc4486bd8b2
7
+ data.tar.gz: 625fb3fb76aaac4189ce12cd2f9af3bfa83491a2ecbbe5192bb35ffe43e121e54a27a318afb60ad938a8e58818bccef38896b919d5b9678ea0af4565c09aab66
@@ -22,3 +22,183 @@ Feature: definitions version
22
22
  And the stdout should not contain anything
23
23
  And the stderr should not contain anything
24
24
 
25
+ Scenario: Set initial explicit version when definition has changed
26
+ Given a file named "ref_doc.adoc" with:
27
+ """
28
+ [define, requirement, TOTO-0001]
29
+ --
30
+ initial text.
31
+ --
32
+ """
33
+ Given a file named "thedoc.adoc" with:
34
+ """
35
+ [define, requirement, TOTO-0001(whatever)]
36
+ --
37
+ modified text.
38
+ --
39
+ """
40
+ And a file named "modifications.yml" with:
41
+ """
42
+ ---
43
+ :update_requirement_version:
44
+ :type: update_def_version
45
+ :config:
46
+ :def_type: requirement
47
+ :first_version: a
48
+ :ref_document: ./ref_doc.adoc
49
+ """
50
+ When I successfully run `defmastership modify --modifications update_requirement_version thedoc.adoc`
51
+ And the stdout should not contain anything
52
+ And the stderr should not contain anything
53
+ Then the file "thedoc.adoc" should contain:
54
+ """
55
+ [define, requirement, TOTO-0001(a)]
56
+ --
57
+ modified text.
58
+ --
59
+ """
60
+
61
+ Scenario: Do not set initial explicit version when definition has NOT changed
62
+ Given a file named "ref_doc.adoc" with:
63
+ """
64
+ [define, requirement, TOTO-0001]
65
+ --
66
+ initial text.
67
+ --
68
+ """
69
+ Given a file named "thedoc.adoc" with:
70
+ """
71
+ [define, requirement, TOTO-0001(whatever)]
72
+ --
73
+ initial text.
74
+ --
75
+ """
76
+ And a file named "modifications.yml" with:
77
+ """
78
+ ---
79
+ :update_requirement_version:
80
+ :type: update_def_version
81
+ :config:
82
+ :def_type: requirement
83
+ :first_version: a
84
+ :ref_document: ./ref_doc.adoc
85
+ """
86
+ When I successfully run `defmastership modify --modifications update_requirement_version thedoc.adoc`
87
+ And the stdout should not contain anything
88
+ And the stderr should not contain anything
89
+ Then the file "thedoc.adoc" should contain:
90
+ """
91
+ [define, requirement, TOTO-0001]
92
+ --
93
+ initial text.
94
+ --
95
+ """
96
+
97
+ Scenario: Set initial explicit version when definition has changed and ref is not an initial version
98
+ Given a file named "ref_doc.adoc" with:
99
+ """
100
+ [define, requirement, TOTO-0001(3)]
101
+ --
102
+ initial text.
103
+ --
104
+ """
105
+ Given a file named "thedoc.adoc" with:
106
+ """
107
+ [define, requirement, TOTO-0001(whatever)]
108
+ --
109
+ modified text.
110
+ --
111
+ """
112
+ And a file named "modifications.yml" with:
113
+ """
114
+ ---
115
+ :update_requirement_version:
116
+ :type: update_def_version
117
+ :config:
118
+ :def_type: requirement
119
+ :first_version: 1
120
+ :ref_document: ./ref_doc.adoc
121
+ """
122
+ When I successfully run `defmastership modify --modifications update_requirement_version thedoc.adoc`
123
+ And the stdout should not contain anything
124
+ And the stderr should not contain anything
125
+ Then the file "thedoc.adoc" should contain:
126
+ """
127
+ [define, requirement, TOTO-0001(4)]
128
+ --
129
+ modified text.
130
+ --
131
+ """
132
+
133
+ Scenario: No initial explicit version when definition is new
134
+ Given a file named "ref_doc.adoc" with:
135
+ """
136
+ [define, requirement, TOTO-0002]
137
+ --
138
+ initial text.
139
+ --
140
+ """
141
+ Given a file named "thedoc.adoc" with:
142
+ """
143
+ [define, requirement, TOTO-0001(whatever)]
144
+ --
145
+ modified text.
146
+ --
147
+ """
148
+ And a file named "modifications.yml" with:
149
+ """
150
+ ---
151
+ :update_requirement_version:
152
+ :type: update_def_version
153
+ :config:
154
+ :def_type: requirement
155
+ :first_version: 1
156
+ :ref_document: ./ref_doc.adoc
157
+ """
158
+ When I successfully run `defmastership modify --modifications update_requirement_version thedoc.adoc`
159
+ And the stdout should not contain anything
160
+ And the stderr should not contain anything
161
+ Then the file "thedoc.adoc" should contain:
162
+ """
163
+ [define, requirement, TOTO-0001]
164
+ --
165
+ modified text.
166
+ --
167
+ """
168
+
169
+ Scenario: update explicit version whith explicit checksum
170
+ Given a file named "ref_doc.adoc" with:
171
+ """
172
+ [define, requirement, TOTO-0001]
173
+ --
174
+ initial text.
175
+ --
176
+ """
177
+ Given a file named "thedoc.adoc" with:
178
+ """
179
+ [define, requirement, TOTO-0001(whatever~abcd1234)]
180
+ --
181
+ modified text.
182
+ --
183
+ """
184
+ And a file named "modifications.yml" with:
185
+ """
186
+ ---
187
+ :update_requirement_version:
188
+ :type: update_def_version
189
+ :config:
190
+ :def_type: requirement
191
+ :first_version: a
192
+ :ref_document: ./ref_doc.adoc
193
+ """
194
+ When I successfully run `defmastership modify --modifications update_requirement_version thedoc.adoc`
195
+ And the stdout should not contain anything
196
+ And the stderr should not contain anything
197
+ Then the file "thedoc.adoc" should contain:
198
+ """
199
+ [define, requirement, TOTO-0001(a~abcd1234)]
200
+ --
201
+ modified text.
202
+ --
203
+ """
204
+
data/lib/defmastership.rb CHANGED
@@ -25,3 +25,6 @@ require('defmastership/rename_included_files_line_modifier')
25
25
 
26
26
  require('defmastership/update_def_checksum_modifier')
27
27
  require('defmastership/update_def_checksum_line_modifier')
28
+
29
+ require('defmastership/update_def_version_modifier')
30
+ require('defmastership/update_def_version_line_modifier')
@@ -2,7 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module DefMastership
5
- # Update definition checksum wih calculated one
5
+ # Update definition checksum with calculated one
6
6
  class UpdateDefChecksumModifier < ModifierBase
7
7
  def replacements
8
8
  %i[replace]
@@ -0,0 +1,58 @@
1
+ # Copyright (c) 2020 Jerome Arbez-Gindre
2
+ # frozen_string_literal: true
3
+
4
+ module DefMastership
5
+ # modify one line after another
6
+ class UpdateDefVersionLineModifier < LineModifierBase
7
+ attr_accessor :document, :ref_document
8
+
9
+ def self.from_config(hash)
10
+ new.from_config(hash)
11
+ end
12
+
13
+ def initialize
14
+ super
15
+ @config = {
16
+ def_type: '',
17
+ ref_document: '',
18
+ first_version: ''
19
+ }
20
+ end
21
+
22
+ def replace(line)
23
+ match = matched?(line)
24
+
25
+ return line unless match
26
+ return line unless match[:type] == def_type
27
+
28
+ version_and_checksum = ''
29
+ if match[:explicit_checksum] || version_string(match)
30
+ version_and_checksum = "(#{version_string(match)}#{match[:explicit_checksum]})"
31
+ end
32
+
33
+ line.gsub(Regexp.new("#{match[:reference]}#{DMRegexp::DEF_VERSION_AND_CHECKSUM}")) do
34
+ "#{match[:reference]}#{version_and_checksum}"
35
+ end
36
+ end
37
+
38
+ private
39
+
40
+ def matched?(line)
41
+ return if line.commented?
42
+ return unless line =~ DMRegexp::DEFINITION
43
+
44
+ Regexp.last_match
45
+ end
46
+
47
+ def version_string(match)
48
+ ref_definition = @ref_document.ref_to_def(match[:reference])
49
+ definition = @document.ref_to_def(match[:reference])
50
+
51
+ return if ref_definition.nil?
52
+ return ref_definition.explicit_version if definition.sha256 == ref_definition.sha256
53
+
54
+ ref_version = @ref_document.ref_to_def(match[:reference]).explicit_version
55
+ ref_version.nil? ? @config[:first_version] : ref_version.next
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,25 @@
1
+ # Copyright (c) 2020 Jerome Arbez-Gindre
2
+ # frozen_string_literal: true
3
+
4
+ module DefMastership
5
+ # Update definition version if the definition has change since
6
+ # reference document
7
+ class UpdateDefVersionModifier < ModifierBase
8
+ def replacements
9
+ %i[replace]
10
+ end
11
+
12
+ def new_line_modifier(config, adoc_texts)
13
+ document = Document.new
14
+ adoc_texts.each do |adoc_file, _|
15
+ document.parse_file_with_preprocessor(adoc_file)
16
+ end
17
+ ref_document = Document.new
18
+ ref_document.parse_file_with_preprocessor(config[:ref_document])
19
+ line_modifier = UpdateDefVersionLineModifier.from_config(config)
20
+ line_modifier.document = document
21
+ line_modifier.ref_document = ref_document
22
+ line_modifier
23
+ end
24
+ end
25
+ end
@@ -2,6 +2,6 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module DefMastership
5
- VERSION = '1.0.9'
5
+ VERSION = '1.0.10'
6
6
  public_constant :VERSION
7
7
  end
@@ -0,0 +1,127 @@
1
+ # Copyright (c) 2020 Jerome Arbez-Gindre
2
+ # frozen_string_literal: true
3
+
4
+ require('defmastership')
5
+
6
+ RSpec.describe(DefMastership::UpdateDefVersionLineModifier) do
7
+ subject(:linemodifier) { described_class.new }
8
+
9
+ describe '.new' do
10
+ it { is_expected.not_to(be(nil)) }
11
+ it { is_expected.to(have_attributes(def_type: '')) }
12
+ it { is_expected.to(have_attributes(changes: [])) }
13
+ it { expect { linemodifier.user_defined_attribute }.to(raise_error(NoMethodError)) }
14
+ end
15
+
16
+ describe '.from_config' do
17
+ subject(:linemodifier) do
18
+ described_class.from_config(
19
+ def_type: 'requirement',
20
+ first_version: 'a'
21
+ )
22
+ end
23
+
24
+ it { is_expected.not_to(be(nil)) }
25
+ it { is_expected.to(have_attributes(def_type: 'requirement')) }
26
+ it { is_expected.to(have_attributes(first_version: 'a')) }
27
+ it { is_expected.to(have_attributes(document: nil)) }
28
+ it { is_expected.to(have_attributes(ref_document: nil)) }
29
+ end
30
+
31
+ describe '#replace' do
32
+ subject(:linemodifier) do
33
+ described_class.from_config(
34
+ def_type: 'requirement',
35
+ first_version: 'a'
36
+ )
37
+ end
38
+
39
+ let(:document) { instance_double(DefMastership::Document, 'document') }
40
+ let(:ref_document) { instance_double(DefMastership::Document, 'ref_document') }
41
+ let(:definition) { instance_double(DefMastership::Definition, 'definition') }
42
+ let(:ref_definition) { instance_double(DefMastership::Definition, 'ref_definitions') }
43
+
44
+ before do
45
+ linemodifier.document = document
46
+ linemodifier.ref_document = ref_document
47
+ allow(File).to(receive(:rename))
48
+ end
49
+
50
+ context 'when definition has not the good type' do
51
+ it do
52
+ expect(linemodifier.replace('[define,req,REFERENCE]'))
53
+ .to(eq('[define,req,REFERENCE]'))
54
+ end
55
+ end
56
+
57
+ context 'when definition has the good type' do
58
+ before do
59
+ allow(document).to(receive(:ref_to_def).with('REFERENCE').and_return(definition))
60
+ allow(definition).to(receive(:sha256).and_return('~abcd1234'))
61
+ end
62
+
63
+ context 'when definition has NOT changed' do
64
+ before do
65
+ allow(ref_document).to(receive(:ref_to_def).with('REFERENCE').and_return(ref_definition))
66
+ allow(ref_definition).to(receive(:sha256).and_return('~abcd1234'))
67
+ end
68
+
69
+ it do
70
+ allow(ref_definition).to(receive(:explicit_version).and_return(nil))
71
+ expect(linemodifier.replace('[define,requirement,REFERENCE]'))
72
+ .to(eq('[define,requirement,REFERENCE]'))
73
+ end
74
+
75
+ it do
76
+ allow(ref_definition).to(receive(:explicit_version).and_return('c'))
77
+ expect(linemodifier.replace('[define,requirement,REFERENCE]'))
78
+ .to(eq('[define,requirement,REFERENCE(c)]'))
79
+ end
80
+
81
+ it do
82
+ allow(ref_definition).to(receive(:explicit_version).and_return('c'))
83
+ expect(linemodifier.replace('[define,requirement,REFERENCE(tyty~1234)]'))
84
+ .to(eq('[define,requirement,REFERENCE(c~1234)]'))
85
+ end
86
+ end
87
+
88
+ context 'when definition has changed' do
89
+ before do
90
+ allow(ref_document).to(receive(:ref_to_def).with('REFERENCE').and_return(ref_definition))
91
+ allow(ref_definition).to(receive(:sha256).and_return('~4321aaaa'))
92
+ end
93
+
94
+ [
95
+ [nil, '', '(a)'],
96
+ ['c', '', '(d)'],
97
+ ['c', '(tyty~1234)', '(d~1234)'],
98
+ ['2', '', '(3)'],
99
+ ['1222', '', '(1223)'],
100
+ ['abb', '', '(abc)']
101
+ ].each do |ref, from, to|
102
+ it do
103
+ allow(ref_definition).to(receive(:explicit_version).and_return(ref))
104
+ expect(linemodifier.replace("[define,requirement,REFERENCE#{from}]"))
105
+ .to(eq("[define,requirement,REFERENCE#{to}]"))
106
+ end
107
+ end
108
+ end
109
+
110
+ context 'when definition is new' do
111
+ before do
112
+ allow(ref_document).to(receive(:ref_to_def).with('REFERENCE').and_return(nil))
113
+ end
114
+
115
+ it do
116
+ expect(linemodifier.replace('[define,requirement,REFERENCE(whatever)]'))
117
+ .to(eq('[define,requirement,REFERENCE]'))
118
+ end
119
+
120
+ it do
121
+ expect(linemodifier.replace('[define,requirement,REFERENCE(~1234)]'))
122
+ .to(eq('[define,requirement,REFERENCE(~1234)]'))
123
+ end
124
+ end
125
+ end
126
+ end
127
+ end
@@ -0,0 +1,80 @@
1
+ # Copyright (c) 2020 Jerome Arbez-Gindre
2
+ # frozen_string_literal: true
3
+
4
+ require('defmastership')
5
+
6
+ RSpec.describe(DefMastership::UpdateDefVersionModifier) do
7
+ subject(:modifier) do
8
+ described_class.new(
9
+ ref_document: 'ref.adoc'
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: { ref_document: 'ref.adoc' })) }
23
+ it { is_expected.to(have_attributes(changes: [])) }
24
+ end
25
+
26
+ describe '#do_modifications' do
27
+ let(:line_modifier) { instance_double(DefMastership::UpdateDefVersionLineModifier, 'lineModifier') }
28
+ let(:document) { instance_double(DefMastership::Document, 'document') }
29
+ let(:ref_document) { instance_double(DefMastership::Document, 'ref_document') }
30
+
31
+ before do
32
+ allow(DefMastership::UpdateDefVersionLineModifier).to(
33
+ receive(:from_config).with(ref_document: 'ref.adoc').and_return(line_modifier)
34
+ )
35
+ allow(DefMastership::Document).to(receive(:new).and_return(document, ref_document))
36
+ allow(document).to(receive(:parse_file_with_preprocessor))
37
+ allow(ref_document).to(receive(:parse_file_with_preprocessor))
38
+ allow(line_modifier).to(receive(:'document=').with(document))
39
+ allow(line_modifier).to(receive(:'ref_document=').with(ref_document))
40
+ allow(line_modifier).to(receive(:replace).with("file1 line1\n").and_return("new file1 line1\n"))
41
+ allow(line_modifier).to(receive(:replace).with('file1 line2').and_return('new file1 line2'))
42
+ allow(line_modifier).to(receive(:replace).with("file2 line1\n").and_return("new file2 line1\n"))
43
+ allow(line_modifier).to(receive(:replace).with('file2 line2').and_return('new file2 line2'))
44
+ allow(line_modifier).to(receive(:config).and_return(ref_document: 'ref.adoc'))
45
+ allow(line_modifier).to(receive(:changes).and_return([%w[from1 to1], %w[from2 to2]]))
46
+ end
47
+
48
+ context 'when detailed expectations' do
49
+ before { modifier.do_modifications(adoc_texts) }
50
+
51
+ it do
52
+ expect(DefMastership::UpdateDefVersionLineModifier).to(
53
+ have_received(:from_config).with(ref_document: 'ref.adoc')
54
+ )
55
+ end
56
+
57
+ it { expect(document).to(have_received(:parse_file_with_preprocessor).with('file1.adoc')) }
58
+ it { expect(document).to(have_received(:parse_file_with_preprocessor).with('file2.adoc')) }
59
+ it { expect(ref_document).to(have_received(:parse_file_with_preprocessor).with('ref.adoc')) }
60
+ it { expect(line_modifier).to(have_received(:'document=').with(document)) }
61
+ it { expect(line_modifier).to(have_received(:'ref_document=').with(ref_document)) }
62
+ it { expect(line_modifier).to(have_received(:replace).with("file1 line1\n")) }
63
+ it { expect(line_modifier).to(have_received(:replace).with('file1 line2')) }
64
+ it { expect(line_modifier).to(have_received(:replace).with("file2 line1\n")) }
65
+ it { expect(line_modifier).to(have_received(:replace).with('file2 line2')) }
66
+ it { expect(line_modifier).to(have_received(:config)) }
67
+ it { expect(line_modifier).to(have_received(:changes)) }
68
+ it { is_expected.to(have_attributes(config: { ref_document: 'ref.adoc' })) }
69
+ it { is_expected.to(have_attributes(changes: [%w[from1 to1], %w[from2 to2]])) }
70
+ end
71
+
72
+ it do
73
+ expected_adoc = {
74
+ 'file1.adoc' => "new file1 line1\nnew file1 line2",
75
+ 'file2.adoc' => "new file2 line1\nnew file2 line2"
76
+ }
77
+ expect(modifier.do_modifications(adoc_texts)).to(eq(expected_adoc))
78
+ end
79
+ end
80
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: defmastership
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.9
4
+ version: 1.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jérôme Arbez-Gindre
@@ -220,6 +220,8 @@ files:
220
220
  - lib/defmastership/rename_included_files_modifier.rb
221
221
  - lib/defmastership/update_def_checksum_line_modifier.rb
222
222
  - lib/defmastership/update_def_checksum_modifier.rb
223
+ - lib/defmastership/update_def_version_line_modifier.rb
224
+ - lib/defmastership/update_def_version_modifier.rb
223
225
  - lib/defmastership/version.rb
224
226
  - spec/spec_helper.rb
225
227
  - spec/unit/defmastership/batch_modifier_spec.rb
@@ -236,6 +238,8 @@ files:
236
238
  - spec/unit/defmastership/rename_included_files_modifier_spec.rb
237
239
  - spec/unit/defmastership/update_def_checksum_line_modifier_spec.rb
238
240
  - spec/unit/defmastership/update_def_checksum_modifier_spec.rb
241
+ - spec/unit/defmastership/update_def_version_line_modifier_spec.rb
242
+ - spec/unit/defmastership/update_def_version_modifier_spec.rb
239
243
  - spec/unit/defmastership_spec.rb
240
244
  homepage: https://gitlab.com/jjag/defmastership/
241
245
  licenses: