defmastership 1.0.5 → 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 (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
@@ -3,6 +3,7 @@
3
3
 
4
4
  require('defmastership')
5
5
  require('ostruct')
6
+ require('csv')
6
7
 
7
8
  RSpec.describe(DefMastership::CSVFormatter) do
8
9
  subject(:formatter) { described_class.new(document, ';') }
@@ -13,130 +14,93 @@ RSpec.describe(DefMastership::CSVFormatter) do
13
14
  it { is_expected.not_to(be(nil)) }
14
15
  end
15
16
 
16
- describe '#header' do
17
- context 'when minimal' do
17
+ describe '#export_to' do
18
+ context 'when wrong explicit checksum' do
19
+ let(:header) { instance_double(DefMastership::CSVFormatterHeader, 'header') }
20
+ let(:body) { instance_double(DefMastership::CSVFormatterBody, 'body') }
21
+ let(:csv) { instance_double(CSV, 'csv') }
22
+
23
+ methods1 = %i[fixed wrong_explicit_checksum labels eref iref attributes]
18
24
  before do
19
- allow(document).to(receive(:labels).with(no_args).and_return([]))
20
- allow(document).to(receive(:eref).with(no_args).and_return({}))
21
- allow(document).to(receive(:iref).with(no_args).and_return(false))
22
- allow(document).to(receive(:attributes).with(no_args).and_return({}))
23
- formatter.header
25
+ allow(CSV).to(receive(:open).and_yield(csv))
26
+ allow(csv).to(receive(:<<))
27
+ allow(DefMastership::CSVFormatterHeader).to(receive(:new).with(document).and_return(header))
28
+ allow(DefMastership::CSVFormatterBody).to(receive(:new).with(document).and_return(body))
29
+ allow(document).to(receive(:definitions).and_return(%i[def1 def2]))
30
+ allow(document).to(receive(:wrong_explicit_checksum?).with(no_args).and_return(true))
31
+ methods1.each do |method|
32
+ allow(header).to(receive(method).with(no_args).and_return(["#{method} header"]))
33
+ allow(body).to(receive(method).with(:def1).and_return(["#{method} def1 body"]))
34
+ allow(body).to(receive(method).with(:def2).and_return(["#{method} def2 body"]))
35
+ end
36
+ formatter.export_to('whatever')
24
37
  end
25
38
 
26
- it { expect(document).to(have_received(:labels).with(no_args)) }
27
-
28
- it { expect(document).to(have_received(:eref).with(no_args)) }
29
-
30
- it { expect(document).to(have_received(:iref).with(no_args)) }
31
-
32
- it { expect(document).to(have_received(:attributes).with(no_args)) }
39
+ methods1.each do |method|
40
+ it { expect(header).to(have_received(method).with(no_args)) }
41
+ it { expect(body).to(have_received(method).with(:def1)) }
42
+ it { expect(body).to(have_received(method).with(:def2)) }
43
+ end
33
44
 
34
- it { expect(formatter.header).to(eq(%w[Type Reference Value])) }
35
- end
45
+ it do
46
+ expect(csv).to(have_received(:<<).with(methods1.map { |method| "#{method} header" }))
47
+ end
36
48
 
37
- context 'when has everything' do
38
- before do
39
- allow(document).to(receive(:labels)
40
- .with(no_args)
41
- .and_return(['Whatever']))
42
- allow(document).to(receive(:eref)
43
- .with(no_args)
44
- .and_return(whatever: { prefix: 'A' },
45
- other: { prefix: 'C', url: 'D' }))
46
- allow(document).to(receive(:iref).with(no_args).and_return(true))
47
- allow(document).to(receive(:attributes)
48
- .with(no_args)
49
- .and_return(whatever: 'E', other: 'F'))
49
+ it do
50
+ expect(csv).to(have_received(:<<).with(methods1.map { |method| "#{method} def1 body" }))
50
51
  end
51
52
 
52
53
  it do
53
- expect(formatter.header).to(eq(%w[Type Reference Value Labels] +
54
- ['A', 'C D', 'Internal links'] +
55
- %w[E F]))
54
+ expect(csv).to(have_received(:<<).with(methods1.map { |method| "#{method} def2 body" }))
56
55
  end
57
56
  end
58
- end
59
57
 
60
- describe '#body' do
61
- let(:definition) { instance_double(DefMastership::Definition, 'definition') }
58
+ context 'when no wrong explicit checksum' do
59
+ let(:header) { instance_double(DefMastership::CSVFormatterHeader, 'header') }
60
+ let(:body) { instance_double(DefMastership::CSVFormatterBody, 'body') }
61
+ let(:csv) { instance_double(CSV, 'csv') }
62
62
 
63
- context 'when minimal' do
63
+ methods2 = %i[fixed labels eref iref attributes]
64
64
  before do
65
- allow(document).to(receive(:labels).with(no_args).and_return([]))
66
- allow(document).to(receive(:eref).with(no_args).and_return({}))
67
- allow(document).to(receive(:iref).with(no_args).and_return(false))
68
- allow(document).to(receive(:attributes).with(no_args).and_return({}))
69
- allow(definition).to(receive(:type).with(no_args).and_return('a'))
70
- allow(definition).to(receive(:reference).with(no_args).and_return('b'))
71
- allow(definition).to(receive(:value).with(no_args).and_return('c'))
72
- formatter.body(definition)
65
+ allow(CSV).to(receive(:open).and_yield(csv))
66
+ allow(csv).to(receive(:<<))
67
+ allow(DefMastership::CSVFormatterHeader).to(receive(:new).with(document).and_return(header))
68
+ allow(DefMastership::CSVFormatterBody).to(receive(:new).with(document).and_return(body))
69
+ allow(document).to(receive(:definitions).and_return(%i[def1 def2]))
70
+ allow(document).to(receive(:wrong_explicit_checksum?).with(no_args).and_return(false))
71
+ methods2.each do |method|
72
+ allow(header).to(receive(method).with(no_args).and_return(["#{method} header"]))
73
+ allow(body).to(receive(method).with(:def1).and_return(["#{method} def1 body"]))
74
+ allow(body).to(receive(method).with(:def2).and_return(["#{method} def2 body"]))
75
+ end
76
+ formatter.export_to('whatever')
73
77
  end
74
78
 
75
- it { expect(document).to(have_received(:labels).with(no_args)) }
76
-
77
- it { expect(document).to(have_received(:eref).with(no_args)) }
78
-
79
- it { expect(document).to(have_received(:iref).with(no_args)) }
80
-
81
- it { expect(document).to(have_received(:attributes).with(no_args)) }
82
-
83
- it { expect(definition).to(have_received(:type).with(no_args)) }
84
-
85
- it { expect(definition).to(have_received(:reference).with(no_args)) }
86
-
87
- it { expect(definition).to(have_received(:value).with(no_args)) }
88
-
89
- it { expect(formatter.body(definition)).to(eq(%w[a b c])) }
90
- end
91
-
92
- context 'when has everything' do
93
- before do
94
- allow(document).to(receive(:labels).with(no_args).and_return(['Whatever']))
95
- allow(document).to(receive(:eref).with(no_args).and_return(
96
- a: 'whatever',
97
- b: 'whatever',
98
- c: 'whatever'
99
- ))
100
- allow(document).to(receive(:iref).with(no_args).and_return(true))
101
- allow(document).to(receive(:attributes).with(no_args).and_return(
102
- a: 'whatever',
103
- b: 'whatever',
104
- c: 'whatever'
105
- ))
106
- allow(definition).to(receive(:type).with(no_args).and_return('a'))
107
- allow(definition).to(receive(:reference).with(no_args).and_return('b'))
108
- allow(definition).to(receive(:value).with(no_args).and_return('c'))
109
- allow(definition).to(receive(:labels).with(no_args).and_return(%w[toto tutu]))
110
- allow(definition).to(receive(:eref).with(no_args).and_return(a: %w[A B], b: [], c: ['C']))
111
- allow(definition).to(receive(:iref).with(no_args).and_return(%w[E F]))
112
- allow(definition).to(receive(:attributes).with(no_args).and_return(a: 'X', b: '', c: 'Y'))
113
- formatter.body(definition)
79
+ methods2.each do |method|
80
+ it { expect(header).to(have_received(method).with(no_args)) }
81
+ it { expect(body).to(have_received(method).with(:def1)) }
82
+ it { expect(body).to(have_received(method).with(:def2)) }
114
83
  end
115
84
 
116
- it { expect(definition).to(have_received(:labels).with(no_args)) }
117
-
118
- it { expect(definition).to(have_received(:eref).exactly(3).times.with(no_args)) }
119
-
120
- it { expect(definition).to(have_received(:iref).with(no_args)) }
85
+ it do
86
+ expect(csv).to(have_received(:<<).with(methods2.map { |method| "#{method} header" }))
87
+ end
121
88
 
122
- it { expect(definition).to(have_received(:attributes).exactly(3).times.with(no_args)) }
89
+ it do
90
+ expect(csv).to(have_received(:<<).with(methods2.map { |method| "#{method} def1 body" }))
91
+ end
123
92
 
124
93
  it do
125
- expect(formatter.body(definition)).to(eq(%w[a b c] + ["toto\ntutu"] +
126
- ["A\nB", '', 'C'] +
127
- ["E\nF"] +
128
- ['X', '', 'Y']))
94
+ expect(csv).to(have_received(:<<).with(methods2.map { |method| "#{method} def2 body" }))
129
95
  end
130
96
  end
131
- end
132
97
 
133
- describe '#export_to' do
134
98
  context 'when #export_to csv file' do
135
99
  let(:target_file) { 'export.csv' }
136
100
  let(:definitions) do
137
101
  [
138
- OpenStruct.new(type: 'a', reference: 'b', value: 'c'),
139
- OpenStruct.new(type: 'd', reference: 'e', value: 'f')
102
+ OpenStruct.new(type: 'a', reference: 'b', value: 'c', sha256: 'd'),
103
+ OpenStruct.new(type: 'd', reference: 'e', value: 'f', sha256: 'g')
140
104
  ]
141
105
  end
142
106
 
@@ -147,24 +111,21 @@ RSpec.describe(DefMastership::CSVFormatter) do
147
111
  allow(document).to(receive(:iref).exactly(3).times.with(no_args).and_return(false))
148
112
  allow(document).to(receive(:attributes).exactly(3).times.with(no_args).and_return({}))
149
113
  allow(document).to(receive(:definitions).with(no_args).and_return(definitions))
114
+ allow(document).to(receive(:wrong_explicit_checksum?).with(no_args).and_return(false))
150
115
  formatter.export_to("#{aruba.current_directory}/#{target_file}")
151
116
  end
152
117
 
153
118
  it { expect(document).to(have_received(:labels).exactly(3).times.with(no_args)) }
154
-
155
119
  it { expect(document).to(have_received(:eref).exactly(3).times.with(no_args)) }
156
-
157
120
  it { expect(document).to(have_received(:iref).exactly(3).times.with(no_args)) }
158
-
159
121
  it { expect(document).to(have_received(:attributes).exactly(3).times.with(no_args)) }
160
-
161
122
  it { expect(document).to(have_received(:definitions).with(no_args)) }
162
123
 
163
124
  it do
164
125
  expect(target_file).to(have_file_content(<<~CSV_FILE))
165
- Type;Reference;Value
166
- a;b;c
167
- d;e;f
126
+ Type;Reference;Value;sha256
127
+ a;b;c;d
128
+ d;e;f;g
168
129
  CSV_FILE
169
130
  end
170
131
  end
@@ -0,0 +1,63 @@
1
+ # Copyright (c) 2020 Jerome Arbez-Gindre
2
+ # frozen_string_literal: true
3
+
4
+ require('defmastership')
5
+
6
+ RSpec.describe(DefMastership::DefinitionParser) do
7
+ subject(:parser) { described_class.new(callback_object) }
8
+
9
+ let(:callback_object) { instance_double('callback_object') }
10
+
11
+ before do
12
+ allow(callback_object).to(receive(:add_new_definition).with(any_args))
13
+ allow(callback_object).to(receive(:add_line).with(any_args))
14
+ end
15
+
16
+ describe 'transitions' do
17
+ it { is_expected.to(have_state(:idle)) }
18
+
19
+ it { is_expected.to(transition_from(:idle).to(:wait_content).on_event(:new_definition, :whatever)) }
20
+
21
+ it { is_expected.to(transition_from(:wait_content).to(:in_block).on_event(:block_delimiter, :whatever)) }
22
+ it { is_expected.to(transition_from(:in_block).to(:idle).on_event(:block_delimiter, :whatever)) }
23
+ it { is_expected.to(transition_from(:idle).to(:idle).on_event(:block_delimiter, :whatever)) }
24
+ it { is_expected.to(transition_from(:single_para).to(:idle).on_event(:block_delimiter, :whatever)) }
25
+
26
+ it { is_expected.to(transition_from(:wait_content).to(:single_para).on_event(:new_line, :whatever)) }
27
+ it { is_expected.to(transition_from(:single_para).to(:single_para).on_event(:new_line, :whatever)) }
28
+ it { is_expected.to(transition_from(:in_block).to(:in_block).on_event(:new_line, :whatever)) }
29
+ it { is_expected.to(transition_from(:idle).to(:idle).on_event(:new_line, :whatever)) }
30
+
31
+ it { is_expected.to(transition_from(:wait_content).to(:idle).on_event(:empty_line, :whatever)) }
32
+ it { is_expected.to(transition_from(:single_para).to(:idle).on_event(:empty_line, :whatever)) }
33
+ it { is_expected.to(transition_from(:idle).to(:idle).on_event(:empty_line, :whatever)) }
34
+ it { is_expected.to(transition_from(:in_block).to(:in_block).on_event(:empty_line, :whatever)) }
35
+ end
36
+
37
+ describe 'actions' do
38
+ it do
39
+ parser.new_definition(:whatever)
40
+ expect(callback_object).to(have_received(:add_new_definition).with(:whatever))
41
+ end
42
+
43
+ it do
44
+ parser.new_definition(:whatever)
45
+ parser.new_line(:other_whatever)
46
+ expect(callback_object).to(have_received(:add_line).with(:other_whatever))
47
+ end
48
+
49
+ it do
50
+ parser.new_definition(:whatever)
51
+ parser.new_line(:other_whatever)
52
+ parser.new_line(:other_whatever2)
53
+ expect(callback_object).to(have_received(:add_line).with(:other_whatever2))
54
+ end
55
+
56
+ it do
57
+ parser.new_definition(:whatever)
58
+ parser.block_delimiter(:other_whatever)
59
+ parser.new_line(:other_whatever2)
60
+ expect(callback_object).to(have_received(:add_line).with(:other_whatever2))
61
+ end
62
+ end
63
+ end
@@ -5,7 +5,7 @@ require('defmastership')
5
5
 
6
6
  RSpec.describe(DefMastership::Definition) do
7
7
  describe '.new' do
8
- context 'without labels' do
8
+ context 'when minimal' do
9
9
  subject do
10
10
  described_class.new(
11
11
  type: 'req',
@@ -22,12 +22,13 @@ RSpec.describe(DefMastership::Definition) do
22
22
  it { is_expected.to(have_attributes(iref: [])) }
23
23
  it { is_expected.to(have_attributes(attributes: {})) }
24
24
  it { is_expected.to(have_attributes(labels: Set.new)) }
25
+ it { is_expected.to(have_attributes(wrong_explicit_checksum: nil)) }
25
26
  end
26
27
 
27
28
  context 'with labels' do
28
29
  subject do
29
30
  described_class.new(
30
- gtype: 'req',
31
+ type: 'req',
31
32
  reference: 'TUTU-001',
32
33
  labels: 'something'
33
34
  )
@@ -35,6 +36,26 @@ RSpec.describe(DefMastership::Definition) do
35
36
 
36
37
  it { is_expected.to(have_attributes(labels: Set['something'])) }
37
38
  end
39
+
40
+ context 'with explicit_checksum' do
41
+ subject(:definition) do
42
+ described_class.new(
43
+ type: 'req',
44
+ reference: 'TUTU-001',
45
+ explicit_checksum: '8cc259e6'
46
+ )
47
+ end
48
+
49
+ it do
50
+ definition << 'def value with a checksum != 8cc259e6'
51
+ expect(definition).to(have_attributes(wrong_explicit_checksum: '8cc259e6'))
52
+ end
53
+
54
+ it do
55
+ definition << 'def value with a good checksum'
56
+ expect(definition).to(have_attributes(wrong_explicit_checksum: nil))
57
+ end
58
+ end
38
59
  end
39
60
 
40
61
  describe '#<<' do
@@ -50,7 +71,7 @@ RSpec.describe(DefMastership::Definition) do
50
71
  expect(definition.value).to(eq('first line'))
51
72
  end
52
73
 
53
- it 'store line when added' do
74
+ it 'stores line when added' do
54
75
  definition << 'first line'
55
76
  expect(definition.lines).to(eq(['first line']))
56
77
  end
@@ -60,10 +81,15 @@ RSpec.describe(DefMastership::Definition) do
60
81
  expect(definition.value).to(eq("first line\nsecond line"))
61
82
  end
62
83
 
63
- it 'store each line when added' do
84
+ it 'stores each line when added' do
64
85
  definition << 'first line' << 'second line'
65
86
  expect(definition.lines).to(eq(['first line', 'second line']))
66
87
  end
88
+
89
+ it 'calculates sha256 of value' do
90
+ definition << 'first line' << 'second line'
91
+ expect(definition.sha256).to(eq('beb0535a'))
92
+ end
67
93
  end
68
94
 
69
95
  describe '#add_eref' do
@@ -4,6 +4,8 @@
4
4
  require('defmastership')
5
5
 
6
6
  RSpec.describe(DefMastership::Document) do
7
+ subject(:document) { described_class.new }
8
+
7
9
  describe '.new' do
8
10
  it { is_expected.not_to(be(nil)) }
9
11
  it { is_expected.to(have_attributes(definitions: [])) }
@@ -14,8 +16,6 @@ RSpec.describe(DefMastership::Document) do
14
16
  end
15
17
 
16
18
  describe '#parse' do
17
- subject(:document) { described_class.new }
18
-
19
19
  context 'with valid definitions' do
20
20
  let(:definition) { instance_double(DefMastership::Definition, 'definition') }
21
21
 
@@ -31,22 +31,45 @@ RSpec.describe(DefMastership::Document) do
31
31
  let(:input_lines) { ['[define, requirement, TOTO-0001]'] }
32
32
 
33
33
  before do
34
- allow(DefMastership::Definition).to(receive(:new).with(
35
- matchdata_including(
36
- type: 'requirement',
37
- reference: 'TOTO-0001'
38
- )
39
- ).and_return(definition))
34
+ allow(DefMastership::Definition).to(
35
+ receive(:new).with(
36
+ matchdata_including(type: 'requirement', reference: 'TOTO-0001')
37
+ ).and_return(definition)
38
+ )
40
39
  document.parse(input_lines)
41
40
  end
42
41
 
43
42
  it do
44
- expect(DefMastership::Definition).to(have_received(:new).with(
45
- matchdata_including(type: 'requirement', reference: 'TOTO-0001')
46
- ))
43
+ expect(DefMastership::Definition).to(
44
+ have_received(:new).with(
45
+ matchdata_including(type: 'requirement', reference: 'TOTO-0001')
46
+ )
47
+ )
47
48
  end
48
49
 
49
50
  it { expect(document).to(have_attributes(definitions: [definition])) }
51
+ it { expect(definition).to(have_received(:labels)) }
52
+ end
53
+
54
+ context 'when simple definition line with explicit checksum' do
55
+ let(:input_lines) { ['[define, requirement, TOTO-0001(ab12)]'] }
56
+
57
+ before do
58
+ allow(DefMastership::Definition).to(
59
+ receive(:new).with(
60
+ matchdata_including(type: 'requirement', reference: 'TOTO-0001', explicit_checksum: 'ab12')
61
+ ).and_return(definition)
62
+ )
63
+ document.parse(input_lines)
64
+ end
65
+
66
+ it do
67
+ expect(DefMastership::Definition).to(
68
+ have_received(:new).with(
69
+ matchdata_including(type: 'requirement', reference: 'TOTO-0001', explicit_checksum: 'ab12')
70
+ )
71
+ )
72
+ end
50
73
  end
51
74
 
52
75
  context 'when complete definition with content' do
@@ -133,11 +156,11 @@ RSpec.describe(DefMastership::Document) do
133
156
  end
134
157
 
135
158
  it do
136
- expect(DefMastership::Definition).to(have_received(:new).with(matchdata_including(
137
- type: 'requirement',
138
- reference: 'TOTO-0001',
139
- labels: 'label1, label2'
140
- )))
159
+ expect(DefMastership::Definition).to(
160
+ have_received(:new).with(
161
+ matchdata_including(type: 'requirement', reference: 'TOTO-0001', labels: 'label1, label2')
162
+ )
163
+ )
141
164
  end
142
165
 
143
166
  it { expect(document.labels).to(eq(Set['bla1', 'bla2'])) }
@@ -158,11 +181,11 @@ RSpec.describe(DefMastership::Document) do
158
181
  end
159
182
 
160
183
  it do
161
- expect(DefMastership::Definition).to(have_received(:new).with(matchdata_including(
162
- type: 'requirement',
163
- reference: 'TOTO-0001',
164
- labels: 'label1,label2'
165
- )))
184
+ expect(DefMastership::Definition).to(
185
+ have_received(:new).with(
186
+ matchdata_including(type: 'requirement', reference: 'TOTO-0001', labels: 'label1,label2')
187
+ )
188
+ )
166
189
  end
167
190
 
168
191
  it { expect(document.labels).to(eq(Set['bla1', 'bla2'])) }
@@ -209,8 +232,10 @@ RSpec.describe(DefMastership::Document) do
209
232
  end
210
233
 
211
234
  before do
212
- allow(definition).to(receive(:add_eref).with(:implements, 'SYSTEM-0012, SYSTEM-0014')
213
- .and_return(definition))
235
+ allow(definition).to(
236
+ receive(:add_eref).with(:implements, 'SYSTEM-0012, SYSTEM-0014')
237
+ .and_return(definition)
238
+ )
214
239
  document.parse(input_lines)
215
240
  end
216
241
 
@@ -289,18 +314,20 @@ RSpec.describe(DefMastership::Document) do
289
314
  end
290
315
 
291
316
  before do
292
- allow(DefMastership::Definition).to(receive(:new).with(matchdata_including(
293
- type: 'requirement',
294
- reference: 'TOTO-0001'
295
- )).and_return(definition))
317
+ allow(DefMastership::Definition).to(
318
+ receive(:new).with(
319
+ matchdata_including(type: 'requirement', reference: 'TOTO-0001')
320
+ ).and_return(definition)
321
+ )
296
322
  document.parse(input_lines)
297
323
  end
298
324
 
299
325
  it do
300
- expect(DefMastership::Definition).to(have_received(:new).with(matchdata_including(
301
- type: 'requirement',
302
- reference: 'TOTO-0001'
303
- )))
326
+ expect(DefMastership::Definition).to(
327
+ have_received(:new).with(
328
+ matchdata_including(type: 'requirement', reference: 'TOTO-0001')
329
+ )
330
+ )
304
331
  end
305
332
  end
306
333
  end
@@ -365,8 +392,9 @@ RSpec.describe(DefMastership::Document) do
365
392
  end
366
393
 
367
394
  before do
368
- allow(DefMastership::Definition).to(receive(:new)
369
- .and_raise('not a valide definition'))
395
+ allow(DefMastership::Definition).to(
396
+ receive(:new).and_raise('not a valide definition')
397
+ )
370
398
  end
371
399
 
372
400
  it do
@@ -385,8 +413,9 @@ RSpec.describe(DefMastership::Document) do
385
413
  end
386
414
 
387
415
  before do
388
- allow(DefMastership::Definition).to(receive(:new)
389
- .and_raise('not a valide definition'))
416
+ allow(DefMastership::Definition).to(
417
+ receive(:new).and_raise('not a valide definition')
418
+ )
390
419
  end
391
420
 
392
421
  it do
@@ -396,4 +425,52 @@ RSpec.describe(DefMastership::Document) do
396
425
  end
397
426
  end
398
427
  end
428
+
429
+ describe '#wrong_explicit_checksum?' do
430
+ subject(:document) { described_class.new }
431
+
432
+ let(:def1) { instance_double(DefMastership::Definition, 'definition') }
433
+ let(:def2) { instance_double(DefMastership::Definition, 'definition') }
434
+ let(:input_lines) do
435
+ [
436
+ '[define, requirement, TOTO-0001]',
437
+ 'def one',
438
+ '',
439
+ '[define, requirement, TOTO-0002]',
440
+ 'def two'
441
+ ]
442
+ end
443
+
444
+ before do
445
+ allow(DefMastership::Definition).to(receive(:new).twice.and_return(def1, def2))
446
+ allow(def1).to(receive(:labels)).and_return([])
447
+ allow(def2).to(receive(:labels)).and_return([])
448
+ allow(def1).to(receive(:<<).and_return(def1))
449
+ allow(def2).to(receive(:<<).and_return(def2))
450
+ end
451
+
452
+ context 'when no wrong explicit checksum' do
453
+ before do
454
+ allow(def1).to(receive(:wrong_explicit_checksum)).and_return(nil)
455
+ allow(def2).to(receive(:wrong_explicit_checksum)).and_return(nil)
456
+ document.parse(input_lines)
457
+ document.wrong_explicit_checksum?
458
+ end
459
+
460
+ it { expect(def1).to(have_received(:wrong_explicit_checksum)) }
461
+ it { expect(def2).to(have_received(:wrong_explicit_checksum)) }
462
+ it { expect(document.wrong_explicit_checksum?).to(eq(false)) }
463
+ end
464
+
465
+ context 'when one req has wrong explicit checksum' do
466
+ before do
467
+ allow(def1).to(receive(:wrong_explicit_checksum)).and_return(nil)
468
+ allow(def2).to(receive(:wrong_explicit_checksum)).and_return('toto')
469
+ document.parse(input_lines)
470
+ document.wrong_explicit_checksum?
471
+ end
472
+
473
+ it { expect(document.wrong_explicit_checksum?).to(eq(true)) }
474
+ end
475
+ end
399
476
  end