defmastership 1.0.7 → 1.0.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -19,8 +19,13 @@ module DefMastership
19
19
  wrong_explicit_checksum ? [wrong_explicit_checksum] : ['']
20
20
  end
21
21
 
22
+ def explicit_version(definition)
23
+ explicit_version = definition.explicit_version
24
+ explicit_version ? [explicit_version] : ['']
25
+ end
26
+
22
27
  def labels(definition)
23
- @doc.labels.empty? ? [] : [definition.labels.to_a.join("\n")]
28
+ [definition.labels.to_a.join("\n")]
24
29
  end
25
30
 
26
31
  def eref(definition)
@@ -28,13 +33,11 @@ module DefMastership
28
33
  end
29
34
 
30
35
  def iref(definition)
31
- @doc.iref ? [definition.iref.join("\n")] : []
36
+ [definition.iref.join("\n")]
32
37
  end
33
38
 
34
39
  def attributes(definition)
35
- @doc.attributes.map do |key, _|
36
- definition.attributes[key]
37
- end
40
+ @doc.attributes.map { |key, _| definition.attributes[key] }
38
41
  end
39
42
  end
40
43
  end
@@ -11,13 +11,17 @@ module DefMastership
11
11
  end
12
12
 
13
13
  def fixed
14
- %w[Type Reference Value sha256]
14
+ %w[Type Reference Value Checksum]
15
15
  end
16
16
 
17
17
  def wrong_explicit_checksum
18
18
  @doc.wrong_explicit_checksum? ? ['Wrong explicit checksum'] : []
19
19
  end
20
20
 
21
+ def explicit_version
22
+ @doc.explicit_version? ? ['Version'] : []
23
+ end
24
+
21
25
  def labels
22
26
  @doc.labels.empty? ? [] : %w[Labels]
23
27
  end
@@ -6,19 +6,19 @@ require 'digest'
6
6
  module DefMastership
7
7
  # DefMastership definition: contains all data of a definition
8
8
  class Definition
9
- attr_reader :type, :reference, :lines, :labels, :eref, :iref, :attributes
9
+ attr_reader :type, :reference, :lines, :labels, :eref, :iref, :attributes, :explicit_version
10
10
 
11
11
  def initialize(match)
12
12
  @type = match[:type]
13
13
  @reference = match[:reference]
14
14
  @lines = []
15
15
  @labels = Set.new
16
- labels = match[:labels]
17
- @labels.merge(labels.split(/\s*,\s*/).to_set) if labels
16
+ @labels.merge(match[:labels].split(/\s*,\s*/).to_set) if match[:labels]
18
17
  @eref = Hash.new([])
19
18
  @iref = []
20
19
  @attributes = {}
21
20
  @explicit_checksum = match[:explicit_checksum]
21
+ @explicit_version = match[:explicit_version]
22
22
  end
23
23
 
24
24
  def <<(new_line)
@@ -31,7 +31,7 @@ module DefMastership
31
31
  end
32
32
 
33
33
  def sha256
