gli 2.9.0 → 2.20.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. checksums.yaml +5 -5
  2. data/.circleci/config.yml +28 -0
  3. data/.gitignore +3 -3
  4. data/.tool-versions +1 -0
  5. data/Gemfile +0 -2
  6. data/README.rdoc +29 -18
  7. data/Rakefile +15 -37
  8. data/bin/ci +29 -0
  9. data/bin/gli +24 -54
  10. data/bin/rake +29 -0
  11. data/bin/setup +5 -0
  12. data/exe/gli +68 -0
  13. data/gli.gemspec +20 -24
  14. data/gli.rdoc +9 -9
  15. data/lib/gli/app.rb +42 -8
  16. data/lib/gli/app_support.rb +17 -5
  17. data/lib/gli/argument.rb +20 -0
  18. data/lib/gli/command.rb +27 -2
  19. data/lib/gli/command_finder.rb +42 -25
  20. data/lib/gli/command_support.rb +13 -7
  21. data/lib/gli/commands/doc.rb +9 -3
  22. data/lib/gli/commands/help.rb +2 -1
  23. data/lib/gli/commands/help_modules/arg_name_formatter.rb +29 -2
  24. data/lib/gli/commands/help_modules/command_help_format.rb +19 -1
  25. data/lib/gli/commands/help_modules/full_synopsis_formatter.rb +5 -4
  26. data/lib/gli/commands/help_modules/global_help_format.rb +1 -1
  27. data/lib/gli/commands/help_modules/options_formatter.rb +4 -6
  28. data/lib/gli/commands/initconfig.rb +3 -6
  29. data/lib/gli/commands/rdoc_document_listener.rb +2 -1
  30. data/lib/gli/commands/scaffold.rb +71 -142
  31. data/lib/gli/dsl.rb +25 -1
  32. data/lib/gli/exceptions.rb +26 -0
  33. data/lib/gli/flag.rb +23 -2
  34. data/lib/gli/gli_option_parser.rb +73 -21
  35. data/lib/gli/option_parser_factory.rb +10 -3
  36. data/lib/gli/options.rb +2 -2
  37. data/lib/gli/switch.rb +4 -0
  38. data/lib/gli/terminal.rb +6 -2
  39. data/lib/gli/version.rb +1 -1
  40. data/lib/gli.rb +2 -0
  41. data/object-model.dot +29 -0
  42. data/object-model.png +0 -0
  43. data/test/apps/todo/Gemfile +1 -1
  44. data/test/apps/todo/bin/todo +16 -6
  45. data/test/apps/todo/lib/todo/commands/create.rb +48 -18
  46. data/test/apps/todo/lib/todo/commands/list.rb +48 -35
  47. data/test/apps/todo/lib/todo/commands/ls.rb +25 -24
  48. data/test/apps/todo/lib/todo/commands/make.rb +42 -39
  49. data/test/apps/todo/todo.gemspec +1 -2
  50. data/test/apps/todo_legacy/todo.gemspec +1 -2
  51. data/test/apps/todo_plugins/commands/third.rb +2 -0
  52. data/test/integration/gli_cli_test.rb +69 -0
  53. data/test/integration/gli_powered_app_test.rb +52 -0
  54. data/test/integration/scaffold_test.rb +30 -0
  55. data/test/integration/test_helper.rb +52 -0
  56. data/test/unit/command_finder_test.rb +54 -0
  57. data/test/{tc_command.rb → unit/command_test.rb} +20 -7
  58. data/test/unit/compound_command_test.rb +17 -0
  59. data/test/{tc_doc.rb → unit/doc_test.rb} +38 -51
  60. data/test/{tc_flag.rb → unit/flag_test.rb} +19 -25
  61. data/test/{tc_gli.rb → unit/gli_test.rb} +92 -49
  62. data/test/{tc_help.rb → unit/help_test.rb} +54 -113
  63. data/test/{init_simplecov.rb → unit/init_simplecov.rb} +0 -0
  64. data/test/{tc_options.rb → unit/options_test.rb} +4 -4
  65. data/test/unit/subcommand_parsing_test.rb +263 -0
  66. data/test/unit/subcommands_test.rb +245 -0
  67. data/test/{fake_std_out.rb → unit/support/fake_std_out.rb} +0 -0
  68. data/test/{config.yaml → unit/support/gli_test_config.yml} +1 -0
  69. data/test/unit/switch_test.rb +49 -0
  70. data/test/{tc_terminal.rb → unit/terminal_test.rb} +28 -3
  71. data/test/unit/test_helper.rb +13 -0
  72. data/test/unit/verbatim_wrapper_test.rb +24 -0
  73. metadata +86 -141
  74. data/.ruby-gemset +0 -1
  75. data/.ruby-version +0 -1
  76. data/.travis.yml +0 -12
  77. data/ObjectModel.graffle +0 -1191
  78. data/bin/report_on_rake_results +0 -10
  79. data/bin/test_all_rubies.sh +0 -6
  80. data/features/gli_executable.feature +0 -90
  81. data/features/gli_init.feature +0 -232
  82. data/features/step_definitions/gli_executable_steps.rb +0 -18
  83. data/features/step_definitions/gli_init_steps.rb +0 -11
  84. data/features/step_definitions/todo_steps.rb +0 -96
  85. data/features/support/env.rb +0 -54
  86. data/features/todo.feature +0 -449
  87. data/features/todo_legacy.feature +0 -128
  88. data/test/option_test_helper.rb +0 -13
  89. data/test/tc_compound_command.rb +0 -22
  90. data/test/tc_subcommand_parsing.rb +0 -104
  91. data/test/tc_subcommands.rb +0 -259
  92. data/test/tc_switch.rb +0 -55
  93. data/test/tc_verbatim_wrapper.rb +0 -36
  94. data/test/test_helper.rb +0 -20
