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.
Files changed (44) hide show
  1. checksums.yaml +8 -8
  2. data/.rubocop.yml +4 -0
  3. data/CHANGELOG.md +4 -0
  4. data/README.md +1 -1
  5. data/Rakefile +0 -2
  6. data/features/support/use_macros4cuke.rb +11 -0
  7. data/lib/macros4cuke/application.rb +0 -3
  8. data/lib/macros4cuke/cli/cmd-line.rb +0 -7
  9. data/lib/macros4cuke/coll-walker-factory.rb +0 -7
  10. data/lib/macros4cuke/constants.rb +1 -1
  11. data/lib/macros4cuke/exceptions.rb +0 -3
  12. data/lib/macros4cuke/formatter/all-notifications.rb +20 -24
  13. data/lib/macros4cuke/formatter/to-gherkin.rb +0 -6
  14. data/lib/macros4cuke/formatter/to-null.rb +70 -79
  15. data/lib/macros4cuke/formatter/to-trace.rb +64 -70
  16. data/lib/macros4cuke/formatting-service.rb +0 -3
  17. data/lib/macros4cuke/macro-collection.rb +0 -3
  18. data/lib/macros4cuke/macro-step-support.rb +0 -3
  19. data/lib/macros4cuke/macro-step.rb +1 -4
  20. data/lib/macros4cuke/templating/comment.rb +37 -43
  21. data/lib/macros4cuke/templating/engine.rb +4 -14
  22. data/lib/macros4cuke/templating/eo-line.rb +10 -19
  23. data/lib/macros4cuke/templating/placeholder.rb +0 -8
  24. data/lib/macros4cuke/templating/section.rb +0 -11
  25. data/lib/macros4cuke/templating/static-text.rb +28 -33
  26. data/lib/macros4cuke/templating/unary-element.rb +0 -4
  27. data/spec/macros4cuke/application_spec.rb +0 -5
  28. data/spec/macros4cuke/cli/cmd-line_spec.rb +213 -223
  29. data/spec/macros4cuke/coll-walker-factory_spec.rb +0 -6
  30. data/spec/macros4cuke/formatter/to-gherkin_spec.rb +0 -9
  31. data/spec/macros4cuke/formatter/to-null_spec.rb +0 -6
  32. data/spec/macros4cuke/formatter/to-trace_spec.rb +0 -6
  33. data/spec/macros4cuke/formatting-service_spec.rb +0 -5
  34. data/spec/macros4cuke/macro-collection_spec.rb +1 -8
  35. data/spec/macros4cuke/macro-step-support_spec.rb +0 -9
  36. data/spec/macros4cuke/macro-step_spec.rb +0 -7
  37. data/spec/macros4cuke/templating/comment_spec.rb +0 -7
  38. data/spec/macros4cuke/templating/engine_spec.rb +0 -10
  39. data/spec/macros4cuke/templating/eo-line_spec.rb +1 -8
  40. data/spec/macros4cuke/templating/placeholder_spec.rb +0 -9
  41. data/spec/macros4cuke/templating/section_spec.rb +0 -13
  42. data/spec/macros4cuke/templating/static_text_spec.rb +0 -6
  43. data/spec/macros4cuke/use-sample-collection.rb +0 -3
  44. 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
