macros4cuke 0.2.04 → 0.2.05
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/HISTORY.md +4 -0
- data/README.md +107 -48
- data/lib/macro_steps.rb +1 -1
- data/lib/macros4cuke/constants.rb +1 -1
- metadata +2 -2
data/HISTORY.md
CHANGED
data/README.md
CHANGED
@@ -100,65 +100,52 @@ The defining step follows the general pattern:
|
|
100
100
|
```
|
101
101
|
|
102
102
|
The defining step has two key components:
|
103
|
-
1. The
|
103
|
+
1. The _quoted sentence_ ```"When I [some phrase]"```. That part
|
104
104
|
specifies the syntax of your future macro-step.
|
105
105
|
2. The multiline text enclosed between the triple quotes (""") and immediately follows the
|
106
|
-
the defining step. It is the place where the sub-steps are listed.
|
106
|
+
the defining step. It is the place where the sub-steps are listed.
|
107
107
|
|
108
|
-
These
|
108
|
+
These two components are detailed now.
|
109
109
|
|
110
110
|
|
111
111
|
#### Specifying the syntax of a macro-step ####
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
And I fill in "Password" with "tweedledee"
|
119
|
-
And I click "Sign in"
|
120
|
-
"""
|
121
|
-
```
|
122
|
-
|
123
|
-
The first line in the snippet is a step that helps to define macro-step.
|
124
|
-
It is a perfectly valid step once your Cucumber project was configured to use __Macros4Cuke__
|
125
|
-
as explained in the Setup section above. The syntax of the new step being created is specified by
|
126
|
-
the text between quotes.
|
127
|
-
Here, for instance, the new step will have for syntax:
|
128
|
-
```cucumber
|
129
|
-
When I [enter my credentials]
|
130
|
-
```
|
131
|
-
It is important to realize that the structure of the sentence outside the quotes ```Given I define the step "..." to mean:```
|
132
|
-
is the syntax of the _defining_ step not of your macro-step.
|
133
|
-
|
134
|
-
A key ingredient of the syntax of a macro-step sentence is its __phrase__, that is, the text on the first line that appears
|
135
|
-
between square brackets [...].
|
136
|
-
In the example at hand, the _phrase_ is the text:
|
137
|
-
```cucumber
|
138
|
-
[enter my credentials]
|
139
|
-
```
|
112
|
+
As just mentioned earlier, the __quoted sentence__ determines the syntax of the new macro-step.
|
113
|
+
Its syntax is more or less free:
|
114
|
+
- The text outside the square brackets follows a fixed pattern. In other words,
|
115
|
+
the quoted sentence MUST always start as follows: ```"When I [...```. Notice however,
|
116
|
+
that the Given, Then keywords are also allowed.
|
117
|
+
- The text delimited by the square brackets [...], is called the __phrase__.
|
140
118
|
|
141
119
|
A few remarks about the __phrase__ part:
|
142
120
|
- It must be unique. In other words, it is not possible to create another
|
143
121
|
macro-step with the same phrase. In fact, Macros4Cuke uses the phrase internally as a mean to identify/name
|
144
122
|
a macro-step.
|
145
|
-
- It may have one or more arguments.
|
146
|
-
is placed inside the phrase.
|
123
|
+
- It may have one or more arguments.
|
147
124
|
Besides that, the text inside the phrase can be arbitrary (well, almost).
|
148
125
|
|
149
|
-
|
126
|
+
A phrase can be without argument as in:
|
150
127
|
```cucumber
|
151
|
-
|
152
|
-
|
128
|
+
# A phrase without argument
|
129
|
+
[enter my credentials]
|
130
|
+
```
|
131
|
+
|
132
|
+
Alternatively, a phrase can have one or more arguments enclosed between chevrons <...>.
|
133
|
+
For instance, the next first phrase has one argument, the second has three arguments:
|
134
|
+
```cucumber
|
135
|
+
[enter my <userid> and <password>]
|
136
|
+
[travel from <origin> to <destination> via <waypoint>]
|
137
|
+
```
|
153
138
|
|
154
|
-
Each argument (variable)
|
139
|
+
Each argument (variable) is enclosed between <...> chevrons. In our last example,
|
155
140
|
the argument names are: _origin_ and _destination_. Notice that _origin_ and _destination_ are
|
156
141
|
variable names that will take a value (if any) when the step is invoked _(more on this later)_.
|
142
|
+
|
157
143
|
|
158
144
|
#### Specifying the sub-steps of a macro-step ####
|
159
145
|
The sub-steps are placed in a Gherkin multiline text, that is, a text that is enclosed between
|
160
|
-
triple quotes ("""). In the
|
161
|
-
```cucumber
|
146
|
+
triple quotes ("""). In the next example,
|
147
|
+
```cucumber
|
148
|
+
Given I define the step "When I [enter my credentials]" to mean:
|
162
149
|
"""
|
163
150
|
Given I landed in the homepage
|
164
151
|
And I fill in "Username" with "tweedledum"
|
@@ -166,9 +153,11 @@ The sub-steps are placed in a Gherkin multiline text, that is, a text that is en
|
|
166
153
|
And I click "Sign in"
|
167
154
|
"""
|
168
155
|
```
|
169
|
-
|
170
|
-
|
171
|
-
|
156
|
+
|
157
|
+
the text between triple quotes enumerates the sub-steps associated with the macro-step.
|
158
|
+
A pleasing aspect is the familiar syntax the sub-steps have: they closely look to genuine steps of a scenario.
|
159
|
+
Sub-steps can also have macro arguments.
|
160
|
+
For instance, the previous step sequence could have two arguments called _userid_ and _password_:
|
172
161
|
```cucumber
|
173
162
|
"""
|
174
163
|
Given I landed in the homepage
|
@@ -177,12 +166,82 @@ enumerates the sub-steps associated with the macro-step. A pleasing aspect is th
|
|
177
166
|
And I click "Sign in"
|
178
167
|
"""
|
179
168
|
```
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
169
|
+
|
170
|
+
### Using(invoking) a macro-step ###
|
171
|
+
The rules for using a given macro-step in a scenario are pretty straightforward:
|
172
|
+
- Follow closely the syntax of the _quoted sentence_ in the macro definition.
|
173
|
+
- Replace every <argument> in the _phrase_ by its actual value between quotes.
|
174
|
+
|
175
|
+
#### Example 1: ####
|
176
|
+
Consider the following macro-step definition:
|
177
|
+
```cucumber
|
178
|
+
Given I define the step "When I [log in as <userid>]" to mean:
|
179
|
+
"""
|
180
|
+
# Sub-steps come here...
|
181
|
+
"""
|
182
|
+
```
|
183
|
+
|
184
|
+
Its quoted sentence is ```"When I [log in as <userid>]"```, therefore
|
185
|
+
the macro-step can be invoked in a scenario like this:
|
186
|
+
```cucumber
|
187
|
+
Given I do this ...
|
188
|
+
When I [log in as "jdoe"]
|
189
|
+
And I do that...
|
190
|
+
```
|
191
|
+
|
192
|
+
#### Example 2: ####
|
193
|
+
Here is another -partial- macro-step definition:
|
194
|
+
```cucumber
|
195
|
+
Given I define the step "When I [travel from <origin> to <destination> via <stop>]" to mean:
|
196
|
+
"""
|
197
|
+
# Sub-steps come here...
|
198
|
+
"""
|
199
|
+
```
|
200
|
+
|
201
|
+
This macro-step can occur in a scenario as:
|
202
|
+
```cucumber
|
203
|
+
When I [travel from "San Francisco" to "New-York" via "Las Vegas"]
|
204
|
+
```
|
205
|
+
|
206
|
+
The actual values for the arguments _origin_, _destination_ and _stop_ are
|
207
|
+
respectively San Francisco, New-York and Las Vegas.
|
208
|
+
|
209
|
+
|
210
|
+
### Passing argument data via a table ###
|
211
|
+
Passing more than three arguments in the phrase becomes problematic for readability reasons.
|
212
|
+
One ends up with lengthy and clumsy steps.
|
213
|
+
Therefore __Macros4Cuke__ has an alternative way to pass data values via a Gherkin table.
|
214
|
+
To enable this mechanism for a given macro, ensure that in its definition the quoted sentence ends with
|
215
|
+
a terminating colon (:) character.
|
216
|
+
|
217
|
+
The next example is based on one of the demo feature files:
|
218
|
+
```cucumber
|
219
|
+
# Next step has a colon after the ']': data can be passed with a table
|
220
|
+
Given I define the step "When I [enter my address as follows]:" to mean:
|
221
|
+
"""
|
222
|
+
When I fill in firstname with "<firstname>"
|
223
|
+
And I fill in lastname with "<lastname>"
|
224
|
+
And I fill in street with "<street_address>"
|
225
|
+
And I fill in postcode with "<postcode>"
|
226
|
+
And I fill in locality with "<city>"
|
227
|
+
And I fill in country with "<country>"
|
228
|
+
"""
|
229
|
+
```
|
230
|
+
|
231
|
+
This step can be used like this:
|
232
|
+
```cucumber
|
233
|
+
When I [enter my address as follows]:"
|
234
|
+
|lastname|Doe|
|
235
|
+
|firstname|John|
|
236
|
+
|street_address| Main Street, 22|
|
237
|
+
|city| Old White Castel|
|
238
|
+
|postcode|JK345|
|
239
|
+
|
240
|
+
Here are few observations worth noticing:
|
241
|
+
- The data table has two columns.
|
242
|
+
- Each row is of the form: |argument name| actual value|. For instance, the argument _street_address_ takes
|
243
|
+
the value "Main Street, 22".
|
244
|
+
- Data rows don't have to follow strictly the order of the arguments in the sub-step sequence.
|
186
245
|
|
187
246
|
Copyright
|
188
247
|
---------
|
data/lib/macro_steps.rb
CHANGED
@@ -13,7 +13,7 @@
|
|
13
13
|
# And I fill in "Password" with "unguessable"
|
14
14
|
# And I click "Submit"
|
15
15
|
# """
|
16
|
-
Given(/^I define the step "(?:When|
|
16
|
+
Given(/^I define the step "(?:Given|When|Then) I \[((?:[^\\\]]|\\.)+\]:?)" to mean:$/) do |macro_phrase, template|
|
17
17
|
add_macro(macro_phrase, template)
|
18
18
|
end
|
19
19
|
|
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.
|
4
|
+
version: 0.2.05
|
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-04-
|
12
|
+
date: 2013-04-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|