macros4cuke 0.2.22 → 0.3.00

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.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 0.3.00 / 2013-05-09 Version number bumped
2
+ * [CHANGE] Class `Templating::Engine` can handle conditional tags (TODO: document).
3
+ * [CHANGE] File `engine_spec.rb`: Added a RSpec examples to test the conditional tags.
4
+
5
+
1
6
  ## 0.2.22 / 2013-05-08
2
7
  [CHANGE] File `README.md`: expanded the section on macro arguments.
3
8
 
@@ -7,7 +12,7 @@
7
12
  * [NEW] Added new class `Templating::Section`, a subclass of `UnaryElement`.
8
13
  * [NEW] Added new class `Templating::ConditionalSection, a subclass of `Section`.
9
14
  * [CHANGE] Method Engine#parse_tag modified in prevision of conditional tags.
10
- * [NEW] File `section_spec.rb`: Added a RSpec to test the Conditional class.
15
+ * [NEW] File `section_spec.rb`: Added a RSpec file to test the Conditional class.
11
16
 
12
17
  ## 0.2.20 / 2013-05-07
13
18
  * [NEW] Added `examples` folder with a first example of an internationalized customisation of __Macros4Cuke__.
@@ -3,7 +3,7 @@
3
3
 
4
4
  module Macros4Cuke # Module used as a namespace
5
5
  # The version number of the gem.
6
- Version = '0.2.22'
6
+ Version = '0.3.00'
7
7
 
8
8
  # Brief description of the gem.
9
9
  Description = "Macros for Cucumber"
@@ -299,7 +299,7 @@ private
299
299
  end
300
300
 
301
301
  compiled_lines = raw_lines.map { |line| compile_line(line) }
302
- return compiled_lines.flatten()
302
+ return compile_sections(compiled_lines.flatten())
303
303
  end
304
304
 
305
305
  # Convert the array of raw entries into full-fledged template elements.
@@ -352,6 +352,37 @@ private
352
352
 
353
353
  return result
354
354
  end
355
+
356
+ # Group the elements by sections.
357
+ # @param flat_sequence [Array] a linear list of elements (including sections)
358
+ def compile_sections(flat_sequence)
359
+ open_sections = [] # The list of nested open sections
360
+ compiled = flat_sequence.each_with_object([]) do |element, subResult|
361
+ case element
362
+ when Section
363
+ open_sections << element
364
+
365
+ when SectionEndMarker
366
+ if open_sections.empty?
367
+ raise StandardError, "End of section</#{element.name}> found while no corresponding section must be closed."
368
+ end
369
+ if element.name != open_sections.last.name
370
+ raise StandardError, "End of section</#{element.name}> doesn't match current section '#{open_sections.last.name}'."
371
+ end
372
+ subResult << open_sections.pop()
373
+
374
+ else
375
+ if open_sections.empty?
376
+ subResult << element
377
+ else
378
+ open_sections.last.add_child(element)
379
+ end
380
+ end
381
+
382
+ end
383
+
384
+ return compiled
385
+ end
355
386
 
356
387
  end # class
357
388
 
@@ -11,6 +11,7 @@ module Templating # Open this namespace to get rid of module qualifier prefixes
11
11
 
12
12
 
13
13
  describe Engine do
14
+ # Sample template (consisting of a sequence of steps)
14
15
  let(:sample_template) do
15
16
  source = <<-SNIPPET
16
17
  Given I landed in the homepage
@@ -20,6 +21,21 @@ describe Engine do
20
21
  And I click "Sign in"
21
22
  SNIPPET
22
23
  end
24
+
25
+ # Template containing two conditional sections
26
+ let(:sophisticated_template) do
27
+ source = <<-SNIPPET
28
+ When I fill in "firstname" with "<firstname>"
29
+ And I fill in "lastname" with "<lastname>"
30
+ <?address>And I fill in "address" with "<address>"</address>
31
+ <?birthdate>
32
+ And I fill in "birthdate" with "<birthdate>"
33
+ </birthdate>
34
+ And I click "Register"
35
+ SNIPPET
36
+ end
37
+
38
+
23
39
 
24
40
  # Rule for default instantiation
25
41
  subject { Engine.new sample_template }
@@ -167,6 +183,11 @@ SNIPPET
167
183
  instance = Engine.new ''
168
184
  instance.source.should be_empty
169
185
  end
186
+
187
+ it "should accept conditional section" do
188
+ lambda { Engine.new sophisticated_template }.should_not raise_error
189
+ instance = Engine.new sophisticated_template
190
+ end
170
191
 
171
192
  it "should complain when a placeholder is empty or blank" do
172
193
  text_w_empty_arg = sample_template.sub(/userid/, '')
@@ -179,6 +200,7 @@ SNIPPET
179
200
  error_message = "The invalid sign '%' occurs in the argument/tag 'user%id'."
180
201
  lambda { Engine.new text_w_empty_arg }.should raise_error(Macros4Cuke::InvalidCharError, error_message)
181
202
  end
203
+
182
204
  end # context
183
205
 
184
206
  context "Provided services" do
@@ -248,6 +270,30 @@ SNIPPET
248
270
  instance = Engine.new ''
249
271
  instance.render(nil, {}).should be_empty
250
272
  end
273
+
274
+
275
+ it "should render conditional sections" do
276
+ instance = Engine.new(sophisticated_template)
277
+
278
+ locals = {'firstname' => "Anon",
279
+ "lastname" => "Eemoos" ,
280
+ "birthdate" => "1976-04-21"
281
+ }
282
+ rendered_text = instance.render(Object.new, locals)
283
+ expected = <<-SNIPPET
284
+ When I fill in "firstname" with "Anon"
285
+ And I fill in "lastname" with "Eemoos"
286
+
287
+
288
+ And I fill in "birthdate" with "1976-04-21"
289
+
290
+ And I click "Register"
291
+ SNIPPET
292
+
293
+ rendered_text.should == expected
294
+
295
+ end
296
+
251
297
 
252
298
  it "should render multivalued actuals" do
253
299
  locals = {'userid' => ["johndoe", "yeti"] } # Silly case
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: macros4cuke
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.22
4
+ version: 0.3.00
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-08 00:00:00.000000000 Z
12
+ date: 2013-05-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: cucumber