34
- Digest::SHA2.new(256).hexdigest(value).split(//).last(8).join
34
+ "~#{Digest::SHA2.new(256).hexdigest(value).split(//).last(8).join}"
35
35
  end
36
36
 
37
37
  def wrong_explicit_checksum
@@ -18,7 +18,6 @@ module DefMastership
18
18
  @attributes = {}
19
19
  @in_literal = true
20
20
  @variables = {}
21
-
22
21
  @definition_parser = DefinitionParser.new(self)
23
22
  end
24
23
 
@@ -44,6 +43,12 @@ module DefMastership
44
43
  end
45
44
  end
46
45
 
46
+ def explicit_version?
47
+ @definitions.reduce(false) do |res, definition|
48
+ res || !definition.explicit_version.nil?
49
+ end
50
+ end
51
+
47
52
  def code_block_delimiter(_match, line)
48
53
  @in_literal ^= true
49
54
  line
@@ -67,17 +72,12 @@ module DefMastership
67
72
 
68
73
  def new_eref_setup(match, line)
69
74
  @eref[match[:refname].to_sym] ||= {}
70
-
71
- @eref[match[:refname].to_sym][match[:symb].to_sym] =
72
- match[:value]
75
+ @eref[match[:refname].to_sym][match[:symb].to_sym] = match[:value]
73
76
  line
74
77
  end
75
78
 
76
79
  def new_eref_def(match, line)
77
- @definitions.last.add_eref(
78
- match[:refname].to_sym,
79
- match[:extrefs]
80
- )
80
+ @definitions.last.add_eref(match[:refname].to_sym, match[:extrefs])
81
81
  line
82
82
  end
83
83
 
@@ -95,10 +95,7 @@ module DefMastership
95
95
  end
96
96
 
97
97
  def new_attribute_value(match, line)
98
- @definitions.last.set_attribute(
99
- match[:attr].to_sym,
100
- match[:value]
101
- )
98
+ @definitions.last.set_attribute(match[:attr].to_sym, match[:value])
102
99
  line
103
100
  end
104
101
 
@@ -108,14 +105,13 @@ module DefMastership
108
105
  end
109
106
 
110
107
  def new_variable_use(_match, line)
111
- new_line = line.dup
112
108
  line.scan(DMRegexp::VARIABLE_USE) do |_|
113
109
  varname = Regexp.last_match[:varname]
114
110
  next if @variables[varname.to_sym].nil?
115
111
 
116
- new_line.gsub!("{#{varname}}", @variables[varname.to_sym])
112
+ line = line.gsub("{#{varname}}", @variables[varname.to_sym])
117
113
  end
118
- new_line
114
+ line
119
115
  end
120
116
 
121
117
  private
@@ -2,6 +2,6 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module DefMastership
5
- VERSION = '1.0.7'
5
+ VERSION = '1.0.8'
6
6
  public_constant :VERSION
7
7
  end
@@ -111,5 +111,13 @@ RSpec.describe(DefMastership::BatchModifier) do
111
111
  it { is_expected.to(have_attributes(config: config_modified)) }
112
112
  it { is_expected.to(have_attributes(changes: [%w[modifier2 from1 to1], %w[modifier3 from2 to2]])) }
113
113
  end
114
+
115
+ context 'with wrong modification' do
116
+ it do
117
+ expect { batchmodifier.apply('wrong-modification') }.to(
118
+ raise_error(ArgumentError, 'wrong-modification is not a known modification')
119
+ )
120
+ end
121
+ end
114
122
  end
115
123
  end
@@ -23,13 +23,9 @@ RSpec.describe(DefMastership::CSVFormatterBody) do
23
23
  end
24
24
 
25
25
  it { expect(definition).to(have_received(:type).with(no_args)) }
26
-
27
26
  it { expect(definition).to(have_received(:reference).with(no_args)) }
28
-
29
27
  it { expect(definition).to(have_received(:value).with(no_args)) }
30
-
31
28
  it { expect(definition).to(have_received(:sha256).with(no_args)) }
32
-
33
29
  it { expect(formatter.fixed(definition)).to(eq(%w[a b c d])) }
34
30
  end
35
31
 
@@ -41,7 +37,6 @@ RSpec.describe(DefMastership::CSVFormatterBody) do
41
37
  end
42
38
 
43
39
  it { expect(definition).to(have_received(:wrong_explicit_checksum).with(no_args)) }
44
-
45
40
  it { expect(formatter.wrong_explicit_checksum(definition)).to(eq([''])) }
46
41
  end
47
42
 
@@ -55,42 +50,48 @@ RSpec.describe(DefMastership::CSVFormatterBody) do
55
50
  end
56
51
  end
57
52
 
58
- describe '#labels' do
59
- context 'when no labels on document' do
53
+ describe '#explicit_version' do
54
+ context 'when no explicit_version' do
60
55
  before do
61
- allow(document).to(receive(:labels).with(no_args).and_return([]))
62
- formatter.labels(definition)
56
+ allow(definition).to(receive(:explicit_version).with(no_args).and_return(nil))
57
+ formatter.explicit_version(definition)
63
58
  end
64
59
 
65
- it { expect(document).to(have_received(:labels).once.with(no_args)) }
66
-
67
- it { expect(formatter.labels(definition)).to(eq([])) }
60
+ it { expect(definition).to(have_received(:explicit_version).with(no_args)) }
61
+ it { expect(formatter.explicit_version(definition)).to(eq([''])) }
68
62
  end
69
63
 
70
- context 'when labels on document' do
71
- before { allow(document).to(receive(:labels).with(no_args).and_return(['whatever'])) }
64
+ context 'when explicit_version' do
65
+ before do
66
+ allow(definition).to(receive(:explicit_version).with(no_args).and_return('ab12'))
67
+ formatter.explicit_version(definition)
68
+ end
72
69
 
73
- context 'when no labels on definition' do
74
- before do
75
- allow(definition).to(receive(:labels).with(no_args).and_return([]))
76
- formatter.labels(definition)
77
- end
70
+ it { expect(formatter.explicit_version(definition)).to(eq(['ab12'])) }
71
+ end
72
+ end
78
73
 
79
- it { expect(definition).to(have_received(:labels).once.with(no_args)) }
74
+ describe '#labels' do
75
+ before { allow(document).to(receive(:labels).with(no_args).and_return(['whatever'])) }
80
76
 
81
- it { expect(formatter.labels(definition)).to(eq([''])) }
77
+ context 'when no labels on definition' do
78
+ before do
79
+ allow(definition).to(receive(:labels).with(no_args).and_return([]))
80
+ formatter.labels(definition)
82
81
  end
83
82
 
84
- context 'when labels on definition' do
85
- before do
86
- allow(definition).to(receive(:labels).with(no_args).and_return(%w[toto tutu]))
87
- formatter.labels(definition)
88
- end
89
-
90
- it { expect(definition).to(have_received(:labels).once.with(no_args)) }
83
+ it { expect(definition).to(have_received(:labels).once.with(no_args)) }
84
+ it { expect(formatter.labels(definition)).to(eq([''])) }
85
+ end
91
86
 
92
- it { expect(formatter.labels(definition)).to(eq(["toto\ntutu"])) }
87
+ context 'when labels on definition' do
88
+ before do
89
+ allow(definition).to(receive(:labels).with(no_args).and_return(%w[toto tutu]))
90
+ formatter.labels(definition)
93
91
  end
92
+
93
+ it { expect(definition).to(have_received(:labels).once.with(no_args)) }
94
+ it { expect(formatter.labels(definition)).to(eq(["toto\ntutu"])) }
94
95
  end
95
96
  end
96
97
 
@@ -102,7 +103,6 @@ RSpec.describe(DefMastership::CSVFormatterBody) do
102
103
  end
103
104
 
104
105
  it { expect(document).to(have_received(:eref).with(no_args)) }
105
-
106
106
  it { expect(formatter.eref(nil)).to(eq([])) }
107
107
  end
108
108
 
@@ -118,47 +118,31 @@ RSpec.describe(DefMastership::CSVFormatterBody) do
118
118
  end
119
119
 
120
120
  it { expect(definition).to(have_received(:eref).exactly(3).times.with(no_args)) }
121
-
122
121
  it { expect(formatter.eref(definition)).to(eq(["A\nB", '', 'C'])) }
123
122
  end
124
123
  end
125
124
 
126
125
  describe '#iref' do
127
- context 'when no iref on the document' do
126
+ before { allow(document).to(receive(:iref).with(no_args).and_return(true)) }
127
+
128
+ context 'when no iref on the definition' do
128
129
  before do
129
- allow(document).to(receive(:iref).with(no_args).and_return(false))
130
+ allow(definition).to(receive(:iref).with(no_args).and_return([]))
130
131
  formatter.iref(definition)
131
132
  end
132
133
 
133
- it { expect(document).to(have_received(:iref).with(no_args)) }
134
-
135
- it { expect(formatter.iref(definition)).to(eq([])) }
134
+ it { expect(definition).to(have_received(:iref).with(no_args)) }
135
+ it { expect(formatter.iref(definition)).to(eq([''])) }
136
136
  end
137
137
 
138
- context 'when iref on the document' do
139
- before { allow(document).to(receive(:iref).with(no_args).and_return(true)) }
140
-
141
- context 'when no iref on the definition' do
142
- before do
143
- allow(definition).to(receive(:iref).with(no_args).and_return([]))
144
- formatter.iref(definition)
145
- end
146
-
147
- it { expect(definition).to(have_received(:iref).with(no_args)) }
148
-
149
- it { expect(formatter.iref(definition)).to(eq([''])) }
138
+ context 'when iref on the definition' do
139
+ before do
140
+ allow(definition).to(receive(:iref).with(no_args).and_return(%w[A B]))
141
+ formatter.iref(definition)
150
142
  end
151
143
 
152
- context 'when iref on the definition' do
153
- before do
154
- allow(definition).to(receive(:iref).with(no_args).and_return(%w[A B]))
155
- formatter.iref(definition)
156
- end
157
-
158
- it { expect(definition).to(have_received(:iref).with(no_args)) }
159
-
160
- it { expect(formatter.iref(definition)).to(eq(["A\nB"])) }
161
- end
144
+ it { expect(definition).to(have_received(:iref).with(no_args)) }
145
+ it { expect(formatter.iref(definition)).to(eq(["A\nB"])) }
162
146
  end
163
147
  end
164
148
 
@@ -170,7 +154,6 @@ RSpec.describe(DefMastership::CSVFormatterBody) do
170
154
  end
171
155
 
172
156
  it { expect(document).to(have_received(:attributes).with(no_args)) }
173
-
174
157
  it { expect(formatter.attributes(nil)).to(eq([])) }
175
158
  end
176
159
 
@@ -185,7 +168,6 @@ RSpec.describe(DefMastership::CSVFormatterBody) do
185
168
  end
186
169
 
187
170
  it { expect(definition).to(have_received(:attributes).exactly(3).times) }
188
-
189
171
  it { expect(formatter.attributes(definition)).to(eq(['X', '', 'Y'])) }
190
172
  end
191
173
  end
@@ -14,7 +14,29 @@ RSpec.describe(DefMastership::CSVFormatterHeader) do
14
14
 
15
15
  describe '#header' do
16
16
  describe '#fixed' do
17
- it { expect(formatter.fixed).to(eq(%w[Type Reference Value sha256])) }
17
+ it { expect(formatter.fixed).to(eq(%w[Type Reference Value Checksum])) }
18
+ end
19
+
20
+ describe '#explicit_version' do
21
+ context 'when no explicit version' do
22
+ before do
23
+ allow(document).to(receive(:explicit_version?).and_return(false))
24
+ formatter.explicit_version
25
+ end
26
+
27
+ it { expect(document).to(have_received(:explicit_version?)) }
28
+
29
+ it { expect(formatter.explicit_version).to(eq([])) }
30
+ end
31
+
32
+ context 'when explicit version' do
33
+ before do
34
+ allow(document).to(receive(:explicit_version?).and_return(true))
35
+ formatter.explicit_version
36
+ end
37
+
38
+ it { expect(formatter.explicit_version).to(eq(['Version'])) }
39
+ end
18
40
  end
19
41
 
20
42
  describe '#wrong_explicit_checksum' do
@@ -15,20 +15,29 @@ RSpec.describe(DefMastership::CSVFormatter) do
15
15
  end
16
16
 
17
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') }
18
+ let(:header) { instance_double(DefMastership::CSVFormatterHeader, 'header') }
19
+ let(:body) { instance_double(DefMastership::CSVFormatterBody, 'body') }
20
+ let(:csv) { instance_double(CSV, 'csv') }
21
+
22
+ before do
23
+ allow(CSV).to(receive(:open).and_yield(csv))
24
+ allow(csv).to(receive(:<<))
25
+ allow(DefMastership::CSVFormatterHeader).to(receive(:new).with(document).and_return(header))
26
+ allow(DefMastership::CSVFormatterBody).to(receive(:new).with(document).and_return(body))
27
+ allow(document).to(receive(:definitions).and_return(%i[def1 def2]))
28
+ allow(document).to(receive(:wrong_explicit_checksum?).with(no_args).and_return(false))
29
+ allow(document).to(receive(:explicit_version?).with(no_args).and_return(false))
30
+ allow(document).to(receive(:labels).with(no_args).and_return([]))
31
+ allow(document).to(receive(:eref).with(no_args).and_return([]))
32
+ allow(document).to(receive(:iref).with(no_args).and_return(false))
33
+ allow(document).to(receive(:attributes).with(no_args).and_return([]))
34
+ end
35
+
36
+ context 'when no variable columns' do
37
+ methods = %i[fixed]
22
38
 
23
- methods1 = %i[fixed wrong_explicit_checksum labels eref iref attributes]
24
39
  before do
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|
40
+ methods.each do |method|
32
41
  allow(header).to(receive(method).with(no_args).and_return(["#{method} header"]))
33
42
  allow(body).to(receive(method).with(:def1).and_return(["#{method} def1 body"]))
34
43
  allow(body).to(receive(method).with(:def2).and_return(["#{method} def2 body"]))
@@ -36,98 +45,226 @@ RSpec.describe(DefMastership::CSVFormatter) do
36
45
  formatter.export_to('whatever')
37
46
  end
38
47
 
39
- methods1.each do |method|
48
+ methods.each do |method|
40
49
  it { expect(header).to(have_received(method).with(no_args)) }
41
50
  it { expect(body).to(have_received(method).with(:def1)) }
42
51
  it { expect(body).to(have_received(method).with(:def2)) }
43
52
  end
44
53
 
45
- it do
46
- expect(csv).to(have_received(:<<).with(methods1.map { |method| "#{method} header" }))
54
+ it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} header" })) }
55
+ it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} def1 body" })) }
56
+ it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} def2 body" })) }
57
+ end
58
+
59
+ context 'when wrong_explicit_checksum' do
60
+ methods = %i[fixed wrong_explicit_checksum]
61
+
62
+ before do
63
+ methods.each do |method|
64
+ allow(header).to(receive(method).with(no_args).and_return(["#{method} header"]))
65
+ allow(body).to(receive(method).with(:def1).and_return(["#{method} def1 body"]))
66
+ allow(body).to(receive(method).with(:def2).and_return(["#{method} def2 body"]))
67
+ end
68
+ allow(document).to(receive(:wrong_explicit_checksum?).with(no_args).and_return(true))
69
+ formatter.export_to('whatever')
47
70
  end