@@ -1,18 +1,7 @@
1
- # 1.9 adds realpath to resolve symlinks; 1.8 doesn't
2
- # have this method, so we add it so we get resolved symlinks
3
- # and compatibility
4
- unless File.respond_to? :realpath
5
- class File
6
- def self.realpath path
7
- return realpath(File.readlink(path)) if symlink?(path)
8
- path
9
- end
10
- end
11
- end
1
+ require_relative "test_helper"
2
+ require_relative "support/fake_std_out"
12
3
 
13
- require 'test_helper'
14
-
15
- class TC_testGLI < Clean::Test::TestCase
4
+ class GLITest < MiniTest::Test
16
5
  include TestHelper
17
6
 
18
7
  def setup
@@ -24,7 +13,7 @@ class TC_testGLI < Clean::Test::TestCase
24
13
  $stderr = @fake_stderr
25
14
  @app = CLIApp.new
26
15
 
27
- @config_file = File.expand_path(File.dirname(File.realpath(__FILE__)) + '/new_config.yaml')
16
+ @config_file = File.expand_path(File.dirname(File.realpath(__FILE__)) + '/support/new_config.yml')
28
17
  @gli_debug = ENV['GLI_DEBUG']
29
18
  @app.error_device=@fake_stderr
30
19
  ENV.delete('GLI_DEBUG')
@@ -84,6 +73,7 @@ class TC_testGLI < Clean::Test::TestCase
84
73
  assert_equal 64, @app.run(['foo']), "Expected exit status to be 64"
85
74
  assert @fake_stderr.contained?(/flag is required/), @fake_stderr.strings.inspect
86
75
  assert @fake_stderr.contained?(/other_flag is required/), @fake_stderr.strings.inspect
76
+ assert @fake_stderr.contained?(/flag is required, other_flag is required/), @fake_stderr.strings.inspect
87
77
  assert !@called
88
78
 
89
79
  assert_equal 0, @app.run(['foo','--flag=bar','--other_flag=blah']), "Expected exit status to be 0 #{@fake_stderr.strings.join(',')}"
@@ -104,6 +94,7 @@ class TC_testGLI < Clean::Test::TestCase
104
94
  assert_equal 64, @app.run(['foo']), "Expected exit status to be 64"
105
95
  assert @fake_stderr.contained?(/flag is required/), @fake_stderr.strings.inspect
106
96
  assert @fake_stderr.contained?(/other_flag is required/), @fake_stderr.strings.inspect
97
+ assert @fake_stderr.contained?(/flag is required, other_flag is required/), @fake_stderr.strings.inspect
107
98
  assert !@called
108
99
 
109
100
  assert_equal 0, @app.run(['--flag=bar','--other_flag=blah','foo']), "Expected exit status to be 0 #{@fake_stderr.strings.join(',')}"
@@ -139,10 +130,12 @@ class TC_testGLI < Clean::Test::TestCase
139
130
  def test_init_from_config
140
131
  failure = nil
141
132
  @app.reset
