macros4cuke 0.5.07 → 0.5.08
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.
- checksums.yaml +8 -8
- data/.rubocop.yml +4 -0
- data/CHANGELOG.md +4 -0
- data/README.md +1 -1
- data/Rakefile +0 -2
- data/features/support/use_macros4cuke.rb +11 -0
- data/lib/macros4cuke/application.rb +0 -3
- data/lib/macros4cuke/cli/cmd-line.rb +0 -7
- data/lib/macros4cuke/coll-walker-factory.rb +0 -7
- data/lib/macros4cuke/constants.rb +1 -1
- data/lib/macros4cuke/exceptions.rb +0 -3
- data/lib/macros4cuke/formatter/all-notifications.rb +20 -24
- data/lib/macros4cuke/formatter/to-gherkin.rb +0 -6
- data/lib/macros4cuke/formatter/to-null.rb +70 -79
- data/lib/macros4cuke/formatter/to-trace.rb +64 -70
- data/lib/macros4cuke/formatting-service.rb +0 -3
- data/lib/macros4cuke/macro-collection.rb +0 -3
- data/lib/macros4cuke/macro-step-support.rb +0 -3
- data/lib/macros4cuke/macro-step.rb +1 -4
- data/lib/macros4cuke/templating/comment.rb +37 -43
- data/lib/macros4cuke/templating/engine.rb +4 -14
- data/lib/macros4cuke/templating/eo-line.rb +10 -19
- data/lib/macros4cuke/templating/placeholder.rb +0 -8
- data/lib/macros4cuke/templating/section.rb +0 -11
- data/lib/macros4cuke/templating/static-text.rb +28 -33
- data/lib/macros4cuke/templating/unary-element.rb +0 -4
- data/spec/macros4cuke/application_spec.rb +0 -5
- data/spec/macros4cuke/cli/cmd-line_spec.rb +213 -223
- data/spec/macros4cuke/coll-walker-factory_spec.rb +0 -6
- data/spec/macros4cuke/formatter/to-gherkin_spec.rb +0 -9
- data/spec/macros4cuke/formatter/to-null_spec.rb +0 -6
- data/spec/macros4cuke/formatter/to-trace_spec.rb +0 -6
- data/spec/macros4cuke/formatting-service_spec.rb +0 -5
- data/spec/macros4cuke/macro-collection_spec.rb +1 -8
- data/spec/macros4cuke/macro-step-support_spec.rb +0 -9
- data/spec/macros4cuke/macro-step_spec.rb +0 -7
- data/spec/macros4cuke/templating/comment_spec.rb +0 -7
- data/spec/macros4cuke/templating/engine_spec.rb +0 -10
- data/spec/macros4cuke/templating/eo-line_spec.rb +1 -8
- data/spec/macros4cuke/templating/placeholder_spec.rb +0 -9
- data/spec/macros4cuke/templating/section_spec.rb +0 -13
- data/spec/macros4cuke/templating/static_text_spec.rb +0 -6
- data/spec/macros4cuke/use-sample-collection.rb +0 -3
- metadata +3 -2
@@ -7,7 +7,6 @@ require_relative './formatter/all-notifications'
|
|
7
7
|
|
8
8
|
|
9
9
|
module Macros4Cuke # Module used as a namespace
|
10
|
-
|
11
10
|
# A worker class that drives the rendering of macro-steps in
|
12
11
|
# any registered format.
|
13
12
|
class FormattingService
|
@@ -66,9 +65,7 @@ class FormattingService
|
|
66
65
|
end
|
67
66
|
end
|
68
67
|
end
|
69
|
-
|
70
68
|
end # class
|
71
|
-
|
72
69
|
end # module
|
73
70
|
|
74
71
|
# End of file
|
@@ -5,7 +5,6 @@ require 'singleton' # We'll use the Singleton design pattern for this class.
|
|
5
5
|
require_relative 'macro-step'
|
6
6
|
|
7
7
|
module Macros4Cuke # Module used as a namespace
|
8
|
-
|
9
8
|
# Represents a container of macros.
|
10
9
|
# It gathers all the macros encountered by Cucumber while "executing"
|
11
10
|
# the feature files.
|
@@ -76,9 +75,7 @@ class MacroCollection
|
|
76
75
|
key = MacroStep.macro_key(aMacroPhrase, useTable, :invokation)
|
77
76
|
return macro_steps[key]
|
78
77
|
end
|
79
|
-
|
80
78
|
end # class
|
81
|
-
|
82
79
|
end # module
|
83
80
|
|
84
81
|
|
@@ -4,7 +4,6 @@ require_relative 'exceptions'
|
|
4
4
|
require_relative 'macro-collection'
|
5
5
|
|
6
6
|
module Macros4Cuke # Module used as a namespace
|
7
|
-
|
8
7
|
# Mix-in module that should be extending World objects in Cucumber.
|
9
8
|
# Synopsis (in env.rb):
|
10
9
|
#
|
@@ -59,9 +58,7 @@ module MacroStepSupport
|
|
59
58
|
def clear_macros()
|
60
59
|
MacroCollection.instance.clear
|
61
60
|
end
|
62
|
-
|
63
61
|
end # module
|
64
|
-
|
65
62
|
end # module
|
66
63
|
|
67
64
|
|
@@ -6,7 +6,6 @@ require_relative 'exceptions'
|
|
6
6
|
require_relative 'templating/engine'
|
7
7
|
|
8
8
|
module Macros4Cuke # Module used as a namespace
|
9
|
-
|
10
9
|
# A macro-step object is a Cucumber step that is itself
|
11
10
|
# an aggregation of lower-level sub-steps.
|
12
11
|
# When a macro-step is used in a scenario, then its execution is equivalent
|
@@ -214,7 +213,7 @@ class MacroStep
|
|
214
213
|
unless use_table?
|
215
214
|
substepsVars.each do |substep_arg|
|
216
215
|
next if thePhraseArgs.include?(substep_arg) ||
|
217
|
-
|
216
|
+
BuiltinParameters.include?(substep_arg)
|
218
217
|
|
219
218
|
fail(UnreachableSubstepArgument.new(substep_arg))
|
220
219
|
end
|
@@ -229,9 +228,7 @@ class MacroStep
|
|
229
228
|
def use_table?()
|
230
229
|
return key =~ /_T$/
|
231
230
|
end
|
232
|
-
|
233
231
|
end # class
|
234
|
-
|
235
232
|
end # module
|
236
233
|
|
237
234
|
# End of file
|
@@ -1,43 +1,37 @@
|
|
1
|
-
# File: eo-line.rb
|
2
|
-
|
3
|
-
|
4
|
-
module Macros4Cuke # Module used as a namespace
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
# used internally
|
9
|
-
|
10
|
-
|
11
|
-
#
|
12
|
-
|
13
|
-
#
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
end # module
|
40
|
-
|
41
|
-
end # module
|
42
|
-
|
43
|
-
# End of file
|
1
|
+
# File: eo-line.rb
|
2
|
+
|
3
|
+
|
4
|
+
module Macros4Cuke # Module used as a namespace
|
5
|
+
# Module containing all classes implementing the simple template engine
|
6
|
+
# used internally in Macros4Cuke.
|
7
|
+
module Templating
|
8
|
+
# Class used internally by the template engine.
|
9
|
+
# Represents a comment from a template.
|
10
|
+
# A static text is a text that is reproduced verbatim
|
11
|
+
# when rendering a template.
|
12
|
+
class Comment
|
13
|
+
# The comment as extracted from the original template.
|
14
|
+
attr_reader(:source)
|
15
|
+
|
16
|
+
|
17
|
+
# @param aSourceText [String] A piece of text extracted
|
18
|
+
# from the template that must be rendered verbatim.
|
19
|
+
def initialize(aSourceText)
|
20
|
+
@source = aSourceText
|
21
|
+
end
|
22
|
+
|
23
|
+
public
|
24
|
+
|
25
|
+
# Render the comment.
|
26
|
+
# Comments are rendered as empty text. This is necessary because
|
27
|
+
# Cucumber::RbSupport::RbWorld#steps complains when it sees a comment.
|
28
|
+
# This method has the same signature as the {Engine#render} method.
|
29
|
+
# @return [String] Empty string ("as is")
|
30
|
+
def render(_, _)
|
31
|
+
return ''
|
32
|
+
end
|
33
|
+
end # class
|
34
|
+
end # module
|
35
|
+
end # module
|
36
|
+
|
37
|
+
# End of file
|
@@ -13,12 +13,9 @@ require_relative 'section' # Load the Section and ConditionalSection
|
|
13
13
|
|
14
14
|
|
15
15
|
module Macros4Cuke # Module used as a namespace
|
16
|
-
|
17
|
-
|
18
16
|
# Module containing all classes implementing the simple template engine
|
19
17
|
# used internally in Macros4Cuke.
|
20
18
|
module Templating
|
21
|
-
|
22
19
|
# A very simple implementation of a templating engine.
|
23
20
|
# Earlier versions of Macros4Cuke relied on the logic-less
|
24
21
|
# Mustache template engine.
|
@@ -77,7 +74,7 @@ class Engine
|
|
77
74
|
# -In case of consecutive eol's only one is rendered.
|
78
75
|
# -In case of comment followed by one eol, both aren't rendered
|
79
76
|
unless element.is_a?(EOLine) &&
|
80
|
-
|
77
|
+
(prev.is_a?(EOLine) || prev.is_a?(Comment))
|
81
78
|
subResult << element.render(aContextObject, theLocals)
|
82
79
|
end
|
83
80
|
prev = element
|
@@ -99,9 +96,6 @@ class Engine
|
|
99
96
|
|
100
97
|
when Section
|
101
98
|
subResult.concat(element.variables)
|
102
|
-
|
103
|
-
else
|
104
|
-
# Do nothing
|
105
99
|
end
|
106
100
|
end
|
107
101
|
|
@@ -316,16 +310,12 @@ class Engine
|
|
316
310
|
msg = 'found while no corresponding section is open.'
|
317
311
|
fail(StandardError, msg_prefix + msg)
|
318
312
|
end
|
319
|
-
if marker.name
|
320
|
-
|
321
|
-
|
322
|
-
end
|
313
|
+
return if marker.name == sections.last.name
|
314
|
+
msg = "doesn't match current section '#{sections.last.name}'."
|
315
|
+
fail(StandardError, msg_prefix + msg)
|
323
316
|
end
|
324
|
-
|
325
317
|
end # class
|
326
|
-
|
327
318
|
end # module
|
328
|
-
|
329
319
|
end # module
|
330
320
|
|
331
321
|
# End of file
|
@@ -2,29 +2,20 @@
|
|
2
2
|
|
3
3
|
|
4
4
|
module Macros4Cuke # Module used as a namespace
|
5
|
-
|
6
|
-
|
7
5
|
# Module containing all classes implementing the simple template engine
|
8
6
|
# used internally in Macros4Cuke.
|
9
7
|
module Templating
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
#
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
# @return [String] An end of line marker. Its exact value is OS-dependent.
|
21
|
-
def render(_, _)
|
22
|
-
return "\n"
|
23
|
-
end
|
24
|
-
end # class
|
25
|
-
|
8
|
+
# Class used internally by the template engine.
|
9
|
+
# Represents an end of line that must be rendered as such.
|
10
|
+
class EOLine
|
11
|
+
# Render an end of line.
|
12
|
+
# This method has the same signature as the {Engine#render} method.
|
13
|
+
# @return [String] An end of line marker. Its exact value is OS-dependent.
|
14
|
+
def render(_, _)
|
15
|
+
return "\n"
|
16
|
+
end
|
17
|
+
end # class
|
26
18
|
end # module
|
27
|
-
|
28
19
|
end # module
|
29
20
|
|
30
21
|
# End of file
|
@@ -5,20 +5,15 @@ require_relative 'unary-element' # Load the superclass
|
|
5
5
|
|
6
6
|
|
7
7
|
module Macros4Cuke # Module used as a namespace
|
8
|
-
|
9
8
|
# Module containing all classes implementing the simple template engine
|
10
9
|
# used internally in Macros4Cuke.
|
11
10
|
module Templating
|
12
|
-
|
13
11
|
# Class used internally by the template engine.
|
14
12
|
# Represents a named placeholder in a template, that is,
|
15
13
|
# a name placed between <..> in the template.
|
16
14
|
# At rendition, a placeholder is replaced by the text value
|
17
15
|
# that is associated with it.
|
18
16
|
class Placeholder < UnaryElement
|
19
|
-
|
20
|
-
public
|
21
|
-
|
22
17
|
# Render the placeholder given the passed arguments.
|
23
18
|
# This method has the same signature as the {Engine#render} method.
|
24
19
|
# @return [String] The text value assigned to the placeholder.
|
@@ -42,11 +37,8 @@ module Templating
|
|
42
37
|
|
43
38
|
return result
|
44
39
|
end
|
45
|
-
|
46
40
|
end # class
|
47
|
-
|
48
41
|
end # module
|
49
|
-
|
50
42
|
end # module
|
51
43
|
|
52
44
|
# End of file
|
@@ -5,12 +5,9 @@ require_relative 'unary-element' # Load the superclass
|
|
5
5
|
|
6
6
|
|
7
7
|
module Macros4Cuke # Module used as a namespace
|
8
|
-
|
9
|
-
|
10
8
|
# Module containing all classes implementing the simple template engine
|
11
9
|
# used internally in Macros4Cuke.
|
12
10
|
module Templating
|
13
|
-
|
14
11
|
# Base class used internally by the template engine.
|
15
12
|
# Represents a section in a template, that is,
|
16
13
|
# a set of template elements for which its rendition depends
|
@@ -41,8 +38,6 @@ class Section < UnaryElement
|
|
41
38
|
subResult << a_child.name
|
42
39
|
when Section
|
43
40
|
subResult.concat(a_child.variables)
|
44
|
-
else
|
45
|
-
# Do nothing
|
46
41
|
end
|
47
42
|
end
|
48
43
|
|
@@ -58,7 +53,6 @@ class Section < UnaryElement
|
|
58
53
|
msg = "Method Section.#{__method__} must be implemented in subclass."
|
59
54
|
fail(NotImplementedError, msg)
|
60
55
|
end
|
61
|
-
|
62
56
|
end # class
|
63
57
|
|
64
58
|
|
@@ -103,14 +97,9 @@ class ConditionalSection < Section
|
|
103
97
|
def to_s()
|
104
98
|
return "<?#{name}>"
|
105
99
|
end
|
106
|
-
|
107
100
|
end # class
|
108
|
-
|
109
|
-
|
110
101
|
SectionEndMarker = Struct.new(:name)
|
111
|
-
|
112
102
|
end # module
|
113
|
-
|
114
103
|
end # module
|
115
104
|
|
116
105
|
# End of file
|
@@ -2,39 +2,34 @@
|
|
2
2
|
|
3
3
|
|
4
4
|
module Macros4Cuke # Module used as a namespace
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
# used internally
|
9
|
-
|
10
|
-
|
11
|
-
#
|
12
|
-
|
13
|
-
#
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
end
|
34
|
-
end # class
|
35
|
-
|
36
|
-
end # module
|
37
|
-
|
5
|
+
# Module containing all classes implementing the simple template engine
|
6
|
+
# used internally in Macros4Cuke.
|
7
|
+
module Templating
|
8
|
+
# Class used internally by the template engine.
|
9
|
+
# Represents a static piece of text from a template.
|
10
|
+
# A static text is a text that is reproduced verbatim
|
11
|
+
# when rendering a template.
|
12
|
+
class StaticText
|
13
|
+
# The static text extracted from the original template.
|
14
|
+
attr_reader(:source)
|
15
|
+
|
16
|
+
|
17
|
+
# @param aSourceText [String] A piece of text extracted
|
18
|
+
# from the template that must be rendered verbatim.
|
19
|
+
def initialize(aSourceText)
|
20
|
+
@source = aSourceText
|
21
|
+
end
|
22
|
+
|
23
|
+
public
|
24
|
+
|
25
|
+
# Render the static text.
|
26
|
+
# This method has the same signature as the {Engine#render} method.
|
27
|
+
# @return [String] Static text is returned verbatim ("as is")
|
28
|
+
def render(_, _)
|
29
|
+
return source
|
30
|
+
end
|
31
|
+
end # class
|
32
|
+
end # module
|
38
33
|
end # module
|
39
34
|
|
40
35
|
# End of file
|
@@ -3,7 +3,6 @@
|
|
3
3
|
|
4
4
|
|
5
5
|
module Macros4Cuke # Module used as a namespace
|
6
|
-
|
7
6
|
# Base class used internally by the template engine.
|
8
7
|
# The generalization of any element from a template that has one variable
|
9
8
|
# whose actual value influences the rendition.
|
@@ -29,9 +28,6 @@ module Macros4Cuke # Module used as a namespace
|
|
29
28
|
|
30
29
|
return actual_value
|
31
30
|
end
|
32
|
-
|
33
31
|
end # class
|
34
|
-
|
35
32
|
end # module
|
36
|
-
|
37
33
|
# End of file
|
@@ -8,9 +8,7 @@ require_relative '../../lib/macros4cuke/exceptions'
|
|
8
8
|
require_relative '../../lib/macros4cuke/application'
|
9
9
|
|
10
10
|
module Macros4Cuke # Open this namespace to avoid module qualifier prefixes
|
11
|
-
|
12
11
|
describe Application do
|
13
|
-
|
14
12
|
before(:each) do
|
15
13
|
@current_wkdir = Dir.getwd
|
16
14
|
Dir.chdir(File.dirname(__FILE__))
|
@@ -106,11 +104,8 @@ MSG_END
|
|
106
104
|
File.delete(".#{file_path}/#{file_name}")
|
107
105
|
delete_dirs('.' + file_path)
|
108
106
|
end
|
109
|
-
|
110
107
|
end # context
|
111
|
-
|
112
108
|
end # describe
|
113
|
-
|
114
109
|
end # module
|
115
110
|
|
116
111
|
|
@@ -1,223 +1,213 @@
|
|
1
|
-
# File: cmd-line_spec.rb
|
2
|
-
|
3
|
-
require 'stringio'
|
4
|
-
require_relative '../../spec_helper'
|
5
|
-
|
6
|
-
require_relative '../../../lib/macros4cuke/exceptions'
|
7
|
-
|
8
|
-
# Load the class under test
|
9
|
-
require_relative '../../../lib/macros4cuke/cli/cmd-line'
|
10
|
-
|
11
|
-
module Macros4Cuke
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
expect
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
err_msg
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
end # context
|
216
|
-
|
217
|
-
end # describe
|
218
|
-
|
219
|
-
end # module
|
220
|
-
|
221
|
-
end # module
|
222
|
-
|
223
|
-
# End of file
|
1
|
+
# File: cmd-line_spec.rb
|
2
|
+
|
3
|
+
require 'stringio'
|
4
|
+
require_relative '../../spec_helper'
|
5
|
+
|
6
|
+
require_relative '../../../lib/macros4cuke/exceptions'
|
7
|
+
|
8
|
+
# Load the class under test
|
9
|
+
require_relative '../../../lib/macros4cuke/cli/cmd-line'
|
10
|
+
|
11
|
+
module Macros4Cuke
|
12
|
+
module CLI
|
13
|
+
describe CmdLine do
|
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
|
+
context 'Creation and initialization:' do
|
47
|
+
it 'should be created without argument' do
|
48
|
+
expect { CmdLine.new }.not_to raise_error
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'should have an command-line parser' do
|
52
|
+
expect(subject.parser).to be_kind_of(OptionParser)
|
53
|
+
end
|
54
|
+
end # context
|
55
|
+
|
56
|
+
|
57
|
+
context 'Informative options:' do
|
58
|
+
it 'should provide short help when command-line is empty' do
|
59
|
+
hijack_stdout
|
60
|
+
short_help = <<-END_MESSAGE
|
61
|
+
For help about the command-line syntax, do:
|
62
|
+
macros4cuke --help
|
63
|
+
END_MESSAGE
|
64
|
+
|
65
|
+
# Application is stopped
|
66
|
+
expect { subject.parse!([]) }.to raise_error(SystemExit)
|
67
|
+
|
68
|
+
# Help text is displayed
|
69
|
+
expect($stdout.string).to eq(short_help)
|
70
|
+
restore_stdout
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'should provide complete help when help requested' do
|
74
|
+
help_options = [ ['-h'], ['--help'] ]
|
75
|
+
help_text = subject.parser.help
|
76
|
+
|
77
|
+
help_options.each do |cmd_line|
|
78
|
+
hijack_stdout
|
79
|
+
# Application is stopped
|
80
|
+
expect { subject.parse!(cmd_line) }.to raise_error(SystemExit)
|
81
|
+
|
82
|
+
# Help text is displayed
|
83
|
+
expect($stdout.string).to eq(help_text)
|
84
|
+
restore_stdout
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'should provide version when it is requested' do
|
89
|
+
version_options = [ ['-v'], ['--version'] ]
|
90
|
+
|
91
|
+
version_options.each do |cmd_line|
|
92
|
+
hijack_stdout
|
93
|
+
# Application is stopped
|
94
|
+
expect { subject.parse!(cmd_line) }.to raise_error(SystemExit)
|
95
|
+
|
96
|
+
# platform versions are displayed
|
97
|
+
|
98
|
+
expect($stdout.string).to eq(Macros4Cuke::Version + "\n")
|
99
|
+
restore_stdout
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'should provide platform data when requested' do
|
104
|
+
verbose_version_options = [ ['-V'], ['--version-verbose'] ]
|
105
|
+
|
106
|
+
cuke = "Cucumber #{Cucumber::VERSION}"
|
107
|
+
ruby = "Ruby #{RUBY_VERSION} #{RUBY_PLATFORM}"
|
108
|
+
full_msg = "#{Macros4Cuke::Version} (using #{cuke}, running on #{ruby})"
|
109
|
+
|
110
|
+
verbose_version_options.each do |cmd_line|
|
111
|
+
hijack_stdout
|
112
|
+
# Application is stopped
|
113
|
+
expect { subject.parse!(cmd_line) }.to raise_error(SystemExit)
|
114
|
+
|
115
|
+
# Version number is displayed
|
116
|
+
expect($stdout.string).to eq(full_msg + "\n")
|
117
|
+
restore_stdout
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end # context
|
121
|
+
|
122
|
+
context 'Error in command-line:' do
|
123
|
+
it 'should complain when detecting an unknown option' do
|
124
|
+
hijack_stderr
|
125
|
+
err_msg = "invalid option: --unknown\n"
|
126
|
+
|
127
|
+
# Application is stopped
|
128
|
+
expect { subject.parse!(['--unknown']) }.to raise_error(SystemExit)
|
129
|
+
|
130
|
+
# Error message text is displayed
|
131
|
+
expect($stderr.string).to eq(err_msg)
|
132
|
+
restore_stderr
|
133
|
+
end
|
134
|
+
|
135
|
+
it 'should complain when an option misses an argument' do
|
136
|
+
hijack_stderr
|
137
|
+
err_msg = <<-END_MESSAGE
|
138
|
+
No argument provided with command line option: --setup
|
139
|
+
END_MESSAGE
|
140
|
+
|
141
|
+
# Application is stopped
|
142
|
+
expect { subject.parse!(['--setup']) }.to raise_error(SystemExit)
|
143
|
+
|
144
|
+
# Error message text is displayed
|
145
|
+
expect($stderr.string).to eq(err_msg)
|
146
|
+
restore_stderr
|
147
|
+
end
|
148
|
+
|
149
|
+
it "should complain when project to setup doesn't exist" do
|
150
|
+
hijack_stderr
|
151
|
+
err_msg = <<-END_MESSAGE
|
152
|
+
Error in command-line:
|
153
|
+
Cannot find the directory 'not_a_dir'.
|
154
|
+
END_MESSAGE
|
155
|
+
|
156
|
+
# Application is stopped
|
157
|
+
args = %w(--setup not_a_dir)
|
158
|
+
expect { subject.parse!(args) }.to raise_error(SystemExit)
|
159
|
+
|
160
|
+
# Error message text is displayed
|
161
|
+
expect($stderr.string).to eq(err_msg)
|
162
|
+
restore_stderr
|
163
|
+
end
|
164
|
+
|
165
|
+
it "should complain when features dir does'nt exist" do
|
166
|
+
mk_subdir('test_dir')
|
167
|
+
|
168
|
+
hijack_stderr
|
169
|
+
err_msg = <<-END_MESSAGE
|
170
|
+
Error in command-line:
|
171
|
+
Cannot find the directory 'test_dir/features'.
|
172
|
+
END_MESSAGE
|
173
|
+
args = %w(--setup ./test_dir)
|
174
|
+
|
175
|
+
# Application is stopped
|
176
|
+
expect { subject.parse!(args) }.to raise_error(SystemExit)
|
177
|
+
|
178
|
+
# Error message text is displayed
|
179
|
+
expect($stderr.string).to eq(err_msg)
|
180
|
+
restore_stderr
|
181
|
+
|
182
|
+
mk_subdir('test_dir/features')
|
183
|
+
hijack_stderr
|
184
|
+
err_msg = <<-END_MESSAGE
|
185
|
+
Error in command-line:
|
186
|
+
Cannot find the directory 'test_dir/features/support'.
|
187
|
+
END_MESSAGE
|
188
|
+
|
189
|
+
# Application is stopped
|
190
|
+
expect { subject.parse!(args) }.to raise_error(SystemExit)
|
191
|
+
|
192
|
+
# Error message text is displayed
|
193
|
+
expect($stderr.string).to eq(err_msg)
|
194
|
+
restore_stderr
|
195
|
+
end
|
196
|
+
|
197
|
+
it 'should not complain when all dirs are present' do
|
198
|
+
mk_subdir('test_dir/features/support')
|
199
|
+
|
200
|
+
expected = { setup: [Pathname.getwd + 'test_dir/features/support'] }
|
201
|
+
expect(subject.parse!(%w(--setup ./test_dir))).to eq(expected)
|
202
|
+
|
203
|
+
file_path = expected[:setup].first
|
204
|
+
Dir.rmdir(file_path)
|
205
|
+
Dir.rmdir(file_path.parent)
|
206
|
+
Dir.rmdir(file_path.parent.parent)
|
207
|
+
end
|
208
|
+
end # context
|
209
|
+
end # describe
|
210
|
+
end # module
|
211
|
+
end # module
|
212
|
+
|
213
|
+
# End of file
|