48
71
 
49
- it do
50
- expect(csv).to(have_received(:<<).with(methods1.map { |method| "#{method} def1 body" }))
72
+ methods.each do |method|
73
+ it { expect(header).to(have_received(method).with(no_args)) }
74
+ it { expect(body).to(have_received(method).with(:def1)) }
75
+ it { expect(body).to(have_received(method).with(:def2)) }
51
76
  end
52
77
 
53
- it do
54
- expect(csv).to(have_received(:<<).with(methods1.map { |method| "#{method} def2 body" }))
78
+ it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} header" })) }
79
+ it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} def1 body" })) }
80
+ it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} def2 body" })) }
81
+ end
82
+
83
+ context 'when explicit_version' do
84
+ methods = %i[fixed explicit_version]
85
+
86
+ before do
87
+ methods.each do |method|
88
+ allow(header).to(receive(method).with(no_args).and_return(["#{method} header"]))
89
+ allow(body).to(receive(method).with(:def1).and_return(["#{method} def1 body"]))
90
+ allow(body).to(receive(method).with(:def2).and_return(["#{method} def2 body"]))
91
+ end
92
+ allow(document).to(receive(:explicit_version?).with(no_args).and_return(true))
93
+ formatter.export_to('whatever')
94
+ end
95
+
96
+ methods.each do |method|
97
+ it { expect(header).to(have_received(method).with(no_args)) }
98
+ it { expect(body).to(have_received(method).with(:def1)) }
99
+ it { expect(body).to(have_received(method).with(:def2)) }
55
100
  end
