macros4cuke 0.2.09 → 0.2.10
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +112 -0
- data/README.md +2 -1
- data/lib/macro_steps.rb +2 -2
- data/lib/macros4cuke/constants.rb +1 -1
- data/lib/macros4cuke/exceptions.rb +28 -1
- data/lib/macros4cuke/macro-step.rb +29 -3
- data/spec/macros4cuke/macro-step_spec.rb +15 -3
- metadata +3 -3
- data/HISTORY.md +0 -111
data/CHANGELOG.md
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
## 0.2.10 / 2013-04-30
|
2
|
+
|
3
|
+
* [CHANGE] `CHANGELOG.md` replaces `HISTORY.md` file. Partial reformatting of historical entries to [Changelogs Convention](tech-angels.github.com/vandamme/#changelogs-convention)
|
4
|
+
* [CHANGE] Method `MacroStep#initialize`: added the detection of two inconsistencies in macro arguments.
|
5
|
+
* [CHANGE] New exception class `UselessPhraseArgument`. Raised when the name of an argument from the phrase never appears in a sub-step.
|
6
|
+
* [CHANGE] New exception class `UnreachableSubstepArgument`. Raised when the name of an argument from a subset never appears in the phrase and the macro-step doesn't allow table.
|
7
|
+
* [CHANGE] New exception class `DataTableNotFound`. Raised when a step expecting a data table arguments gets anything else.
|
8
|
+
* [CHANGE] File `macro-step_spec.rb`: Added examples covering the new validation rules in `MacroStep#initialize` method.
|
9
|
+
* [FIX] `UnknownArgumentError#initialize` Typo in error message.
|
10
|
+
|
11
|
+
## 0.2.09 / 2013-04-29
|
12
|
+
|
13
|
+
* [CHANGE] Added one capturing group in regexp of macro defining step to detect data passing via table.
|
14
|
+
* [CHANGE] Class `MacroStep`: added an explicit argument for data passing via table mode.
|
15
|
+
|
16
|
+
|
17
|
+
## 0.2.08 / 2013-04-29
|
18
|
+
|
19
|
+
* [CHANGE] Signature of `MacroStep#expand` changed.
|
20
|
+
* [CHANGE] `MacroStep#validate_params` method is now private
|
21
|
+
* [CHANGE] File `macro-step_spec.rb` updated.
|
22
|
+
* [CHANGE] `MacroCollection#render_steps`method updated.
|
23
|
+
* [CHANGE] File `macro-step_spec.rb`: added test case when a macro is called with unknown argument.
|
24
|
+
* [FIX] macro-step.rb: added a missing `require 'exceptions'`.
|
25
|
+
|
26
|
+
## 0.2.07 / 2013-04-29
|
27
|
+
|
28
|
+
* [FIX] Editorial improvements in `README.md`, corrected one inaccurate sentence.
|
29
|
+
|
30
|
+
|
31
|
+
## 0.2.06 / 2013-04-28
|
32
|
+
|
33
|
+
* [CHANGE] Formatting improvements in `README.md`.
|
34
|
+
|
35
|
+
|
36
|
+
## 0.2.05 / 2013-04-28
|
37
|
+
|
38
|
+
* [CHANGE] Expanded `README.md` with macro-step invokation, passing data value via a table.
|
39
|
+
|
40
|
+
|
41
|
+
## 0.2.04 / 2013-4-27
|
42
|
+
|
43
|
+
* [FIX] `MacroCollection#add_macro method`: typo correction.
|
44
|
+
|
45
|
+
|
46
|
+
## 0.2.03 / Unreleased
|
47
|
+
|
48
|
+
* [CHANGE] Regexp of defining step is more general: it accepts the Gherkin adverbs `Given, When, Then, And`.
|
49
|
+
|
50
|
+
|
51
|
+
## 0.2.02 / 2013-4-26
|
52
|
+
|
53
|
+
* [CHANGE] Added an example in `template-engine_spec.rb` file.
|
54
|
+
* [CHANGE] Expanded `README.md` file.
|
55
|
+
|
56
|
+
|
57
|
+
## 0.2.01 / 2013-4-26
|
58
|
+
|
59
|
+
* [CHANGE] Regexps in step definitions accept escape character sequence.
|
60
|
+
* [CHANGE] Expanded `README.md` file.
|
61
|
+
* [FIX] Corrected remnant of Mustache template in `travelling_demo.feature` file.
|
62
|
+
|
63
|
+
|
64
|
+
## 0.2.00 / 2013-4-25 Version number was bumped
|
65
|
+
|
66
|
+
* [CHANGE] Replaced the Mustache template engine by own lightweight TemplateEngine
|
67
|
+
* [CHANGE] Macro-step arguments have a syntax that is closer to Gherkin's scenario outlines.
|
68
|
+
* [CHANGE] Upgraded TemplateEngine class to become a simple templating system.
|
69
|
+
* [CHANGE] Remove dependency to mustache gem.
|
70
|
+
* [CHANGE] All demos updated to new syntax.
|
71
|
+
* [CHANGE] examples in `README.md` updated.
|
72
|
+
|
73
|
+
|
74
|
+
## 0.1.07 / 2013-4-24
|
75
|
+
|
76
|
+
* [CHANGE] Added new class `TemplateEngine`.
|
77
|
+
|
78
|
+
|
79
|
+
## 0.1.06 / 2013-4-24
|
80
|
+
|
81
|
+
* [FIX] Format fix in README.md
|
82
|
+
* [FIX] `HISTORY.md` file updated with missing entries/
|
83
|
+
|
84
|
+
|
85
|
+
## 0.1.05 / Unreleased
|
86
|
+
|
87
|
+
* [CHANGE] `demo_steps.rb`. Added few step definitions that emit output to the screen (so that at least something is shown in the demo).
|
88
|
+
* [CHANGE] `MacroStep` class: regexp slightly reworked to accept escaped double quotes in actual values.
|
89
|
+
* [CHANGE] `travelling_demo.feature`: Added one example with escaped quotes in actual value.
|
90
|
+
|
91
|
+
|
92
|
+
## 0.1.04 / 2013-4-23
|
93
|
+
|
94
|
+
* [ENHANCEMENT] Gherkin comments are allowed in sub-steps sequence. Previous version supported only Mustache comments.
|
95
|
+
* [CHANGE] Added a few more examples in the `travelling-demo.feature` file.
|
96
|
+
|
97
|
+
|
98
|
+
## 0.1.03 / 2013-4-23
|
99
|
+
|
100
|
+
* [CHANGE] `README.md` slightly reworked and added link to Mustache.
|
101
|
+
* [CHANGE] File `env.rb`: moved all dependencies on Macros4Cuke to the file `macro_support.rb`
|
102
|
+
* [CHANGE] File `travelling-demo.feature`: Demo feature file with output on the screen (the other demos don't display any result).
|
103
|
+
|
104
|
+
|
105
|
+
## 0.0.02 / 2013-04-21
|
106
|
+
|
107
|
+
* [CHANGE] `README.md`: added a reference to the features folder.
|
108
|
+
|
109
|
+
|
110
|
+
## 0.0.01 / 2013-04-21
|
111
|
+
|
112
|
+
* [FEATURE] Initial public working version
|
data/README.md
CHANGED
@@ -168,7 +168,8 @@ Sub-steps can also have macro arguments.
|
|
168
168
|
```
|
169
169
|
|
170
170
|
### Using (invoking) a macro-step ###
|
171
|
-
|
171
|
+
A macro-step can only be invoked after its definition has been read by Cucumber.
|
172
|
+
The syntax rules for using a given macro-step in a scenario are pretty straightforward:
|
172
173
|
- Follow closely the syntax of the _quoted sentence_ in the macro definition.
|
173
174
|
- Replace every \<argument\> in the _phrase_ by its actual value between quotes.
|
174
175
|
|
data/lib/macro_steps.rb
CHANGED
@@ -28,7 +28,7 @@ When(/^I \[((?:[^\\\]]|\\.)+)\]$/) do |macro_phrase|
|
|
28
28
|
end
|
29
29
|
|
30
30
|
|
31
|
-
# This step is used to invoke a macro-step with a table argument.
|
31
|
+
# This step is used to invoke a macro-step with a data table argument.
|
32
32
|
# Example:
|
33
33
|
# When I [enter my credentials as]:
|
34
34
|
# |userid |guest |
|
@@ -36,7 +36,7 @@ end
|
|
36
36
|
When(/^I \[([^\]]+)\]:$/) do |macro_phrase, table_argument|
|
37
37
|
# Ensure that the second argument is of the correct type
|
38
38
|
unless table_argument.kind_of?(Cucumber::Ast::Table)
|
39
|
-
raise
|
39
|
+
raise Macros4Cuke::DataTableNotFound, "This step must have a data table as an argument."
|
40
40
|
end
|
41
41
|
|
42
42
|
# This will call the macro with the given phrase.
|
@@ -15,6 +15,23 @@ class DuplicateMacroError < Macros4CukeError
|
|
15
15
|
end
|
16
16
|
end # class
|
17
17
|
|
18
|
+
# Raised when one defines an argument name in a macro-step's phrase
|
19
|
+
# and that argument name does not appear in any sub-step.
|
20
|
+
class UselessPhraseArgument < Macros4CukeError
|
21
|
+
def initialize(anArgName)
|
22
|
+
super("The phrase argument '#{anArgName}' does not appear in a sub-step.")
|
23
|
+
end
|
24
|
+
end # class
|
25
|
+
|
26
|
+
|
27
|
+
|
28
|
+
# Raised when one defines an argument name in a macro-step's phrase
|
29
|
+
# and that argument name does not appear in any sub-step.
|
30
|
+
class UnreachableSubstepArgument < Macros4CukeError
|
31
|
+
def initialize(anArgName)
|
32
|
+
super("The sub-step argument '#{anArgName}' does not appear in the phrase.")
|
33
|
+
end
|
34
|
+
end # class
|
18
35
|
|
19
36
|
|
20
37
|
# Raised when one invokes a macro-step with an unknown phrase.
|
@@ -30,11 +47,21 @@ end # class
|
|
30
47
|
# that has an unknown name.
|
31
48
|
class UnknownArgumentError < Macros4CukeError
|
32
49
|
def initialize(argName)
|
33
|
-
super("Unknown macro-
|
50
|
+
super("Unknown macro-step argument '#{argName}'.")
|
34
51
|
end
|
35
52
|
end # class
|
36
53
|
|
37
54
|
|
55
|
+
|
56
|
+
# Raised when one invokes a macro-step without a required data table argument
|
57
|
+
class DataTableNotFound < Macros4CukeError
|
58
|
+
def initialize(argName)
|
59
|
+
super("The macro-step is missing a data table argument.")
|
60
|
+
end
|
61
|
+
end # class
|
62
|
+
|
63
|
+
|
64
|
+
|
38
65
|
# Raised when Macros4Cuke encountered an issue
|
39
66
|
# that it can't handle properly.
|
40
67
|
class InternalError < Macros4CukeError
|
@@ -26,19 +26,22 @@ 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
|
-
# [useTable] A boolean that indicates whether a table
|
29
|
+
# [useTable] A boolean that indicates whether a data table must be used to pass actual values.
|
30
30
|
def initialize(aMacroPhrase, theSubsteps, useTable)
|
31
31
|
@key = self.class.macro_key(aMacroPhrase, useTable, :definition)
|
32
32
|
|
33
33
|
# Retrieve the macro arguments embedded in the phrase.
|
34
34
|
@phrase_args = scan_arguments(aMacroPhrase, :definition)
|
35
|
-
@args = @phrase_args.dup()
|
36
35
|
|
37
36
|
# Manipulate the substeps source text
|
38
37
|
substeps_processed = preprocess(theSubsteps)
|
39
38
|
|
40
39
|
@renderer = TemplateEngine.new(substeps_processed)
|
41
|
-
|
40
|
+
substeps_vars = renderer.variables
|
41
|
+
|
42
|
+
|
43
|
+
@args = validate_phrase_args(@phrase_args, substeps_vars)
|
44
|
+
@args.concat(substeps_vars)
|
42
45
|
@args.uniq!
|
43
46
|
end
|
44
47
|
|
@@ -169,6 +172,29 @@ private
|
|
169
172
|
|
170
173
|
return processed.join("\n")
|
171
174
|
end
|
175
|
+
|
176
|
+
# Check for inconsistencies between the argument names in the phrase and the substeps part.
|
177
|
+
def validate_phrase_args(thePhraseArgs, substepsVars)
|
178
|
+
# Error when the phrase names an argument that never occurs in the substeps
|
179
|
+
thePhraseArgs.each do |phrase_arg|
|
180
|
+
raise UselessPhraseArgument.new(phrase_arg) unless substepsVars.include? phrase_arg
|
181
|
+
end
|
182
|
+
|
183
|
+
# Error when a substep has an argument that never appears in the phrase and the macro-step does not use data table.
|
184
|
+
unless use_table?
|
185
|
+
substepsVars.each do |substep_arg|
|
186
|
+
raise UnreachableSubstepArgument.new(substep_arg) unless thePhraseArgs.include? substep_arg
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
return thePhraseArgs.dup()
|
191
|
+
end
|
192
|
+
|
193
|
+
|
194
|
+
# Return true, if the macro-step requires a data table to pass actual values of the arguments.
|
195
|
+
def use_table?()
|
196
|
+
return key =~ /_T$/
|
197
|
+
end
|
172
198
|
|
173
199
|
end # class
|
174
200
|
|
@@ -29,9 +29,21 @@ end
|
|
29
29
|
|
30
30
|
context "Creation & initialization" do
|
31
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
|
32
|
+
lambda { MacroStep.new(sample_phrase, sample_template, true) }.should_not raise_error
|
34
33
|
end
|
34
|
+
|
35
|
+
|
36
|
+
it "should complain when a sub-step argument can never be assigned a value via the phrase" do
|
37
|
+
error_message = "The sub-step argument 'password' does not appear in the phrase."
|
38
|
+
lambda { MacroStep.new(sample_phrase, sample_template, false) }.should raise_error(Macros4Cuke::UnreachableSubstepArgument, error_message)
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
it "should complain when an argument from the phrase never occurs in a substep" do
|
43
|
+
a_phrase = "enter my credentials as <foobar>"
|
44
|
+
error_message = "The phrase argument 'foobar' does not appear in a sub-step."
|
45
|
+
lambda { MacroStep.new(a_phrase, sample_template, true) }.should raise_error(Macros4Cuke::UselessPhraseArgument, error_message)
|
46
|
+
end
|
35
47
|
|
36
48
|
|
37
49
|
it "should know its key" do
|
@@ -82,7 +94,7 @@ SNIPPET
|
|
82
94
|
|
83
95
|
it "should complain when an unknown variable is used" do
|
84
96
|
# Error case: there is no macro argument called <unknown>
|
85
|
-
error_message = "Unknown macro-
|
97
|
+
error_message = "Unknown macro-step argument 'unknown'."
|
86
98
|
lambda { subject.expand(phrase_instance, [ ['unknown', 'anything'] ]) }.should raise_error(UnknownArgumentError, error_message)
|
87
99
|
end
|
88
100
|
|
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.10
|
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-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -66,7 +66,7 @@ extensions: []
|
|
66
66
|
extra_rdoc_files: []
|
67
67
|
files:
|
68
68
|
- cucumber.yml
|
69
|
-
-
|
69
|
+
- CHANGELOG.md
|
70
70
|
- LICENSE.txt
|
71
71
|
- README.md
|
72
72
|
- lib/macros4cuke.rb
|
data/HISTORY.md
DELETED
@@ -1,111 +0,0 @@
|
|
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
|
-
|
8
|
-
## [0.2.08]
|
9
|
-
#### Changes:
|
10
|
-
* Class MacroStep: method validate_params is now private, the signature of expand method has changed.
|
11
|
-
* macro-step.rb: added a missing require 'exceptions'.
|
12
|
-
* macro-step_spec.rb: updated to taken into account the above change. Added test case when a macro is called with unknown argument.
|
13
|
-
* Class MacroCollection#render_steps updated for the above change.
|
14
|
-
|
15
|
-
## [0.2.07]
|
16
|
-
#### Changes:
|
17
|
-
* Editorial improvements in README.md, corrected one inaccurate sentence.
|
18
|
-
|
19
|
-
|
20
|
-
## [0.2.06]
|
21
|
-
#### Changes:
|
22
|
-
* Formatting improvements in README.md.
|
23
|
-
|
24
|
-
|
25
|
-
## [0.2.05]
|
26
|
-
#### Changes:
|
27
|
-
* Expanded README.md with macro-step invokation, passing data value via a table.
|
28
|
-
|
29
|
-
## [0.2.04]
|
30
|
-
### Fixes:
|
31
|
-
* Class MacroCollection#add_macro: typo correction.
|
32
|
-
|
33
|
-
## [0.2.03]
|
34
|
-
### Changes:
|
35
|
-
* Regexp of defining step is more general: it accepts the Gherkin adverbs Given, When, Then, And.
|
36
|
-
|
37
|
-
|
38
|
-
## [0.2.02]
|
39
|
-
### Changes:
|
40
|
-
* Added an example in template-engine_spec.rb file.
|
41
|
-
|
42
|
-
### Documentation:
|
43
|
-
* Expanded the README.md file.
|
44
|
-
|
45
|
-
## [0.2.01]
|
46
|
-
### Changes:
|
47
|
-
* Regexp in the step definitions are more robust: they accept escape character sequence.
|
48
|
-
|
49
|
-
### Fixes:
|
50
|
-
* Corrected remnant of Mustache template in travelling_demo.feature file.
|
51
|
-
|
52
|
-
|
53
|
-
### Documentation:
|
54
|
-
* Expanded the README.md file.
|
55
|
-
|
56
|
-
|
57
|
-
## [0.2.00] Version number was bumped
|
58
|
-
### Changes:
|
59
|
-
* Replaced the Mustache template engine by own lightweight TemplateEngine
|
60
|
-
* Macro-step arguments have a syntax that is closer to Gherkin's scenario outlines.
|
61
|
-
* Upgraded TemplateEngine class to become a simple templating system.
|
62
|
-
* Remove dependency to mustache gem.
|
63
|
-
|
64
|
-
### Documentation:
|
65
|
-
* All demos updated to new syntax.
|
66
|
-
* Updated the examples in README.md
|
67
|
-
|
68
|
-
|
69
|
-
## [0.1.07]
|
70
|
-
### Changes:
|
71
|
-
* Added new class TemplateEngine.
|
72
|
-
|
73
|
-
|
74
|
-
## [0.1.06]
|
75
|
-
|
76
|
-
### Documentation:
|
77
|
-
* Format fix in README.md
|
78
|
-
* HISTORY.md file updated
|
79
|
-
|
80
|
-
## [0.1.05]
|
81
|
-
### Changes:
|
82
|
-
* demo_steps.rb: A few step definitions emits output to the screen (so that at least something is shown in the demo).
|
83
|
-
* MacroStep class: regexp slightly reworked to accept escaped double quotes in actual values.
|
84
|
-
* travelling_demo.feature: added one example with escaped quotes in actual value.
|
85
|
-
|
86
|
-
|
87
|
-
## [0.1.04]
|
88
|
-
### New features:
|
89
|
-
* Gherkin comments are allowed in sub-steps sequence. Previous version supported only Mustache comments.
|
90
|
-
|
91
|
-
### Changes:
|
92
|
-
* Added a few more examples in the 'travelling-demo.feature' file.
|
93
|
-
|
94
|
-
|
95
|
-
## [0.1.03]
|
96
|
-
### Documentation
|
97
|
-
* README.md: slightly reworked and added link to Mustache.
|
98
|
-
|
99
|
-
### Changes:
|
100
|
-
* env.rb: All dependencies on Macros4Cuke were moved to the file macro_support.rb
|
101
|
-
* travelling-demo.feature: Demo feature file with output on the screen (the other demos don't display any result).
|
102
|
-
|
103
|
-
|
104
|
-
## [0.0.02]
|
105
|
-
### Documentation
|
106
|
-
* In README: added a reference to the features folder.
|
107
|
-
|
108
|
-
## [0.0.01]
|
109
|
-
|
110
|
-
### New features
|
111
|
-
* Initial public working version
|