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
@@ -1,3 +1,4 @@
1
+ # Copyright (c) 2020 Jerome Arbez-Gindre
1
2
  # frozen_string_literal: true
2
3
 
3
4
  require('defmastership')
@@ -12,88 +13,112 @@ RSpec.describe(DefMastership::CSVFormatterHeader) do
12
13
  end
13
14
 
14
15
  describe '#header' do
15
- describe '#fixed_header' do
16
- it { expect(formatter.fixed_header).to(eq(%w[Type Reference Value])) }
16
+ describe '#fixed' do
17
+ it { expect(formatter.fixed).to(eq(%w[Type Reference Value sha256])) }
17
18
  end
18
19
 
19
- describe '#labels_header' do
20
+ describe '#wrong_explicit_checksum' do
21
+ context 'when no wrong explicit checksum' do
22
+ before do
23
+ allow(document).to(receive(:wrong_explicit_checksum?).and_return(false))
24
+ formatter.wrong_explicit_checksum
25
+ end
26
+
27
+ it { expect(document).to(have_received(:wrong_explicit_checksum?)) }
28
+
29
+ it { expect(formatter.wrong_explicit_checksum).to(eq([])) }
30
+ end
31
+
32
+ context 'when wrong explicit checksum' do
33
+ before do
34
+ allow(document).to(receive(:wrong_explicit_checksum?).and_return(true))
35
+ formatter.wrong_explicit_checksum
36
+ end
37
+
38
+ it { expect(formatter.wrong_explicit_checksum).to(eq(['Wrong explicit checksum'])) }
39
+ end
40
+ end
41
+
42
+ describe '#labels' do
20
43
  context 'when no labels' do
21
44
  before do
22
45
  allow(document).to(receive(:labels).and_return([]))
23
- formatter.labels_header
46
+ formatter.labels
24
47
  end
25
48
 
26
49
  it { expect(document).to(have_received(:labels)) }
27
50
 
28
- it { expect(formatter.labels_header).to(eq([])) }
51
+ it { expect(formatter.labels).to(eq([])) }
29
52
  end
30
53
 
31
54
  context 'when there is labels' do
32
55
  before { allow(document).to(receive(:labels).and_return(['Whatever'])) }
33
56
 
34
- it { expect(formatter.labels_header).to(eq(['Labels'])) }
57
+ it { expect(formatter.labels).to(eq(['Labels'])) }
35
58
  end
36
59
  end
37
60
 
38
- describe '#eref_header' do
61
+ describe '#eref' do
39
62
  context 'when no eref' do
40
63
  before do
41
64
  allow(document).to(receive(:eref).and_return({}))
42
- formatter.eref_header
65
+ formatter.eref
43
66
  end
44
67
 
45
68
  it { expect(document).to(have_received(:eref)) }
46
69
 
47
- it { expect(formatter.eref_header).to(eq([])) }
70
+ it { expect(formatter.eref).to(eq([])) }
48
71
  end
49
72
 
50
73
  context 'when eref' do
51
74
  before do
52
- allow(document).to(receive(:eref).and_return(
53
- whatever: { prefix: 'A' },
54
- other: { prefix: 'C', url: 'D' }
55
- ))
75
+ allow(document).to(
76
+ receive(:eref).and_return(
77
+ whatever: { prefix: 'A' },
78
+ other: { prefix: 'C', url: 'D' }
79
+ )
80
+ )
56
81
  end
57
82
 
58
- it { expect(formatter.eref_header).to(eq(['A', 'C D'])) }
83
+ it { expect(formatter.eref).to(eq(%w[A C])) }
59
84
  end
60
85
  end
61
86
 
62
- describe '#iref_header' do
87
+ describe '#iref' do
63
88
  context 'when no iref' do
64
89
  before do
65
90
  allow(document).to(receive(:iref).and_return(false))
66
- formatter.iref_header
91
+ formatter.iref
67
92
  end