142
- @app.config_file(File.expand_path(File.dirname(File.realpath(__FILE__)) + '/config.yaml'))
133
+ @app.config_file(File.expand_path(File.dirname(File.realpath(__FILE__)) + '/support/gli_test_config.yml'))
143
134
  @app.flag :f
144
135
  @app.switch :s
145
136
  @app.flag :g
137
+ @app.default_value true
138
+ @app.switch :t
146
139
  called = false
147
140
  @app.command :command do |c|
148
141
  c.flag :f
@@ -157,6 +150,7 @@ class TC_testGLI < Clean::Test::TestCase
157
150
  assert !o[:f]
158
151
  assert !g[:s]
159
152
  assert o[:s]
153
+ assert !g[:t]
160
154
  rescue Exception => ex
161
155
  failure = ex
162
156
  end
@@ -170,7 +164,7 @@ class TC_testGLI < Clean::Test::TestCase
170
164
  def test_command_line_overrides_config
171
165
  failure = nil
172
166
  @app.reset
173
- @app.config_file(File.expand_path(File.dirname(File.realpath(__FILE__)) + '/config.yaml'))
167
+ @app.config_file(File.expand_path(File.dirname(File.realpath(__FILE__)) + '/support/gli_test_config.yml'))
174
168
  @app.flag :f
175
169
  @app.switch :s
176
170
  @app.flag :g
@@ -202,7 +196,7 @@ class TC_testGLI < Clean::Test::TestCase
202
196
  end
203
197
 
204
198
  def test_no_overwrite_config
205
- config_file = File.expand_path(File.dirname(File.realpath(__FILE__)) + '/config.yaml')
199
+ config_file = File.expand_path(File.dirname(File.realpath(__FILE__)) + '/support/gli_test_config.yml')
206
200
  config_file_contents = File.read(config_file)
207
201
  @app.reset
208
202
  @app.config_file(config_file)
@@ -227,9 +221,9 @@ class TC_testGLI < Clean::Test::TestCase
227
221
  @app.reset
228
222
  @app.config_file(@config_file)
229
223
  @app.flag :f
230
- @app.switch :s
224
+ @app.switch :s, :salias
231
225
  @app.switch :w
232
- @app.flag :bigflag
226
+ @app.flag :bigflag, :bigalias
233
227
  @app.flag :biggestflag
234
228
  @app.command :foo do |c|
235
229
  end
@@ -247,7 +241,9 @@ class TC_testGLI < Clean::Test::TestCase
247
241
 
248
242
  assert_equal 'foo',written_config[:f]
249
243
  assert_equal 'bleorgh',written_config[:bigflag]
244
+ assert !written_config[:bigalias]
250
245
  assert written_config[:s]
246
+ assert !written_config[:salias]
251
247
  assert !written_config[:w]
252
248
  assert_nil written_config[:biggestflag]
253
249
  assert written_config[GLI::InitConfig::COMMANDS_KEY]
@@ -513,7 +509,7 @@ class TC_testGLI < Clean::Test::TestCase
513
509
  end
514
510
  @switch_value = nil
515
511
 
516
- assert_raises(RuntimeError) do
512
+ assert_raises(RuntimeError) do
517
513
  @app.command [:foo] do |c|
518
514
  c.switch :switch, :default_value => true, :negatable => false
519
515
  end
@@ -663,6 +659,23 @@ class TC_testGLI < Clean::Test::TestCase
663
659
  assert_raises(GLI::CustomExit) { @app.run(['foo']) }
664
660
  end
665
661
 
662
+ def test_gli_help_does_not_raise_on_debug
663
+ ENV['GLI_DEBUG'] = 'true'
664
+
665
+ @app.reset
666
+ @app.command(:multiply) do |c|
667
+ c.action do |g,o,a|
668
+ # Nothing
669
+ end
670
+ end
671
+
672
+ begin
673
+ @app.run(['multiply', '--help'])
674
+ rescue GLI::CustomExit
675
+ assert false, "Expected no exception"
676
+ end
677
+ end
678
+
666
679
  class ConvertMe
667
680
  attr_reader :value
668
681
  def initialize(value)
@@ -697,6 +710,48 @@ class TC_testGLI < Clean::Test::TestCase
697
710
  assert_equal 'crud',@baz.value
698
711
  end
699
712
 
