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,100 @@
1
+ # frozen_string_literal: true
2
+
3
+ require('defmastership')
4
+
5
+ RSpec.describe(DefMastership::CSVFormatterHeader) do
6
+ subject(:formatter) { described_class.new(document) }
7
+
8
+ let(:document) { instance_double(DefMastership::Document, 'document') }
9
+
10
+ describe '.new' do
11
+ it { is_expected.not_to(be(nil)) }
12
+ end
13
+
14
+ describe '#header' do
15
+ describe '#fixed_header' do
16
+ it { expect(formatter.fixed_header).to(eq(%w[Type Reference Value])) }
17
+ end
18
+
19
+ describe '#labels_header' do
20
+ context 'when no labels' do
21
+ before do
22
+ allow(document).to(receive(:labels).and_return([]))
23
+ formatter.labels_header
24
+ end
25
+
26
+ it { expect(document).to(have_received(:labels)) }
27
+
28
+ it { expect(formatter.labels_header).to(eq([])) }
29
+ end
30
+
31
+ context 'when there is labels' do
32
+ before { allow(document).to(receive(:labels).and_return(['Whatever'])) }
33
+
34
+ it { expect(formatter.labels_header).to(eq(['Labels'])) }
35
+ end
36
+ end
37
+
38
+ describe '#eref_header' do
39
+ context 'when no eref' do
40
+ before do
41
+ allow(document).to(receive(:eref).and_return({}))
42
+ formatter.eref_header
43
+ end
44
+
45
+ it { expect(document).to(have_received(:eref)) }
46
+
47
+ it { expect(formatter.eref_header).to(eq([])) }
48
+ end
49
+
50
+ context 'when eref' do
51
+ before do
52
+ allow(document).to(receive(:eref).and_return(
53
+ whatever: { prefix: 'A' },
54
+ other: { prefix: 'C', url: 'D' }
55
+ ))
56
+ end
57
+
58
+ it { expect(formatter.eref_header).to(eq(['A', 'C D'])) }
59
+ end
60
+ end
61
+
62
+ describe '#iref_header' do
63
+ context 'when no iref' do
64
+ before do
65
+ allow(document).to(receive(:iref).and_return(false))
66
+ formatter.iref_header
67
+ end
68
+
69
+ it { expect(document).to(have_received(:iref)) }
70
+
71
+ it { expect(formatter.iref_header).to(eq([])) }
72
+ end
73
+
74
+ context 'when iref' do
75
+ before { allow(document).to(receive(:iref).and_return(true)) }
76
+
77
+ it { expect(formatter.iref_header).to(eq(['Internal links'])) }
78
+ end
79
+ end
80
+
81
+ describe '#attributes_header' do
82
+ context 'when no attributes' do
83
+ before do
84
+ allow(document).to(receive(:attributes).and_return({}))
85
+ formatter.attributes_header
86
+ end
87
+
88
+ it { expect(document).to(have_received(:attributes)) }
89
+
90
+ it { expect(formatter.attributes_header).to(eq([])) }
91
+ end
92
+
93
+ context 'when attributes' do
94
+ before { allow(document).to(receive(:attributes).and_return(whatever: 'A', other: 'B')) }
95
+
96
+ it { expect(formatter.attributes_header).to(eq(%w[A B])) }
97
+ end
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,171 @@
1
+ # frozen_string_literal: true
2
+
3
+ require('defmastership')
4
+ require('ostruct')
5
+
6
+ RSpec.describe(DefMastership::CSVFormatter) do
7
+ subject(:formatter) { described_class.new(document) }
8
+
9
+ let(:document) { instance_double(DefMastership::Document, 'document') }
10
+
11
+ describe '.new' do
12
+ it { is_expected.not_to(be(nil)) }
13
+ end
14
+
15
+ describe '#header' do
16
+ context 'when minimal' do
17
+ before do
18
+ allow(document).to(receive(:labels).with(no_args).and_return([]))
19
+ allow(document).to(receive(:eref).with(no_args).and_return({}))
20
+ allow(document).to(receive(:iref).with(no_args).and_return(false))
21
+ allow(document).to(receive(:attributes).with(no_args).and_return({}))
22
+ formatter.header
23
+ end
24
+
25
+ it { expect(document).to(have_received(:labels).with(no_args)) }
26
+
27
+ it { expect(document).to(have_received(:eref).with(no_args)) }
28
+
29
+ it { expect(document).to(have_received(:iref).with(no_args)) }
30
+
31
+ it { expect(document).to(have_received(:attributes).with(no_args)) }
32
+
33
+ it { expect(formatter.header).to(eq(%w[Type Reference Value])) }
34
+ end
35
+
36
+ context 'when has everything' do
37
+ before do
38
+ allow(document).to(receive(:labels)
39
+ .with(no_args)
40
+ .and_return(['Whatever']))
41
+ allow(document).to(receive(:eref)
42
+ .with(no_args)
43
+ .and_return(whatever: { prefix: 'A' },
44
+ other: { prefix: 'C', url: 'D' }))
45
+ allow(document).to(receive(:iref).with(no_args).and_return(true))
46
+ allow(document).to(receive(:attributes)
47
+ .with(no_args)
48
+ .and_return(whatever: 'E', other: 'F'))
49
+ end
50
+
51
+ it do
52
+ expect(formatter.header).to(eq(%w[Type Reference Value Labels] +
53
+ ['A', 'C D', 'Internal links'] +
54
+ %w[E F]))
55
+ end
56
+ end
57
+ end
58
+
59
+ describe '#body' do
60
+ let(:definition) { instance_double(DefMastership::Definition, 'definition') }
61
+
62
+ context 'when minimal' do
63
+ before do
64
+ allow(document).to(receive(:labels).with(no_args).and_return([]))
65
+ allow(document).to(receive(:eref).with(no_args).and_return({}))
66
+ allow(document).to(receive(:iref).with(no_args).and_return(false))
67
+ allow(document).to(receive(:attributes).with(no_args).and_return({}))
68
+ allow(definition).to(receive(:type).with(no_args).and_return('a'))
69
+ allow(definition).to(receive(:reference).with(no_args).and_return('b'))
70
+ allow(definition).to(receive(:value).with(no_args).and_return('c'))
71
+ formatter.body(definition)
72
+ end
73
+
74
+ it { expect(document).to(have_received(:labels).with(no_args)) }
75
+
76
+ it { expect(document).to(have_received(:eref).with(no_args)) }
77
+
78
+ it { expect(document).to(have_received(:iref).with(no_args)) }
79
+
80
+ it { expect(document).to(have_received(:attributes).with(no_args)) }
81
+
82
+ it { expect(definition).to(have_received(:type).with(no_args)) }
83
+
84
+ it { expect(definition).to(have_received(:reference).with(no_args)) }
85
+
86
+ it { expect(definition).to(have_received(:value).with(no_args)) }
87
+
88
+ it { expect(formatter.body(definition)).to(eq(%w[a b c])) }
89
+ end
90
+
91
+ context 'when has everything' do
92
+ before do
93
+ allow(document).to(receive(:labels).with(no_args).and_return(['Whatever']))
94
+ allow(document).to(receive(:eref).with(no_args).and_return(
95
+ a: 'whatever',
96
+ b: 'whatever',
97
+ c: 'whatever'
98
+ ))
99
+ allow(document).to(receive(:iref).with(no_args).and_return(true))
100
+ allow(document).to(receive(:attributes).with(no_args).and_return(
101
+ a: 'whatever',
102
+ b: 'whatever',
103
+ c: 'whatever'
104
+ ))
105
+ allow(definition).to(receive(:type).with(no_args).and_return('a'))
106
+ allow(definition).to(receive(:reference).with(no_args).and_return('b'))
107
+ allow(definition).to(receive(:value).with(no_args).and_return('c'))
108
+ allow(definition).to(receive(:labels).with(no_args).and_return(%w[toto tutu]))
109
+ allow(definition).to(receive(:eref).with(no_args).and_return(a: %w[A B], b: [], c: ['C']))
110
+ allow(definition).to(receive(:iref).with(no_args).and_return(%w[E F]))
111
+ allow(definition).to(receive(:attributes).with(no_args).and_return(a: 'X', b: '', c: 'Y'))
112
+ formatter.body(definition)
113
+ end
114
+
115
+ it { expect(definition).to(have_received(:labels).with(no_args)) }
116
+
117
+ it { expect(definition).to(have_received(:eref).exactly(3).times.with(no_args)) }
118
+
119
+ it { expect(definition).to(have_received(:iref).with(no_args)) }
120
+
121
+ it { expect(definition).to(have_received(:attributes).exactly(3).times.with(no_args)) }
122
+
123
+ it do
124
+ expect(formatter.body(definition)).to(eq(%w[a b c] + ["toto\ntutu"] +
125
+ ["A\nB", '', 'C'] +
126
+ ["E\nF"] +
127
+ ['X', '', 'Y']))
128
+ end
129
+ end
130
+ end
131
+
132
+ describe '#export_to' do
133
+ context 'when #export_to csv file' do
134
+ let(:target_file) { 'export.csv' }
135
+ let(:definitions) do
136
+ [
137
+ OpenStruct.new(type: 'a', reference: 'b', value: 'c'),
138
+ OpenStruct.new(type: 'd', reference: 'e', value: 'f')
139
+ ]
140
+ end
141
+
142
+ before do
143
+ setup_aruba
144
+ allow(document).to(receive(:labels).exactly(3).times.with(no_args).and_return([]))
145
+ allow(document).to(receive(:eref).exactly(3).times.with(no_args).and_return({}))
146
+ allow(document).to(receive(:iref).exactly(3).times.with(no_args).and_return(false))
147
+ allow(document).to(receive(:attributes).exactly(3).times.with(no_args).and_return({}))
148
+ allow(document).to(receive(:definitions).with(no_args).and_return(definitions))
149
+ formatter.export_to("#{aruba.current_directory}/#{target_file}")
150
+ end
151
+
152
+ it { expect(document).to(have_received(:labels).exactly(3).times.with(no_args)) }
153
+
154
+ it { expect(document).to(have_received(:eref).exactly(3).times.with(no_args)) }
155
+
156
+ it { expect(document).to(have_received(:iref).exactly(3).times.with(no_args)) }
157
+
158
+ it { expect(document).to(have_received(:attributes).exactly(3).times.with(no_args)) }
159
+
160
+ it { expect(document).to(have_received(:definitions).with(no_args)) }
161
+
162
+ it do
163
+ expect(target_file).to(have_file_content(<<~CSV_FILE))
164
+ Type,Reference,Value
165
+ a,b,c
166
+ d,e,f
167
+ CSV_FILE
168
+ end
169
+ end
170
+ end
171
+ end
@@ -0,0 +1,110 @@
1
+ # frozen_string_literal: true
2
+
3
+ require('defmastership')
4
+
5
+ RSpec.describe(DefMastership::Definition) do
6
+ describe '.new' do
7
+ context 'without labels' do
8
+ subject do
9
+ described_class.new(
10
+ type: 'req',
11
+ reference: 'TUTU-001'
12
+ )
13
+ end
14
+
15
+ it { is_expected.not_to(be(nil)) }
16
+ it { is_expected.to(have_attributes(type: 'req')) }
17
+ it { is_expected.to(have_attributes(reference: 'TUTU-001')) }
18
+ it { is_expected.to(have_attributes(lines: [])) }
19
+ it { is_expected.to(have_attributes(value: '')) }
20
+ it { is_expected.to(have_attributes(eref: {})) }
21
+ it { is_expected.to(have_attributes(iref: [])) }
22
+ it { is_expected.to(have_attributes(attributes: {})) }
23
+ it { is_expected.to(have_attributes(labels: Set.new)) }
24
+ end
25
+
26
+ context 'with labels' do
27
+ subject do
28
+ described_class.new(
29
+ gtype: 'req',
30
+ reference: 'TUTU-001',
31
+ labels: 'something'
32
+ )
33
+ end
34
+
35
+ it { is_expected.to(have_attributes(labels: Set['something'])) }
36
+ end
37
+ end
38
+
39
+ describe '#<<' do
40
+ subject(:definition) do
41
+ described_class.new(
42
+ type: 'req',
43
+ reference: 'TUTU-001'
44
+ )
45
+ end
46
+
47
+ it 'has value when one line is added' do
48
+ definition << 'first line'
49
+ expect(definition.value).to(eq('first line'))
50
+ end
51
+
52
+ it 'store line when added' do
53
+ definition << 'first line'
54
+ expect(definition.lines).to(eq(['first line']))
55
+ end
56
+
57
+ it 'has multiline value when multiple lines are added' do
58
+ definition << 'first line' << 'second line'
59
+ expect(definition.value).to(eq("first line\nsecond line"))
60
+ end
61
+
62
+ it 'store each line when added' do
63
+ definition << 'first line' << 'second line'
64
+ expect(definition.lines).to(eq(['first line', 'second line']))
65
+ end
66
+ end
67
+
68
+ describe '#add_eref' do
69
+ subject(:definition) do
70
+ described_class.new(
71
+ type: 'req',
72
+ reference: 'TUTU-001'
73
+ )
74
+ end
75
+
76
+ it 'shall accept to add one eref' do
77
+ definition.add_eref(:foo, ' tutu, titi , pouet')
78
+ expect(definition.eref[:foo]).to(eq(%w[tutu titi pouet]))
79
+ end
80
+ end
81
+
82
+ describe '#add_iref' do
83
+ subject(:definition) do
84
+ described_class.new(
85
+ type: 'req',
86
+ reference: 'TUTU-001'
87
+ )
88
+ end
89
+
90
+ it 'shall accept to add multiple iref' do
91
+ definition.add_iref('toto')
92
+ definition.add_iref('tutu')
93
+ expect(definition.iref).to(eq(%w[toto tutu]))
94
+ end
95
+ end
96
+
97
+ describe '#set_attribute' do
98
+ subject(:definition) do
99
+ described_class.new(
100
+ type: 'req',
101
+ reference: 'TUTU-001'
102
+ )
103
+ end
104
+
105
+ it 'shall accept to set attribute' do
106
+ definition.set_attribute(:whatever, 'value')
107
+ expect(definition.attributes[:whatever]).to(eq('value'))
108
+ end
109
+ end
110
+ end
@@ -0,0 +1,398 @@
1
+ # frozen_string_literal: true
2
+
3
+ require('defmastership')
4
+
5
+ RSpec.describe(DefMastership::Document) do
6
+ describe '.new' do
7
+ it { is_expected.not_to(be(nil)) }
8
+ it { is_expected.to(have_attributes(definitions: [])) }
9
+ it { is_expected.to(have_attributes(eref: {})) }
10
+ it { is_expected.to(have_attributes(iref: false)) }
11
+ it { is_expected.to(have_attributes(attributes: {})) }
12
+ it { is_expected.to(have_attributes(variables: {})) }
13
+ end
14
+
15
+ describe '#parse' do
16
+ subject(:document) { described_class.new }
17
+
18
+ context 'with valid definitions' do
19
+ let(:definition) { instance_double(DefMastership::Definition, 'definition') }
20
+
21
+ before do
22
+ allow(DefMastership::Definition).to(receive(:new).and_return(definition))
23
+ allow(definition).to(receive(:labels).and_return(Set.new))
24
+ allow(definition).to(receive(:<<).and_return(definition))
25
+ allow(definition).to(receive(:add_eref).and_return(definition))
26
+ allow(definition).to(receive(:add_iref).and_return(definition))
27
+ end
28
+
29
+ context 'when simple definition line' do
30
+ let(:input_lines) { ['[define, requirement, TOTO-0001]'] }
31
+
32
+ before do
33
+ allow(DefMastership::Definition).to(receive(:new).with(
34
+ matchdata_including(
35
+ type: 'requirement',
36
+ reference: 'TOTO-0001'
37
+ )
38
+ ).and_return(definition))
39
+ document.parse(input_lines)
40
+ end
41
+
42
+ it do
43
+ expect(DefMastership::Definition).to(have_received(:new).with(
44
+ matchdata_including(type: 'requirement', reference: 'TOTO-0001')
45
+ ))
46
+ end
47
+
48
+ it { expect(document).to(have_attributes(definitions: [definition])) }
49
+ end
50
+
51
+ context 'when complete definition with content' do
52
+ let(:input_lines) do
53
+ [
54
+ '[define, requirement, TOTO-0001]',
55
+ '--',
56
+ 'a',
57
+ 'b',
58
+ '--',
59
+ 'not included'
60
+ ]
61
+ end
62
+
63
+ before do
64
+ allow(definition).to(receive(:<<).and_return(definition))
65
+ document.parse(input_lines)
66
+ end
67
+
68
+ it { expect(definition).to(have_received(:<<).with('a')) }
69
+
70
+ it { expect(definition).to(have_received(:<<).with('b')) }
71
+ end
72
+
73
+ context 'when definition with one paragraph' do
74
+ let(:input_lines) do
75
+ [
76
+ '[define, requirement, TOTO-0001]',
77
+ 'one line',
78
+ 'another line',
79
+ '',
80
+ 'not included'
81
+ ]
82
+ end
83
+
84
+ before do
85
+ allow(definition).to(receive(:<<).and_return(definition))
86
+ document.parse(input_lines)
87
+ end
88
+
89
+ it { expect(definition).to(have_received(:<<).with('one line')) }
90
+
91
+ it { expect(definition).to(have_received(:<<).with('another line')) }
92
+ end
93
+
94
+ context 'when definition with one paragraph followed by a block' do
95
+ let(:input_lines) do
96
+ [
97
+ '[define, requirement, TOTO-0001]',
98
+ 'one line',
99
+ 'another line',
100
+ '--',
101
+ 'not included',
102
+ '--'
103
+ ]
104
+ end
105
+
106
+ before { document.parse(input_lines) }
107
+
108
+ it { expect(definition).not_to(have_received(:<<).with('not included')) }
109
+ end
110
+
111
+ context 'when block without definition' do
112
+ let(:input_lines) { ['--', 'first line', '--'] }
113
+
114
+ it do
115
+ document.parse(input_lines)
116
+ expect(document.definitions).to(eq([]))
117
+ end
118
+ end
119
+
120
+ context 'when definition with labels' do
121
+ let(:input_lines) do
122
+ [
123
+ '[define, requirement, TOTO-0001, [label1, label2]]',
124
+ 'one line',
125
+ 'not included'
126
+ ]
127
+ end
128
+
129
+ before do
130
+ allow(definition).to(receive(:labels).and_return(Set['bla1', 'bla2']))
131
+ document.parse(input_lines)
132
+ end
133
+
134
+ it do
135
+ expect(DefMastership::Definition).to(have_received(:new).with(matchdata_including(
136
+ type: 'requirement',
137
+ reference: 'TOTO-0001',
138
+ labels: 'label1, label2'
139
+ )))
140
+ end
141
+
142
+ it { expect(document.labels).to(eq(Set['bla1', 'bla2'])) }
143
+ end
144
+
145
+ context 'when definition with labels without spaces' do
146
+ let(:input_lines) do
147
+ [
148
+ '[define,requirement,TOTO-0001,[label1,label2]]',
149
+ 'one line',
150
+ 'not included'
151
+ ]
152
+ end
153
+
154
+ before do
155
+ allow(definition).to(receive(:labels).and_return(Set['bla1', 'bla2']))
156
+ document.parse(input_lines)
157
+ end
158
+
159
+ it do
160
+ expect(DefMastership::Definition).to(have_received(:new).with(matchdata_including(
161
+ type: 'requirement',
162
+ reference: 'TOTO-0001',
163
+ labels: 'label1,label2'
164
+ )))
165
+ end
166
+
167
+ it { expect(document.labels).to(eq(Set['bla1', 'bla2'])) }
168
+ end
169
+
170
+ context 'when setup external links' do
171
+ let(:input_lines) do
172
+ [
173
+ ':eref-implements-prefix: Participate to:',
174
+ ':eref-implements-url: ./other_document.html',
175
+ 'one line',
176
+ 'not included'
177
+ ]
178
+ end
179
+
180
+ before { document.parse(input_lines) }
181
+
182
+ it { expect(document.eref[:implements]).to(eq(prefix: 'Participate to:', url: './other_document.html')) }
183
+ end
184
+
185
+ context 'when setup external links without url' do
186
+ let(:input_lines) do
187
+ [
188
+ ':eref-implements-prefix: Participate to:',
189
+ 'one line',
190
+ 'not included'
191
+ ]
192
+ end
193
+
194
+ it do
195
+ document.parse(input_lines)
196
+ expect(document.eref[:implements])
197
+ .to(eq(prefix: 'Participate to:'))
198
+ end
199
+ end
200
+
201
+ context 'when define external links' do
202
+ let(:input_lines) do
203
+ [
204
+ '[define, requirement, TOTO-0001]',
205
+ 'one line',
206
+ 'defs:eref[implements, [SYSTEM-0012, SYSTEM-0014]]'
207
+ ]
208
+ end
209
+
210
+ before do
211
+ allow(definition).to(receive(:add_eref).with(:implements, 'SYSTEM-0012, SYSTEM-0014')
212
+ .and_return(definition))
213
+ document.parse(input_lines)
214
+ end
215
+
216
+ it { expect(definition).to(have_received(:add_eref).with(:implements, 'SYSTEM-0012, SYSTEM-0014')) }
217
+ end
218
+
219
+ context 'when define internal links' do
220
+ let(:input_lines) do
221
+ [
222
+ '[define, requirement, TOTO-0001]',
223
+ 'defs:iref[toto] defs:iref[tutu]',
224
+ 'defs:iref[pouet]'
225
+ ]
226
+ end
227
+
228
+ before do
229
+ allow(definition).to(receive(:add_iref))
230
+ document.parse(input_lines)
231
+ end
232
+
233
+ it { expect(definition).to(have_received(:add_iref).with('toto')) }
234
+ it { expect(definition).to(have_received(:add_iref).with('tutu')) }
235
+ it { expect(definition).to(have_received(:add_iref).with('pouet')) }
236
+ it { expect(document.iref).to(eq(true)) }
237
+ end
238
+
239
+ context 'when configure attributes' do
240
+ let(:input_lines) do
241
+ [
242
+ ':attr-myattribute-prefix: My attribute:',
243
+ ':attr-myotherone-prefix: My other attribute:'
244
+ ]
245
+ end
246
+
247
+ before { document.parse(input_lines) }
248
+
249
+ it { expect(document.attributes).to(eq(myattribute: 'My attribute:', myotherone: 'My other attribute:')) }
250
+ end
251
+
252
+ context 'when setup attributes value' do
253
+ let(:input_lines) do
254
+ [
255
+ '[define, requirement, TOTO-0001]',
256
+ 'defs:attribute[myattribute, My value]'
257
+ ]
258
+ end
259
+
260
+ before do
261
+ allow(definition).to(receive(:set_attribute).with(:myattribute, 'My value'))
262
+ document.parse(input_lines)
263
+ end
264
+
265
+ it { expect(definition).to(have_received(:set_attribute).with(:myattribute, 'My value')) }
266
+ end
267
+
268
+ context 'when putting comments' do
269
+ let(:input_lines) do
270
+ [
271
+ '[define, requirement, TOTO-0001]',
272
+ '// defs:iref[toto] defs:iref[tutu]'
273
+ ]
274
+ end
275
+
276
+ it do
277
+ document.parse(input_lines)
278
+ expect(document.iref).to(eq(false))
279
+ end
280
+ end
281
+
282
+ context 'when definition in wrong literal block' do
283
+ let(:input_lines) do
284
+ [
285
+ '1234',
286
+ '[define, requirement, TOTO-0001]'
287
+ ]
288
+ end
289
+
290
+ before do
291
+ allow(DefMastership::Definition).to(receive(:new).with(matchdata_including(
292
+ type: 'requirement',
293
+ reference: 'TOTO-0001'
294
+ )).and_return(definition))
295
+ document.parse(input_lines)
296
+ end
297
+
298
+ it do
299
+ expect(DefMastership::Definition).to(have_received(:new).with(matchdata_including(
300
+ type: 'requirement',
301
+ reference: 'TOTO-0001'
302
+ )))
303
+ end
304
+ end
305
+ end
306
+
307
+ context 'when variables replacement' do
308
+ let(:definition) { instance_double(DefMastership::Definition, 'definition') }
309
+
310
+ before do
311
+ allow(DefMastership::Definition).to(receive(:new).and_return(definition))
312
+ allow(definition).to(receive(:labels).and_return(Set.new))
313
+ allow(definition).to(receive(:<<).and_return(definition))
314
+ document.parse(input_lines)
315
+ end
316
+
317
+ context 'when defined variable' do
318
+ let(:input_lines) do
319
+ [
320
+ ':variable: one value',
321
+ '[define, requirement, TOTO-0001]',
322
+ 'bef {variable} aft'
323
+ ]
324
+ end
325
+
326
+ it { expect(document).to(have_attributes(variables: { variable: 'one value' })) }
327
+
328
+ it { expect(definition).to(have_received(:<<).with('bef one value aft')) }
329
+ end
330
+
331
+ context 'when not defined variable' do
332
+ let(:input_lines) do
333
+ [
334
+ '[define, requirement, TOTO-0001]',
335
+ 'bef {variable} aft'
336
+ ]
337
+ end
338
+
339
+ it { expect(definition).to(have_received(:<<).with('bef {variable} aft')) }
340
+ end
341
+
342
+ context 'when multiple defined variables' do
343
+ let(:input_lines) do
344
+ [
345
+ ':variable: one',
346
+ ':variable2: two',
347
+ '[define, requirement, TOTO-0001]',
348
+ 'bef {variable} {variable2} aft'
349
+ ]
350
+ end
351
+
352
+ it { expect(definition).to(have_received(:<<).with('bef one two aft')) }
353
+ end
354
+ end
355
+
356
+ context 'with invalid definitions' do
357
+ context 'when definition in literal block' do
358
+ let(:input_lines) do
359
+ [
360
+ '....',
361
+ '[define, requirement, TOTO-0001]',
362
+ '....'
363
+ ]
364
+ end
365
+
366
+ before do
367
+ allow(DefMastership::Definition).to(receive(:new)
368
+ .and_raise('not a valide definition'))
369
+ end
370
+
371
+ it do
372
+ document.parse(input_lines)
373
+ expect(document).to(have_attributes(definitions: []))
374
+ end
375
+ end
376
+
377
+ context 'when definition in comment block' do
378
+ let(:input_lines) do
379
+ [
380
+ '////',
381
+ '[define, requirement, TOTO-0001]',
382
+ '////'
383
+ ]
384
+ end
385
+
386
+ before do
387
+ allow(DefMastership::Definition).to(receive(:new)
388
+ .and_raise('not a valide definition'))
389
+ end
390
+
391
+ it do
392
+ document.parse(input_lines)
393
+ expect(document).to(have_attributes(definitions: []))
394
+ end
395
+ end
396
+ end
397
+ end
398
+ end