defmastership 1.0.5 → 1.0.6

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -12,12 +12,65 @@ Feature: The extract command
12
12
  Second line.
13
13
  --
14
14
  """
15
- When I run `defmastership export toto.adoc`
15
+ When I successfully run `defmastership export toto.adoc`
16
16
  Then the file "toto.csv" should contain:
17
17
  """
18
- Type,Reference,Value
18
+ Type,Reference,Value,sha256
19
19
  requirement,TOTO-0001,"Exemple of multiline requirement.
20
- Second line."
20
+ Second line.",b86dcbde
21
+ """
22
+ And the stdout should not contain anything
23
+ And the stderr should not contain anything
24
+
25
+ Scenario: Extract one definition with WRONG explicit checksum to CSV
26
+ Given a file named "toto.adoc" with:
27
+ """
28
+ [define, requirement, TOTO-0001(babe1234)]
29
+ def one
30
+ """
31
+ When I successfully run `defmastership export toto.adoc`
32
+ Then the file "toto.csv" should contain:
33
+ """
34
+ Type,Reference,Value,sha256,Wrong explicit checksum
35
+ requirement,TOTO-0001,def one,d27cb5c3,babe1234
36
+ """
37
+ And the stdout should not contain anything
38
+ And the stderr should not contain anything
39
+
40
+ Scenario: Extract two definitions with one WRONG explicit checksum to CSV
41
+ Given a file named "toto.adoc" with:
42
+ """
43
+ [define, requirement, TOTO-0001(d27cb5c3)]
44
+ def one
45
+
46
+ [define, requirement, TOTO-0002(babe1234)]
47
+ def two
48
+ """
49
+ When I successfully run `defmastership export toto.adoc`
50
+ Then the file "toto.csv" should contain:
51
+ """
52
+ Type,Reference,Value,sha256,Wrong explicit checksum
53
+ requirement,TOTO-0001,def one,d27cb5c3,\"\"
54
+ requirement,TOTO-0002,def two,b80e1be5,babe1234
55
+ """
56
+ And the stdout should not contain anything
57
+ And the stderr should not contain anything
58
+
59
+ Scenario: Extract one definition with explicit checksum to CSV
60
+ Given a file named "toto.adoc" with:
61
+ """
62
+ [define, requirement, TOTO-0001(b86dcbde)]
63
+ --
64
+ Exemple of multiline requirement.
65
+ Second line.
66
+ --
67
+ """
68
+ When I successfully run `defmastership export toto.adoc`
69
+ Then the file "toto.csv" should contain:
70
+ """
71
+ Type,Reference,Value,sha256
72
+ requirement,TOTO-0001,"Exemple of multiline requirement.
73
+ Second line.",b86dcbde
21
74
  """
22
75
  And the stdout should not contain anything
23
76
  And the stderr should not contain anything
@@ -31,12 +84,12 @@ Feature: The extract command
31
84
  Second line.
32
85
  --
33
86
  """
34
- When I run `defmastership export --separator=';' toto.adoc`
87
+ When I successfully run `defmastership export --separator=';' toto.adoc`
35
88
  Then the file "toto.csv" should contain:
36
89
  """
37
- Type;Reference;Value
90
+ Type;Reference;Value;sha256
38
91
  requirement;TOTO-0001;"Exemple of multiline requirement.
39
- Second line."
92
+ Second line.";b86dcbde
40
93
  """
41
94
 
42
95
  Scenario: Extract one definition with variable to CSV
@@ -51,13 +104,13 @@ Feature: The extract command
51
104
  Third line with {not_defined_variable}.
52
105
  --
53
106
  """
54
- When I run `defmastership export toto.adoc`
107
+ When I successfully run `defmastership export toto.adoc`
55
108
  Then the file "toto.csv" should contain:
56
109
  """
57
- Type,Reference,Value
110
+ Type,Reference,Value,sha256
58
111
  requirement,TOTO-0001,"Exemple of multiline requirement with variable: Variable content.
59
112
  Variable content : Variable content Toto.
60
- Third line with {not_defined_variable}."
113
+ Third line with {not_defined_variable}.",3bf370ed
61
114
  """
62
115
  And the stdout should not contain anything
63
116
  And the stderr should not contain anything
@@ -79,13 +132,14 @@ Feature: The extract command
79
132
  Second line.
80
133
  --
81
134
  """
82
- When I run `defmastership export toto.adoc`
135
+ When I successfully run `defmastership export toto.adoc`
83
136
  Then the file "toto.csv" should contain:
84
137
  """
85
- Type,Reference,Value
138
+ Type,Reference,Value,sha256
86
139
  requirement,TOTO-0001,"Exemple of multiline requirement.
87
- Second line."
88
- something_else,TOTO-0003,"only one paragraphe.\nwith two sentences."
140
+ Second line.",b86dcbde
141
+ something_else,TOTO-0003,"only one paragraphe.
142
+ with two sentences.",4761e172
89
143
  """
90
144
  And the file "toto.csv" should not contain:
91
145
  """
@@ -107,7 +161,7 @@ Feature: The extract command
107
161
  only one line
108
162
  ....
109
163
  """
110
- When I run `defmastership export toto.adoc`
164
+ When I successfully run `defmastership export toto.adoc`
111
165
  Then the file "toto.csv" should not contain:
112
166
  """
113
167
  something_else
@@ -128,7 +182,7 @@ Feature: The extract command
128
182
  only one line
129
183
  ////
130
184
  """
131
- When I run `defmastership export toto.adoc`
185
+ When I successfully run `defmastership export toto.adoc`
132
186
  Then the file "toto.csv" should not contain:
133
187
  """
134
188
  something_else
@@ -151,7 +205,7 @@ Feature: The extract command
151
205
  ////
152
206
  [define, something_else, TOTO-0003]
153
207
  """
154
- When I run `defmastership export toto.adoc`
208
+ When I successfully run `defmastership export toto.adoc`
155
209
  Then the file "toto.csv" should contain:
156
210
  """
157
211
  something_else
@@ -168,12 +222,12 @@ Feature: The extract command
168
222
  Second line.
169
223
  --
170
224
  """
171
- When I run `defmastership export toto.adoc`
225
+ When I successfully run `defmastership export toto.adoc`
172
226
  Then the file "toto.csv" should contain:
173
227
  """
174
- Type,Reference,Value,Labels
228
+ Type,Reference,Value,sha256,Labels
175
229
  requirement,TOTO-0001,"Exemple of multiline requirement.
176
- Second line.","label1
230
+ Second line.",b86dcbde,"label1
177
231
  label2"
178
232
  """
179
233
  And the stdout should not contain anything
@@ -191,12 +245,12 @@ Feature: The extract command
191
245
  --
192
246
  defs:eref[implements, [SYSTEM-0012, SYSTEM-0014]]
193
247
  """
194
- When I run `defmastership export toto.adoc`
248
+ When I successfully run `defmastership export toto.adoc`
195
249
  Then the file "toto.csv" should contain:
196
250
  """
197
- Type,Reference,Value,Participate to: ./the_other_document.html
251
+ Type,Reference,Value,sha256,Participate to:
198
252
  requirement,TOTO-0001,"Exemple of multiline requirement.
199
- Second line.","SYSTEM-0012
253
+ Second line.",b86dcbde,"SYSTEM-0012
200
254
  SYSTEM-0014"
201
255
  """
202
256
  And the stdout should not contain anything
@@ -214,12 +268,12 @@ Feature: The extract command
214
268
  --
215
269
  defs:eref[implements, [SYSTEM-0012, SYSTEM-0014]]
216
270
  """
217
- When I run `defmastership export toto.adoc`
271
+ When I successfully run `defmastership export toto.adoc`
218
272
  Then the file "toto.csv" should contain:
219
273
  """
220
- Type,Reference,Value,Participate to:
274
+ Type,Reference,Value,sha256,Participate to:
221
275
  requirement,TOTO-0001,"Exemple of multiline requirement.
222
- Second line.","SYSTEM-0012
276
+ Second line.",b86dcbde,"SYSTEM-0012
223
277
  SYSTEM-0014"
224
278
  """
225
279
  And the stdout should not contain anything
@@ -236,14 +290,14 @@ Feature: The extract command
236
290
  --
237
291
  defs:eref[implements, [SYSTEM-0012, SYSTEM-0014]]
238
292
  """
239
- When I run `defmastership export toto.adoc`
293
+ When I successfully run `defmastership export toto.adoc`
240
294
  Then the stdout should not contain anything
241
295
  And the stderr should not contain anything
242
296
  And the file "toto.csv" should contain:
243
297
  """