713
+ def test_that_flags_can_be_used_multiple_times
714
+ @app.reset
715
+ @app.flag :flag, :multiple => true
716
+ @app.command :foo do |c|
717
+ c.action do |options, _, _|
718
+ @flag = options[:flag]
719
+ end
720
+ end
721
+
722
+ assert_equal 0,@app.run(%w(--flag 1 --flag=2 --flag 3 foo)),@fake_stderr.to_s
723
+
724
+ assert_equal ['1','2','3'],@flag
725
+ end
726
+
727
+ def test_that_multiple_use_flags_are_empty_arrays_by_default
728
+ @app.reset
729
+ @app.flag :flag, :multiple => true
730
+ @app.command :foo do |c|
731
+ c.action do |options, _, _|
732
+ @flag = options[:flag]
733
+ end
734
+ end
735
+
736
+ assert_equal 0,@app.run(['foo']),@fake_stderr.to_s
737
+
738
+ assert_equal [],@flag
739
+ end
740
+
741
+ def test_that_multiple_use_flags_can_take_other_defaults
742
+ @app.reset
743
+ @app.flag :flag, :multiple => true, :default_value => ['1']
744
+ @app.command :foo do |c|
745
+ c.action do |options, _, _|
746
+ @flag = options[:flag]
747
+ end
748
+ end
749
+
750
+ assert_equal 0,@app.run(['foo']),@fake_stderr.to_s
751
+
752
+ assert_equal ['1'],@flag
753
+ end
754
+
700
755
  def test_that_we_mutate_ARGV_by_default
701
756
  @app.reset
702
757
  @app.flag :f
@@ -748,38 +803,26 @@ class TC_testGLI < Clean::Test::TestCase
748
803
  do_test_switch_create_compact(object)
749
804
  end
750
805
 
751
- def some_descriptions
752
- lambda {
753
- @description = 'this is a description'
754
- @long_description = 'this is a very long description'
755
- }
756
- end
757
-
758
- def assert_switch_was_made(object,switch)
759
- lambda {
760
- assert object.switches[switch]
761
- assert_equal @description,object.switches[switch].description,"For switch #{switch}"
762
- assert_equal @long_description,object.switches[switch].long_description,"For switch #{switch}"
763
- assert(object.usage != nil) if object.respond_to? :usage
764
- }
765
- end
766
-
767
806
  def do_test_switch_create_classic(object)
768
- Given some_descriptions
769
- When {
770
- object.desc @description
771
- object.long_desc @long_description
772
- object.switch :f
773
- }
774
- Then assert_switch_was_made(object,:f)
807
+ @description = 'this is a description'
808
+ @long_description = 'this is a very long description'
809
+ object.desc @description
810
+ object.long_desc @long_description
811
+ object.switch :f
812
+ assert object.switches[:f]
813
+ assert_equal @description,object.switches[:f].description,"For switch #{:f}"
814
+ assert_equal @long_description,object.switches[:f].long_description,"For switch #{:f}"
815
+ assert(object.usage != nil) if object.respond_to? :usage
775
816
  end
776
817
 
777
818
  def do_test_switch_create_compact(object)
778
- Given some_descriptions
779
- When {
780
- object.switch :g, :desc => @description, :long_desc => @long_description
781
- }
782
- Then assert_switch_was_made(object,:g)
819
+ @description = 'this is a description'
820
+ @long_description = 'this is a very long description'
821
+ object.switch :g, :desc => @description, :long_desc => @long_description
822
+ assert object.switches[:g]
823
+ assert_equal @description,object.switches[:g].description,"For switch #{:g}"
824
+ assert_equal @long_description,object.switches[:g].long_description,"For switch #{:g}"
825
+ assert(object.usage != nil) if object.respond_to? :usage
783
826
  end
784
827
 
785
828
  def do_test_switch_create_twice(object)
@@ -1,6 +1,6 @@
1
- require 'test_helper'
1
+ require_relative "test_helper"
2
2
 
3
- class TC_testHelp < Clean::Test::TestCase
3
+ class HelpTest < MiniTest::Test
4
4
  include TestHelper
5
5
 
6
6
  def setup
@@ -24,86 +24,61 @@ class TC_testHelp < Clean::Test::TestCase
24
24
  include GLI::App
25
25
  end
26
26
 
27
- test_that "the help command is configured properly when created" do
28
- Given {
29
- app = TestApp.new
30
- app.subcommand_option_handling :normal
31
- @command = GLI::Commands::Help.new(app,@output,@error)
32
- }
33
- Then {
34
- assert_equal 'help',@command.name.to_s
35
- assert_nil @command.aliases
36
- assert_equal 'command',@command.arguments_description
37
- assert_not_nil @command.description
38
- assert_not_nil @command.long_description
39
- assert @command.skips_pre
40
- assert @command.skips_post
41
- assert @command.skips_around
42
- }
27
+ def test_help_command_configured_properly_when_created
28
+ app = TestApp.new
29
+ app.subcommand_option_handling :normal
30
+ @command = GLI::Commands::Help.new(app,@output,@error)
31
+ assert_equal 'help',@command.name.to_s
32
+ assert_nil @command.aliases
33
+ assert_equal 'command',@command.arguments_description
34
+ refute_nil @command.description
35
+ refute_nil @command.long_description
36
+ assert @command.skips_pre
37
+ assert @command.skips_post
38
+ assert @command.skips_around
43
39
  end
44
40
 
45
- test_that "the help command can be configured to skip things declaratively" do
46
- Given {
41
+ def test_the_help_command_can_be_configured_to_skip_things_declaratively
47
42
  app = TestApp.new
48
43
  app.subcommand_option_handling :normal
49
44
  @command = GLI::Commands::Help.new(app,@output,@error)
50
45
  GLI::Commands::Help.skips_pre = false
51
46
  GLI::Commands::Help.skips_post = false
52
47
  GLI::Commands::Help.skips_around = false
53
- }
54
- Then {
55
48
  assert !@command.skips_pre
56
49
  assert !@command.skips_post
57
50
  assert !@command.skips_around
58
- }
59
51
  end
60
52
 
61
- test_that "the help command can be configured to skip things declaratively regardless of when it the object was created" do
62
- Given {
53
+ def test_the_help_command_can_be_configured_to_skip_things_declaratively_regardless_of_when_the_object_was_created
63
54
  GLI::Commands::Help.skips_pre = false
64
55
  GLI::Commands::Help.skips_post = false
65
56
  GLI::Commands::Help.skips_around = false
66
57
  app = TestApp.new
67
58
  app.subcommand_option_handling :normal
68
59
  @command = GLI::Commands::Help.new(app,@output,@error)
69
- }
70
- Then {
71
60
  assert !@command.skips_pre
72
61
  assert !@command.skips_post
73
62
  assert !@command.skips_around
74
- }
75
63
  end
76
64
 
77
- test_that "invoking help with no arguments results in listing all commands and global options" do
78
- Given a_GLI_app
79
- And {
65
+ def test_invoking_help_with_no_arguments_results_in_listing_all_commands_and_global_options
66
+ setup_GLI_app
80
67
  @command = GLI::Commands::Help.new(@app,@output,@error)
81
- }
82
- When {
83
68
  @command.execute({},{},[])
84
- }
85
- Then {
86
69
  assert_top_level_help_output
87
- }
88
70
  end
89
71
 
90
- test_that "invoking help with a command that doesn't exist shows an error" do
91
- Given a_GLI_app
92
- And {
72
+ def test_invoking_help_with_a_command_that_doesnt_exist_shows_an_error
73
+ setup_GLI_app
93
74
  @command = GLI::Commands::Help.new(@app,@output,@error)
94
75
  @unknown_command_name = any_command_name
95
- }
96
- When {
97
76
  @command.execute({},{},[@unknown_command_name])
98
- }
99
- Then {
100
77
  assert_error_contained(/error: Unknown command '#{@unknown_command_name}'./)
101
- }
102
78
  end
103
79
 
104
- test_that "invoking help with a known command shows help for that command" do
105
- Given a_GLI_app
106
- And {
80
+ def test_invoking_help_with_a_known_command_shows_help_for_that_command
81
+ setup_GLI_app
107
82
  @command_name = cm = any_command_name
108
83
  @desc = d = any_desc
109
84
  @long_desc = ld = any_desc
@@ -127,11 +102,7 @@ class TC_testHelp < Clean::Test::TestCase
127
102
  end
128
103
  end
129
104
  @command = GLI::Commands::Help.new(@app,@output,@error)
130
- }
131
- When {
132
105
  @command.execute({},{},[@command_name])
133
- }
134
- Then {
135
106
  assert_output_contained(@command_name,"Name of the command")
136
107
  assert_output_contained(@desc,"Short description")
137
108
  assert_output_contained(@long_desc,"Long description")
@@ -139,27 +110,19 @@ class TC_testHelp < Clean::Test::TestCase
139
110
  assert_output_contained(@switch_desc,"switch description")
140
111
  assert_output_contained("-" + @flag,"command flag")
141
112
  assert_output_contained(@flag_desc,"flag description")
142
- }
143
113
  end
