macros4cuke 0.3.02 → 0.3.03

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
+ ## 0.3.03 / 2013-05-11
2
+ [CHANGE] File `README.md`: added section on conditional section.
3
+
1
4
  ## 0.3.02 / 2013-05-11
2
- * [FIX] File `macro_steps.rb`: Recovered. Was missing in the 0.3.01 distribution!
5
+ * [FIX] File `macro_steps.rb`: Recovered. Was missing in the 0.3.01 gem!
3
6
 
4
7
  ## 0.3.01 / 2013-05-10
5
8
  * [NEW] features/ folder: added `demo06.feature` file showing the new conditional section.
data/README.md CHANGED
@@ -15,6 +15,9 @@ __Macros4Cuke__ is a lightweight library that adds a macro facility your Cucumbe
15
15
  * Macro-steps may have data arguments,
16
16
  * Data values can be passed to the sub-steps.
17
17
 
18
+ In addtion, since version 0.3.01:
19
+ * Sub-steps can be made conditional.
20
+
18
21
  ## A quick example ##
19
22
  Here is a macro-step example taken from our demo files:
20
23
  ```cucumber
@@ -73,11 +76,13 @@ World(Macros4Cuke::MacroStepSupport)
73
76
 
74
77
  * Step 2: Import the macro-management steps
75
78
  In your `/features/step_definitions/` folder:
76
- - Create a Ruby file (say, 'use\_macro\_steps.rb') with the following line:
79
+ - The cleanest is to create a Ruby file (say, 'use\_macro\_steps.rb') with the line:
77
80
 
78
81
  ```ruby
79
82
  require 'macros4cuke/../macro_steps'
80
83
  ```
84
+ - Alternatively, you could directly add the require in one of your step definition file.
85
+
81
86
 
82
87
  That's it! Now you can start writing macros in your Cucumber project.
83
88
 
@@ -89,9 +94,9 @@ Working with a macro-step is a two-stages process:
89
94
 
90
95
  Let's begin by taking a closer look at the definition part.
91
96
  ### Defining a macro-step ###
92
- To create a macro-step, you'll need to use a _defining_ step bundled with Macros4Cuke.
97
+ To create a macro-step, you'll need to use a __defining__ step bundled with Macros4Cuke.
93
98
  It is a rather unusual Cucumber step in the sense that its sole purpose is to build another step!
94
- The defining step follows the general pattern:
99
+ The _defining step_ follows the general pattern:
95
100
  ```cucumber
96
101
  Given I define the step "When I [some phrase]" to mean:
97
102
  """
@@ -110,10 +115,10 @@ These two components are detailed now.
110
115
 
111
116
  #### Specifying the syntax of a macro-step ####
112
117
  As just mentioned earlier, the __quoted sentence__ determines the syntax of the new macro-step.
113
- Its syntax is more or less free:
118
+ Its syntax is defined like this:
114
119
  - The text outside the square brackets follows a fixed pattern. In other words,
115
120
  the quoted sentence MUST always start as follows: ```"When I [...```. Notice however,
116
- that the Given, Then keywords are also allowed.
121
+ that the Given, Then and '*' keywords are also allowed.
117
122
  - The text delimited by the square brackets [...], is called the __phrase__.
118
123
 
119
124
  A few remarks about the __phrase__ part:
@@ -209,7 +214,7 @@ respectively San Francisco, New-York and Las Vegas.
209
214
 
210
215
 
211
216
  ### Passing argument data via a table ###
212
- Passing more than three arguments in the phrase becomes problematic for readability reasons.
217
+ Passing more than three arguments in the phrase becomes problematic from a readability viewpoint.
213
218
  One ends up with lengthy and clumsy steps.
214
219
  Therefore __Macros4Cuke__ has an alternative way to pass data values via a Gherkin table.
215
220
  To enable this mechanism for a given macro, ensure that in its definition the quoted sentence ends with
@@ -284,6 +289,55 @@ For any argument that can receive a value through a data table, three situations
284
289
  3. There is no row for that argument. The argument is unbound (nil) but is rendered as an empty text.
285
290
 
286
291
 
292
+ ## Conditional sections in substeps. ##
293
+ To make the macros more flexible, it is possible to define conditional sections in the substep sequence.
294
+ The general pattern for the conditional section is:
295
+ ```cucumber
296
+ <?foobar>
297
+ substep1
298
+ substep2
299
+ </foobar>
300
+ ```
301
+
302
+ This works like this:
303
+ ```<?foobar>``` marks the begin of a conditional section. The end of that section is marked by ```</foobar>```.
304
+ Anything that is in this section will be executed provided the argument ```foobar``` has a value bound to it.
305
+ Stated otherwise, when ```foobar``` has no value at invokation, then ```substep1``` and ```substep2``` will be skipped.
306
+ Conditional sections are useful for steps that are optional or for which an empty value '' isn't equal to no value.
307
+ This is the case in user interface testing: skipping a field or entering a field and leaving it empty may
308
+ lead to very different system behaviour (e.g. setting the focus in a field can trigger UI-events).
309
+
310
+ Consider the following example:
311
+
312
+ ```cucumber
313
+ Given I define the step "* I [fill in the form with]:" to mean:
314
+ """
315
+ When I fill in "first_name" with "<firstname>"
316
+ And I fill in "last_name" with "<lastname>"
317
+ And I fill in "street_address" with "<street_address>"
318
+ And I fill in "zip" with "<postcode>"
319
+ And I fill in "city" with "<city>"
320
+ # Let's assume that e-mail is optional
321
+ <?email>
322
+ And I fill in "email" with "<email>"
323
+ </email>
324
+ And I click "Save"
325
+ """
326
+ ```
327
+
328
+ When invoked like this:
329
+ ```cucumber
330
+ When I [fill in the form with]:
331
+ |firstname |Alice|
332
+ |lastname | Inn |
333
+ |street_address| 11, No Street|
334
+ |city| Nowhere-City|
335
+ |country|Wonderland|
336
+ ```
337
+
338
+ the substep concerning the email address won't be executed since the email argument isn't used at invokation.
339
+
340
+
287
341
 
288
342
  ## With great power comes great responsibility. ##
289
343
  _Stan Lee_
@@ -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.3.02'
6
+ Version = '0.3.03'
7
7
 
8
8
  # Brief description of the gem.
9
9
  Description = "Macros for Cucumber"
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.3.02
4
+ version: 0.3.03
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: