macros4cuke 0.2.08 → 0.2.09
Sign up to get free protection for your applications and to get access to all the features.
data/HISTORY.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
## [0.2.09]
|
2
|
+
#### Changes:
|
3
|
+
* Added one dedicated capturing group in regexp of macro defining step.
|
4
|
+
* Class MacroStep: initialize method and others. Added an explicit argument for use table mode.
|
5
|
+
* This impacts the MacroSupport module and the MacroCollection class.
|
6
|
+
|
7
|
+
|
1
8
|
## [0.2.08]
|
2
9
|
#### Changes:
|
3
10
|
* Class MacroStep: method validate_params is now private, the signature of expand method has changed.
|
data/lib/macro_steps.rb
CHANGED
@@ -13,15 +13,17 @@
|
|
13
13
|
# And I fill in "Password" with "unguessable"
|
14
14
|
# And I click "Submit"
|
15
15
|
# """
|
16
|
-
|
17
|
-
|
16
|
+
# The regexp has two capturing group: one for the phrase, a second for the terminating colon (:)
|
17
|
+
Given(/^I define the step "(?:Given|When|Then) I \[((?:[^\\\]]|\\.)+)\](:?)" to mean:$/) do |macro_phrase, colon_present, template|
|
18
|
+
use_table = (colon_present == ':')
|
19
|
+
add_macro(macro_phrase, template, use_table)
|
18
20
|
end
|
19
21
|
|
20
22
|
# This step is used to invoke a simple macro-step
|
21
23
|
# Example:
|
22
24
|
# When I [log in as "guest"]
|
23
25
|
#
|
24
|
-
When(/^I \[((?:[^\\\]]|\\.)
|
26
|
+
When(/^I \[((?:[^\\\]]|\\.)+)\]$/) do |macro_phrase|
|
25
27
|
invoke_macro(macro_phrase) # This will call the macro with the given phrase
|
26
28
|
end
|
27
29
|
|
@@ -31,7 +33,7 @@ end
|
|
31
33
|
# When I [enter my credentials as]:
|
32
34
|
# |userid |guest |
|
33
35
|
# |password|unguessable|
|
34
|
-
When(/^I \[([^\]]
|
36
|
+
When(/^I \[([^\]]+)\]:$/) do |macro_phrase, table_argument|
|
35
37
|
# Ensure that the second argument is of the correct type
|
36
38
|
unless table_argument.kind_of?(Cucumber::Ast::Table)
|
37
39
|
raise StandardError, "This step must have a data table as an argument."
|
@@ -31,14 +31,14 @@ public
|
|
31
31
|
# Pre-condition: there is no existing macro with the same key.
|
32
32
|
# [aPhrase] The text that is enclosed between the square brackets.
|
33
33
|
# [aTemplate] A text that consists of a sequence of Cucumber steps.
|
34
|
-
#
|
35
|
-
def add_macro(aPhrase, aTemplate)
|
36
|
-
new_macro = MacroStep.new(aPhrase, aTemplate)
|
34
|
+
# [useTable] A boolean that indicates whether a table should be used to pass actual values.
|
35
|
+
def add_macro(aPhrase, aTemplate, useTable)
|
36
|
+
new_macro = MacroStep.new(aPhrase, aTemplate, useTable)
|
37
37
|
|
38
38
|
# Prevent collision of macros (macros with same phrase).
|
39
39
|
# This can occur if a macro was defined in a background section.
|
40
40
|
# An exception is raised if the phrase syntax of both macros are the
|
41
|
-
raise DuplicateMacroError.new(aPhrase) if find_macro(aPhrase)
|
41
|
+
raise DuplicateMacroError.new(aPhrase) if find_macro(aPhrase, useTable)
|
42
42
|
|
43
43
|
@macro_steps[new_macro.key] = new_macro
|
44
44
|
|
@@ -52,8 +52,8 @@ public
|
|
52
52
|
# Each couple is of the form: argument name, a value.
|
53
53
|
# Multiple rows with same argument name are acceptable.
|
54
54
|
def render_steps(aPhrase, rawData = nil)
|
55
|
-
|
56
|
-
macro = find_macro(aPhrase)
|
55
|
+
useTable = ! rawData.nil?
|
56
|
+
macro = find_macro(aPhrase, useTable)
|
57
57
|
raise UnknownMacroError.new(aPhrase) if macro.nil?
|
58
58
|
|
59
59
|
# Render the steps
|
@@ -62,8 +62,8 @@ public
|
|
62
62
|
|
63
63
|
private
|
64
64
|
# Retrieve the macro, given a phrase.
|
65
|
-
def find_macro(aMacroPhrase)
|
66
|
-
return @macro_steps[MacroStep::macro_key(aMacroPhrase, :invokation)]
|
65
|
+
def find_macro(aMacroPhrase, useTable)
|
66
|
+
return @macro_steps[MacroStep::macro_key(aMacroPhrase, useTable, :invokation)]
|
67
67
|
end
|
68
68
|
|
69
69
|
end # class
|
@@ -26,9 +26,9 @@ public
|
|
26
26
|
# Pre-condition: there is no existing macro with the same key.
|
27
27
|
# [aPhrase] The text that is enclosed between the square brackets.
|
28
28
|
# [aTemplate] A text that consists of a sequence of Cucumber steps.
|
29
|
-
#
|
30
|
-
def add_macro(aPhrase, aTemplate)
|
31
|
-
MacroCollection::instance.add_macro(aPhrase, aTemplate)
|
29
|
+
# [useTable] A boolean that indicates whether a table should be used to pass actual values.
|
30
|
+
def add_macro(aPhrase, aTemplate, useTable)
|
31
|
+
MacroCollection::instance.add_macro(aPhrase, aTemplate, useTable)
|
32
32
|
end
|
33
33
|
|
34
34
|
|
@@ -26,8 +26,9 @@ class MacroStep
|
|
26
26
|
# Constructor.
|
27
27
|
# [aMacroPhrase] The text from the macro step definition that is between the square brackets.
|
28
28
|
# [theSubsteps] The source text of the steps to be expanded upon macro invokation.
|
29
|
-
|
30
|
-
|
29
|
+
# [useTable] A boolean that indicates whether a table should be used to pass actual values.
|
30
|
+
def initialize(aMacroPhrase, theSubsteps, useTable)
|
31
|
+
@key = self.class.macro_key(aMacroPhrase, useTable, :definition)
|
31
32
|
|
32
33
|
# Retrieve the macro arguments embedded in the phrase.
|
33
34
|
@phrase_args = scan_arguments(aMacroPhrase, :definition)
|
@@ -51,11 +52,14 @@ class MacroStep
|
|
51
52
|
# - Each underscore character is removed.
|
52
53
|
# - Every sequence of one or more space(s) is converted into an underscore
|
53
54
|
# - Each placeholder (i.e. = delimiters + enclosed text) is converted into a letter X.
|
54
|
-
# -
|
55
|
+
# - when useTable is true, concatenate: _T
|
55
56
|
# Example:
|
56
57
|
# Consider the macro phrase: 'create the following "contactType" contact]:'
|
57
58
|
# The resulting macro_key is: 'create_the_following_X_contact_T'
|
58
|
-
|
59
|
+
# [aMacroPhrase] The text from the macro step definition that is between the square brackets.
|
60
|
+
# [useTable] A boolean that indicates whether a table should be used to pass actual values.
|
61
|
+
# [mode] one of the following: :definition, :invokation
|
62
|
+
def self.macro_key(aMacroPhrase, useTable, mode)
|
59
63
|
stripped_phrase = aMacroPhrase.strip # Remove leading ... trailing space(s)
|
60
64
|
|
61
65
|
# Remove every underscore
|
@@ -77,12 +81,7 @@ class MacroStep
|
|
77
81
|
# Each text between quotes or chevron is replaced by the letter X
|
78
82
|
normalized = stripped_phrase.gsub(pattern, 'X')
|
79
83
|
|
80
|
-
|
81
|
-
key = if normalized.end_with?("]")
|
82
|
-
normalized.chop()
|
83
|
-
else
|
84
|
-
normalized.sub(/\]:/, '_T')
|
85
|
-
end
|
84
|
+
key = normalized + (useTable ? '_T' : '')
|
86
85
|
|
87
86
|
return key
|
88
87
|
end
|
@@ -9,7 +9,7 @@ require_relative '../../lib/macros4cuke/macro-step' # The class under test
|
|
9
9
|
module Macros4Cuke # Open the module to avoid lengthy qualified names
|
10
10
|
|
11
11
|
describe MacroStep do
|
12
|
-
let(:sample_phrase) { "enter my credentials as <userid>
|
12
|
+
let(:sample_phrase) { "enter my credentials as <userid>" }
|
13
13
|
|
14
14
|
let(:sample_template) do
|
15
15
|
snippet = <<-SNIPPET
|
@@ -24,12 +24,13 @@ SNIPPET
|
|
24
24
|
end
|
25
25
|
|
26
26
|
# Default instantiation rule
|
27
|
-
subject { MacroStep.new(sample_phrase, sample_template) }
|
27
|
+
subject { MacroStep.new(sample_phrase, sample_template, true) }
|
28
28
|
|
29
29
|
|
30
30
|
context "Creation & initialization" do
|
31
|
-
it "should be created with a phrase and a
|
32
|
-
lambda { MacroStep.new(sample_phrase, sample_template) }.should_not raise_error
|
31
|
+
it "should be created with a phrase, substeps and a table use indicator" do
|
32
|
+
lambda { MacroStep.new(sample_phrase, sample_template, true) }.should_not raise_error
|
33
|
+
lambda { MacroStep.new(sample_phrase, sample_template, false) }.should_not raise_error
|
33
34
|
end
|
34
35
|
|
35
36
|
|
@@ -50,7 +51,7 @@ end
|
|
50
51
|
|
51
52
|
context "Provided services" do
|
52
53
|
|
53
|
-
let(:phrase_instance) {%Q|enter my credentials as "nobody"
|
54
|
+
let(:phrase_instance) {%Q|enter my credentials as "nobody"|}
|
54
55
|
|
55
56
|
it "should render the substeps" do
|
56
57
|
text = subject.expand(phrase_instance, [ ['password', 'no-secret'] ])
|