macros4cuke 0.2.00 → 0.2.01
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY.md +7 -6
- data/README.md +164 -86
- data/features/demo02.feature +33 -33
- data/features/travelling-demo.feature +113 -113
- data/lib/macro_steps.rb +46 -46
- data/lib/macros4cuke/constants.rb +1 -1
- metadata +18 -2
data/HISTORY.md
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
## [0.2.00] Version number was bumped
|
2
2
|
### Changes:
|
3
|
-
*
|
4
|
-
|
5
|
-
|
6
|
-
*
|
3
|
+
* Regexp in the step definitions are more robust: they accept escape character sequence.
|
4
|
+
|
5
|
+
### Fixes:
|
6
|
+
* Corrected remnant of Mustache template in travelling_demo.feature file.
|
7
|
+
|
7
8
|
|
8
9
|
### Documentation:
|
9
|
-
*
|
10
|
-
|
10
|
+
* Expanded the README.md file.
|
11
|
+
|
11
12
|
|
12
13
|
|
13
14
|
## [0.1.07]
|
data/README.md
CHANGED
@@ -1,87 +1,165 @@
|
|
1
|
-
Macros4Cuke
|
2
|
-
===========
|
3
|
-
|
4
|
-
_Add macros to your Cucumber scenarios._
|
5
|
-
[Homepage](https://github.com/famished-tiger/Macros4Cuke)
|
6
|
-
|
7
|
-
__Macros4Cuke__ gives you the opportunity to factor out repeated steps
|
8
|
-
in your Cucumber scenarios. You can create (macro-)steps directly in feature files.
|
9
|
-
To each macro-step, it is possible to associate a sequence of sub-steps
|
10
|
-
that will be executed every time a macro-step occurs in a scenario.
|
11
|
-
|
12
|
-
### Highlights ###
|
13
|
-
* Works with out-of-the-box Cucumber
|
14
|
-
* Simple installation and setup (no programming required),
|
15
|
-
* Substep sequence can be of arbitrary length,
|
16
|
-
* Macro-steps may have data arguments,
|
17
|
-
* Data values can be passed to the sub-steps.
|
18
|
-
|
19
|
-
##
|
20
|
-
Here is an example taken from our demo files:
|
21
|
-
```cucumber
|
22
|
-
Given I define the step "When I [enter my userid <userid> and password <password>]" to mean:
|
23
|
-
"""
|
24
|
-
Given I landed in the homepage
|
25
|
-
When I click "Sign in"
|
26
|
-
And I fill in "Username" with "<userid>"
|
27
|
-
And I fill in "Password" with "<password>"
|
28
|
-
And I click "Submit"
|
29
|
-
"""
|
30
|
-
```
|
31
|
-
|
32
|
-
Notice how the arguments _userid_ and _password_ are enclosed between chevrons (angle brackets) <...>.
|
33
|
-
|
34
|
-
|
35
|
-
That macro-step can then be used in a scenario like this:
|
36
|
-
```cucumber
|
37
|
-
When I [enter my userid "jdoe" and password "hello-world"]
|
38
|
-
```
|
39
|
-
|
40
|
-
When it is executed, the last macro-step (invokation) as the same effect as:
|
41
|
-
```cucumber
|
42
|
-
Given I landed in the homepage
|
43
|
-
When I click "Sign in"
|
44
|
-
And I fill in "Username" with "jdoe"
|
45
|
-
And I fill in "Password" with "hello-world"
|
46
|
-
And I click "Submit"
|
47
|
-
"""
|
48
|
-
```
|
49
|
-
|
50
|
-
In other words, this sequence of 5 steps can be replaced by just one.
|
51
|
-
Macros4Cuke not only helps in getting rid of the repeated step sequences,
|
52
|
-
it allows the feature writers to create themselves higher-level steps
|
53
|
-
that are closer to the business logic.
|
54
|
-
|
55
|
-
See also the working examples in the features folder.
|
56
|
-
|
57
|
-
##
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
```
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
1
|
+
Macros4Cuke
|
2
|
+
===========
|
3
|
+
|
4
|
+
_Add macros to your Cucumber scenarios._
|
5
|
+
[Homepage](https://github.com/famished-tiger/Macros4Cuke)
|
6
|
+
|
7
|
+
__Macros4Cuke__ gives you the opportunity to factor out repeated steps
|
8
|
+
in your Cucumber scenarios. You can create (macro-)steps directly in feature files.
|
9
|
+
To each macro-step, it is possible to associate a sequence of sub-steps
|
10
|
+
that will be executed every time a macro-step occurs in a scenario.
|
11
|
+
|
12
|
+
### Highlights ###
|
13
|
+
* Works with out-of-the-box Cucumber
|
14
|
+
* Simple installation and setup (no programming required),
|
15
|
+
* Substep sequence can be of arbitrary length,
|
16
|
+
* Macro-steps may have data arguments,
|
17
|
+
* Data values can be passed to the sub-steps.
|
18
|
+
|
19
|
+
## A quick example ##
|
20
|
+
Here is an example taken from our demo files:
|
21
|
+
```cucumber
|
22
|
+
Given I define the step "When I [enter my userid <userid> and password <password>]" to mean:
|
23
|
+
"""
|
24
|
+
Given I landed in the homepage
|
25
|
+
When I click "Sign in"
|
26
|
+
And I fill in "Username" with "<userid>"
|
27
|
+
And I fill in "Password" with "<password>"
|
28
|
+
And I click "Submit"
|
29
|
+
"""
|
30
|
+
```
|
31
|
+
|
32
|
+
Notice how the arguments _userid_ and _password_ are enclosed between chevrons (angle brackets) <...>.
|
33
|
+
|
34
|
+
|
35
|
+
That macro-step can then be used in a scenario like this:
|
36
|
+
```cucumber
|
37
|
+
When I [enter my userid "jdoe" and password "hello-world"]
|
38
|
+
```
|
39
|
+
|
40
|
+
When it is executed, the last macro-step (invokation) as the same effect as:
|
41
|
+
```cucumber
|
42
|
+
Given I landed in the homepage
|
43
|
+
When I click "Sign in"
|
44
|
+
And I fill in "Username" with "jdoe"
|
45
|
+
And I fill in "Password" with "hello-world"
|
46
|
+
And I click "Submit"
|
47
|
+
"""
|
48
|
+
```
|
49
|
+
|
50
|
+
In other words, this sequence of 5 steps can be replaced by just one.
|
51
|
+
Macros4Cuke not only helps in getting rid of the repeated step sequences,
|
52
|
+
it allows the feature writers to create themselves higher-level steps
|
53
|
+
that are closer to the business logic.
|
54
|
+
|
55
|
+
See also the working examples in the features folder.
|
56
|
+
|
57
|
+
## Setup ##
|
58
|
+
### Installation ###
|
59
|
+
To install the macros4cuke gem:
|
60
|
+
```bash
|
61
|
+
$[sudo] gem install macros4cuke
|
62
|
+
```
|
63
|
+
|
64
|
+
### Setting up your Cucumber project ####
|
65
|
+
|
66
|
+
* Step 1: Add support for macros in your Cucumber project
|
67
|
+
In your `/features/support/` folder:
|
68
|
+
- Create a Ruby file (e.g. 'macro\_support.rb') with the following contents:
|
69
|
+
|
70
|
+
```ruby
|
71
|
+
require 'macros4cuke'
|
72
|
+
World(Macros4Cuke::MacroStepSupport)
|
73
|
+
```
|
74
|
+
|
75
|
+
* Step 2: Import the macro-management steps
|
76
|
+
In your `/features/step_definitions/` folder:
|
77
|
+
- Create a Ruby file (say, 'use\_macro\_steps.rb') with the following line:
|
78
|
+
|
79
|
+
```ruby
|
80
|
+
require 'macros4cuke/../macro_steps'
|
81
|
+
```
|
82
|
+
|
83
|
+
That's it! Now you can start writing macros in your Cucumber project.
|
84
|
+
|
85
|
+
|
86
|
+
## Getting started ##
|
87
|
+
Working with a macro-step is a two-stages process:
|
88
|
+
1. First, the definition of a new macro-step
|
89
|
+
2. Second, the use of that macro-step in a scenario.
|
90
|
+
|
91
|
+
Let's begin by taking a closer look at the definition step.
|
92
|
+
### Defining a macro-step ###
|
93
|
+
There are three questions to keep in mind when creating a new macro-step:
|
94
|
+
1. What is its syntax?
|
95
|
+
2. What are its substeps?
|
96
|
+
3. Does it need arguments?
|
97
|
+
|
98
|
+
#### Specifying the syntax of a macro-step ####
|
99
|
+
Let's begin with a simple example:
|
100
|
+
```cucumber
|
101
|
+
Given I define the step "When I [enter my credentials]" to mean:
|
102
|
+
"""
|
103
|
+
Given I landed in the homepage
|
104
|
+
And I fill in "Username" with "tweedledum"
|
105
|
+
And I fill in "Password" with "tweedledee"
|
106
|
+
And I click "Sign in"
|
107
|
+
"""
|
108
|
+
```
|
109
|
+
|
110
|
+
The first line in the snippet is a step that helps to define macro-step.
|
111
|
+
It is a perfectly valid step once your Cucumber project was configured to use __Macros4Cuke__
|
112
|
+
as explained in the Setup section above.
|
113
|
+
The syntax of a macro-step sentence is defined by its __phrase__, that is, the text on the first line that appears
|
114
|
+
between square brackets [...].
|
115
|
+
In the example at hand, the _phrase_ is the text:
|
116
|
+
```cucumber
|
117
|
+
[enter my credentials]
|
118
|
+
```
|
119
|
+
|
120
|
+
A few remarks about the __phrase__ part:
|
121
|
+
- It must be unique. In other words, it is not possible to create another
|
122
|
+
macro-step with the same phrase. In fact, Macros4Cuke uses the phrase internally as a mean to identify/name
|
123
|
+
a macro-step.
|
124
|
+
- It may have one or more arguments. The example above illustrates the simplest case where no argument
|
125
|
+
is placed inside the phrase.
|
126
|
+
Besides that, the text inside the phrase can be arbitrary (well, almost).
|
127
|
+
|
128
|
+
The next phrase takes two arguments:
|
129
|
+
```cucumber
|
130
|
+
[travel from <origin> to <destination>]
|
131
|
+
```
|
132
|
+
|
133
|
+
Each argument (variable), is enclosed between <...> chevrons. In our last example,
|
134
|
+
the argument names are: _origin_ and _destination_. Notice that _origin_ and _destination_ are
|
135
|
+
variable names that will take a value (if any) when the step is invoked _(more on this later)_.
|
136
|
+
|
137
|
+
#### Specifying the sub-steps of a macro-step ####
|
138
|
+
The sub-steps are placed in a Gherkin multiline text, that is, a text that is enclosed between
|
139
|
+
triple quotes ("""). In the earlier example, the text
|
140
|
+
```cucumber
|
141
|
+
"""
|
142
|
+
Given I landed in the homepage
|
143
|
+
And I fill in "Username" with "tweedledum"
|
144
|
+
And I fill in "Password" with "tweedledee"
|
145
|
+
And I click "Sign in"
|
146
|
+
"""
|
147
|
+
```
|
148
|
+
enumerates the sub-steps associated with the macro-step. A pleasing aspect is the familiar syntax
|
149
|
+
the sub-steps have: they closely look to steps in a genuine scenario. Sub-steps can also have macro arguments.
|
150
|
+
For instance, the previous step sequence may have two arguments called _userid_ and _password_:
|
151
|
+
```cucumber
|
152
|
+
"""
|
153
|
+
Given I landed in the homepage
|
154
|
+
And I fill in "Username" with "<userid>"
|
155
|
+
And I fill in "Password" with "<password>"
|
156
|
+
And I click "Sign in"
|
157
|
+
"""
|
158
|
+
```
|
159
|
+
|
160
|
+
|
161
|
+
---
|
162
|
+
|
163
|
+
Copyright
|
164
|
+
---------
|
87
165
|
Copyright (c) 2013, Dimitri Geshef. See [LICENSE.txt](https://github.com/famished-tiger/Macros4Cuke/blob/master/LICENSE.txt) for details.
|
data/features/demo02.feature
CHANGED
@@ -1,34 +1,34 @@
|
|
1
|
-
# File: demo02.feature
|
2
|
-
|
3
|
-
Feature: Show the use of a basic macro with one argument
|
4
|
-
As a Cuke user
|
5
|
-
So that I enjoy writing scenario.
|
6
|
-
|
7
|
-
|
8
|
-
Scenario: Creating a basic scenario with one argument
|
9
|
-
# The next step creates a macro(-step)
|
10
|
-
# The syntax of the new macro-step is specified between the double quotes.
|
11
|
-
# The steps to execute when the macro is used/invoked are listed in the multiline triple quotes arguments.
|
12
|
-
# The macro argument is put between chevrons <...>.
|
13
|
-
Given I define the step "When I [log in as <userid>]" to mean:
|
14
|
-
"""
|
15
|
-
Given I landed in the homepage
|
16
|
-
When I click "Sign in"
|
17
|
-
And I fill in "Username" with "<userid>"
|
18
|
-
And I fill in "Password" with "unguessable"
|
19
|
-
And I click "Submit"
|
20
|
-
"""
|
21
|
-
|
22
|
-
Scenario: Let's use the macro we created above
|
23
|
-
# Here the macro is invoked. Actual value for the argument is put between double quotes.
|
24
|
-
When I [log in as "guest"]
|
25
|
-
|
26
|
-
# The next step verifies that the steps from the macro were effectively executed.
|
27
|
-
Then I expect the following step trace:
|
28
|
-
"""
|
29
|
-
Invoked step: ... I landed in the homepage
|
30
|
-
Invoked step: ... I click "Sign in"
|
31
|
-
Invoked step: ... I fill in "Username" with "guest"
|
32
|
-
Invoked step: ... I fill in "Password" with "unguessable"
|
33
|
-
Invoked step: ... I click "Submit"
|
1
|
+
# File: demo02.feature
|
2
|
+
|
3
|
+
Feature: Show the use of a basic macro with one argument
|
4
|
+
As a Cuke user
|
5
|
+
So that I enjoy writing scenario.
|
6
|
+
|
7
|
+
|
8
|
+
Scenario: Creating a basic scenario with one argument
|
9
|
+
# The next step creates a macro(-step)
|
10
|
+
# The syntax of the new macro-step is specified between the double quotes.
|
11
|
+
# The steps to execute when the macro is used/invoked are listed in the multiline triple quotes arguments.
|
12
|
+
# The macro argument is put between chevrons <...>.
|
13
|
+
Given I define the step "When I [log in\[\] as <userid>]" to mean:
|
14
|
+
"""
|
15
|
+
Given I landed in the homepage
|
16
|
+
When I click "Sign in"
|
17
|
+
And I fill in "Username" with "<userid>"
|
18
|
+
And I fill in "Password" with "unguessable"
|
19
|
+
And I click "Submit"
|
20
|
+
"""
|
21
|
+
|
22
|
+
Scenario: Let's use the macro we created above
|
23
|
+
# Here the macro is invoked. Actual value for the argument is put between double quotes.
|
24
|
+
When I [log in\[\] as "guest"]
|
25
|
+
|
26
|
+
# The next step verifies that the steps from the macro were effectively executed.
|
27
|
+
Then I expect the following step trace:
|
28
|
+
"""
|
29
|
+
Invoked step: ... I landed in the homepage
|
30
|
+
Invoked step: ... I click "Sign in"
|
31
|
+
Invoked step: ... I fill in "Username" with "guest"
|
32
|
+
Invoked step: ... I fill in "Password" with "unguessable"
|
33
|
+
Invoked step: ... I click "Submit"
|
34
34
|
"""
|
@@ -1,113 +1,113 @@
|
|
1
|
-
# File: travelling-demo.feature
|
2
|
-
|
3
|
-
Feature: Show -visually- the several ways to use macros
|
4
|
-
As a Cuke user
|
5
|
-
So that I enjoy writing scenario.
|
6
|
-
|
7
|
-
|
8
|
-
Scenario: Definition of a simple macro-step with two arguments
|
9
|
-
Given I define the step "When I [travel from <origin> to <destination>]" to mean:
|
10
|
-
"""
|
11
|
-
When I leave <origin>
|
12
|
-
And I arrive in <destination>
|
13
|
-
"""
|
14
|
-
|
15
|
-
Scenario: Do a simple travel
|
16
|
-
# Call a macro-step defined earlier
|
17
|
-
When I [travel from "Brussels" to "Rome"]
|
18
|
-
|
19
|
-
# You should see the output:
|
20
|
-
# I leave Brussels
|
21
|
-
# I arrive in Rome
|
22
|
-
|
23
|
-
# Actual values can have embedded double quotes provided they are escaped.
|
24
|
-
When I [travel from "Tampa" to "\"Little Italy\""]
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
Scenario: Defining a macro calling other macro(s)
|
30
|
-
Given I define the step "When I [travel from <origin> to <destination> and back]" to mean:
|
31
|
-
"""
|
32
|
-
# The next two steps are, in fact, macro-step invokations
|
33
|
-
When I [travel from "<origin>" to "<destination>"]
|
34
|
-
When I [travel from "
|
35
|
-
"""
|
36
|
-
|
37
|
-
Scenario: Do a travel back and forth
|
38
|
-
When I [travel from "Paris" to "London" and back]
|
39
|
-
|
40
|
-
# You should see the output:
|
41
|
-
# I leave Paris
|
42
|
-
# I arrive in London
|
43
|
-
# I leave London
|
44
|
-
# I arrive in Paris
|
45
|
-
|
46
|
-
|
47
|
-
Scenario: Defining a macro that requires a data table
|
48
|
-
Given I define the step "When I [fill in the form with]:" to mean:
|
49
|
-
"""
|
50
|
-
When I type "<firstname>"
|
51
|
-
And I type "<lastname>"
|
52
|
-
And I type "<street_address>"
|
53
|
-
And I type "<postcode>"
|
54
|
-
And I type "<city>"
|
55
|
-
And I type "<country>"
|
56
|
-
"""
|
57
|
-
|
58
|
-
Scenario: Using a macro-step with a data table
|
59
|
-
When I [fill in the form with]:
|
60
|
-
|firstname| Sherlock|
|
61
|
-
|lastname | Holmes |
|
62
|
-
|street_address| 221B, Baker Street|
|
63
|
-
|city |London |
|
64
|
-
|postcode|NW1 6XE |
|
65
|
-
|country | U.K. |
|
66
|
-
|
67
|
-
# You should see the output:
|
68
|
-
# Sherlock
|
69
|
-
# Holmes
|
70
|
-
# 221B, Baker Street
|
71
|
-
# London
|
72
|
-
# U.K.
|
73
|
-
|
74
|
-
|
75
|
-
When I [fill in the form with]:
|
76
|
-
|firstname| Albert |
|
77
|
-
|lastname | Einstein|
|
78
|
-
|street_address| 22, Mercer Street|
|
79
|
-
|city |Princeton|
|
80
|
-
|country| U.S.A |
|
81
|
-
|
82
|
-
# You should see the output:
|
83
|
-
# Albert
|
84
|
-
# Einstein
|
85
|
-
# 22, Mercer Street
|
86
|
-
|
87
|
-
# Princeton
|
88
|
-
# U.S.A
|
89
|
-
|
90
|
-
# Did you notice the empty line in the previous output.
|
91
|
-
# Guess what? We forgot to specify a value for the postcode argument.
|
92
|
-
|
93
|
-
|
94
|
-
Scenario: Demonstrate that it is possible to use a sub-step with a data table
|
95
|
-
Given I define the step "When I [fill in, as a Londonian, the form with]:" to mean:
|
96
|
-
"""
|
97
|
-
When I [fill in the form with]:
|
98
|
-
|firstname| <firstname>|
|
99
|
-
|lastname | <lastname> |
|
100
|
-
|street_address| <street_address>|
|
101
|
-
|postcode|<postcode> |
|
102
|
-
# The next two lines have hard-coded values
|
103
|
-
|city |London |
|
104
|
-
|country | U.K. |
|
105
|
-
"""
|
106
|
-
|
107
|
-
# Let's try...
|
108
|
-
When I [fill in, as a Londonian, the form with]:
|
109
|
-
|firstname| Prime|
|
110
|
-
|lastname | Minister |
|
111
|
-
|street_address| 10, Downing Street|
|
112
|
-
|
113
|
-
|
1
|
+
# File: travelling-demo.feature
|
2
|
+
|
3
|
+
Feature: Show -visually- the several ways to use macros
|
4
|
+
As a Cuke user
|
5
|
+
So that I enjoy writing scenario.
|
6
|
+
|
7
|
+
|
8
|
+
Scenario: Definition of a simple macro-step with two arguments
|
9
|
+
Given I define the step "When I [travel from <origin> to <destination>]" to mean:
|
10
|
+
"""
|
11
|
+
When I leave <origin>
|
12
|
+
And I arrive in <destination>
|
13
|
+
"""
|
14
|
+
|
15
|
+
Scenario: Do a simple travel
|
16
|
+
# Call a macro-step defined earlier
|
17
|
+
When I [travel from "Brussels" to "Rome"]
|
18
|
+
|
19
|
+
# You should see the output:
|
20
|
+
# I leave Brussels
|
21
|
+
# I arrive in Rome
|
22
|
+
|
23
|
+
# Actual values can have embedded double quotes provided they are escaped.
|
24
|
+
When I [travel from "Tampa" to "\"Little Italy\""]
|
25
|
+
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
Scenario: Defining a macro calling other macro(s)
|
30
|
+
Given I define the step "When I [travel from <origin> to <destination> and back]" to mean:
|
31
|
+
"""
|
32
|
+
# The next two steps are, in fact, macro-step invokations
|
33
|
+
When I [travel from "<origin>" to "<destination>"]
|
34
|
+
When I [travel from "<destination>" to "<origin>"]
|
35
|
+
"""
|
36
|
+
|
37
|
+
Scenario: Do a travel back and forth
|
38
|
+
When I [travel from "Paris" to "London" and back]
|
39
|
+
|
40
|
+
# You should see the output:
|
41
|
+
# I leave Paris
|
42
|
+
# I arrive in London
|
43
|
+
# I leave London
|
44
|
+
# I arrive in Paris
|
45
|
+
|
46
|
+
|
47
|
+
Scenario: Defining a macro that requires a data table
|
48
|
+
Given I define the step "When I [fill in the form with]:" to mean:
|
49
|
+
"""
|
50
|
+
When I type "<firstname>"
|
51
|
+
And I type "<lastname>"
|
52
|
+
And I type "<street_address>"
|
53
|
+
And I type "<postcode>"
|
54
|
+
And I type "<city>"
|
55
|
+
And I type "<country>"
|
56
|
+
"""
|
57
|
+
|
58
|
+
Scenario: Using a macro-step with a data table
|
59
|
+
When I [fill in the form with]:
|
60
|
+
|firstname| Sherlock|
|
61
|
+
|lastname | Holmes |
|
62
|
+
|street_address| 221B, Baker Street|
|
63
|
+
|city |London |
|
64
|
+
|postcode|NW1 6XE |
|
65
|
+
|country | U.K. |
|
66
|
+
|
67
|
+
# You should see the output:
|
68
|
+
# Sherlock
|
69
|
+
# Holmes
|
70
|
+
# 221B, Baker Street
|
71
|
+
# London
|
72
|
+
# U.K.
|
73
|
+
|
74
|
+
|
75
|
+
When I [fill in the form with]:
|
76
|
+
|firstname| Albert |
|
77
|
+
|lastname | Einstein|
|
78
|
+
|street_address| 22, Mercer Street|
|
79
|
+
|city |Princeton|
|
80
|
+
|country| U.S.A |
|
81
|
+
|
82
|
+
# You should see the output:
|
83
|
+
# Albert
|
84
|
+
# Einstein
|
85
|
+
# 22, Mercer Street
|
86
|
+
|
87
|
+
# Princeton
|
88
|
+
# U.S.A
|
89
|
+
|
90
|
+
# Did you notice the empty line in the previous output.
|
91
|
+
# Guess what? We forgot to specify a value for the postcode argument.
|
92
|
+
|
93
|
+
|
94
|
+
Scenario: Demonstrate that it is possible to use a sub-step with a data table
|
95
|
+
Given I define the step "When I [fill in, as a Londonian, the form with]:" to mean:
|
96
|
+
"""
|
97
|
+
When I [fill in the form with]:
|
98
|
+
|firstname| <firstname>|
|
99
|
+
|lastname | <lastname> |
|
100
|
+
|street_address| <street_address>|
|
101
|
+
|postcode|<postcode> |
|
102
|
+
# The next two lines have hard-coded values
|
103
|
+
|city |London |
|
104
|
+
|country | U.K. |
|
105
|
+
"""
|
106
|
+
|
107
|
+
# Let's try...
|
108
|
+
When I [fill in, as a Londonian, the form with]:
|
109
|
+
|firstname| Prime|
|
110
|
+
|lastname | Minister |
|
111
|
+
|street_address| 10, Downing Street|
|
112
|
+
|
113
|
+
|
data/lib/macro_steps.rb
CHANGED
@@ -1,47 +1,47 @@
|
|
1
|
-
# File: macro_steps.rb
|
2
|
-
# Purpose: step definitions that help to build macro-steps (i.e. a step that is equivalent to a sequence of steps)
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
# This step is used to define a macro-step
|
7
|
-
# Example:
|
8
|
-
# Given I define the step "When I [log in as
|
9
|
-
# """
|
10
|
-
# Given I landed in the homepage
|
11
|
-
# When I click "Sign in"
|
12
|
-
# And I fill in "Username" with "
|
13
|
-
# And I fill in "Password" with "unguessable"
|
14
|
-
# And I click "Submit"
|
15
|
-
# """
|
16
|
-
|
17
|
-
Given(/^I define the step "When I \[([
|
18
|
-
add_macro(macro_phrase, template)
|
19
|
-
end
|
20
|
-
|
21
|
-
# This step is used to invoke a simple macro-step
|
22
|
-
# Example:
|
23
|
-
# When I [log in as "guest"]
|
24
|
-
#
|
25
|
-
When(/^I \[([
|
26
|
-
invoke_macro(macro_phrase) # This will call the macro with the given phrase
|
27
|
-
end
|
28
|
-
|
29
|
-
|
30
|
-
# This step is used to invoke a macro-step with a table argument.
|
31
|
-
# Example:
|
32
|
-
# When I [enter my credentials as]:
|
33
|
-
# |userid |guest |
|
34
|
-
# |password|unguessable|
|
35
|
-
When(/^I \[([^\]]+\]:)$/) do |macro_phrase, table_argument|
|
36
|
-
# Ensure that the second argument is of the correct type
|
37
|
-
unless table_argument.kind_of?(Cucumber::Ast::Table)
|
38
|
-
raise StandardError, "This step must have a data table as an argument."
|
39
|
-
end
|
40
|
-
|
41
|
-
# This will call the macro with the given phrase.
|
42
|
-
# The second argument consists of a hash with pairs of the kind: argument name => actual value
|
43
|
-
invoke_macro(macro_phrase, table_argument.rows_hash())
|
44
|
-
end
|
45
|
-
|
46
|
-
|
1
|
+
# File: macro_steps.rb
|
2
|
+
# Purpose: step definitions that help to build macro-steps (i.e. a step that is equivalent to a sequence of steps)
|
3
|
+
|
4
|
+
|
5
|
+
|
6
|
+
# This step is used to define a macro-step
|
7
|
+
# Example:
|
8
|
+
# Given I define the step "When I [log in as {{userid}}]" to mean:
|
9
|
+
# """
|
10
|
+
# Given I landed in the homepage
|
11
|
+
# When I click "Sign in"
|
12
|
+
# And I fill in "Username" with "{{userid}}"
|
13
|
+
# And I fill in "Password" with "unguessable"
|
14
|
+
# And I click "Submit"
|
15
|
+
# """
|
16
|
+
|
17
|
+
Given(/^I define the step "When I \[((?:[^\\\]]|\\.)+\]:?)" to mean:$/) do |macro_phrase, template|
|
18
|
+
add_macro(macro_phrase, template)
|
19
|
+
end
|
20
|
+
|
21
|
+
# This step is used to invoke a simple macro-step
|
22
|
+
# Example:
|
23
|
+
# When I [log in as "guest"]
|
24
|
+
#
|
25
|
+
When(/^I \[((?:[^\\\]]|\\.)+\])$/) do |macro_phrase|
|
26
|
+
invoke_macro(macro_phrase) # This will call the macro with the given phrase
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
# This step is used to invoke a macro-step with a table argument.
|
31
|
+
# Example:
|
32
|
+
# When I [enter my credentials as]:
|
33
|
+
# |userid |guest |
|
34
|
+
# |password|unguessable|
|
35
|
+
When(/^I \[([^\]]+\]:)$/) do |macro_phrase, table_argument|
|
36
|
+
# Ensure that the second argument is of the correct type
|
37
|
+
unless table_argument.kind_of?(Cucumber::Ast::Table)
|
38
|
+
raise StandardError, "This step must have a data table as an argument."
|
39
|
+
end
|
40
|
+
|
41
|
+
# This will call the macro with the given phrase.
|
42
|
+
# The second argument consists of a hash with pairs of the kind: argument name => actual value
|
43
|
+
invoke_macro(macro_phrase, table_argument.rows_hash())
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
47
|
# End of file
|
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.01
|
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-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -43,6 +43,22 @@ dependencies:
|
|
43
43
|
- - ! '>='
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '2.00'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.00'
|
46
62
|
description: ! "\tMacros4Cuke is a lightweight library that adds a macro facility
|
47
63
|
your Cucumber scenarios.\n In short, you can create any new step that replaces
|
48
64
|
a sequence of lower-level steps.\n All this can be done directly in your feature
|