macros4cuke 0.3.12 → 0.3.13
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/.rubocop.yml +18 -0
- data/CHANGELOG.md +4 -0
- data/examples/demo/features/step_definitions/use_macro_steps.rb +5 -2
- data/examples/demo/features/support/env.rb +1 -1
- data/examples/demo/features/support/macro_support.rb +3 -2
- data/examples/i18n/fr/features/step_definitions/use_macro_steps.rb +6 -3
- data/examples/i18n/fr/features/support/macro_support.rb +2 -1
- data/features/step_definitions/demo_steps.rb +4 -3
- data/features/step_definitions/use_macro_steps.rb +5 -2
- data/features/support/env.rb +5 -3
- data/features/support/macro_support.rb +3 -2
- data/lib/macros4cuke/constants.rb +10 -7
- data/lib/macros4cuke/macro-collection.rb +14 -7
- data/lib/macros4cuke/macro-step-support.rb +19 -10
- data/lib/macros4cuke/macro-step.rb +22 -11
- data/lib/macros4cuke/templating/engine.rb +1 -0
- data/spec/spec_helper.rb +1 -0
- metadata +3 -2
data/.rubocop.yml
ADDED
data/CHANGELOG.md
CHANGED
@@ -1,8 +1,11 @@
|
|
1
|
+
# encoding: utf-8
|
1
2
|
# File: use_macro_steps.rb
|
2
|
-
# Place a copy of this file in the feature/step_definitions folder
|
3
|
+
# Place a copy of this file in the feature/step_definitions folder
|
4
|
+
# of your own Cucumber-based project.
|
3
5
|
|
4
6
|
# The following require will load the step definitions from Macros4Cuke.
|
5
|
-
# This allows feature file authors to use macro steps
|
7
|
+
# This allows feature file authors to use macro steps
|
8
|
+
# in their Cucumber scenarios.
|
6
9
|
require 'macros4cuke/../macro_steps'
|
7
10
|
|
8
11
|
# End of file
|
@@ -1,7 +1,8 @@
|
|
1
|
-
# encoding: utf-8
|
1
|
+
# encoding: utf-8
|
2
2
|
# File: macro_support.rb
|
3
3
|
# Purpose: Add the support for macros in Cucumber.
|
4
|
-
# This file is meant to be put next to the 'env.rb' file
|
4
|
+
# This file is meant to be put next to the 'env.rb' file
|
5
|
+
# of your Cucumeber project.
|
5
6
|
|
6
7
|
|
7
8
|
# Macros4Cuke step one: Load modules and classes from the gem.
|
@@ -9,18 +9,21 @@ end
|
|
9
9
|
|
10
10
|
|
11
11
|
Quand(/^j(?:e |')\[((?:[^\\\]]|\\.)+)\]$/) do |macro_phrase|
|
12
|
-
|
12
|
+
# This will call the macro with the given phrase
|
13
|
+
invoke_macro(macro_phrase)
|
13
14
|
end
|
14
15
|
|
15
16
|
|
16
17
|
Quand(/^j(?:e |')\[([^\]]+)\]:$/) do |macro_phrase, table_argument|
|
17
18
|
# Ensure that the second argument is of the correct type
|
18
19
|
unless table_argument.kind_of?(Cucumber::Ast::Table)
|
19
|
-
|
20
|
+
error_message = "This step must have a data table as an argument."
|
21
|
+
raise Macros4Cuke::DataTableNotFound, error_message
|
20
22
|
end
|
21
23
|
|
22
24
|
# This will call the macro with the given phrase.
|
23
|
-
# The second argument consists of an array with couples
|
25
|
+
# The second argument consists of an array with couples
|
26
|
+
# of the kind: [argument name, actual value]
|
24
27
|
invoke_macro(macro_phrase, table_argument.raw)
|
25
28
|
end
|
26
29
|
|
@@ -1,7 +1,8 @@
|
|
1
1
|
# encoding: utf-8 You should see a paragraph character: §
|
2
2
|
# File: macro_support.rb
|
3
3
|
# Purpose: Add the support for macros in Cucumber.
|
4
|
-
# This file is meant to be put next to the 'env.rb' file
|
4
|
+
# This file is meant to be put next to the 'env.rb' file
|
5
|
+
# of your Cucumeber project.
|
5
6
|
|
6
7
|
|
7
8
|
# Macros4Cuke step one: Load modules and classes from the gem.
|
@@ -1,17 +1,18 @@
|
|
1
|
+
# encoding: utf-8
|
1
2
|
# File: demo_steps.rb
|
2
3
|
# A few step definitions for demo and testing purpose.
|
3
4
|
|
4
5
|
When(/^I landed in the homepage$/) do
|
5
|
-
trace_steps <<
|
6
|
+
trace_steps << 'Invoked step: ... I landed in the homepage'
|
6
7
|
end
|
7
8
|
|
8
9
|
When(/^I click "([^"]*)"$/) do |element|
|
9
|
-
trace_steps <<
|
10
|
+
trace_steps << "Invoked step: ... I click \"#{element}\""
|
10
11
|
end
|
11
12
|
|
12
13
|
|
13
14
|
When(/^I fill in "(.*?)" with "(.*?)"$/) do |element, text|
|
14
|
-
trace_steps <<
|
15
|
+
trace_steps << "Invoked step: ... I fill in \"#{element}\" with \"#{text}\""
|
15
16
|
end
|
16
17
|
|
17
18
|
|
@@ -1,8 +1,11 @@
|
|
1
|
+
# encoding: utf-8
|
1
2
|
# File: use_macro_steps.rb
|
2
|
-
# Place a copy of this file in the feature/step_definitions folder
|
3
|
+
# Place a copy of this file in the feature/step_definitions folder
|
4
|
+
# of your own Cucumber-based project.
|
3
5
|
|
4
6
|
# The following require will load the step definitions from Macros4Cuke.
|
5
|
-
# This allows feature file authors to use macro steps
|
7
|
+
# This allows feature file authors to use macro steps
|
8
|
+
# in their Cucumber scenarios.
|
6
9
|
require 'macros4cuke/../macro_steps'
|
7
10
|
|
8
11
|
# End of file
|
data/features/support/env.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|
# encoding: utf-8 You should see a paragraph character: §
|
2
2
|
# File: env.rb
|
3
|
-
# Purpose: Allow Cucumber to load the sample application configuration
|
4
|
-
#
|
3
|
+
# Purpose: Allow Cucumber to load the sample application configuration
|
4
|
+
# and hooks.
|
5
|
+
# It also demonstrate what to do in your env.rb file
|
6
|
+
# to use the Macros4Cuke gem.
|
5
7
|
|
6
8
|
begin
|
7
9
|
require 'simplecov'
|
8
|
-
rescue LoadError
|
10
|
+
rescue LoadError => exc
|
9
11
|
# Gobble silently the exception if simplecov isn't installed.
|
10
12
|
end
|
11
13
|
|
@@ -1,7 +1,8 @@
|
|
1
|
-
# encoding: utf-8
|
1
|
+
# encoding: utf-8
|
2
2
|
# File: macro_support.rb
|
3
3
|
# Purpose: Add the support for macros in Cucumber.
|
4
|
-
# This file is meant to be put next to the 'env.rb' file
|
4
|
+
# This file is meant to be put next to the 'env.rb' file
|
5
|
+
# of your Cucumeber project.
|
5
6
|
|
6
7
|
|
7
8
|
# Macros4Cuke step one: Load modules and classes from the gem.
|
@@ -1,24 +1,27 @@
|
|
1
|
+
# encoding: utf-8
|
1
2
|
# File: constants.rb
|
2
3
|
# Purpose: definition of Macros4Cuke constants.
|
3
4
|
|
4
5
|
module Macros4Cuke # Module used as a namespace
|
5
|
-
|
6
|
-
|
6
|
+
# The version number of the gem.
|
7
|
+
Version = '0.3.13'
|
7
8
|
|
8
9
|
# Brief description of the gem.
|
9
10
|
Description = "Macros for Cucumber"
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
12
|
+
# Constant Macros4Cuke::RootDir contains the absolute path of Rodent's
|
13
|
+
# root directory. Note: it also ends with a slash character.
|
14
|
+
unless defined?(RootDir)
|
15
|
+
# The initialisation of constant RootDir is guarded in order
|
16
|
+
# to avoid multiple initialisation (not allowed for constants)
|
14
17
|
|
15
18
|
# The root folder of Macros4Cuke.
|
16
|
-
|
19
|
+
RootDir = begin
|
17
20
|
require 'pathname' # Load Pathname class from standard library
|
18
21
|
rootdir = Pathname(__FILE__).dirname.parent.parent.expand_path()
|
19
22
|
rootdir.to_s() + '/' # Append trailing slash character to it
|
20
23
|
end
|
21
|
-
|
24
|
+
end
|
22
25
|
end # module
|
23
26
|
|
24
27
|
# End of file
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# encoding: utf-8
|
1
2
|
# File: macro-collection.rb
|
2
3
|
# Purpose: Implementation of the MacroCollection class.
|
3
4
|
|
@@ -7,8 +8,9 @@ require_relative "macro-step"
|
|
7
8
|
module Macros4Cuke # Module used as a namespace
|
8
9
|
|
9
10
|
# Represents a container of macros.
|
10
|
-
# It gathers all the macros encountered by Cucumber while "executing"
|
11
|
-
#
|
11
|
+
# It gathers all the macros encountered by Cucumber while "executing"
|
12
|
+
# the feature files.
|
13
|
+
# @note This is a singleton class: there is only one macro collection object.
|
12
14
|
class MacroCollection
|
13
15
|
include Singleton # Use the Singleton design pattern.
|
14
16
|
|
@@ -19,9 +21,11 @@ class MacroCollection
|
|
19
21
|
public
|
20
22
|
# Add a new macro.
|
21
23
|
# Pre-condition: there is no existing macro with the same key.
|
22
|
-
# @param aPhrase [String] The text that is enclosed between
|
24
|
+
# @param aPhrase [String] The text that is enclosed between
|
25
|
+
# the square brackets.
|
23
26
|
# @param aTemplate [String] A text that consists of a sequence of sub-steps.
|
24
|
-
# @param useTable [boolean] A flag indicating whether a table should be
|
27
|
+
# @param useTable [boolean] A flag indicating whether a table should be
|
28
|
+
# used to pass actual values.
|
25
29
|
def add_macro(aPhrase, aTemplate, useTable)
|
26
30
|
new_macro = MacroStep.new(aPhrase, aTemplate, useTable)
|
27
31
|
|
@@ -38,7 +42,8 @@ public
|
|
38
42
|
# and (optionally) given a table of values.
|
39
43
|
# Return the rendered steps as a text.
|
40
44
|
# @param aPhrase [String] an instance of the macro phrase.
|
41
|
-
# @param rawData [Array or nil] An Array with coupples of the form:
|
45
|
+
# @param rawData [Array or nil] An Array with coupples of the form:
|
46
|
+
# [macro argument name, a value].
|
42
47
|
# Multiple rows with same argument name are acceptable.
|
43
48
|
# @return [String]
|
44
49
|
def render_steps(aPhrase, rawData = nil)
|
@@ -52,7 +57,8 @@ public
|
|
52
57
|
|
53
58
|
|
54
59
|
# Clear/remove all macro definitions from the collection.
|
55
|
-
# Post-condition: we are back to the same situation as
|
60
|
+
# Post-condition: we are back to the same situation as
|
61
|
+
# no macro was ever defined.
|
56
62
|
def clear()
|
57
63
|
macro_steps.clear()
|
58
64
|
end
|
@@ -67,7 +73,8 @@ public
|
|
67
73
|
private
|
68
74
|
# Retrieve the macro, given a phrase.
|
69
75
|
def find_macro(aMacroPhrase, useTable)
|
70
|
-
|
76
|
+
key = MacroStep.macro_key(aMacroPhrase, useTable, :invokation)
|
77
|
+
return macro_steps[key]
|
71
78
|
end
|
72
79
|
|
73
80
|
end # class
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# encoding: utf-8
|
1
2
|
# File: macro-step-support.rb
|
2
3
|
|
3
4
|
require_relative "exceptions"
|
@@ -10,28 +11,35 @@ module Macros4Cuke # Module used as a namespace
|
|
10
11
|
#
|
11
12
|
# require 'macros4cuke'
|
12
13
|
# ...
|
13
|
-
#
|
14
|
+
# # Extend the world object with this module.
|
15
|
+
# World(Macros4Cuke::MacroStepSupport)
|
14
16
|
#
|
15
17
|
module MacroStepSupport
|
16
18
|
public
|
17
19
|
|
18
20
|
# Add a new macro.
|
19
21
|
# Pre-condition: there is no existing macro with the same key.
|
20
|
-
# @param aPhrase [String] The text that is enclosed between
|
21
|
-
#
|
22
|
-
# @param
|
22
|
+
# @param aPhrase [String] The text that is enclosed between
|
23
|
+
# the square brackets [...].
|
24
|
+
# @param aTemplate [String] The text template that consists of a sequence
|
25
|
+
# of sub-steps.
|
26
|
+
# @param useTable [boolean] A flag that indicates whether a table should be
|
27
|
+
# used to pass actual values.
|
23
28
|
def add_macro(aPhrase, aTemplate, useTable)
|
24
|
-
MacroCollection
|
29
|
+
MacroCollection.instance.add_macro(aPhrase, aTemplate, useTable)
|
25
30
|
end
|
26
31
|
|
27
32
|
|
28
33
|
# Invoke a macro with given phrase and (optionally) a table of values
|
29
|
-
# @param aPhraseInstance [String] an instance of the macro phrase.
|
30
|
-
#
|
34
|
+
# @param aPhraseInstance [String] an instance of the macro phrase.
|
35
|
+
# That is, the text between [...] and with zero or more actual values.
|
36
|
+
# @param rawData [Array or nil] An Array with coupples of the form:
|
37
|
+
# [macro argument name, a value].
|
31
38
|
# Multiple rows with same argument name are acceptable.
|
32
39
|
def invoke_macro(aPhraseInstance, rawData = nil)
|
33
40
|
# Generate a text rendition of the step to be executed.
|
34
|
-
|
41
|
+
collection = MacroCollection.instance()
|
42
|
+
rendered_steps = collection.render_steps(aPhraseInstance, rawData)
|
35
43
|
|
36
44
|
# Let Cucumber execute the sub-steps
|
37
45
|
steps(rendered_steps)
|
@@ -39,9 +47,10 @@ public
|
|
39
47
|
|
40
48
|
|
41
49
|
# Clear (remove) all the macro-step definitions.
|
42
|
-
# After this, we are in the same situation when no macro-step
|
50
|
+
# After this, we are in the same situation when no macro-step
|
51
|
+
# was ever defined.
|
43
52
|
def clear_macros()
|
44
|
-
MacroCollection
|
53
|
+
MacroCollection.instance.clear()
|
45
54
|
end
|
46
55
|
|
47
56
|
end # module
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# encoding: utf-8
|
1
2
|
# File: macro-step.rb
|
2
3
|
# Purpose: Implementation of the MacroStep class.
|
3
4
|
|
@@ -99,7 +100,8 @@ class MacroStep
|
|
99
100
|
# Render the steps from the template, given the values
|
100
101
|
# taken by the parameters
|
101
102
|
# @param aPhrase [String] an instance of the macro phrase.
|
102
|
-
# @param rawData [Array or nil] An Array with coupples of the form:
|
103
|
+
# @param rawData [Array or nil] An Array with coupples of the form:
|
104
|
+
# [macro argument name, a value].
|
103
105
|
# Multiple rows with same argument name are acceptable.
|
104
106
|
def expand(aPhrase, rawData)
|
105
107
|
params = validate_params(aPhrase, rawData)
|
@@ -109,7 +111,8 @@ class MacroStep
|
|
109
111
|
private
|
110
112
|
# Build a Hash from the given raw data.
|
111
113
|
# @param aPhrase [String] an instance of the macro phrase.
|
112
|
-
# @param rawData [Array or nil] An Array with coupples of the form:
|
114
|
+
# @param rawData [Array or nil] An Array with coupples of the form:
|
115
|
+
# [macro argument name, a value].
|
113
116
|
# Multiple rows with same argument name are acceptable.
|
114
117
|
def validate_params(aPhrase, rawData)
|
115
118
|
macro_parameters = {}
|
@@ -169,28 +172,35 @@ private
|
|
169
172
|
end
|
170
173
|
|
171
174
|
# Return the substeps text after some transformation
|
172
|
-
# [theSubstepsSource] The source text of the steps
|
175
|
+
# [theSubstepsSource] The source text of the steps
|
176
|
+
# to be expanded upon macro invokation.
|
173
177
|
def preprocess(theSubstepsSource)
|
174
178
|
# Split text into lines
|
175
179
|
lines = theSubstepsSource.split(/\r\n?|\n/)
|
176
180
|
|
177
|
-
# Reject comment lines. This necessary because
|
181
|
+
# Reject comment lines. This is necessary because
|
182
|
+
# Cucumber::RbSupport::RbWorld#steps complains when it sees a comment.
|
178
183
|
processed = lines.reject { |a_line| a_line =~ /\s*#/ }
|
179
184
|
|
180
185
|
return processed.join("\n")
|
181
186
|
end
|
182
187
|
|
183
|
-
# Check for inconsistencies between the argument names
|
188
|
+
# Check for inconsistencies between the argument names
|
189
|
+
# in the phrase and the substeps part.
|
184
190
|
def validate_phrase_args(thePhraseArgs, substepsVars)
|
185
191
|
# Error when the phrase names an argument that never occurs in the substeps
|
186
192
|
thePhraseArgs.each do |phrase_arg|
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
193
|
+
unless substepsVars.include? phrase_arg
|
194
|
+
raise UselessPhraseArgument.new(phrase_arg)
|
195
|
+
end
|
196
|
+
end
|
197
|
+
# Error when a substep has an argument that never appears in the phrase
|
198
|
+
# and the macro-step does not use data table.
|
191
199
|
unless use_table?
|
192
200
|
substepsVars.each do |substep_arg|
|
193
|
-
|
201
|
+
unless thePhraseArgs.include? substep_arg
|
202
|
+
raise UnreachableSubstepArgument.new(substep_arg)
|
203
|
+
end
|
194
204
|
end
|
195
205
|
end
|
196
206
|
|
@@ -198,7 +208,8 @@ private
|
|
198
208
|
end
|
199
209
|
|
200
210
|
|
201
|
-
# Return true, if the macro-step requires a data table
|
211
|
+
# Return true, if the macro-step requires a data table
|
212
|
+
# to pass actual values of the arguments.
|
202
213
|
def use_table?()
|
203
214
|
return key =~ /_T$/
|
204
215
|
end
|
data/spec/spec_helper.rb
CHANGED
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.3.
|
4
|
+
version: 0.3.13
|
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-05-
|
12
|
+
date: 2013-05-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: cucumber
|
@@ -81,6 +81,7 @@ executables: []
|
|
81
81
|
extensions: []
|
82
82
|
extra_rdoc_files: []
|
83
83
|
files:
|
84
|
+
- .rubocop.yml
|
84
85
|
- .rspec
|
85
86
|
- .ruby-gemset
|
86
87
|
- .ruby-version
|