244
- Type,Reference,Value,Participate to:
298
+ Type,Reference,Value,sha256,Participate to:
245
299
  requirement,TOTO-0001,"Exemple of multiline requirement.
246
- Second line.","SYSTEM-0012
300
+ Second line.",b86dcbde,"SYSTEM-0012
247
301
  SYSTEM-0014"
248
302
  """
249
303
 
@@ -257,12 +311,12 @@ Feature: The extract command
257
311
  --
258
312
  please see defs:iref[TOTO-0002]
259
313
  """
260
- When I run `defmastership export toto.adoc`
314
+ When I successfully run `defmastership export toto.adoc`
261
315
  Then the file "toto.csv" should contain:
262
316
  """
263
- Type,Reference,Value,Internal links
317
+ Type,Reference,Value,sha256,Internal links
264
318
  requirement,TOTO-0001,"Exemple of multiline requirement.
265
- Second line: defs:iref[TOTO-0001], defs:iref[TOTO-0123].","TOTO-0001
319
+ Second line: defs:iref[TOTO-0001], defs:iref[TOTO-0123].",059b7188,"TOTO-0001
266
320
  TOTO-0123
267
321
  TOTO-0002"
268
322
  """
@@ -281,12 +335,12 @@ Feature: The extract command
281
335
  defs:attribute[verifiedby, Beautiful Test]
282
336
  defs:attribute[criticity, Very cool]
283
337
  """
284
- When I run `defmastership export toto.adoc`
338
+ When I successfully run `defmastership export toto.adoc`
285
339
  And the stdout should not contain anything
286
340
  Then the file "toto.csv" should contain:
287
341
  """