101
+
102
+ it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} header" })) }
103
+ it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} def1 body" })) }
104
+ it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} def2 body" })) }
56
105
  end
57
106
 
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') }
107
+ context 'when labels' do
108
+ methods = %i[fixed labels]
62
109
 
63
- methods2 = %i[fixed labels eref iref attributes]
64
110
  before do
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|
111
+ methods.each do |method|
72
112
  allow(header).to(receive(method).with(no_args).and_return(["#{method} header"]))
73
113
  allow(body).to(receive(method).with(:def1).and_return(["#{method} def1 body"]))
74
114
  allow(body).to(receive(method).with(:def2).and_return(["#{method} def2 body"]))
75
115
  end
116
+ allow(document).to(receive(:labels).with(no_args).and_return([:whatever]))
76
117
  formatter.export_to('whatever')
77
118
  end
78
119
 
79
- methods2.each do |method|
120
+ methods.each do |method|
80
121
  it { expect(header).to(have_received(method).with(no_args)) }
81
122
  it { expect(body).to(have_received(method).with(:def1)) }
82
123
  it { expect(body).to(have_received(method).with(:def2)) }
83
124
  end
84
125
 
85
- it do
86
- expect(csv).to(have_received(:<<).with(methods2.map { |method| "#{method} header" }))
126
+ it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} header" })) }
127
+ it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} def1 body" })) }
128
+ it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} def2 body" })) }
129
+ end
130
+
131
+ context 'when eref' do
132
+ methods = %i[fixed eref]
133
+
134
+ before do
135
+ methods.each do |method|
136
+ allow(header).to(receive(method).with(no_args).and_return(["#{method} header"]))
137
+ allow(body).to(receive(method).with(:def1).and_return(["#{method} def1 body"]))
138
+ allow(body).to(receive(method).with(:def2).and_return(["#{method} def2 body"]))
139
+ end
140
+ allow(document).to(receive(:eref).with(no_args).and_return([:whatever]))
141
+ formatter.export_to('whatever')
87
142
  end
