defmastership 1.0.1 → 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 (54) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/.gitlab-ci.yml +20 -0
  4. data/.rubocop.yml +5 -4
  5. data/Gemfile +1 -0
  6. data/LICENSE +22 -0
  7. data/Rakefile +2 -2
  8. data/bin/defmastership +25 -17
  9. data/cucumber.yml +2 -0
  10. data/defmastership.gemspec +18 -11
  11. data/features/changeref.feature +82 -129
  12. data/features/export.feature +102 -31
  13. data/features/modify.feature +143 -0
  14. data/features/rename_included_files.feature +121 -0
  15. data/features/step_definitions/defmastership_steps.rb +1 -0
  16. data/features/support/env.rb +1 -0
  17. data/lib/defmastership.rb +12 -3
  18. data/lib/defmastership/batch_modifier.rb +33 -0
  19. data/lib/defmastership/{ref_changer.rb → change_ref_line_modifier.rb} +19 -35
  20. data/lib/defmastership/change_ref_modifier.rb +15 -0
  21. data/lib/defmastership/comment_filter.rb +1 -0
  22. data/lib/defmastership/constants.rb +15 -1
  23. data/lib/defmastership/csv_formatter.rb +19 -18
  24. data/lib/defmastership/csv_formatter_body.rb +12 -6
  25. data/lib/defmastership/csv_formatter_header.rb +12 -10
  26. data/lib/defmastership/definition.rb +12 -0
  27. data/lib/defmastership/definition_parser.rb +46 -0
  28. data/lib/defmastership/document.rb +44 -75
  29. data/lib/defmastership/filters.rb +30 -0
  30. data/lib/defmastership/line_modifier_base.rb +29 -0
  31. data/lib/defmastership/modifier_base.rb +29 -0
  32. data/lib/defmastership/rename_included_files_line_modifier.rb +126 -0
  33. data/lib/defmastership/rename_included_files_modifier.rb +30 -0
  34. data/lib/defmastership/version.rb +2 -1
  35. data/spec/spec_helper.rb +2 -0
  36. data/spec/unit/defmastership/batch_modifier_spec.rb +115 -0
  37. data/spec/unit/defmastership/{ref_changer_spec.rb → change_ref_line_modifier_spec.rb} +49 -26
  38. data/spec/unit/defmastership/change_ref_modifier_spec.rb +76 -0
  39. data/spec/unit/defmastership/comment_filter_spec.rb +9 -4
  40. data/spec/unit/defmastership/csv_formatter_body_spec.rb +62 -37
  41. data/spec/unit/defmastership/csv_formatter_header_spec.rb +47 -22
  42. data/spec/unit/defmastership/csv_formatter_spec.rb +67 -105
  43. data/spec/unit/defmastership/definition_parser_spec.rb +63 -0
  44. data/spec/unit/defmastership/definition_spec.rb +31 -4
  45. data/spec/unit/defmastership/document_spec.rb +113 -35
  46. data/spec/unit/defmastership/rename_included_files_line_modifier_spec.rb +203 -0
  47. data/spec/unit/defmastership/rename_included_files_modifier_spec.rb +67 -0
  48. data/spec/unit/defmastership_spec.rb +1 -0
  49. metadata +44 -17
  50. data/Gemfile.lock +0 -140
  51. data/lib/defmastership/batch_changer.rb +0 -40
  52. data/lib/defmastership/project_ref_changer.rb +0 -27
  53. data/spec/unit/defmastership/batch_changer_spec.rb +0 -108
  54. data/spec/unit/defmastership/project_ref_changer_spec.rb +0 -79
@@ -12,16 +12,86 @@ 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
21
  """
22
22
  And the stdout should not contain anything
23
23
  And the stderr should not contain anything
24
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
74
+ """
75
+ And the stdout should not contain anything
76
+ And the stderr should not contain anything
77
+
78
+ Scenario: Extract to CSV with alternative CSV separator
79
+ Given a file named "toto.adoc" with:
80
+ """
81
+ [define, requirement, TOTO-0001]
82
+ --
83
+ Exemple of multiline requirement.
84
+ Second line.
85
+ --
86
+ """
87
+ When I successfully run `defmastership export --separator=';' toto.adoc`
88
+ Then the file "toto.csv" should contain:
89
+ """
90
+ Type;Reference;Value;sha256
91
+ requirement;TOTO-0001;"Exemple of multiline requirement.
92
+ Second line.";b86dcbde
93
+ """
94
+
25
95
  Scenario: Extract one definition with variable to CSV
26
96
  Given a file named "toto.adoc" with:
27
97
  """
@@ -34,13 +104,13 @@ Feature: The extract command
34
104
  Third line with {not_defined_variable}.
35
105
  --
36
106
  """
37
- When I run `defmastership export toto.adoc`
107
+ When I successfully run `defmastership export toto.adoc`
38
108
  Then the file "toto.csv" should contain:
39
109
  """
40
- Type,Reference,Value
110
+ Type,Reference,Value,sha256
41
111
  requirement,TOTO-0001,"Exemple of multiline requirement with variable: Variable content.
42
112
  Variable content : Variable content Toto.
43
- Third line with {not_defined_variable}."
113
+ Third line with {not_defined_variable}.",3bf370ed
44
114
  """
45
115
  And the stdout should not contain anything
46
116
  And the stderr should not contain anything
@@ -62,13 +132,14 @@ Feature: The extract command
62
132
  Second line.
63
133
  --
64
134
  """
65
- When I run `defmastership export toto.adoc`
135
+ When I successfully run `defmastership export toto.adoc`
66
136
  Then the file "toto.csv" should contain:
67
137
  """