68
93
 
69
94
  it { expect(document).to(have_received(:iref)) }
70
95
 
71
- it { expect(formatter.iref_header).to(eq([])) }
96
+ it { expect(formatter.iref).to(eq([])) }
72
97
  end
73
98
 
74
99
  context 'when iref' do
75
100
  before { allow(document).to(receive(:iref).and_return(true)) }
76
101
 
77
- it { expect(formatter.iref_header).to(eq(['Internal links'])) }
102
+ it { expect(formatter.iref).to(eq(['Internal links'])) }
78
103
  end
79
104
  end
80
105
 
81
- describe '#attributes_header' do
106
+ describe '#attributes' do
82
107
  context 'when no attributes' do
83
108
  before do
84
109
  allow(document).to(receive(:attributes).and_return({}))
85
- formatter.attributes_header
110
+ formatter.attributes
86
111
  end
87
112
 
88
113
  it { expect(document).to(have_received(:attributes)) }
89
114
 
90
- it { expect(formatter.attributes_header).to(eq([])) }
115
+ it { expect(formatter.attributes).to(eq([])) }
91
116
  end
92
117
 
93
118
  context 'when attributes' do
94
119
  before { allow(document).to(receive(:attributes).and_return(whatever: 'A', other: 'B')) }
95
120
 
96
- it { expect(formatter.attributes_header).to(eq(%w[A B])) }
121
+ it { expect(formatter.attributes).to(eq(%w[A B])) }
97
122
  end
98
123
  end
99
124
  end
@@ -1,10 +1,12 @@
1
+ # Copyright (c) 2020 Jerome Arbez-Gindre
1
2
  # frozen_string_literal: true
2
3
 
3
4
  require('defmastership')
4
5
  require('ostruct')
6
+ require('csv')
5
7
 
6
8
  RSpec.describe(DefMastership::CSVFormatter) do
7
- subject(:formatter) { described_class.new(document) }
9
+ subject(:formatter) { described_class.new(document, ';') }
8
10
 
9
11
  let(:document) { instance_double(DefMastership::Document, 'document') }
10
12
 
@@ -12,130 +14,93 @@ RSpec.describe(DefMastership::CSVFormatter) do
12
14
  it { is_expected.not_to(be(nil)) }
13
15
  end
14
16
 
15
- describe '#header' do
16
- 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]
17
24
  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
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')
23
37
  end
24
38
 
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)) }
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
32
44
 
33
- it { expect(formatter.header).to(eq(%w[Type Reference Value])) }
34
- end
45
+ it do
46
+ expect(csv).to(have_received(:<<).with(methods1.map { |method| "#{method} header" }))
47
+ end
35
48
 
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
+ it do
50
+ expect(csv).to(have_received(:<<).with(methods1.map { |method| "#{method} def1 body" }))
49
51
  end
50
52
 
51
53
  it do
52
- expect(formatter.header).to(eq(%w[Type Reference Value Labels] +
53
- ['A', 'C D', 'Internal links'] +
54
- %w[E F]))
54
+ expect(csv).to(have_received(:<<).with(methods1.map { |method| "#{method} def2 body" }))
55
55
  end
56
56
  end
57
- end
58
57
 
59
- describe '#body' do
60
- 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') }
61
62
 
62
- context 'when minimal' do
63
+ methods2 = %i[fixed labels eref iref attributes]
63
64
  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)
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')
72
77
  end
73
78
 
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)
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)) }
113
83
  end
114
84
 
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)) }
85
+ it do
86
+ expect(csv).to(have_received(:<<).with(methods2.map { |method| "#{method} header" }))
87
+ end
120
88
 
121
- 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
122
92
 
123
93
  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']))
94
+ expect(csv).to(have_received(:<<).with(methods2.map { |method| "#{method} def2 body" }))
128
95
  end
129
96
  end
130
- end
131
97
 
