macros4cuke 0.4.08 → 0.4.09
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/.rubocop.yml +3 -0
- data/.travis.yml +6 -0
- data/CHANGELOG.md +4 -0
- data/README.md +5 -3
- data/features/{1_Basics → 1_the_basics}/README.md +0 -0
- data/features/{1_Basics → 1_the_basics}/demo01.feature +5 -5
- data/features/{2_Macros_with_arguments → 2_macros_with_arguments}/README.md +0 -0
- data/features/{2_Macros_with_arguments → 2_macros_with_arguments}/demo02.feature +10 -10
- data/features/{2_Macros_with_arguments → 2_macros_with_arguments}/demo03.feature +5 -5
- data/features/{3_Macros_with_table_arguments → 3_macros_with_table_arguments}/README.md +0 -0
- data/features/{3_Macros_with_table_arguments → 3_macros_with_table_arguments}/demo04.feature +5 -5
- data/features/{3_Macros_with_table_arguments → 3_macros_with_table_arguments}/demo05.feature +4 -4
- data/features/{4_Conditional_steps → 4_conditional_steps}/demo06.feature +18 -16
- data/features/{5_Goodies → 5_goodies}/demo07.feature +6 -5
- data/features/{5_Goodies → 5_goodies}/demo08.feature +0 -0
- data/features/step_definitions/demo_steps.rb +5 -4
- data/lib/macro_steps.rb +6 -6
- data/lib/macros4cuke/coll-walker-factory.rb +12 -12
- data/lib/macros4cuke/constants.rb +4 -4
- data/lib/macros4cuke/formatter/all-notifications.rb +8 -8
- data/lib/macros4cuke/formatter/to-gherkin.rb +2 -2
- data/lib/macros4cuke/formatter/to-null.rb +10 -10
- data/lib/macros4cuke/formatting-service.rb +74 -74
- data/lib/macros4cuke/macro-collection.rb +13 -13
- data/lib/macros4cuke/macro-step-support.rb +19 -12
- data/lib/macros4cuke/macro-step.rb +48 -48
- data/lib/macros4cuke/templating/engine.rb +79 -79
- data/lib/macros4cuke/templating/placeholder.rb +52 -52
- data/lib/macros4cuke/templating/section.rb +116 -116
- data/lib/macros4cuke/templating/template-element.rb +88 -88
- data/lib/macros4cuke/templating/unary-element.rb +37 -37
- data/lib/macros4cuke.rb +1 -1
- data/spec/macros4cuke/coll-walker-factory_spec.rb +269 -269
- data/spec/macros4cuke/formatter/to-gherkin_spec.rb +5 -5
- data/spec/macros4cuke/formatter/to-null_spec.rb +62 -62
- data/spec/macros4cuke/formatter/to-trace_spec.rb +8 -8
- data/spec/macros4cuke/formatting-service_spec.rb +7 -7
- data/spec/macros4cuke/macro-collection_spec.rb +3 -3
- data/spec/macros4cuke/macro-step-support_spec.rb +4 -4
- data/spec/macros4cuke/macro-step_spec.rb +8 -8
- data/spec/macros4cuke/templating/comment_spec.rb +45 -0
- data/spec/macros4cuke/templating/engine_spec.rb +23 -23
- data/spec/macros4cuke/templating/eo-line_spec.rb +39 -0
- data/spec/macros4cuke/templating/section_spec.rb +1 -1
- data/spec/macros4cuke/templating/static_text_spec.rb +45 -0
- data/spec/macros4cuke/use-sample-collection.rb +7 -7
- data/spec/spec_helper.rb +3 -3
- metadata +31 -14
@@ -1,269 +1,269 @@
|
|
1
|
-
# File: collection-walker_spec.rb
|
2
|
-
|
3
|
-
require_relative '../spec_helper'
|
4
|
-
|
5
|
-
# Load mix-in module for creating a sample collection of macro-steps
|
6
|
-
require_relative 'use-sample-collection'
|
7
|
-
|
8
|
-
# Load the class under test
|
9
|
-
require_relative '../../lib/macros4cuke/coll-walker-factory'
|
10
|
-
|
11
|
-
module Macros4Cuke # Open this namespace to avoid module qualifier prefixes
|
12
|
-
|
13
|
-
describe CollWalkerFactory do
|
14
|
-
include UseSampleCollection # Add convenience methods for sample collection
|
15
|
-
|
16
|
-
|
17
|
-
before(:all) do
|
18
|
-
# Fill the collection of macro-steps with sample steps
|
19
|
-
fill_collection
|
20
|
-
end
|
21
|
-
|
22
|
-
after(:all) do
|
23
|
-
# Clear the collection to prevent interference between spec files
|
24
|
-
macro_coll.clear
|
25
|
-
end
|
26
|
-
|
27
|
-
context 'Initialization:' do
|
28
|
-
it 'should be created without parameter' do
|
29
|
-
expect { CollWalkerFactory.new }.not_to raise_error
|
30
|
-
end
|
31
|
-
|
32
|
-
end # context
|
33
|
-
|
34
|
-
context 'Provided factory services:' do
|
35
|
-
# Default factory instantiation
|
36
|
-
subject { CollWalkerFactory.new }
|
37
|
-
|
38
|
-
it 'should build a walker for the given macro collection' do
|
39
|
-
walker = subject.build_walker(macro_coll)
|
40
|
-
expect(walker).to be_kind_of(Enumerator)
|
41
|
-
end
|
42
|
-
end # context
|
43
|
-
|
44
|
-
context 'Provided walker services:' do
|
45
|
-
# Default walker instantiation
|
46
|
-
subject do
|
47
|
-
factory = CollWalkerFactory.new
|
48
|
-
factory.build_walker(macro_coll)
|
49
|
-
end
|
50
|
-
|
51
|
-
|
52
|
-
it 'should notify the start of the visit of the collection' do
|
53
|
-
initial_event = subject.next
|
54
|
-
expect(initial_event).to eq([:on_collection, 0, macro_coll])
|
55
|
-
end
|
56
|
-
|
57
|
-
it 'should notify the visit of a first macro step' do
|
58
|
-
1.times { subject.next }
|
59
|
-
first_step = subject.next
|
60
|
-
step1 = macro_coll.macro_steps.values[0]
|
61
|
-
expect(first_step).to eq([:on_step, 1, step1])
|
62
|
-
end
|
63
|
-
|
64
|
-
it 'should notify the visit of the phrase of the first macro step' do
|
65
|
-
2.times { subject.next }
|
66
|
-
first_phrase = subject.next
|
67
|
-
sample_phrase1 = UseSampleCollection::SamplePhrase1
|
68
|
-
expect(first_phrase).to eq([:on_phrase, 2, sample_phrase1, true])
|
69
|
-
end
|
70
|
-
|
71
|
-
it 'should notify the visit of the substeps renderer of the first step' do
|
72
|
-
3.times { subject.next }
|
73
|
-
first_step = macro_coll.macro_steps.values[0]
|
74
|
-
first_renderer = subject.next
|
75
|
-
expectation = [:on_renderer, 2, first_step.renderer]
|
76
|
-
expect(first_renderer).to eq(expectation)
|
77
|
-
end
|
78
|
-
|
79
|
-
it 'should notify the visit of the internal representation of substeps' do
|
80
|
-
first_step = macro_coll.macro_steps.values[0]
|
81
|
-
substep_chunks = first_step.renderer.representation
|
82
|
-
4.times { subject.next }
|
83
|
-
text_representation = subject.next
|
84
|
-
expectation = [:on_source, 3, first_step.renderer.source]
|
85
|
-
expect(text_representation).to eq(expectation)
|
86
|
-
|
87
|
-
first_substep_piece = subject.next
|
88
|
-
expectation = [:on_static_text, 3, substep_chunks[0].source]
|
89
|
-
expect(first_substep_piece).to eq(expectation)
|
90
|
-
|
91
|
-
second_substep_piece = subject.next
|
92
|
-
expect(second_substep_piece).to eq([:on_eol, 3, nil])
|
93
|
-
|
94
|
-
third_substep_piece = subject.next
|
95
|
-
expectation = [:on_static_text, 3, substep_chunks[2].source]
|
96
|
-
expect(third_substep_piece).to eq(expectation)
|
97
|
-
|
98
|
-
fourth_substep_piece = subject.next
|
99
|
-
expect(fourth_substep_piece).to eq([:on_eol, 3, nil])
|
100
|
-
|
101
|
-
fifth_substep_piece = subject.next
|
102
|
-
expectation = [:on_static_text, 3, substep_chunks[4].source]
|
103
|
-
expect(fifth_substep_piece).to eq(expectation)
|
104
|
-
|
105
|
-
sixth_substep_piece = subject.next
|
106
|
-
expectation = [:on_placeholder, 3, substep_chunks[5].name]
|
107
|
-
expect(sixth_substep_piece).to eq(expectation)
|
108
|
-
|
109
|
-
seventh_substep_piece = subject.next
|
110
|
-
expectation = [:on_static_text, 3, substep_chunks[6].source]
|
111
|
-
expect(seventh_substep_piece).to eq(expectation)
|
112
|
-
|
113
|
-
eighth_substep_piece = subject.next
|
114
|
-
expect(eighth_substep_piece).to eq([:on_eol, 3, nil])
|
115
|
-
|
116
|
-
ninth_substep_piece = subject.next
|
117
|
-
expectation = [:on_static_text, 3, substep_chunks[8].source]
|
118
|
-
expect(ninth_substep_piece).to eq(expectation)
|
119
|
-
|
120
|
-
tenth_substep_piece = subject.next
|
121
|
-
expectation = [:on_placeholder, 3, substep_chunks[9].name]
|
122
|
-
expect(tenth_substep_piece).to eq(expectation)
|
123
|
-
|
124
|
-
eleventh_substep_piece = subject.next
|
125
|
-
expectation = [:on_static_text, 3, substep_chunks[10].source]
|
126
|
-
expect(eleventh_substep_piece).to eq(expectation)
|
127
|
-
|
128
|
-
twelfth_substep_piece = subject.next
|
129
|
-
expect(twelfth_substep_piece).to eq([:on_eol, 3, nil])
|
130
|
-
|
131
|
-
thirtieth_substep_piece = subject.next
|
132
|
-
expectation = [:on_static_text, 3, substep_chunks[12].source]
|
133
|
-
expect(thirtieth_substep_piece).to eq(expectation)
|
134
|
-
|
135
|
-
fourteenth_substep_piece = subject.next
|
136
|
-
expect(fourteenth_substep_piece).to eq([:on_eol, 3, nil])
|
137
|
-
|
138
|
-
fifteenth_substep_piece = subject.next
|
139
|
-
expect(fifteenth_substep_piece).to eq([:on_renderer_end, 2, nil])
|
140
|
-
end
|
141
|
-
|
142
|
-
it 'should notify the visit of a following macro step' do
|
143
|
-
(4 + 15 + 1).times { subject.next }
|
144
|
-
end_step = subject.next
|
145
|
-
expect(end_step).to eq([:on_step_end, 1, nil])
|
146
|
-
a_step = subject.next
|
147
|
-
expect(a_step).to eq([:on_step, 1, macro_coll.macro_steps.values[1]])
|
148
|
-
end
|
149
|
-
|
150
|
-
it 'should notify the visit of the phrase of a following macro step' do
|
151
|
-
(4 + 16 + 2).times { subject.next }
|
152
|
-
phrase = subject.next
|
153
|
-
sample_phrase = UseSampleCollection::SamplePhrase2
|
154
|
-
expect(phrase).to eq([:on_phrase, 2, sample_phrase, true])
|
155
|
-
end
|
156
|
-
|
157
|
-
it 'should notify the visit of the substeps of a following step' do
|
158
|
-
(4 + 16 + 3).times { subject.next }
|
159
|
-
a_renderer = subject.next
|
160
|
-
second_step = macro_coll.macro_steps.values[1]
|
161
|
-
expect(a_renderer).to eq([:on_renderer, 2, second_step.renderer])
|
162
|
-
end
|
163
|
-
|
164
|
-
it 'should notify the visit in substeps of following step' do
|
165
|
-
second_step = macro_coll.macro_steps.values[1]
|
166
|
-
substep_chunks = second_step.renderer.representation.dup
|
167
|
-
substep_chunks.map! do |ck|
|
168
|
-
if ck.kind_of?(Templating::Section)
|
169
|
-
[ck, ck.children, ck].flatten
|
170
|
-
else
|
171
|
-
ck
|
172
|
-
end
|
173
|
-
end
|
174
|
-
substep_chunks.flatten!
|
175
|
-
|
176
|
-
(4 + 16 + 4).times { subject.next }
|
177
|
-
substeps_text = subject.next
|
178
|
-
expectation = [:on_source, 3, second_step.renderer.source]
|
179
|
-
expect(substeps_text).to eq(expectation)
|
180
|
-
|
181
|
-
first_substep_piece = subject.next
|
182
|
-
expectation = [:on_static_text, 3, substep_chunks[0].source]
|
183
|
-
expect(first_substep_piece).to eq(expectation)
|
184
|
-
|
185
|
-
[
|
186
|
-
[:on_placeholder, 3, :name], # 0
|
187
|
-
[:on_static_text, 3, :source], # 1
|
188
|
-
[:on_eol, 3, nil], # 2
|
189
|
-
[:on_static_text, 3, :source], # 3
|
190
|
-
[:on_placeholder, 3, :name], # 4
|
191
|
-
[:on_static_text, 3, :source], # 5
|
192
|
-
[:on_eol, 3, nil], # 6
|
193
|
-
[:on_static_text, 3, :source], # 7
|
194
|
-
[:on_placeholder, 3, :name], # 8
|
195
|
-
[:on_static_text, 3, :source], # 9
|
196
|
-
[:on_eol, 3, nil], # 10
|
197
|
-
[:on_static_text, 3, :source], # 11
|
198
|
-
[:on_placeholder, 3, :name], # 12
|
199
|
-
[:on_static_text, 3, :source], # 13
|
200
|
-
[:on_eol, 3, nil], # 14
|
201
|
-
[:on_static_text, 3, :source], # 15
|
202
|
-
[:on_placeholder, 3, :name], # 16
|
203
|
-
[:on_static_text, 3, :source], # 17
|
204
|
-
[:on_eol, 3, nil], # 18
|
205
|
-
[:on_static_text, 3, :source], # 19
|
206
|
-
[:on_placeholder, 3, :name], # 20
|
207
|
-
[:on_static_text, 3, :source], # 21
|
208
|
-
[:on_eol, 3, nil], # 22
|
209
|
-
[:on_eol, 3, nil], # 23
|
210
|
-
[:on_comment, 3, :source], # 24
|
211
|
-
[:on_eol, 3, nil], # 25
|
212
|
-
[:on_comment, 3, :source], # 26
|
213
|
-
[:on_eol, 3, nil], # 27
|
214
|
-
[:on_comment, 3, :source], # 28
|
215
|
-
[:on_eol, 3, nil], # 29
|
216
|
-
[:on_section, 3, :name], # 30
|
217
|
-
[:on_static_text, 4, :source], # 31
|
218
|
-
[:on_placeholder, 4, :name], # 32
|
219
|
-
[:on_static_text, 4, :source], # 33
|
220
|
-
[:on_eol, 4, nil], # 34
|
221
|
-
[:on_section_end, 3, nil], # 35
|
222
|
-
[:on_eol, 3, nil], # 36
|
223
|
-
[:on_comment, 3, :source], # 37
|
224
|
-
[:on_eol, 3, nil], # 38
|
225
|
-
[:on_comment, 3, :source], # 39
|
226
|
-
[:on_eol, 3, nil], # 40
|
227
|
-
[:on_comment, 3, :source], # 41
|
228
|
-
[:on_eol, 3, nil], # 42
|
229
|
-
[:on_section, 3, :name], # 43
|
230
|
-
[:on_static_text, 4, :source], # 44
|
231
|
-
[:on_placeholder, 4, :name], # 45
|
232
|
-
[:on_static_text, 4, :source], # 46
|
233
|
-
[:on_eol, 4, nil], # 47
|
234
|
-
[:on_section_end, 3, nil], # 48
|
235
|
-
[:on_static_text, 3, :source], # 49
|
236
|
-
[:on_eol, 3, nil], # 50
|
237
|
-
[:on_renderer_end, 2, nil], # 51
|
238
|
-
[:on_step_end, 1, nil], # 52
|
239
|
-
[:on_collection_end, 0, nil] # 53
|
240
|
-
].each_with_index do |event, i|
|
241
|
-
actual = subject.next
|
242
|
-
expect(actual[0]).to eq(event[0])
|
243
|
-
expect(actual[1]).to eq(event[1])
|
244
|
-
unless event[2].nil?
|
245
|
-
expected_obj = substep_chunks[i + 1]
|
246
|
-
expect(actual[2]).to eq(expected_obj.send(event[2]))
|
247
|
-
end
|
248
|
-
end
|
249
|
-
expect { subject.next }.to raise_error(StopIteration)
|
250
|
-
|
251
|
-
end
|
252
|
-
|
253
|
-
# Must be last test script since it pollutes the macro-collection
|
254
|
-
it 'should complain when visiting an unsupported node' do
|
255
|
-
first_step = macro_coll.macro_steps.values[0]
|
256
|
-
first_step.renderer.representation.insert(2, :not_a_valid_element)
|
257
|
-
err_type = Macros4Cuke::InternalError
|
258
|
-
err_msg = "Don't know how to format a Symbol."
|
259
|
-
expect { subject.each { |x| } }.to raise_error(err_type, err_msg)
|
260
|
-
end
|
261
|
-
|
262
|
-
end # context
|
263
|
-
|
264
|
-
end # describe
|
265
|
-
|
266
|
-
end # module
|
267
|
-
|
268
|
-
|
269
|
-
# End of file
|
1
|
+
# File: collection-walker_spec.rb
|
2
|
+
|
3
|
+
require_relative '../spec_helper'
|
4
|
+
|
5
|
+
# Load mix-in module for creating a sample collection of macro-steps
|
6
|
+
require_relative 'use-sample-collection'
|
7
|
+
|
8
|
+
# Load the class under test
|
9
|
+
require_relative '../../lib/macros4cuke/coll-walker-factory'
|
10
|
+
|
11
|
+
module Macros4Cuke # Open this namespace to avoid module qualifier prefixes
|
12
|
+
|
13
|
+
describe CollWalkerFactory do
|
14
|
+
include UseSampleCollection # Add convenience methods for sample collection
|
15
|
+
|
16
|
+
|
17
|
+
before(:all) do
|
18
|
+
# Fill the collection of macro-steps with sample steps
|
19
|
+
fill_collection
|
20
|
+
end
|
21
|
+
|
22
|
+
after(:all) do
|
23
|
+
# Clear the collection to prevent interference between spec files
|
24
|
+
macro_coll.clear
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'Initialization:' do
|
28
|
+
it 'should be created without parameter' do
|
29
|
+
expect { CollWalkerFactory.new }.not_to raise_error
|
30
|
+
end
|
31
|
+
|
32
|
+
end # context
|
33
|
+
|
34
|
+
context 'Provided factory services:' do
|
35
|
+
# Default factory instantiation
|
36
|
+
subject { CollWalkerFactory.new }
|
37
|
+
|
38
|
+
it 'should build a walker for the given macro collection' do
|
39
|
+
walker = subject.build_walker(macro_coll)
|
40
|
+
expect(walker).to be_kind_of(Enumerator)
|
41
|
+
end
|
42
|
+
end # context
|
43
|
+
|
44
|
+
context 'Provided walker services:' do
|
45
|
+
# Default walker instantiation
|
46
|
+
subject do
|
47
|
+
factory = CollWalkerFactory.new
|
48
|
+
factory.build_walker(macro_coll)
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
it 'should notify the start of the visit of the collection' do
|
53
|
+
initial_event = subject.next
|
54
|
+
expect(initial_event).to eq([:on_collection, 0, macro_coll])
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'should notify the visit of a first macro step' do
|
58
|
+
1.times { subject.next }
|
59
|
+
first_step = subject.next
|
60
|
+
step1 = macro_coll.macro_steps.values[0]
|
61
|
+
expect(first_step).to eq([:on_step, 1, step1])
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'should notify the visit of the phrase of the first macro step' do
|
65
|
+
2.times { subject.next }
|
66
|
+
first_phrase = subject.next
|
67
|
+
sample_phrase1 = UseSampleCollection::SamplePhrase1
|
68
|
+
expect(first_phrase).to eq([:on_phrase, 2, sample_phrase1, true])
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'should notify the visit of the substeps renderer of the first step' do
|
72
|
+
3.times { subject.next }
|
73
|
+
first_step = macro_coll.macro_steps.values[0]
|
74
|
+
first_renderer = subject.next
|
75
|
+
expectation = [:on_renderer, 2, first_step.renderer]
|
76
|
+
expect(first_renderer).to eq(expectation)
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'should notify the visit of the internal representation of substeps' do
|
80
|
+
first_step = macro_coll.macro_steps.values[0]
|
81
|
+
substep_chunks = first_step.renderer.representation
|
82
|
+
4.times { subject.next }
|
83
|
+
text_representation = subject.next
|
84
|
+
expectation = [:on_source, 3, first_step.renderer.source]
|
85
|
+
expect(text_representation).to eq(expectation)
|
86
|
+
|
87
|
+
first_substep_piece = subject.next
|
88
|
+
expectation = [:on_static_text, 3, substep_chunks[0].source]
|
89
|
+
expect(first_substep_piece).to eq(expectation)
|
90
|
+
|
91
|
+
second_substep_piece = subject.next
|
92
|
+
expect(second_substep_piece).to eq([:on_eol, 3, nil])
|
93
|
+
|
94
|
+
third_substep_piece = subject.next
|
95
|
+
expectation = [:on_static_text, 3, substep_chunks[2].source]
|
96
|
+
expect(third_substep_piece).to eq(expectation)
|
97
|
+
|
98
|
+
fourth_substep_piece = subject.next
|
99
|
+
expect(fourth_substep_piece).to eq([:on_eol, 3, nil])
|
100
|
+
|
101
|
+
fifth_substep_piece = subject.next
|
102
|
+
expectation = [:on_static_text, 3, substep_chunks[4].source]
|
103
|
+
expect(fifth_substep_piece).to eq(expectation)
|
104
|
+
|
105
|
+
sixth_substep_piece = subject.next
|
106
|
+
expectation = [:on_placeholder, 3, substep_chunks[5].name]
|
107
|
+
expect(sixth_substep_piece).to eq(expectation)
|
108
|
+
|
109
|
+
seventh_substep_piece = subject.next
|
110
|
+
expectation = [:on_static_text, 3, substep_chunks[6].source]
|
111
|
+
expect(seventh_substep_piece).to eq(expectation)
|
112
|
+
|
113
|
+
eighth_substep_piece = subject.next
|
114
|
+
expect(eighth_substep_piece).to eq([:on_eol, 3, nil])
|
115
|
+
|
116
|
+
ninth_substep_piece = subject.next
|
117
|
+
expectation = [:on_static_text, 3, substep_chunks[8].source]
|
118
|
+
expect(ninth_substep_piece).to eq(expectation)
|
119
|
+
|
120
|
+
tenth_substep_piece = subject.next
|
121
|
+
expectation = [:on_placeholder, 3, substep_chunks[9].name]
|
122
|
+
expect(tenth_substep_piece).to eq(expectation)
|
123
|
+
|
124
|
+
eleventh_substep_piece = subject.next
|
125
|
+
expectation = [:on_static_text, 3, substep_chunks[10].source]
|
126
|
+
expect(eleventh_substep_piece).to eq(expectation)
|
127
|
+
|
128
|
+
twelfth_substep_piece = subject.next
|
129
|
+
expect(twelfth_substep_piece).to eq([:on_eol, 3, nil])
|
130
|
+
|
131
|
+
thirtieth_substep_piece = subject.next
|
132
|
+
expectation = [:on_static_text, 3, substep_chunks[12].source]
|
133
|
+
expect(thirtieth_substep_piece).to eq(expectation)
|
134
|
+
|
135
|
+
fourteenth_substep_piece = subject.next
|
136
|
+
expect(fourteenth_substep_piece).to eq([:on_eol, 3, nil])
|
137
|
+
|
138
|
+
fifteenth_substep_piece = subject.next
|
139
|
+
expect(fifteenth_substep_piece).to eq([:on_renderer_end, 2, nil])
|
140
|
+
end
|
141
|
+
|
142
|
+
it 'should notify the visit of a following macro step' do
|
143
|
+
(4 + 15 + 1).times { subject.next }
|
144
|
+
end_step = subject.next
|
145
|
+
expect(end_step).to eq([:on_step_end, 1, nil])
|
146
|
+
a_step = subject.next
|
147
|
+
expect(a_step).to eq([:on_step, 1, macro_coll.macro_steps.values[1]])
|
148
|
+
end
|
149
|
+
|
150
|
+
it 'should notify the visit of the phrase of a following macro step' do
|
151
|
+
(4 + 16 + 2).times { subject.next }
|
152
|
+
phrase = subject.next
|
153
|
+
sample_phrase = UseSampleCollection::SamplePhrase2
|
154
|
+
expect(phrase).to eq([:on_phrase, 2, sample_phrase, true])
|
155
|
+
end
|
156
|
+
|
157
|
+
it 'should notify the visit of the substeps of a following step' do
|
158
|
+
(4 + 16 + 3).times { subject.next }
|
159
|
+
a_renderer = subject.next
|
160
|
+
second_step = macro_coll.macro_steps.values[1]
|
161
|
+
expect(a_renderer).to eq([:on_renderer, 2, second_step.renderer])
|
162
|
+
end
|
163
|
+
|
164
|
+
it 'should notify the visit in substeps of following step' do
|
165
|
+
second_step = macro_coll.macro_steps.values[1]
|
166
|
+
substep_chunks = second_step.renderer.representation.dup
|
167
|
+
substep_chunks.map! do |ck|
|
168
|
+
if ck.kind_of?(Templating::Section)
|
169
|
+
[ck, ck.children, ck].flatten
|
170
|
+
else
|
171
|
+
ck
|
172
|
+
end
|
173
|
+
end
|
174
|
+
substep_chunks.flatten!
|
175
|
+
|
176
|
+
(4 + 16 + 4).times { subject.next }
|
177
|
+
substeps_text = subject.next
|
178
|
+
expectation = [:on_source, 3, second_step.renderer.source]
|
179
|
+
expect(substeps_text).to eq(expectation)
|
180
|
+
|
181
|
+
first_substep_piece = subject.next
|
182
|
+
expectation = [:on_static_text, 3, substep_chunks[0].source]
|
183
|
+
expect(first_substep_piece).to eq(expectation)
|
184
|
+
|
185
|
+
[
|
186
|
+
[:on_placeholder, 3, :name], # 0
|
187
|
+
[:on_static_text, 3, :source], # 1
|
188
|
+
[:on_eol, 3, nil], # 2
|
189
|
+
[:on_static_text, 3, :source], # 3
|
190
|
+
[:on_placeholder, 3, :name], # 4
|
191
|
+
[:on_static_text, 3, :source], # 5
|
192
|
+
[:on_eol, 3, nil], # 6
|
193
|
+
[:on_static_text, 3, :source], # 7
|
194
|
+
[:on_placeholder, 3, :name], # 8
|
195
|
+
[:on_static_text, 3, :source], # 9
|
196
|
+
[:on_eol, 3, nil], # 10
|
197
|
+
[:on_static_text, 3, :source], # 11
|
198
|
+
[:on_placeholder, 3, :name], # 12
|
199
|
+
[:on_static_text, 3, :source], # 13
|
200
|
+
[:on_eol, 3, nil], # 14
|
201
|
+
[:on_static_text, 3, :source], # 15
|
202
|
+
[:on_placeholder, 3, :name], # 16
|
203
|
+
[:on_static_text, 3, :source], # 17
|
204
|
+
[:on_eol, 3, nil], # 18
|
205
|
+
[:on_static_text, 3, :source], # 19
|
206
|
+
[:on_placeholder, 3, :name], # 20
|
207
|
+
[:on_static_text, 3, :source], # 21
|
208
|
+
[:on_eol, 3, nil], # 22
|
209
|
+
[:on_eol, 3, nil], # 23
|
210
|
+
[:on_comment, 3, :source], # 24
|
211
|
+
[:on_eol, 3, nil], # 25
|
212
|
+
[:on_comment, 3, :source], # 26
|
213
|
+
[:on_eol, 3, nil], # 27
|
214
|
+
[:on_comment, 3, :source], # 28
|
215
|
+
[:on_eol, 3, nil], # 29
|
216
|
+
[:on_section, 3, :name], # 30
|
217
|
+
[:on_static_text, 4, :source], # 31
|
218
|
+
[:on_placeholder, 4, :name], # 32
|
219
|
+
[:on_static_text, 4, :source], # 33
|
220
|
+
[:on_eol, 4, nil], # 34
|
221
|
+
[:on_section_end, 3, nil], # 35
|
222
|
+
[:on_eol, 3, nil], # 36
|
223
|
+
[:on_comment, 3, :source], # 37
|
224
|
+
[:on_eol, 3, nil], # 38
|
225
|
+
[:on_comment, 3, :source], # 39
|
226
|
+
[:on_eol, 3, nil], # 40
|
227
|
+
[:on_comment, 3, :source], # 41
|
228
|
+
[:on_eol, 3, nil], # 42
|
229
|
+
[:on_section, 3, :name], # 43
|
230
|
+
[:on_static_text, 4, :source], # 44
|
231
|
+
[:on_placeholder, 4, :name], # 45
|
232
|
+
[:on_static_text, 4, :source], # 46
|
233
|
+
[:on_eol, 4, nil], # 47
|
234
|
+
[:on_section_end, 3, nil], # 48
|
235
|
+
[:on_static_text, 3, :source], # 49
|
236
|
+
[:on_eol, 3, nil], # 50
|
237
|
+
[:on_renderer_end, 2, nil], # 51
|
238
|
+
[:on_step_end, 1, nil], # 52
|
239
|
+
[:on_collection_end, 0, nil] # 53
|
240
|
+
].each_with_index do |event, i|
|
241
|
+
actual = subject.next
|
242
|
+
expect(actual[0]).to eq(event[0])
|
243
|
+
expect(actual[1]).to eq(event[1])
|
244
|
+
unless event[2].nil?
|
245
|
+
expected_obj = substep_chunks[i + 1]
|
246
|
+
expect(actual[2]).to eq(expected_obj.send(event[2]))
|
247
|
+
end
|
248
|
+
end
|
249
|
+
expect { subject.next }.to raise_error(StopIteration)
|
250
|
+
|
251
|
+
end
|
252
|
+
|
253
|
+
# Must be last test script since it pollutes the macro-collection
|
254
|
+
it 'should complain when visiting an unsupported node' do
|
255
|
+
first_step = macro_coll.macro_steps.values[0]
|
256
|
+
first_step.renderer.representation.insert(2, :not_a_valid_element)
|
257
|
+
err_type = Macros4Cuke::InternalError
|
258
|
+
err_msg = "Don't know how to format a Symbol."
|
259
|
+
expect { subject.each { |x| } }.to raise_error(err_type, err_msg)
|
260
|
+
end
|
261
|
+
|
262
|
+
end # context
|
263
|
+
|
264
|
+
end # describe
|
265
|
+
|
266
|
+
end # module
|
267
|
+
|
268
|
+
|
269
|
+
# End of file
|
@@ -102,19 +102,19 @@ SNIPPET
|
|
102
102
|
service = FormattingService.new
|
103
103
|
service.register(subject)
|
104
104
|
expect { service.start!(macro_coll) }.not_to raise_error
|
105
|
-
|
105
|
+
|
106
106
|
# Line-by-line comparison
|
107
107
|
actual_lines = subject.io.string.split(/\r\n?|\n/)
|
108
108
|
expected_lines = expected_output.split(/\r\n?|\n/)
|
109
|
-
|
109
|
+
|
110
110
|
# Exclude line 1 (because it is time-dependent) from the comparison
|
111
111
|
actual_lines.shift
|
112
112
|
expected_lines.shift
|
113
|
-
|
113
|
+
|
114
114
|
# Remove starting/ending spaces
|
115
115
|
actual_lines.map!(&:strip)
|
116
|
-
expected_lines.map!(&:strip)
|
117
|
-
|
116
|
+
expected_lines.map!(&:strip)
|
117
|
+
|
118
118
|
expect(actual_lines).to eq(expected_lines)
|
119
119
|
end
|
120
120
|
|