88
143
 
89
- it do
90
- expect(csv).to(have_received(:<<).with(methods2.map { |method| "#{method} def1 body" }))
144
+ methods.each do |method|
145
+ it { expect(header).to(have_received(method).with(no_args)) }
146
+ it { expect(body).to(have_received(method).with(:def1)) }
147
+ it { expect(body).to(have_received(method).with(:def2)) }
148
+ end
149
+
150
+ it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} header" })) }
151
+ it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} def1 body" })) }
152
+ it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} def2 body" })) }
153
+ end
154
+
155
+ context 'when iref' do
156
+ methods = %i[fixed iref]
157
+
158
+ before do
159
+ methods.each do |method|
160
+ allow(header).to(receive(method).with(no_args).and_return(["#{method} header"]))
161
+ allow(body).to(receive(method).with(:def1).and_return(["#{method} def1 body"]))
162
+ allow(body).to(receive(method).with(:def2).and_return(["#{method} def2 body"]))
163
+ end
164
+ allow(document).to(receive(:iref).with(no_args).and_return(true))
165
+ formatter.export_to('whatever')
91
166
  end
92
167
 
93
- it do
94
- expect(csv).to(have_received(:<<).with(methods2.map { |method| "#{method} def2 body" }))
168
+ methods.each do |method|
169
+ it { expect(header).to(have_received(method).with(no_args)) }
170
+ it { expect(body).to(have_received(method).with(:def1)) }
171
+ it { expect(body).to(have_received(method).with(:def2)) }
95
172
  end