144
114
 
145
- test_that 'invoking help for an app with no global options omits [global options] from the usage string' do
146
- Given a_GLI_app(:no_options)
147
- And {
115
+ def test_invoking_help_with_no_global_options_omits_the_global_options_placeholder_from_usage
116
+ setup_GLI_app(:no_options)
148
117
  @command = GLI::Commands::Help.new(@app,@output,@error)
149
- }
150
- When {
151
118
  @command.execute({},{},[])
152
- }
153
- Then {
154
119
  refute_output_contained(/\[global options\] command \[command options\] \[arguments\.\.\.\]/)
155
120
  refute_output_contained('GLOBAL OPTIONS')
156
121
  assert_output_contained(/command \[command options\] \[arguments\.\.\.\]/)
157
- }
158
122
  end
159
123
 
160
- test_that "invoking help with a known command when no global options are present omits [global options] from the usage string" do
161
- Given a_GLI_app(:no_options)
162
- And {
124
+ def test_invoking_help_with_a_known_command_when_no_global_options_are_present_omits_placeholder_from_the_usage_string
125
+ setup_GLI_app(:no_options)
163
126
  @command_name = cm = any_command_name
164
127
  @desc = d = any_desc
165
128
  @long_desc = ld = any_desc
@@ -183,20 +146,14 @@ class TC_testHelp < Clean::Test::TestCase
183
146
  end
184
147
  end
185
148
  @command = GLI::Commands::Help.new(@app,@output,@error)
186
- }
187
- When {
188
149
  @command.execute({},{},[@command_name])
189
- }
190
- Then {
191
150
  refute_output_contained(/\[global options\]/)
192
151
  assert_output_contained(/\[command options\]/)
193
152
  assert_output_contained('COMMAND OPTIONS')
194
- }
195
153
  end
196
154
 
197
- test_that "invoking help with a known command when no global options nor command options are present omits [global options] and [command options] from the usage string" do
198
- Given a_GLI_app(:no_options)
199
- And {
155
+ def test_omits_both_placeholders_when_no_options_present
156
+ setup_GLI_app(:no_options)
200
157
  @command_name = cm = any_command_name
201
158
  @desc = d = any_desc
202
159
  @long_desc = ld = any_desc
@@ -209,20 +166,14 @@ class TC_testHelp < Clean::Test::TestCase
209
166
  end
210
167
  end
211
168
  @command = GLI::Commands::Help.new(@app,@output,@error)
212
- }
213
- When {
214
169
  @command.execute({},{},[@command_name])
215
- }
216
- Then {
217
170
  refute_output_contained(/\[global options\]/)
218
171
  refute_output_contained(/\[command options\]/)
219
172
  refute_output_contained('COMMAND OPTIONS')
220
- }
221
173
  end
222
174
 
223
- test_that "invoking help with a known command that has no command options omits [command options] from the usage string" do
224
- Given a_GLI_app
225
- And {
175
+ def test_no_command_options_omits_command_options_placeholder
176
+ setup_GLI_app
226
177
  @command_name = cm = any_command_name
227
178
  @desc = d = any_desc
228
179
  @long_desc = ld = any_desc
@@ -235,19 +186,13 @@ class TC_testHelp < Clean::Test::TestCase
235
186
  end
236
187
  end
237
188
  @command = GLI::Commands::Help.new(@app,@output,@error)
238
- }
239
- When {
240
189
  @command.execute({},{},[@command_name])
241
- }
242
- Then {
243
190
  assert_output_contained(/\[global options\]/)
244
191
  refute_output_contained(/\[command options\]/)
245
192
  refute_output_contained('COMMAND OPTIONS')
246
- }
247
193
  end
248
194
 
249
- test_that "omitting default_description doesn't blow up" do
250
- Given {
195
+ def test_omitting_default_description_doesnt_blow_up
251
196
  app = TestApp.new
252
197
  app.instance_eval do
253
198
  subcommand_option_handling :normal
@@ -266,23 +211,20 @@ class TC_testHelp < Clean::Test::TestCase
266
211
  end
267
212
  end
268
213
  @command = GLI::Commands::Help.new(app,@output,@error)
269
- }
270
- When {
271
- @code = lambda { @command.execute({},{},['top']) }
272
- }
273
- Then {
274
- assert_nothing_raised(&@code)
275
- }
214
+ begin
215
+ @command.execute({},{},['top'])
216
+ rescue => ex
217
+ assert false, "Expected no exception, got: #{ex.message}"
218
+ end
276
219
  end
