macros4cuke 0.1.04 → 0.1.06
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY.md +18 -3
- data/README.md +18 -2
- data/features/travelling-demo.feature +5 -0
- data/lib/macros4cuke/constants.rb +1 -1
- data/lib/macros4cuke/macro-step.rb +7 -3
- data/lib/macros4cuke/template-engine.rb +64 -0
- metadata +3 -2
data/HISTORY.md
CHANGED
@@ -1,13 +1,28 @@
|
|
1
|
+
## [0.1.06]
|
2
|
+
|
3
|
+
### Documentation:
|
4
|
+
* Format fix in README.md
|
5
|
+
* HISTORY.md file updated
|
6
|
+
|
7
|
+
## [0.1.05]
|
8
|
+
### Changes:
|
9
|
+
* demo_steps.rb: A few step definitions emits output to the screen (so that at least something is shown in the demo).
|
10
|
+
* MacroStep class: regexp slightly reworked to accept escaped double quotes in actual values.
|
11
|
+
* travelling_demo.feature: added one example with escaped quotes in actual value.
|
12
|
+
|
13
|
+
|
1
14
|
## [0.1.04]
|
2
|
-
|
15
|
+
### New features:
|
3
16
|
* Gherkin comments are allowed in sub-steps sequence. Previous version supported only Mustache comments.
|
4
|
-
|
17
|
+
|
18
|
+
### Changes:
|
5
19
|
* Added a few more examples in the 'travelling-demo.feature' file.
|
6
20
|
|
7
21
|
|
8
22
|
## [0.1.03]
|
9
23
|
### Documentation
|
10
|
-
* README.md: slightly reworked and added link to Mustache.
|
24
|
+
* README.md: slightly reworked and added link to Mustache.
|
25
|
+
|
11
26
|
### Changes:
|
12
27
|
* env.rb: All dependencies on Macros4Cuke were moved to the file macro_support.rb
|
13
28
|
* travelling-demo.feature: Demo feature file with output on the screen (the other demos don't display any result).
|
data/README.md
CHANGED
@@ -38,27 +38,43 @@ That macro-step can then be used in a scenario like this:
|
|
38
38
|
When I [enter my userid "jdoe" and password "hello-world"]
|
39
39
|
```
|
40
40
|
|
41
|
+
When it is executed, the last macro-step (invokation) as the same effect as:
|
42
|
+
```cucumber
|
43
|
+
Given I landed in the homepage
|
44
|
+
When I click "Sign in"
|
45
|
+
And I fill in "Username" with "jdoe"
|
46
|
+
And I fill in "Password" with "hello-world"
|
47
|
+
And I click "Submit"
|
48
|
+
"""
|
49
|
+
```
|
50
|
+
|
51
|
+
In other words, this sequence of 5 steps can be replaced by just one.
|
52
|
+
Macros4Cuke not only helps in getting rid of the repeated step sequences,
|
53
|
+
it allows the feature writers to create themselves higher-level steps
|
54
|
+
that are closer to the business logic.
|
55
|
+
|
41
56
|
See also the working examples in the features folder.
|
42
57
|
|
43
58
|
## Install and setup ##
|
44
59
|
* Step 1: Install the macros4cuke gem:
|
45
60
|
```bash
|
46
|
-
gem install macros4cuke
|
61
|
+
[sudo] gem install macros4cuke
|
47
62
|
```
|
48
63
|
|
49
64
|
|
50
65
|
* Step 2: Add support for macros in your Cucumber project
|
51
66
|
In your /features/support/ folder:
|
52
67
|
- Create a Ruby file (e.g. 'macro\_support.rb') with the following contents:
|
68
|
+
|
53
69
|
```ruby
|
54
70
|
require 'macros4cuke'
|
55
|
-
|
56
71
|
World(Macros4Cuke::MacroStepSupport)
|
57
72
|
```
|
58
73
|
|
59
74
|
* Step 3: Import the macro-management steps
|
60
75
|
In your /features/step_definitions/ folder:
|
61
76
|
- Create a ruby file (say, 'use\_macro\_steps.rb') with the following line:
|
77
|
+
|
62
78
|
```ruby
|
63
79
|
require 'macros4cuke/../macro_steps'
|
64
80
|
```
|
@@ -19,6 +19,11 @@ Scenario: Do a simple travel
|
|
19
19
|
# You should see the output:
|
20
20
|
# I leave Brussels
|
21
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
|
+
# Notice the HTML-escaping done by Mustache
|
22
27
|
|
23
28
|
|
24
29
|
|
@@ -50,6 +50,7 @@ class MacroStep
|
|
50
50
|
# In invokation mode, a placeholder is delimited by double quotes.
|
51
51
|
# The rule for building the identifier are:
|
52
52
|
# - Leading and trailing space(s) are removed.
|
53
|
+
# - Each underscore character is removed.
|
53
54
|
# - Every sequence of one or more space(s) is converted into an underscore
|
54
55
|
# - Each placeholder (i.e. = delimiters + enclosed text) is converted into a letter X.
|
55
56
|
# - The endings are transformed as follows: ] => '', ]: => _T
|
@@ -59,17 +60,20 @@ class MacroStep
|
|
59
60
|
def self.macro_key(aMacroPhrase, mode)
|
60
61
|
stripped_phrase = aMacroPhrase.strip # Remove leading ... trailing space(s)
|
61
62
|
|
63
|
+
# Remove every underscore
|
64
|
+
stripped_phrase.gsub!(/_/, '')
|
62
65
|
|
63
66
|
# Replace all consecutive whitespaces by an underscore
|
64
67
|
stripped_phrase.gsub!(/\s+/, '_')
|
65
68
|
|
66
69
|
|
67
|
-
# Determine the pattern to isolate each argument/
|
70
|
+
# Determine the pattern to isolate each argument/parameter with its delimiters
|
68
71
|
pattern = case mode
|
69
72
|
when :definition
|
70
73
|
/\{{2,3}[^}]*\}{2,3}/
|
71
74
|
when :invokation
|
72
|
-
/"[
|
75
|
+
/"([^\\"]|\\.)*"/
|
76
|
+
|
73
77
|
end
|
74
78
|
|
75
79
|
# Each text between quotes or mustaches is replaced by the letter X
|
@@ -144,7 +148,7 @@ private
|
|
144
148
|
when :definition
|
145
149
|
/{{{([^}]*)}}}|{{([^}]*)}}/ # Two capturing groups!...
|
146
150
|
when :invokation
|
147
|
-
/"([
|
151
|
+
/"((?:[^\\"]|\\.)*)"/
|
148
152
|
else
|
149
153
|
raise InternalError, "Internal error: Unknown mode argument #{mode}"
|
150
154
|
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# File: template-engine.rb
|
2
|
+
# Purpose: Implementation of the MacroStep class.
|
3
|
+
|
4
|
+
require 'strscan' # Use the StringScanner for lexical analysis.
|
5
|
+
|
6
|
+
module Macros4Cuke # Module used as a namespace
|
7
|
+
|
8
|
+
|
9
|
+
class TemplateEngine
|
10
|
+
|
11
|
+
def self.parse(aTextLine)
|
12
|
+
#return [] if aTextLine.empty?
|
13
|
+
scanner = StringScanner.new(aTextLine)
|
14
|
+
result = []
|
15
|
+
|
16
|
+
until scanner.eos?
|
17
|
+
# Scan tag at current position...
|
18
|
+
tag_literal = scanner.scan(/<(?:[^\\<>]|\\.)*>/)
|
19
|
+
result << [:dynamic, tag_literal.gsub(/^<|>$/, '')] unless tag_literal.nil?
|
20
|
+
# TODO: remove next line
|
21
|
+
p tag_literal unless tag_literal.nil?
|
22
|
+
|
23
|
+
# ... or scan plain text at current position
|
24
|
+
text_literal = scanner.scan(/(?:[^\\<>]|\\.)+/)
|
25
|
+
result << [:static, text_literal] unless text_literal.nil?
|
26
|
+
# TODO: remove next line
|
27
|
+
p text_literal unless text_literal.nil?
|
28
|
+
|
29
|
+
if tag_literal.nil? && text_literal.nil?
|
30
|
+
# Unsuccessful scanning: we have improperly balanced chevrons.
|
31
|
+
# We will analyze the opening and closing chevrons...
|
32
|
+
p aTextLine
|
33
|
+
no_escaped = aTextLine.gsub(/\\<|\\>/, "--") # First: replace escaped chevron(s)
|
34
|
+
p no_escaped
|
35
|
+
unbalance = 0 # = count of < - count of > (can only be 0 or -temporarily- 1)
|
36
|
+
|
37
|
+
no_escaped.scan(/(.)/) do |match|
|
38
|
+
p match
|
39
|
+
case match[0]
|
40
|
+
when '<'
|
41
|
+
p "found <"
|
42
|
+
unbalance += 1
|
43
|
+
when '>'
|
44
|
+
p 'found >'
|
45
|
+
unbalance -= 1
|
46
|
+
end
|
47
|
+
|
48
|
+
raise StandardError, "Nested opening chevron '<'." if unbalance > 1
|
49
|
+
raise StandardError, "Missing opening chevron '<'." if unbalance < 0
|
50
|
+
end
|
51
|
+
|
52
|
+
raise StandardError, "Missing closing chevron '>'." if unbalance == 1
|
53
|
+
raise StandardError, "Internal error[unbalance=#{unbalance}]. Cannot parse:\n'#{aTextLine}'"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
return result
|
58
|
+
end
|
59
|
+
|
60
|
+
end # class
|
61
|
+
|
62
|
+
end # module
|
63
|
+
|
64
|
+
# 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.1.
|
4
|
+
version: 0.1.06
|
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-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -78,6 +78,7 @@ files:
|
|
78
78
|
- lib/macros4cuke/macro-collection.rb
|
79
79
|
- lib/macros4cuke/macro-step-support.rb
|
80
80
|
- lib/macros4cuke/macro-step.rb
|
81
|
+
- lib/macros4cuke/template-engine.rb
|
81
82
|
- features/demo01.feature
|
82
83
|
- features/demo02.feature
|
83
84
|
- features/demo03.feature
|