173
+
174
+ it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} header" })) }
175
+ it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} def1 body" })) }
176
+ it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} def2 body" })) }
96
177
  end
97
178
 
98
- context 'when #export_to csv file' do
99
- let(:target_file) { 'export.csv' }
100
- let(:definitions) do
101
- [
102
- OpenStruct.new(type: 'a', reference: 'b', value: 'c', sha256: 'd'),
103
- OpenStruct.new(type: 'd', reference: 'e', value: 'f', sha256: 'g')
104
- ]
179
+ context 'when attributes' do
180
+ methods = %i[fixed attributes]
181
+
182
+ before do
183
+ methods.each do |method|
184
+ allow(header).to(receive(method).with(no_args).and_return(["#{method} header"]))
185
+ allow(body).to(receive(method).with(:def1).and_return(["#{method} def1 body"]))
186
+ allow(body).to(receive(method).with(:def2).and_return(["#{method} def2 body"]))
187
+ end
188
+ allow(document).to(receive(:attributes).with(no_args).and_return([:whatever]))
189
+ formatter.export_to('whatever')
190
+ end
191
+
192
+ methods.each do |method|
193
+ it { expect(header).to(have_received(method).with(no_args)) }
194
+ it { expect(body).to(have_received(method).with(:def1)) }
195
+ it { expect(body).to(have_received(method).with(:def2)) }
105
196
  end
106
197
 
198
+ it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} header" })) }
199
+ it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} def1 body" })) }
200
+ it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} def2 body" })) }
201
+ end
202
+
203
+ context 'when every colums' do
204
+ methods = %i[fixed wrong_explicit_checksum explicit_version labels eref iref attributes]
205
+
107
206
  before do
