macros4cuke 0.1.03 → 0.1.04
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 +7 -0
- data/features/step_definitions/demo_steps.rb +1 -1
- data/features/travelling-demo.feature +53 -9
- data/lib/macros4cuke/constants.rb +1 -1
- data/lib/macros4cuke/macro-step.rb +19 -4
- metadata +1 -1
data/HISTORY.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
## [0.1.04]
|
2
|
+
## New features:
|
3
|
+
* Gherkin comments are allowed in sub-steps sequence. Previous version supported only Mustache comments.
|
4
|
+
## Changes:
|
5
|
+
* Added a few more examples in the 'travelling-demo.feature' file.
|
6
|
+
|
7
|
+
|
1
8
|
## [0.1.03]
|
2
9
|
### Documentation
|
3
10
|
* README.md: slightly reworked and added link to Mustache.
|
@@ -21,10 +21,11 @@ Scenario: Do a simple travel
|
|
21
21
|
# I arrive in Rome
|
22
22
|
|
23
23
|
|
24
|
+
|
24
25
|
Scenario: Defining a macro calling other macro(s)
|
25
26
|
Given I define the step "When I [travel from {{origin}} to {{destination}} and back]" to mean:
|
26
27
|
"""
|
27
|
-
|
28
|
+
# The next two steps are, in fact, macro-step invokations
|
28
29
|
When I [travel from "{{origin}}" to "{{destination}}"]
|
29
30
|
When I [travel from "{{destination}}" to "{{origin}}"]
|
30
31
|
"""
|
@@ -42,20 +43,22 @@ Scenario: Do a travel back and forth
|
|
42
43
|
Scenario: Defining a macro that requires a data table
|
43
44
|
Given I define the step "When I [fill in the form with]:" to mean:
|
44
45
|
"""
|
45
|
-
When I type {{firstname}}
|
46
|
-
And I type {{lastname}}
|
47
|
-
And I type {{street_address}}
|
48
|
-
And I type {{
|
49
|
-
And I type {{
|
46
|
+
When I type "{{firstname}}"
|
47
|
+
And I type "{{lastname}}"
|
48
|
+
And I type "{{street_address}}"
|
49
|
+
And I type "{{postcode}}"
|
50
|
+
And I type "{{city}}"
|
51
|
+
And I type "{{country}}"
|
50
52
|
"""
|
51
53
|
|
52
54
|
Scenario: Using a macro-step with a data table
|
53
55
|
When I [fill in the form with]:
|
54
56
|
|firstname| Sherlock|
|
55
|
-
|lastname|Holmes|
|
57
|
+
|lastname | Holmes |
|
56
58
|
|street_address| 221B, Baker Street|
|
57
|
-
|city|London|
|
58
|
-
|
|
59
|
+
|city |London |
|
60
|
+
|postcode|NW1 6XE |
|
61
|
+
|country | U.K. |
|
59
62
|
|
60
63
|
# You should see the output:
|
61
64
|
# Sherlock
|
@@ -63,3 +66,44 @@ Scenario: Using a macro-step with a data table
|
|
63
66
|
# 221B, Baker Street
|
64
67
|
# London
|
65
68
|
# U.K.
|
69
|
+
|
70
|
+
|
71
|
+
When I [fill in the form with]:
|
72
|
+
|firstname| Albert |
|
73
|
+
|lastname | Einstein|
|
74
|
+
|street_address| 22, Mercer Street|
|
75
|
+
|city |Princeton|
|
76
|
+
|country| U.S.A |
|
77
|
+
|
78
|
+
# You should see the output:
|
79
|
+
# Albert
|
80
|
+
# Einstein
|
81
|
+
# 22, Mercer Street
|
82
|
+
|
83
|
+
# Princeton
|
84
|
+
# U.S.A
|
85
|
+
|
86
|
+
# Did you notice the empty line in the previous output.
|
87
|
+
# Guess what? We forgot to specify a value for the postcode argument.
|
88
|
+
|
89
|
+
|
90
|
+
Scenario: Demonstrate that it is possible to use a sub-step with a data table
|
91
|
+
Given I define the step "When I [fill in, as a Londonian, the form with]:" to mean:
|
92
|
+
"""
|
93
|
+
When I [fill in the form with]:
|
94
|
+
|firstname| {{firstname}}|
|
95
|
+
|lastname | {{lastname}} |
|
96
|
+
|street_address| {{street_address}}|
|
97
|
+
|postcode|{{postcode}} |
|
98
|
+
# The next two lines have hard-coded values
|
99
|
+
|city |London |
|
100
|
+
|country | U.K. |
|
101
|
+
"""
|
102
|
+
|
103
|
+
# Let's try...
|
104
|
+
When I [fill in, as a Londonian, the form with]:
|
105
|
+
|firstname| Prime|
|
106
|
+
|lastname | Minister |
|
107
|
+
|street_address| 10, Downing Street|
|
108
|
+
|
109
|
+
|
@@ -22,18 +22,21 @@ class MacroStep
|
|
22
22
|
|
23
23
|
|
24
24
|
# Constructor.
|
25
|
-
# [aMacroPhrase]
|
26
|
-
# [
|
27
|
-
def initialize(aMacroPhrase,
|
25
|
+
# [aMacroPhrase] The text from the macro step definition that is between the square brackets.
|
26
|
+
# [theSubsteps] The source text of the steps to be expanded upon macro invokation.
|
27
|
+
def initialize(aMacroPhrase, theSubsteps)
|
28
28
|
@name = self.class.macro_key(aMacroPhrase, :definition)
|
29
29
|
|
30
30
|
# Retrieve the macro arguments embedded in the phrase.
|
31
31
|
@phrase_args = scan_arguments(aMacroPhrase, :definition)
|
32
32
|
@args = @phrase_args.dup()
|
33
33
|
|
34
|
+
# Manipulate the substeps source text (e.g. remove comment lines)
|
35
|
+
substeps_processed = preprocess(theSubsteps)
|
36
|
+
|
34
37
|
# The expansion text is a Mustache template
|
35
38
|
@renderer = Mustache.new
|
36
|
-
renderer.template =
|
39
|
+
renderer.template = substeps_processed
|
37
40
|
|
38
41
|
# Retrieve the Mustache tag names from the template and add them as macro arguments
|
39
42
|
add_tags_multi(renderer.template.tokens())
|
@@ -148,6 +151,18 @@ private
|
|
148
151
|
raw_result = aMacroPhrase.scan(pattern)
|
149
152
|
return raw_result.flatten.compact
|
150
153
|
end
|
154
|
+
|
155
|
+
# Return the substeps text after some transformation
|
156
|
+
# [theSubstepsSource] The source text of the steps to be expanded upon macro invokation.
|
157
|
+
def preprocess(theSubstepsSource)
|
158
|
+
# Split text into lines
|
159
|
+
lines = theSubstepsSource.split(/\r\n?|\n/)
|
160
|
+
|
161
|
+
# Reject comment lines. This necessary because Cucumber::RbSupport::RbWorld#steps complains when it sees a comment.
|
162
|
+
processed = lines.reject { |a_line| a_line =~ /\s*#/ }
|
163
|
+
|
164
|
+
return processed.join("\n")
|
165
|
+
end
|
151
166
|
|
152
167
|
# Visit an array of tokens of which the first element is the :multi symbol.
|
153
168
|
# Every found template variable is added to the 'args' attribute.
|