132
- describe '#export_to' do
133
98
  context 'when #export_to csv file' do
134
99
  let(:target_file) { 'export.csv' }
135
100
  let(:definitions) do
136
101
  [
137
- OpenStruct.new(type: 'a', reference: 'b', value: 'c'),
138
- 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')
139
104
  ]
140
105
  end
141
106
 
@@ -146,24 +111,21 @@ RSpec.describe(DefMastership::CSVFormatter) do
146
111
  allow(document).to(receive(:iref).exactly(3).times.with(no_args).and_return(false))
147
112
  allow(document).to(receive(:attributes).exactly(3).times.with(no_args).and_return({}))
148
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))
149
115
  formatter.export_to("#{aruba.current_directory}/#{target_file}")
150
116
  end
151
117
 
152
118
  it { expect(document).to(have_received(:labels).exactly(3).times.with(no_args)) }
153
-
154
119
  it { expect(document).to(have_received(:eref).exactly(3).times.with(no_args)) }
155
-
156
120
  it { expect(document).to(have_received(:iref).exactly(3).times.with(no_args)) }
157
-
158
121
  it { expect(document).to(have_received(:attributes).exactly(3).times.with(no_args)) }
159
-
160
122
  it { expect(document).to(have_received(:definitions).with(no_args)) }
161
123
 
162
124
  it do
163
125
  expect(target_file).to(have_file_content(<<~CSV_FILE))
164
- Type,Reference,Value
165
- a,b,c
166
- d,e,f
126
+ Type;Reference;Value;sha256
127
+ a;b;c;d
128
+ d;e;f;g
167
129
  CSV_FILE
168
130
  end
169
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
@@ -1,10 +1,11 @@
1
+ # Copyright (c) 2020 Jerome Arbez-Gindre
1
2
  # frozen_string_literal: true
2
3
 
3
4
  require('defmastership')
4
5
 
5
6
  RSpec.describe(DefMastership::Definition) do
6
7
  describe '.new' do
7
- context 'without labels' do
8
+ context 'when minimal' do
8
9
  subject do
9
10
  described_class.new(
10
11
  type: 'req',
@@ -21,12 +22,13 @@ RSpec.describe(DefMastership::Definition) do
21
22
  it { is_expected.to(have_attributes(iref: [])) }
22
23
  it { is_expected.to(have_attributes(attributes: {})) }
23
24
  it { is_expected.to(have_attributes(labels: Set.new)) }
25
+ it { is_expected.to(have_attributes(wrong_explicit_checksum: nil)) }
24
26
  end
25
27
 
26
28
  context 'with labels' do
27
29
  subject do
28
30
  described_class.new(
29
- gtype: 'req',
31
+ type: 'req',
30
32
  reference: 'TUTU-001',
31
33
  labels: 'something'
32
34
  )
@@ -34,6 +36,26 @@ RSpec.describe(DefMastership::Definition) do
34
36
 
35
37
  it { is_expected.to(have_attributes(labels: Set['something'])) }
36
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
37
59
  end
38
60
 
39
61
  describe '#<<' do
@@ -49,7 +71,7 @@ RSpec.describe(DefMastership::Definition) do
49
71
  expect(definition.value).to(eq('first line'))
50
72
  end
51
73
 
52
- it 'store line when added' do
74
+ it 'stores line when added' do
53
75
  definition << 'first line'
54
76
  expect(definition.lines).to(eq(['first line']))
55
77
  end
@@ -59,10 +81,15 @@ RSpec.describe(DefMastership::Definition) do
59
81
  expect(definition.value).to(eq("first line\nsecond line"))
60
82
  end
61
83
 
62
- it 'store each line when added' do
84
+ it 'stores each line when added' do
63
85
  definition << 'first line' << 'second line'
64
86
  expect(definition.lines).to(eq(['first line', 'second line']))
65
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
66
93
  end
67
94
 
68
95
  describe '#add_eref' do