288
- Type,Reference,Value,Verified by:,Criticity:
289
- requirement,TOTO-0001,One single line.,Beautiful Test,Very cool
342
+ Type,Reference,Value,sha256,Verified by:,Criticity:
343
+ requirement,TOTO-0001,One single line.,554b0ff5,Beautiful Test,Very cool
290
344
  """
291
345
  And the stdout should not contain anything
292
346
  And the stderr should not contain anything
@@ -0,0 +1,143 @@
1
+ Feature: The modify command
2
+ As a Responsible of definitions for a given document
3
+ In order to manage to applu predefined modifications
4
+ I want defmastership to apply automatic modifications
5
+
6
+ Scenario: Change one modifier
7
+ Given a file named "modifications.yml" with:
8
+ """
9
+ ---
10
+ :temp-references:
11
+ :type: change_ref
12
+ :config:
13
+ :from_regexp: TOTO-TEMP-[X\d]{4}
14
+ :to_template: TOTO-%<next_ref>04d
15
+ :next_ref: 123
16
+ """
17
+ And a file named "thedoc.adoc" with:
18
+ """
19
+ [define, requirement, TOTO-TEMP-XXX1]
20
+ """
21
+ When I successfully run `defmastership modify --modifications temp-references thedoc.adoc`
22
+ Then the stdout should not contain anything
23
+ And the stderr should not contain anything
24
+ And the file "modifications.yml" should contain:
25
+ """
26
+ ---
27
+ :temp-references:
28
+ :type: change_ref
29
+ :config:
30
+ :from_regexp: TOTO-TEMP-[X\d]{4}
31
+ :to_template: TOTO-%<next_ref>04d
32
+ :next_ref: 124
33
+ """
34
+ And the file "thedoc.adoc" should contain:
35
+ """
36
+ [define, requirement, TOTO-0123]
37
+ """
38
+
39
+ Scenario: Make modifications with yaml file parameter
40
+ Given a file named "pouet.yml" with:
41
+ """
42
+ ---
43
+ :toto:
44
+ :type: change_ref
45
+ :config:
46
+ :from_regexp: TOTO-TEMP-[X\d]{4}
47
+ :to_template: TOTO-%<next_ref>04d
48
+ :next_ref: 123
49
+ """
50
+ And a file named "thedoc.adoc" with:
51
+ """
52
+ [define, requirement, TOTO-TEMP-XXX1]
53
+ """
54
+ When I successfully run `defmastership modify --modifications-file=pouet.yml --modifications toto thedoc.adoc`
55
+ Then the stdout should not contain anything
56
+ And the stderr should not contain anything
57
+ And the file "pouet.yml" should contain:
58
+ """
59
+ ---
60
+ :toto:
61
+ :type: change_ref
62
+ :config:
63
+ :from_regexp: TOTO-TEMP-[X\d]{4}
64
+ :to_template: TOTO-%<next_ref>04d
65
+ :next_ref: 124
66
+ """
67
+ And the file "thedoc.adoc" should contain:
68
+ """
69
+ [define, requirement, TOTO-0123]
70
+ """
71
+
72
+ Scenario: Generate a table with changes
73
+ Given a file named "modifications.yml" with:
74
+ """
75
+ ---
76
+ :temp-references:
77
+ :type: change_ref
78
+ :config:
79
+ :from_regexp: TOTO-TEMP-[X\d]{4}
80
+ :to_template: TOTO-%<next_ref>04d
81
+ :next_ref: 123
82
+ """
83
+ And a file named "thedoc.adoc" with:
84
+ """
85
+ [define, requirement, TOTO-TEMP-XXX1]
86
+ [define, requirement, TOTO-TEMP-XXX2]
87
+ """
88
+ When I successfully run `defmastership modify --modifications temp-references --changes-summary=changes.csv thedoc.adoc`
89
+ Then the stderr should not contain anything
90
+ And the stdout should not contain anything
91
+ And the file "changes.csv" should contain:
92
+ """
93
+ Modifier,Was,Becomes
94
+ temp-references,TOTO-TEMP-XXX1,TOTO-0123
95
+ temp-references,TOTO-TEMP-XXX2,TOTO-0124
96
+ """
97
+
98
+ Scenario: Apply two modifcations
99
+ Given a file named "modifications.yml" with:
100
+ """
101
+ ---
102
+ :temp-references:
103
+ :type: change_ref
104
+ :config:
105
+ :from_regexp: TOTO-TEMP-[X\d]{4}
106
+ :to_template: TOTO-%<next_ref>04d
107
+ :next_ref: 123
108
+ :tata_or_titi:
109
+ :type: change_ref
110
+ :config:
111
+ :from_regexp: "(?<tata_or_titi>TATA|TITI)-TEMP-[X\\d]{4}"
112
+ :to_template: "%<tata_or_titi>s-%<next_ref>07d"
113
+ :next_ref: 432
114
+ """
115
+ And a file named "thedoc.adoc" with:
116
+ """
117
+ [define, requirement, TOTO-TEMP-XXX1]
118
+ [define, requirement, TITI-TEMP-XXX2]
119
+ """
120
+ When I successfully run `defmastership modify --modifications temp-references,tata_or_titi --changes-summary=changes.csv thedoc.adoc`
121
+ Then the stdout should not contain anything
122
+ And the stderr should not contain anything
123
+ And the file "modifications.yml" should contain:
124
+ """
125
+ ---
126
+ :temp-references:
127
+ :type: change_ref
128
+ :config:
129
+ :from_regexp: TOTO-TEMP-[X\d]{4}
130
+ :to_template: TOTO-%<next_ref>04d
131
+ :next_ref: 124
132
+ :tata_or_titi:
133
+ :type: change_ref
134
+ :config:
135
+ :from_regexp: "(?<tata_or_titi>TATA|TITI)-TEMP-[X\\d]{4}"
136
+ :to_template: "%<tata_or_titi>s-%<next_ref>07d"
137
+ :next_ref: 433
138
+ """
139
+ And the file "thedoc.adoc" should contain:
140
+ """
141
+ [define, requirement, TOTO-0123]
142
+ [define, requirement, TITI-0000432]
143
+ """
@@ -0,0 +1,121 @@
1
+
2
+ Feature: The rename_included_files command
3
+ As a Responsible of definitions for a given document.
4
+ In order to easy traceability with included files,
5
+ I want defmastership to change filename of included files to reflect
6
+ reference.
7
+
8
+ Scenario: do NOT change the filename of a file NOT included in a definition
9
+ Given a file named "modifications.yml" with:
10
+ """
11
+ ---
12
+ :rename_included_png:
13
+ :type: rename_included_files
14
+ :config:
15
+ :from_regexp: (?<origin>.*\.png)
16
+ :to_template: "%<reference>s_%<origin>s"
17
+ """
18
+ And a file named "thedoc.adoc" with:
19
+ """
20
+ include::any_path/one_file.png[]
21
+ """
22
+ And a directory named "any_path"
23
+ And an empty file named "any_path/one_file.png"
24
+ When I successfully run `defmastership modify --modifications rename_included_png thedoc.adoc`
25
+ Then the stdout should not contain anything
26
+ And the stderr should not contain anything
27
+ And the file "thedoc.adoc" should contain:
28
+ """
29
+ include::any_path/one_file.png[]
30
+ """
31
+ And the file "any_path/one_file.png" should exist
32
+
33
+ Scenario: change the filename of a file included in a definition
34
+ Given a file named "modifications.yml" with:
35
+ """
36
+ ---
37
+ :rename_included_png:
38
+ :type: rename_included_files
39
+ :config:
40
+ :from_regexp: (?<origin>.*\.png)
41
+ :to_template: "%<reference>s_%<origin>s"
42
+ """
43
+ And a file named "thedoc.adoc" with:
44
+ """
45
+ [define, requirement, TOTO-WHATEVER-123]
46
+ include::any_path/one_file.png[]
47
+ """
48
+ And a directory named "any_path"
49
+ And an empty file named "any_path/one_file.png"
50
+ When I successfully run `defmastership modify --modifications rename_included_png thedoc.adoc`
51
+ Then the stdout should not contain anything
52
+ And the stderr should not contain anything
53
+ And the file "thedoc.adoc" should contain:
54
+ """
55
+ [define, requirement, TOTO-WHATEVER-123]
56
+ include::any_path/TOTO-WHATEVER-123_one_file.png[]
57
+ """
58
+ And the file "any_path/one_file.png" should not exist
59
+ And the file "any_path/TOTO-WHATEVER-123_one_file.png" should exist
60
+
61
+ Scenario: change the filename with variable in path
62
+ Given a file named "modifications.yml" with:
63
+ """
64
+ ---
65
+ :rename_included_png:
66
+ :type: rename_included_files
67
+ :config:
68
+ :from_regexp: (?<origin>.*\.png)
69
+ :to_template: "%<reference>s_%<origin>s"
70
+ """
71
+ And a file named "thedoc.adoc" with:
72
+ """
73
+ :any: one
74
+ :path: two
75
+ [define, requirement, TOTO-WHATEVER-123]
76
+ include::{any}_{path}/one_file.png[]
77
+ """
78
+ And a directory named "one_two"
79
+ And an empty file named "one_two/one_file.png"
80
+ When I successfully run `defmastership modify --modifications rename_included_png thedoc.adoc`
81
+ Then the stdout should not contain anything
82
+ And the stderr should not contain anything
83
+ And the file "thedoc.adoc" should contain:
84
+ """
85
+ :any: one
86
+ :path: two
87
+ [define, requirement, TOTO-WHATEVER-123]
88
+ include::{any}_{path}/TOTO-WHATEVER-123_one_file.png[]
89
+ """
90
+ And the file "one_two/one_file.png" should not exist
91
+ And the file "one_two/TOTO-WHATEVER-123_one_file.png" should exist
92
+
93
+ Scenario: DO NOT change the filename again and again
94
+ Given a file named "modifications.yml" with:
95
+ """
96
+ ---
97
+ :rename_included_png:
98
+ :type: rename_included_files
99
+ :config:
100
+ :from_regexp: (?<origin>.*\.png)
101
+ :cancel_if_match: TOTO-WHATEVER
102
+ :to_template: "%<reference>s_%<origin>s"
103
+ """
104
+ And a file named "thedoc.adoc" with:
105
+ """
106
+ [define, requirement, TOTO-WHATEVER-123]
107
+ include::any_path/TOTO-WHATEVER-123_one_file.png[]
108
+ """
109
+ And a directory named "any_path"
110
+ And an empty file named "any_path/TOTO-WHATEVER-123_one_file.png"
111
+ When I successfully run `defmastership modify --modifications rename_included_png thedoc.adoc`
112
+ Then the stdout should not contain anything
113
+ And the stderr should not contain anything
114
+ And the file "thedoc.adoc" should contain:
115
+ """
116
+ [define, requirement, TOTO-WHATEVER-123]
117
+ include::any_path/TOTO-WHATEVER-123_one_file.png[]
118
+ """
119
+ And the file "any_path/one_file.png" should not exist
120
+ And the file "any_path/TOTO-WHATEVER-123_one_file.png" should exist
121
+