108
- setup_aruba
109
- allow(document).to(receive(:labels).exactly(3).times.with(no_args).and_return([]))
110
- allow(document).to(receive(:eref).exactly(3).times.with(no_args).and_return({}))
111
- allow(document).to(receive(:iref).exactly(3).times.with(no_args).and_return(false))
112
- allow(document).to(receive(:attributes).exactly(3).times.with(no_args).and_return({}))
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))
115
- formatter.export_to("#{aruba.current_directory}/#{target_file}")
116
- end
117
-
118
- it { expect(document).to(have_received(:labels).exactly(3).times.with(no_args)) }
119
- it { expect(document).to(have_received(:eref).exactly(3).times.with(no_args)) }
120
- it { expect(document).to(have_received(:iref).exactly(3).times.with(no_args)) }
121
- it { expect(document).to(have_received(:attributes).exactly(3).times.with(no_args)) }
122
- it { expect(document).to(have_received(:definitions).with(no_args)) }
123
-
124
- it do
125
- expect(target_file).to(have_file_content(<<~CSV_FILE))
126
- Type;Reference;Value;sha256
127
- a;b;c;d
128
- d;e;f;g
129
- CSV_FILE
207
+ methods.each do |method|
208
+ allow(header).to(receive(method).with(no_args).and_return(["#{method} header"]))
209
+ allow(body).to(receive(method).with(:def1).and_return(["#{method} def1 body"]))
210
+ allow(body).to(receive(method).with(:def2).and_return(["#{method} def2 body"]))
211
+ end
212
+ allow(document).to(receive(:wrong_explicit_checksum?).with(no_args).and_return(true))
213
+ allow(document).to(receive(:explicit_version?).with(no_args).and_return(true))
214
+ allow(document).to(receive(:labels).with(no_args).and_return([:whatever]))
215
+ allow(document).to(receive(:eref).with(no_args).and_return([:whatever]))
216
+ allow(document).to(receive(:iref).with(no_args).and_return(true))
217
+ allow(document).to(receive(:attributes).with(no_args).and_return([:whatever]))
218
+ formatter.export_to('whatever')
130
219
  end
220
+
221
+ methods.each do |method|
222
+ it { expect(header).to(have_received(method).with(no_args)) }
223
+ it { expect(body).to(have_received(method).with(:def1)) }
224
+ it { expect(body).to(have_received(method).with(:def2)) }
225
+ end
226
+
227
+ it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} header" })) }
228
+ it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} def1 body" })) }
229
+ it { expect(csv).to(have_received(:<<).with(methods.map { |method| "#{method} def2 body" })) }
230
+ end
231
+ end
232
+
233
+ context 'when #export_to csv file' do
234
+ let(:target_file) { 'export.csv' }
235
+ let(:definitions) do
236
+ [
237
+ OpenStruct.new(type: 'a', reference: 'b', value: 'c', sha256: 'd'),
238
+ OpenStruct.new(type: 'd', reference: 'e', value: 'f', sha256: 'g')
239
+ ]
240
+ end
241
+
242
+ before do
243
+ setup_aruba
244
+ allow(document).to(receive(:labels).with(no_args).and_return([]))
245
+ allow(document).to(receive(:eref).with(no_args).and_return({}))
246
+ allow(document).to(receive(:iref).with(no_args).and_return(false))
247
+ allow(document).to(receive(:attributes).with(no_args).and_return({}))
248
+ allow(document).to(receive(:definitions).with(no_args).and_return(definitions))
249
+ allow(document).to(receive(:wrong_explicit_checksum?).with(no_args).and_return(false))
250
+ allow(document).to(receive(:explicit_version?).with(no_args).and_return(false))
251
+ formatter.export_to("#{aruba.current_directory}/#{target_file}")
252
+ end
253
+
254
+ it { expect(document).to(have_received(:labels).with(no_args)) }
255
+ it { expect(document).to(have_received(:eref).with(no_args)) }
256
+ it { expect(document).to(have_received(:iref).with(no_args)) }
257
+ it { expect(document).to(have_received(:attributes).with(no_args)) }
258
+ it { expect(document).to(have_received(:definitions).with(no_args)) }
259
+ it { expect(document).to(have_received(:wrong_explicit_checksum?).with(no_args)) }
260
+ it { expect(document).to(have_received(:explicit_version?).with(no_args)) }
261
+
262
+ it do
263
+ expect(target_file).to(have_file_content(<<~CSV_FILE))
264
+ Type;Reference;Value;Checksum
265
+ a;b;c;d
266
+ d;e;f;g
267
+ CSV_FILE
131
268
  end
132
269
  end
133
270
  end