277
220
 
278
221
  private
279
222
 
280
- def a_GLI_app(omit_options=false)
281
- lambda {
223
+ def setup_GLI_app(omit_options=false)
282
224
  @program_description = program_description = any_desc
283
225
  @flags = flags = [
284
- [any_desc.strip,any_arg_name,[any_option]],
285
- [any_desc.strip,any_arg_name,[any_option,any_long_option]],
226
+ [any_desc.strip,:foo,[any_option]],
227
+ [any_desc.strip,:bar,[any_option,any_long_option]],
286
228
  ]
287
229
  @switches = switches = [
288
230
  [any_desc.strip,[any_option]],
@@ -302,24 +244,23 @@ private
302
244
  unless omit_options
303
245
  flags.each do |(description,arg,flag_names)|
304
246
  desc description
305
- arg_name arg
306
- flag flag_names
247
+ arg_name arg
248
+ flag flag_names
307
249
  end
308
250
 
309
251
  switches.each do |(description,switch_names)|
310
252
  desc description
311
- switch switch_names
253
+ switch switch_names
312
254
  end
313
255
  end
314
256
 
315
257
  commands.each do |(description,command_names)|
316
258
  desc description
317
- command command_names do |c|
318
- c.action {}
259
+ command command_names do |c|
260
+ c.action {}
319
261
  end
320
262
  end
321
263
  end
322
- }
323
264
  end
324
265
 
325
266
  def assert_top_level_help_output
@@ -357,29 +298,29 @@ private
357
298
 
358
299
  def refute_output_contained(string_or_regexp,desc='')
359
300
  string_or_regexp = /#{string_or_regexp}/ if string_or_regexp.kind_of?(String)
360
- assert_no_match string_or_regexp,@output.string,desc
301
+ refute_match string_or_regexp,@output.string,desc
361
302
  end
362
303
 
363
304
  def any_option
364
305
  ('a'..'z').to_a[@option_index].tap { @option_index += 1 }
365
306
  end
366
-
367
- def any_long_option
368
- Faker::Lorem.words(10)[rand(10)]
369
- end
370
307
 
371
- def any_arg_name
372
- any_string :max => 20
308
+ def any_long_option
309
+ ["foo","bar","blah"].sample
373
310
  end
374
311
 
375
312
  def any_desc
376
- Faker::Lorem.words(10).join(' ')[0..30].gsub(/\s*$/,'')
313
+ [
314
+ "This command does some stuff",
315
+ "Do things and whatnot",
316
+ "Behold the power of this command"
317
+ ].sample
377
318
  end
378
319
 
379
320
  def any_command_name
380
- command_name = Faker::Lorem.words(10)[rand(10)]
321
+ command_name = ["new","edit","delete","create","update"].sample
381
322
  while @command_names_used.include?(command_name)
382
- command_name = Faker::Lorem.words(10)[rand(10)]
323
+ command_name = ["new","edit","delete","create","update"].sample
383
324
  end
384
325
  @command_names_used << command_name
385
326
  command_name
File without changes
@@ -1,6 +1,6 @@
1
- require 'test_helper'
1
+ require_relative "test_helper"
2
2
 
3
- class TC_testOptions < Clean::Test::TestCase
3
+ class OptiosnTest < MiniTest::Test
4
4
  include TestHelper
5
5
 
6
6
  def test_by_method
@@ -10,7 +10,7 @@ class TC_testOptions < Clean::Test::TestCase
10
10
  assert_equal 'verbose', o[:name]
11
11
  assert_equal 'verbose', o['name']
12
12
  end
13
-
13
+
14
14
  def test_by_string
15
15
  o = GLI::Options.new
16
16
  o['name'] = 'verbose'
@@ -18,7 +18,7 @@ class TC_testOptions < Clean::Test::TestCase
18
18
  assert_equal 'verbose', o[:name]
19
19
  assert_equal 'verbose', o['name']
20
20
  end
21
-
21
+
22
22
  def test_by_symbol
23
23
  o = GLI::Options.new
24
24
  o[:name] = 'verbose'