- BuiltinParameters.include?(substep_arg)
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
- # 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(_, _)
34
- return ''
35
- end
36
- end # class
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
- (prev.is_a?(EOLine) || prev.is_a?(Comment))
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 != sections.last.name
320
- msg = "doesn't match current section '#{sections.last.name}'."
321
- fail(StandardError, msg_prefix + msg)
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
- # 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(_, _)
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
- # 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(_, _)
32
- return source
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
- module CLI
14
-
15
- describe CmdLine do
16
- before(:each) do
17
- @current_wkdir = Dir.getwd
18
- Dir.chdir(File.dirname(__FILE__))
19
- end
20
-
21
- after(:each) do
22
- Dir.chdir(@current_wkdir)
23
- end
24
-
25
- def hijack_stdout()
26
- @orig_stdout = $stdout
27
- $stdout = StringIO.new('', 'w')
28
- end
29
-
30
- def restore_stdout()
31
- $stdout = @orig_stdout
32
- end
33
-
34
- def hijack_stderr()
35
- @orig_stderr = $stderr
36
- $stderr = StringIO.new('', 'w')
37
- end
38
-
39
- def restore_stderr()
40
- $stderr = @orig_stderr
41
- end
42
-
43
- def mk_subdir(relativePath)
44
- subdir = File.dirname(__FILE__) + '/' + relativePath
45
- Dir.mkdir(subdir)
46
- end
47
-
48
- context 'Creation and initialization:' do
49
- it 'should be created without argument' do
50
- expect { CmdLine.new }.not_to raise_error
51
- end
52
-
53
- it 'should have an command-line parser' do
54
- expect(subject.parser).to be_kind_of(OptionParser)
55
- end
56
-
57
- end # context
58
-
59
-
60
- context 'Informative options:' do
61
-
62
- it 'should provide short help when command-line is empty' do
63
- hijack_stdout
64
- short_help = <<-END_MESSAGE
65
- For help about the command-line syntax, do:
66
- macros4cuke --help
67
- END_MESSAGE
68
-
69
- # Application is stopped
70
- expect { subject.parse!([]) }.to raise_error(SystemExit)
71
-
72
- # Help text is displayed
73
- expect($stdout.string).to eq(short_help)
74
- restore_stdout
75
- end
76
-
77
- it 'should provide complete help when help requested' do
78
- help_options = [ ['-h'], ['--help'] ]
79
- help_text = subject.parser.help
80
-
81
- help_options.each do |cmd_line|
82
- hijack_stdout
83
- # Application is stopped
84
- expect { subject.parse!(cmd_line) }.to raise_error(SystemExit)
85
-
86
- # Help text is displayed
87
- expect($stdout.string).to eq(help_text)
88
- restore_stdout
89
- end
90
- end
91
-
92
- it 'should provide version when it is requested' do
93
- version_options = [ ['-v'], ['--version'] ]
94
-
95
- version_options.each do |cmd_line|
96
- hijack_stdout
97
- # Application is stopped
98
- expect { subject.parse!(cmd_line) }.to raise_error(SystemExit)
99
-
100
- # platform versions are displayed
101
-
102
- expect($stdout.string).to eq(Macros4Cuke::Version + "\n")
103
- restore_stdout
104
- end
105
- end
106
-
107
- it 'should provide platform data when requested' do
108
- verbose_version_options = [ ['-V'], ['--version-verbose'] ]
109
-
110
- cuke = "Cucumber #{Cucumber::VERSION}"
111
- ruby = "Ruby #{RUBY_VERSION} #{RUBY_PLATFORM}"
112
- full_msg = "#{Macros4Cuke::Version} (using #{cuke}, running on #{ruby})"
113
-
114
- verbose_version_options.each do |cmd_line|
115
- hijack_stdout
116
- # Application is stopped
117
- expect { subject.parse!(cmd_line) }.to raise_error(SystemExit)
118
-
119
- # Version number is displayed
120
- expect($stdout.string).to eq(full_msg + "\n")
121
- restore_stdout
122
- end
123
- end
124
-
125
- end # context
126
-
127
- context 'Error in command-line:' do
128
-
129
- it 'should complain when detecting an unknown option' do
130
- hijack_stderr
131
- err_msg = "invalid option: --unknown\n"
132
-
133
- # Application is stopped
134
- expect { subject.parse!(['--unknown']) }.to raise_error(SystemExit)
135
-
136
- # Error message text is displayed
137
- expect($stderr.string).to eq(err_msg)
138
- restore_stderr
139
- end
140
-
141
- it 'should complain when an option misses an argument' do
142
- hijack_stderr
143
- err_msg = <<-END_MESSAGE
144
- No argument provided with command line option: --setup
145
- END_MESSAGE
146
-
147
- # Application is stopped
148
- expect { subject.parse!(['--setup']) }.to raise_error(SystemExit)
149
-
150
- # Error message text is displayed
151
- expect($stderr.string).to eq(err_msg)
152
- restore_stderr
153
- end
154
-
155
- it "should complain when project to setup doesn't exist" do
156
- hijack_stderr
157
- err_msg = <<-END_MESSAGE
158
- Error in command-line:
159
- Cannot find the directory 'not_a_dir'.
160
- END_MESSAGE
161
-
162
- # Application is stopped
163
- args = %w(--setup not_a_dir)
164
- expect { subject.parse!(args) }.to raise_error(SystemExit)
165
-
166
- # Error message text is displayed
167
- expect($stderr.string).to eq(err_msg)
168
- restore_stderr
169
- end
170
-
171
- it "should complain when features dir does'nt exist" do
172
- mk_subdir('test_dir')
173
-
174
- hijack_stderr
175
- err_msg = <<-END_MESSAGE
176
- Error in command-line:
177
- Cannot find the directory 'test_dir/features'.
178
- END_MESSAGE
179
- args = %w(--setup ./test_dir)
180
-
181
- # Application is stopped
182
- expect { subject.parse!(args) }.to raise_error(SystemExit)
183
-
184
- # Error message text is displayed
185
- expect($stderr.string).to eq(err_msg)
186
- restore_stderr
187
-
188
- mk_subdir('test_dir/features')
189
- hijack_stderr
190
- err_msg = <<-END_MESSAGE
191
- Error in command-line:
192
- Cannot find the directory 'test_dir/features/support'.
193
- END_MESSAGE
194
-
195
- # Application is stopped
196
- expect { subject.parse!(args) }.to raise_error(SystemExit)
197
-
198
- # Error message text is displayed
199
- expect($stderr.string).to eq(err_msg)
200
- restore_stderr
201
- end
202
-
203
- it 'should not complain when all dirs are present' do
204
- mk_subdir('test_dir/features/support')
205
-
206
- expected = { setup: [Pathname.getwd + 'test_dir/features/support'] }
207
- expect(subject.parse!(%w(--setup ./test_dir))).to eq(expected)
208
-
209
- file_path = expected[:setup].first
210
- Dir.rmdir(file_path)
211
- Dir.rmdir(file_path.parent)
212
- Dir.rmdir(file_path.parent.parent)
213
- end
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