macros4cuke 0.4.09 → 0.5.03
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/.travis.yml +2 -2
- data/CHANGELOG.md +17 -0
- data/README.md +41 -22
- data/bin/macros4cuke +15 -0
- data/examples/demo/features/support/use_macros4cuke.rb +12 -0
- data/examples/i18n/fr/features/demo01-fr.feature +13 -0
- data/examples/i18n/fr/features/step_definitions/demo_steps.rb +5 -0
- data/examples/i18n/fr/features/step_definitions/{use_macro_steps.rb → macro_steps_fr.rb} +3 -2
- data/examples/i18n/fr/features/support/use_macros4cuke.rb +12 -0
- data/examples/i18n/nl/cucumber.yml +6 -0
- data/examples/i18n/nl/features/demo01-nl.feature +40 -0
- data/examples/i18n/nl/features/step_definitions/demo_steps.rb +21 -0
- data/examples/i18n/nl/features/step_definitions/macro_steps_nl.rb +31 -0
- data/examples/i18n/nl/features/support/use_macros4cuke.rb +12 -0
- data/features/support/use_macros4cuke.rb +11 -0
- data/lib/macros4cuke.rb +1 -0
- data/lib/macros4cuke/application.rb +75 -0
- data/lib/macros4cuke/cli/cmd-line.rb +142 -0
- data/lib/macros4cuke/constants.rb +2 -2
- data/lib/macros4cuke/cucumber.rb +16 -0
- data/lib/macros4cuke/exceptions.rb +25 -1
- data/lib/macros4cuke/templating/comment.rb +43 -0
- data/lib/macros4cuke/templating/eo-line.rb +30 -0
- data/lib/macros4cuke/templating/static-text.rb +40 -0
- data/lib/macros4cuke/templating/template-element.rb +7 -88
- data/spec/macros4cuke/application_spec.rb +117 -0
- data/spec/macros4cuke/cli/cmd-line_spec.rb +223 -0
- data/spec/macros4cuke/macro-collection_spec.rb +1 -1
- data/spec/macros4cuke/macro-step-support_spec.rb +1 -1
- data/spec/macros4cuke/templating/comment_spec.rb +1 -1
- data/spec/macros4cuke/templating/eo-line_spec.rb +2 -2
- data/spec/macros4cuke/templating/static_text_spec.rb +1 -1
- data/templates/use_macros4cuke.erb +12 -0
- metadata +35 -19
- data/examples/demo/features/step_definitions/use_macro_steps.rb +0 -10
- data/examples/demo/features/support/macro_support.rb +0 -16
- data/examples/i18n/fr/features/support/macro_support.rb +0 -17
- data/features/step_definitions/use_macro_steps.rb +0 -10
- data/features/support/macro_support.rb +0 -16
@@ -0,0 +1,142 @@
|
|
1
|
+
# File: cli.rb
|
2
|
+
|
3
|
+
# Access the OptionParser library from the standard Ruby library
|
4
|
+
require 'optparse'
|
5
|
+
require 'pathname'
|
6
|
+
|
7
|
+
require 'cucumber/platform'
|
8
|
+
require_relative '../constants'
|
9
|
+
|
10
|
+
module Macros4Cuke # Module used as a namespace
|
11
|
+
|
12
|
+
# Module dedicated to the command-line interface
|
13
|
+
module CLI
|
14
|
+
|
15
|
+
|
16
|
+
# Manages the application command-line interface (CLI).
|
17
|
+
# It is merely a thin wrapper around the OptionParser library.
|
18
|
+
# Responsibilities:
|
19
|
+
#- Specify the command-line syntax,
|
20
|
+
#- Return the result of the command-line parsing
|
21
|
+
# Examples of command lines:
|
22
|
+
# --setup PROJ_PATH
|
23
|
+
# --suggest
|
24
|
+
class CmdLine
|
25
|
+
ShortHelpMsg = <<-END_MSG
|
26
|
+
For help about the command-line syntax, do:
|
27
|
+
macros4cuke --help
|
28
|
+
END_MSG
|
29
|
+
|
30
|
+
# A Hash with the result of the command-line parse.
|
31
|
+
attr_reader(:options)
|
32
|
+
|
33
|
+
# OptionParser object
|
34
|
+
attr_reader(:parser)
|
35
|
+
|
36
|
+
# Constructor.
|
37
|
+
def initialize()
|
38
|
+
@options = {}
|
39
|
+
|
40
|
+
@parser = OptionParser.new do |opts|
|
41
|
+
opts.banner = <<-EOS
|
42
|
+
Usage: macros4cuke [options]
|
43
|
+
The command-line options are:
|
44
|
+
EOS
|
45
|
+
# Mandatory argument
|
46
|
+
msg_p1 = 'Make the Cucumber project at given path '
|
47
|
+
msg_p2 = 'ready for macro-steps.'
|
48
|
+
opts.on('--setup PROJECT_PATH', msg_p1 + msg_p2) do |project_path|
|
49
|
+
valid_path = validated_feature_path(project_path)
|
50
|
+
options[:setup] ||= []
|
51
|
+
options[:setup] << valid_path
|
52
|
+
end
|
53
|
+
|
54
|
+
# No argument, shows at tail. This will print an options summary.
|
55
|
+
opts.on_tail('-h', '--help', 'Show this message') do
|
56
|
+
# puts opts
|
57
|
+
options[:help] = true
|
58
|
+
end
|
59
|
+
|
60
|
+
opts.on_tail('-v', '--version', 'Display version number.') do
|
61
|
+
puts Macros4Cuke::Version
|
62
|
+
options[:version] = true
|
63
|
+
end
|
64
|
+
|
65
|
+
version_verbose_msg = 'Display gem and platform version numbers.'
|
66
|
+
opts.on_tail('-V', '--version-verbose', version_verbose_msg) do
|
67
|
+
cuke = "Cucumber #{Cucumber::VERSION}"
|
68
|
+
ruby = "Ruby #{RUBY_VERSION} #{RUBY_PLATFORM}"
|
69
|
+
msg = "#{Macros4Cuke::Version} (using #{cuke}, running on #{ruby})"
|
70
|
+
puts msg
|
71
|
+
options[:version] = true
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
public
|
78
|
+
|
79
|
+
# Perform the command-line parsing
|
80
|
+
def parse!(theCmdLineArgs)
|
81
|
+
begin
|
82
|
+
parser.parse!(theCmdLineArgs.dup)
|
83
|
+
rescue Macros4Cuke::CmdLineError => exc
|
84
|
+
$stderr.puts exc.message
|
85
|
+
exit
|
86
|
+
|
87
|
+
rescue OptionParser::InvalidOption => exc
|
88
|
+
$stderr.puts exc.message
|
89
|
+
exit
|
90
|
+
|
91
|
+
rescue OptionParser::MissingArgument => exc
|
92
|
+
err_msg = ''
|
93
|
+
exc.args.each do |arg|
|
94
|
+
err_msg << "No argument provided with command line option: #{arg}\n"
|
95
|
+
end
|
96
|
+
$stderr.puts err_msg
|
97
|
+
exit
|
98
|
+
end
|
99
|
+
|
100
|
+
# When no option provided then display minimalistic help info
|
101
|
+
short_help if options.empty?
|
102
|
+
|
103
|
+
show_help if options[:help]
|
104
|
+
|
105
|
+
# Some options stop the application
|
106
|
+
exit if options[:version] || options[:help]
|
107
|
+
|
108
|
+
return options
|
109
|
+
end
|
110
|
+
|
111
|
+
private
|
112
|
+
|
113
|
+
# Given the project path, retrieve its /features dir.
|
114
|
+
def validated_feature_path(theProjectPath)
|
115
|
+
dirs = [theProjectPath, 'features', 'support']
|
116
|
+
feature_path = dirs.reduce(Pathname.getwd) do |path, dir_name|
|
117
|
+
path = path + dir_name
|
118
|
+
unless path.exist?
|
119
|
+
fail DirectoryNotFound.new(path.relative_path_from(Pathname.getwd))
|
120
|
+
end
|
121
|
+
path
|
122
|
+
end
|
123
|
+
|
124
|
+
return feature_path
|
125
|
+
end
|
126
|
+
|
127
|
+
def show_help()
|
128
|
+
puts parser.help
|
129
|
+
end
|
130
|
+
|
131
|
+
def short_help()
|
132
|
+
puts ShortHelpMsg
|
133
|
+
exit
|
134
|
+
end
|
135
|
+
|
136
|
+
end # class
|
137
|
+
|
138
|
+
end # module
|
139
|
+
|
140
|
+
end # module
|
141
|
+
|
142
|
+
# End of file
|
@@ -3,10 +3,10 @@
|
|
3
3
|
|
4
4
|
module Macros4Cuke # Module used as a namespace
|
5
5
|
# The version number of the gem.
|
6
|
-
Version = '0.
|
6
|
+
Version = '0.5.03'
|
7
7
|
|
8
8
|
# Brief description of the gem.
|
9
|
-
Description = '
|
9
|
+
Description = 'Add your own macro-steps to Cucumber scenarios'
|
10
10
|
|
11
11
|
# Constant Macros4Cuke::RootDir contains the absolute path of Macro4Cuke's
|
12
12
|
# root directory. Note: it also ends with a slash character.
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# File: cucumber.rb
|
2
|
+
# Purpose: Load Macros4Cuke modules and classes, register its step definitions
|
3
|
+
|
4
|
+
# Load modules and classes from the gem.
|
5
|
+
require_relative 'constants'
|
6
|
+
require_relative 'macro-step-support'
|
7
|
+
|
8
|
+
|
9
|
+
# Extend the world object with the mix-in module
|
10
|
+
# that adds the support for macros in Cucumber.
|
11
|
+
World(Macros4Cuke::MacroStepSupport)
|
12
|
+
|
13
|
+
# Register the step definitions from Macros4Cuke
|
14
|
+
require_relative '../macro_steps'
|
15
|
+
|
16
|
+
# End of file
|
@@ -7,11 +7,35 @@ module Macros4Cuke # Module used as a namespace
|
|
7
7
|
class Macros4CukeError < StandardError
|
8
8
|
end # class
|
9
9
|
|
10
|
+
# @abstract
|
11
|
+
# Specialized command-line errors.
|
12
|
+
class CmdLineError < Macros4CukeError
|
13
|
+
def initialize(aMessage)
|
14
|
+
msg = "Error in command-line:\n"
|
15
|
+
super(msg + aMessage)
|
16
|
+
end
|
17
|
+
end # class
|
18
|
+
|
19
|
+
class DirectoryNotFound < CmdLineError
|
20
|
+
def initialize(aDirPath)
|
21
|
+
msg = "Cannot find the directory '#{aDirPath}'."
|
22
|
+
super(msg)
|
23
|
+
end
|
24
|
+
end # class
|
25
|
+
|
26
|
+
|
27
|
+
class SupportFileExists < CmdLineError
|
28
|
+
def initialize(aDirPath)
|
29
|
+
msg = "The file '#{aDirPath}' already exists."
|
30
|
+
super(msg)
|
31
|
+
end
|
32
|
+
end # class
|
33
|
+
|
10
34
|
# Raised when one attempts to define a new macro
|
11
35
|
# that has the same phrase as an existing macro.
|
12
36
|
class DuplicateMacroError < Macros4CukeError
|
13
37
|
def initialize(aPhrase)
|
14
|
-
super("A macro-step with phrase '#{aPhrase}' already
|
38
|
+
super("A macro-step with phrase '#{aPhrase}' already exists.")
|
15
39
|
end
|
16
40
|
end # class
|
17
41
|
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# File: eo-line.rb
|
2
|
+
|
3
|
+
|
4
|
+
module Macros4Cuke # Module used as a namespace
|
5
|
+
|
6
|
+
|
7
|
+
# Module containing all classes implementing the simple template engine
|
8
|
+
# used internally in Macros4Cuke.
|
9
|
+
module Templating
|
10
|
+
|
11
|
+
# Class used internally by the template engine.
|
12
|
+
# Represents a comment from a template.
|
13
|
+
# A static text is a text that is reproduced verbatim
|
14
|
+
# when rendering a template.
|
15
|
+
class Comment
|
16
|
+
# The comment as extracted from the original template.
|
17
|
+
attr_reader(:source)
|
18
|
+
|
19
|
+
|
20
|
+
# @param aSourceText [String] A piece of text extracted
|
21
|
+
# from the template that must be rendered verbatim.
|
22
|
+
def initialize(aSourceText)
|
23
|
+
@source = aSourceText
|
24
|
+
end
|
25
|
+
|
26
|
+
public
|
27
|
+
|
28
|
+
# Render the comment.
|
29
|
+
# Comments are rendered as empty text. This is necessary because
|
30
|
+
# Cucumber::RbSupport::RbWorld#steps complains when it sees a comment.
|
31
|
+
# This method has the same signature as the {Engine#render} method.
|
32
|
+
# @return [String] Empty string ("as is")
|
33
|
+
def render(aContextObject, theLocals)
|
34
|
+
return ''
|
35
|
+
end
|
36
|
+
end # class
|
37
|
+
|
38
|
+
|
39
|
+
end # module
|
40
|
+
|
41
|
+
end # module
|
42
|
+
|
43
|
+
# End of file
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# File: eo-line.rb
|
2
|
+
|
3
|
+
|
4
|
+
module Macros4Cuke # Module used as a namespace
|
5
|
+
|
6
|
+
|
7
|
+
# Module containing all classes implementing the simple template engine
|
8
|
+
# used internally in Macros4Cuke.
|
9
|
+
module Templating
|
10
|
+
|
11
|
+
|
12
|
+
# Class used internally by the template engine.
|
13
|
+
# Represents an end of line that must be rendered as such.
|
14
|
+
class EOLine
|
15
|
+
|
16
|
+
public
|
17
|
+
|
18
|
+
# Render an end of line.
|
19
|
+
# This method has the same signature as the {Engine#render} method.
|
20
|
+
# @return [String] An end of line marker. Its exact value is OS-dependent.
|
21
|
+
def render(aContextObject, theLocals)
|
22
|
+
return "\n"
|
23
|
+
end
|
24
|
+
end # class
|
25
|
+
|
26
|
+
end # module
|
27
|
+
|
28
|
+
end # module
|
29
|
+
|
30
|
+
# End of file
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# File: static-text.rb
|
2
|
+
|
3
|
+
|
4
|
+
module Macros4Cuke # Module used as a namespace
|
5
|
+
|
6
|
+
|
7
|
+
# Module containing all classes implementing the simple template engine
|
8
|
+
# used internally in Macros4Cuke.
|
9
|
+
module Templating
|
10
|
+
|
11
|
+
# Class used internally by the template engine.
|
12
|
+
# Represents a static piece of text from a template.
|
13
|
+
# A static text is a text that is reproduced verbatim
|
14
|
+
# when rendering a template.
|
15
|
+
class StaticText
|
16
|
+
# The static text extracted from the original template.
|
17
|
+
attr_reader(:source)
|
18
|
+
|
19
|
+
|
20
|
+
# @param aSourceText [String] A piece of text extracted
|
21
|
+
# from the template that must be rendered verbatim.
|
22
|
+
def initialize(aSourceText)
|
23
|
+
@source = aSourceText
|
24
|
+
end
|
25
|
+
|
26
|
+
public
|
27
|
+
|
28
|
+
# Render the static text.
|
29
|
+
# This method has the same signature as the {Engine#render} method.
|
30
|
+
# @return [String] Static text is returned verbatim ("as is")
|
31
|
+
def render(aContextObject, theLocals)
|
32
|
+
return source
|
33
|
+
end
|
34
|
+
end # class
|
35
|
+
|
36
|
+
end # module
|
37
|
+
|
38
|
+
end # module
|
39
|
+
|
40
|
+
# End of file
|
@@ -1,88 +1,7 @@
|
|
1
|
-
# File: template-element.rb
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
require_relative '
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
module Macros4Cuke # Module used as a namespace
|
10
|
-
|
11
|
-
|
12
|
-
# Module containing all classes implementing the simple template engine
|
13
|
-
# used internally in Macros4Cuke.
|
14
|
-
module Templating
|
15
|
-
|
16
|
-
# Class used internally by the template engine.
|
17
|
-
# Represents a static piece of text from a template.
|
18
|
-
# A static text is a text that is reproduced verbatim
|
19
|
-
# when rendering a template.
|
20
|
-
class StaticText
|
21
|
-
# The static text extracted from the original template.
|
22
|
-
attr_reader(:source)
|
23
|
-
|
24
|
-
|
25
|
-
# @param aSourceText [String] A piece of text extracted
|
26
|
-
# from the template that must be rendered verbatim.
|
27
|
-
def initialize(aSourceText)
|
28
|
-
@source = aSourceText
|
29
|
-
end
|
30
|
-
|
31
|
-
public
|
32
|
-
|
33
|
-
# Render the static text.
|
34
|
-
# This method has the same signature as the {Engine#render} method.
|
35
|
-
# @return [String] Static text is returned verbatim ("as is")
|
36
|
-
def render(aContextObject, theLocals)
|
37
|
-
return source
|
38
|
-
end
|
39
|
-
end # class
|
40
|
-
|
41
|
-
|
42
|
-
# Class used internally by the template engine.
|
43
|
-
# Represents a comment from a template.
|
44
|
-
# A static text is a text that is reproduced verbatim
|
45
|
-
# when rendering a template.
|
46
|
-
class Comment
|
47
|
-
# The comment as extracted from the original template.
|
48
|
-
attr_reader(:source)
|
49
|
-
|
50
|
-
|
51
|
-
# @param aSourceText [String] A piece of text extracted
|
52
|
-
# from the template that must be rendered verbatim.
|
53
|
-
def initialize(aSourceText)
|
54
|
-
@source = aSourceText
|
55
|
-
end
|
56
|
-
|
57
|
-
public
|
58
|
-
|
59
|
-
# Render the comment.
|
60
|
-
# Comments are rendered as empty text. This is necessary because
|
61
|
-
# Cucumber::RbSupport::RbWorld#steps complains when it sees a comment.
|
62
|
-
# This method has the same signature as the {Engine#render} method.
|
63
|
-
# @return [String] Empty string ("as is")
|
64
|
-
def render(aContextObject, theLocals)
|
65
|
-
return ''
|
66
|
-
end
|
67
|
-
end # class
|
68
|
-
|
69
|
-
|
70
|
-
# Class used internally by the template engine.
|
71
|
-
# Represents an end of line that must be rendered as such.
|
72
|
-
class EOLine
|
73
|
-
|
74
|
-
public
|
75
|
-
|
76
|
-
# Render an end of line.
|
77
|
-
# This method has the same signature as the {Engine#render} method.
|
78
|
-
# @return [String] An end of line marker. Its exact value is OS-dependent.
|
79
|
-
def render(aContextObject, theLocals)
|
80
|
-
return "\n"
|
81
|
-
end
|
82
|
-
end # class
|
83
|
-
|
84
|
-
end # module
|
85
|
-
|
86
|
-
end # module
|
87
|
-
|
88
|
-
# End of file
|
1
|
+
# File: template-element.rb
|
2
|
+
|
3
|
+
require_relative 'static-text'
|
4
|
+
require_relative 'comment'
|
5
|
+
require_relative 'eo-line'
|
6
|
+
|
7
|
+
# End of file
|
@@ -0,0 +1,117 @@
|
|
1
|
+
# File: macro-collection_spec.rb
|
2
|
+
|
3
|
+
require_relative '../spec_helper'
|
4
|
+
|
5
|
+
require_relative '../../lib/macros4cuke/exceptions'
|
6
|
+
|
7
|
+
# Load the class under test
|
8
|
+
require_relative '../../lib/macros4cuke/application'
|
9
|
+
|
10
|
+
module Macros4Cuke # Open this namespace to avoid module qualifier prefixes
|
11
|
+
|
12
|
+
describe Application do
|
13
|
+
|
14
|
+
before(:each) do
|
15
|
+
@current_wkdir = Dir.getwd
|
16
|
+
Dir.chdir(File.dirname(__FILE__))
|
17
|
+
end
|
18
|
+
|
19
|
+
after(:each) do
|
20
|
+
Dir.chdir(@current_wkdir)
|
21
|
+
end
|
22
|
+
|
23
|
+
def hijack_stdout()
|
24
|
+
@orig_stdout = $stdout
|
25
|
+
$stdout = StringIO.new('', 'w')
|
26
|
+
end
|
27
|
+
|
28
|
+
def restore_stdout()
|
29
|
+
$stdout = @orig_stdout
|
30
|
+
end
|
31
|
+
|
32
|
+
def hijack_stderr()
|
33
|
+
@orig_stderr = $stderr
|
34
|
+
$stderr = StringIO.new('', 'w')
|
35
|
+
end
|
36
|
+
|
37
|
+
def restore_stderr()
|
38
|
+
$stderr = @orig_stderr
|
39
|
+
end
|
40
|
+
|
41
|
+
def mk_subdir(relativePath)
|
42
|
+
subdir = File.dirname(__FILE__) + '/' + relativePath
|
43
|
+
Dir.mkdir(subdir)
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
context 'Creation & initialization:' do
|
48
|
+
it 'should be created without argument' do
|
49
|
+
expect { Application.new }.not_to raise_error
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'should not have any option at creation' do
|
53
|
+
expect(subject.options).to be_empty
|
54
|
+
end
|
55
|
+
end # context
|
56
|
+
|
57
|
+
context 'Provided services:' do
|
58
|
+
def make_dirs()
|
59
|
+
mk_subdir('test_dir')
|
60
|
+
mk_subdir('test_dir/features')
|
61
|
+
mk_subdir('test_dir/features/support')
|
62
|
+
end
|
63
|
+
|
64
|
+
def delete_dirs(aFilepath)
|
65
|
+
a_path = Pathname.new(aFilepath)
|
66
|
+
Dir.rmdir(a_path)
|
67
|
+
Dir.rmdir(a_path.parent)
|
68
|
+
Dir.rmdir(a_path.parent.parent)
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'should create a support file when requested' do
|
72
|
+
make_dirs
|
73
|
+
|
74
|
+
file_path = './test_dir/features/support'
|
75
|
+
file_name = 'use_macros4cuke.rb'
|
76
|
+
|
77
|
+
subject.run!(%w(--setup ./test_dir))
|
78
|
+
expect(File.exist?(file_path + '/' + file_name)).to be_true
|
79
|
+
|
80
|
+
File.delete(file_path + '/' + file_name)
|
81
|
+
delete_dirs(file_path)
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'should complain when the support file already exists' do
|
85
|
+
make_dirs
|
86
|
+
|
87
|
+
file_path = '/test_dir/features/support'
|
88
|
+
file_name = 'use_macros4cuke.rb'
|
89
|
+
args = %w(--setup ./test_dir)
|
90
|
+
my_dir = File.dirname(__FILE__)
|
91
|
+
|
92
|
+
expect { subject.run!(args) }.not_to raise_error
|
93
|
+
|
94
|
+
hijack_stderr
|
95
|
+
err_msg = <<-MSG_END
|
96
|
+
Error in command-line:
|
97
|
+
The file '#{my_dir}/test_dir/features/support/use_macros4cuke.rb' already exists.
|
98
|
+
MSG_END
|
99
|
+
|
100
|
+
expect { subject.run!(args) }.to raise_error(SystemExit)
|
101
|
+
|
102
|
+
# Error message text is displayed
|
103
|
+
expect($stderr.string).to eq(err_msg)
|
104
|
+
restore_stderr
|
105
|
+
|
106
|
+
File.delete(".#{file_path}/#{file_name}")
|
107
|
+
delete_dirs('.' + file_path)
|
108
|
+
end
|
109
|
+
|
110
|
+
end # context
|
111
|
+
|
112
|
+
end # describe
|
113
|
+
|
114
|
+
end # module
|
115
|
+
|
116
|
+
|
117
|
+
# End of file
|