68
- Type,Reference,Value
138
+ Type,Reference,Value,sha256
69
139
  requirement,TOTO-0001,"Exemple of multiline requirement.
70
- Second line."
71
- 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
72
143
  """
73
144
  And the file "toto.csv" should not contain:
74
145
  """
@@ -90,7 +161,7 @@ Feature: The extract command
90
161
  only one line
91
162
  ....
92
163
  """
93
- When I run `defmastership export toto.adoc`
164
+ When I successfully run `defmastership export toto.adoc`
94
165
  Then the file "toto.csv" should not contain:
95
166
  """
96
167
  something_else
@@ -111,7 +182,7 @@ Feature: The extract command
111
182
  only one line
112
183
  ////
113
184
  """
114
- When I run `defmastership export toto.adoc`
185
+ When I successfully run `defmastership export toto.adoc`
115
186
  Then the file "toto.csv" should not contain:
116
187
  """
117
188
  something_else
@@ -134,7 +205,7 @@ Feature: The extract command
134
205
  ////
135
206
  [define, something_else, TOTO-0003]
136
207
  """
137
- When I run `defmastership export toto.adoc`
208
+ When I successfully run `defmastership export toto.adoc`
138
209
  Then the file "toto.csv" should contain:
139
210
  """
140
211
  something_else
@@ -151,12 +222,12 @@ Feature: The extract command
151
222
  Second line.
152
223
  --
153
224
  """
154
- When I run `defmastership export toto.adoc`
225
+ When I successfully run `defmastership export toto.adoc`
155
226
  Then the file "toto.csv" should contain:
156
227
  """
157
- Type,Reference,Value,Labels
228
+ Type,Reference,Value,sha256,Labels
158
229
  requirement,TOTO-0001,"Exemple of multiline requirement.
159
- Second line.","label1
230
+ Second line.",b86dcbde,"label1
160
231
  label2"
161
232
  """
162
233
  And the stdout should not contain anything
@@ -174,12 +245,12 @@ Feature: The extract command
174
245
  --
175
246
  defs:eref[implements, [SYSTEM-0012, SYSTEM-0014]]
176
247
  """
177
- When I run `defmastership export toto.adoc`
248
+ When I successfully run `defmastership export toto.adoc`
178
249
  Then the file "toto.csv" should contain:
179
250
  """
180
- Type,Reference,Value,Participate to: ./the_other_document.html
251
+ Type,Reference,Value,sha256,Participate to:
181
252
  requirement,TOTO-0001,"Exemple of multiline requirement.
182
- Second line.","SYSTEM-0012
253
+ Second line.",b86dcbde,"SYSTEM-0012
183
254
  SYSTEM-0014"
184
255
  """
185
256
  And the stdout should not contain anything
@@ -197,12 +268,12 @@ Feature: The extract command
197
268
  --
198
269
  defs:eref[implements, [SYSTEM-0012, SYSTEM-0014]]
199
270
  """
200
- When I run `defmastership export toto.adoc`
271
+ When I successfully run `defmastership export toto.adoc`
201
272
  Then the file "toto.csv" should contain:
202
273
  """
203
- Type,Reference,Value,Participate to:
274
+ Type,Reference,Value,sha256,Participate to:
204
275
  requirement,TOTO-0001,"Exemple of multiline requirement.
205
- Second line.","SYSTEM-0012
276
+ Second line.",b86dcbde,"SYSTEM-0012
206
277
  SYSTEM-0014"
207
278
  """
208
279
  And the stdout should not contain anything
@@ -219,14 +290,14 @@ Feature: The extract command
219
290
  --
220
291
  defs:eref[implements, [SYSTEM-0012, SYSTEM-0014]]
221
292
  """
222
- When I run `defmastership export toto.adoc`
293
+ When I successfully run `defmastership export toto.adoc`
223
294
  Then the stdout should not contain anything
224
295
  And the stderr should not contain anything
225
296
  And the file "toto.csv" should contain:
226
297
  """
227
- Type,Reference,Value,Participate to:
298
+ Type,Reference,Value,sha256,Participate to:
228
299
  requirement,TOTO-0001,"Exemple of multiline requirement.
229
- Second line.","SYSTEM-0012
300
+ Second line.",b86dcbde,"SYSTEM-0012
230
301
  SYSTEM-0014"
231
302
  """
232
303
 
@@ -240,12 +311,12 @@ Feature: The extract command
240
311
  --
241
312
  please see defs:iref[TOTO-0002]
242
313
  """
243
- When I run `defmastership export toto.adoc`
314
+ When I successfully run `defmastership export toto.adoc`
244
315
  Then the file "toto.csv" should contain:
245
316
  """
246
- Type,Reference,Value,Internal links
317
+ Type,Reference,Value,sha256,Internal links
247
318
  requirement,TOTO-0001,"Exemple of multiline requirement.
248
- 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
249
320
  TOTO-0123
250
321
  TOTO-0002"
251
322
  """
@@ -264,12 +335,12 @@ Feature: The extract command
264
335
  defs:attribute[verifiedby, Beautiful Test]
265
336
  defs:attribute[criticity, Very cool]
266
337
  """
267
- When I run `defmastership export toto.adoc`
338
+ When I successfully run `defmastership export toto.adoc`
268
339
  And the stdout should not contain anything
269
340
  Then the file "toto.csv" should contain:
270
341
  """
271
- Type,Reference,Value,Verified by:,Criticity:
272
- 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
273
344
  """
274
345
  And the stdout should not contain anything
275
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
+