hammer_cli 3.6.0 → 3.8.0

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 (91) hide show
  1. checksums.yaml +4 -4
  2. data/bin/hammer +1 -6
  3. data/config/cli_config.template.yml +3 -3
  4. data/doc/release_notes.md +24 -0
  5. data/lib/hammer_cli/abstract.rb +1 -1
  6. data/lib/hammer_cli/defaults_commands.rb +0 -1
  7. data/lib/hammer_cli/help/builder.rb +7 -8
  8. data/lib/hammer_cli/i18n/find_task.rb +88 -0
  9. data/lib/hammer_cli/i18n.rb +4 -0
  10. data/lib/hammer_cli/logger.rb +2 -2
  11. data/lib/hammer_cli/modules.rb +1 -1
  12. data/lib/hammer_cli/options/normalizers.rb +4 -7
  13. data/lib/hammer_cli/options/validators/dsl.rb +1 -1
  14. data/lib/hammer_cli/output/adapter/csv.rb +0 -1
  15. data/lib/hammer_cli/output/dsl.rb +1 -1
  16. data/lib/hammer_cli/output/fields.rb +1 -1
  17. data/lib/hammer_cli/output/formatters.rb +4 -4
  18. data/lib/hammer_cli/settings.rb +7 -0
  19. data/lib/hammer_cli/ssloptions.rb +3 -3
  20. data/lib/hammer_cli/subcommand.rb +1 -0
  21. data/lib/hammer_cli/task_helper.rb +84 -0
  22. data/lib/hammer_cli/testing/output_matchers.rb +1 -1
  23. data/lib/hammer_cli/utils.rb +1 -13
  24. data/lib/hammer_cli/version.rb +1 -1
  25. data/locale/Makefile.def +29 -7
  26. data/locale/ca/LC_MESSAGES/hammer-cli.mo +0 -0
  27. data/locale/cs_CZ/LC_MESSAGES/hammer-cli.mo +0 -0
  28. data/locale/de/LC_MESSAGES/hammer-cli.mo +0 -0
  29. data/locale/en/LC_MESSAGES/hammer-cli.mo +0 -0
  30. data/locale/en_GB/LC_MESSAGES/hammer-cli.mo +0 -0
  31. data/locale/es/LC_MESSAGES/hammer-cli.mo +0 -0
  32. data/locale/fr/LC_MESSAGES/hammer-cli.mo +0 -0
  33. data/locale/it/LC_MESSAGES/hammer-cli.mo +0 -0
  34. data/locale/ja/LC_MESSAGES/hammer-cli.mo +0 -0
  35. data/locale/ka/LC_MESSAGES/hammer-cli.mo +0 -0
  36. data/locale/ko/LC_MESSAGES/hammer-cli.mo +0 -0
  37. data/locale/pt_BR/LC_MESSAGES/hammer-cli.mo +0 -0
  38. data/locale/ru/LC_MESSAGES/hammer-cli.mo +0 -0
  39. data/locale/zh_CN/LC_MESSAGES/hammer-cli.mo +0 -0
  40. data/locale/zh_TW/LC_MESSAGES/hammer-cli.mo +0 -0
  41. data/man/hammer.1.gz +0 -0
  42. data/test/functional/defaults_test.rb +0 -1
  43. data/test/functional/help_test.rb +1 -1
  44. data/test/test_helper.rb +1 -1
  45. data/test/unit/abstract_test.rb +54 -54
  46. data/test/unit/apipie/command_test.rb +27 -28
  47. data/test/unit/apipie/option_builder_test.rb +28 -28
  48. data/test/unit/apipie/option_definition_test.rb +6 -6
  49. data/test/unit/apipie/test_helper.rb +3 -0
  50. data/test/unit/bash_test.rb +21 -21
  51. data/test/unit/command_extensions_test.rb +68 -68
  52. data/test/unit/completer_test.rb +57 -57
  53. data/test/unit/csv_parser_test.rb +12 -12
  54. data/test/unit/defaults_test.rb +3 -3
  55. data/test/unit/exception_handler_test.rb +3 -3
  56. data/test/unit/help/builder_test.rb +7 -7
  57. data/test/unit/help/definition/abstract_item_test.rb +2 -2
  58. data/test/unit/help/definition/list_test.rb +2 -2
  59. data/test/unit/help/definition/note_test.rb +2 -2
  60. data/test/unit/help/definition/section_test.rb +2 -2
  61. data/test/unit/help/definition/text_test.rb +2 -2
  62. data/test/unit/help/definition_test.rb +36 -36
  63. data/test/unit/help/text_builder_test.rb +39 -39
  64. data/test/unit/history_test.rb +8 -8
  65. data/test/unit/i18n_test.rb +2 -2
  66. data/test/unit/logger_test.rb +3 -3
  67. data/test/unit/main_test.rb +7 -7
  68. data/test/unit/modules_test.rb +24 -25
  69. data/test/unit/option_builder_test.rb +1 -1
  70. data/test/unit/options/matcher_test.rb +15 -15
  71. data/test/unit/options/normalizers_test.rb +92 -88
  72. data/test/unit/options/option_definition_test.rb +13 -13
  73. data/test/unit/options/option_family_test.rb +7 -7
  74. data/test/unit/options/sources/saved_defaults_test.rb +0 -4
  75. data/test/unit/options/validators/dsl_test.rb +35 -35
  76. data/test/unit/output/adapter/abstract_test.rb +13 -13
  77. data/test/unit/output/adapter/base_test.rb +36 -36
  78. data/test/unit/output/adapter/csv_test.rb +44 -44
  79. data/test/unit/output/adapter/json_test.rb +38 -38
  80. data/test/unit/output/adapter/table_test.rb +47 -55
  81. data/test/unit/output/adapter/yaml_test.rb +38 -38
  82. data/test/unit/output/definition_test.rb +43 -43
  83. data/test/unit/output/dsl_test.rb +19 -19
  84. data/test/unit/output/field_filter_test.rb +10 -10
  85. data/test/unit/output/fields_test.rb +27 -27
  86. data/test/unit/output/formatters_test.rb +39 -39
  87. data/test/unit/output/output_test.rb +14 -14
  88. data/test/unit/output/record_collection_test.rb +18 -18
  89. data/test/unit/settings_test.rb +35 -35
  90. data/test/unit/utils_test.rb +30 -27
  91. metadata +10 -21
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
data/man/hammer.1.gz CHANGED
Binary file
@@ -24,7 +24,6 @@ describe 'commands' do
24
24
  let(:cmd) { ['defaults', 'list'] }
25
25
 
26
26
  it 'prints all defaults' do
27
- header = 'Parameter,Value'
28
27
  default_values = {
29
28
  :organization_id => {
30
29
  :value => 3,
@@ -45,7 +45,7 @@ describe 'help' do
45
45
 
46
46
  it 'prints additional help' do
47
47
  result = run_cmd(['-h'], {}, CmdWithHelp)
48
- result.out.must_equal [
48
+ _(result.out).must_equal [
49
49
  'Usage:',
50
50
  ' hammer [OPTIONS]',
51
51
  '',
data/test/test_helper.rb CHANGED
@@ -9,7 +9,7 @@ end
9
9
  SimpleCov.root Pathname.new(File.dirname(__FILE__) + "../../../")
10
10
 
11
11
  require 'minitest/autorun'
12
- require 'minitest/spec'
12
+ require 'minitest/unit'
13
13
  require "minitest-spec-context"
14
14
  require "mocha/minitest"
15
15
 
@@ -8,15 +8,15 @@ describe HammerCLI::AbstractCommand do
8
8
  let(:cmd_class) { Class.new(HammerCLI::AbstractCommand) }
9
9
  let(:cmd) { cmd_class.new("", { :adapter => :silent }) }
10
10
  it "should define adapter" do
11
- cmd.adapter.must_equal :base
11
+ _(cmd.adapter).must_equal :base
12
12
  end
13
13
 
14
14
  it "should provide instance of output with default adapter set" do
15
- cmd.output.default_adapter.must_equal cmd.adapter
15
+ _(cmd.output.default_adapter).must_equal cmd.adapter
16
16
  end
17
17
 
18
18
  it "should hold instance of output definition" do
19
- cmd.output_definition.must_be_instance_of HammerCLI::Output::Definition
19
+ _(cmd.output_definition).must_be_instance_of HammerCLI::Output::Definition
20
20
  end
21
21
 
22
22
  it "can append existing definition" do
@@ -26,7 +26,7 @@ describe HammerCLI::AbstractCommand do
26
26
 
27
27
  cmd_class.output(definition) do
28
28
  end
29
- cmd_class.output_definition.fields.length.must_equal definition.fields.length
29
+ _(cmd_class.output_definition.fields.length).must_equal definition.fields.length
30
30
  end
31
31
 
32
32
  it "can append existing definition without passing a block" do
@@ -35,7 +35,7 @@ describe HammerCLI::AbstractCommand do
35
35
  definition.fields << Fields::Field.new
36
36
 
37
37
  cmd_class.output(definition)
38
- cmd_class.output_definition.fields.length.must_equal definition.fields.length
38
+ _(cmd_class.output_definition.fields.length).must_equal definition.fields.length
39
39
  end
40
40
 
41
41
  it "can define fields" do
@@ -43,7 +43,7 @@ describe HammerCLI::AbstractCommand do
43
43
  field :test_1, "test 1"
44
44
  field :test_2, "test 2"
45
45
  end
46
- cmd_class.output_definition.fields.length.must_equal 2
46
+ _(cmd_class.output_definition.fields.length).must_equal 2
47
47
  end
48
48
  end
49
49
 
@@ -66,19 +66,19 @@ describe HammerCLI::AbstractCommand do
66
66
 
67
67
  it "should return instance of hammer cli exception handler by default" do
68
68
  cmd = ModA::ModB::TestCmd.new ""
69
- cmd.exception_handler.must_be_instance_of HammerCLI::ExceptionHandler
69
+ _(cmd.exception_handler).must_be_instance_of HammerCLI::ExceptionHandler
70
70
  end
71
71
 
72
72
  it "should return instance of exception handler class defined in a module" do
73
73
  ModA::ModB.expects(:exception_handler_class).returns(Handler)
74
74
  cmd = ModA::ModB::TestCmd.new ""
75
- cmd.exception_handler.must_be_instance_of Handler
75
+ _(cmd.exception_handler).must_be_instance_of Handler
76
76
  end
77
77
 
78
78
  it "should return instance of exception handler class defined deeper in a module hierrarchy" do
79
79
  ModA.expects(:exception_handler_class).returns(Handler)
80
80
  cmd = ModA::ModB::TestCmd.new ""
81
- cmd.exception_handler.must_be_instance_of Handler
81
+ _(cmd.exception_handler).must_be_instance_of Handler
82
82
  end
83
83
  end
84
84
 
@@ -94,7 +94,7 @@ describe HammerCLI::AbstractCommand do
94
94
  it "should log what has been executed" do
95
95
  test_command = Class.new(HammerCLI::AbstractCommand).new("")
96
96
  test_command.run []
97
- @log_output.readline.strip.must_equal "INFO HammerCLI::AbstractCommand : Called with options: {}"
97
+ _(@log_output.readline.strip).must_equal "INFO HammerCLI::AbstractCommand : Called with options: {}"
98
98
  end
99
99
 
100
100
 
@@ -108,7 +108,7 @@ describe HammerCLI::AbstractCommand do
108
108
  it "should have logger named by the class by default" do
109
109
  test_command = Class.new(TestLogCmd).new("")
110
110
  test_command.run []
111
- @log_output.read.must_include "ERROR TestLogCmd : Test"
111
+ _(@log_output.read).must_include "ERROR TestLogCmd : Test"
112
112
  end
113
113
 
114
114
  class TestLogCmd2 < HammerCLI::AbstractCommand
@@ -121,7 +121,7 @@ describe HammerCLI::AbstractCommand do
121
121
  it "should have logger that accepts custom name" do
122
122
  test_command = Class.new(TestLogCmd2).new("")
123
123
  test_command.run []
124
- @log_output.read.must_include "ERROR My logger : Test"
124
+ _(@log_output.read).must_include "ERROR My logger : Test"
125
125
  end
126
126
 
127
127
  class TestLogCmd3 < HammerCLI::AbstractCommand
@@ -134,7 +134,7 @@ describe HammerCLI::AbstractCommand do
134
134
  it "should have logger that can inspect object" do
135
135
  test_command = Class.new(TestLogCmd3).new("")
136
136
  test_command.run []
137
- @log_output.read.must_include "DEBUG TestLogCmd3 : Test\n{}"
137
+ _(@log_output.read).must_include "DEBUG TestLogCmd3 : Test\n{}"
138
138
  end
139
139
 
140
140
  class TestLogCmd4 < HammerCLI::AbstractCommand
@@ -147,7 +147,7 @@ describe HammerCLI::AbstractCommand do
147
147
  it "should have logger.watch output without colors" do
148
148
  test_command = Class.new(TestLogCmd4).new("")
149
149
  test_command.run []
150
- @log_output.read.must_include "DEBUG TestLogCmd4 : Test\n{\n :a => \"a\"\n}"
150
+ _(@log_output.read).must_include "DEBUG TestLogCmd4 : Test\n{\n :a => \"a\"\n}"
151
151
  end
152
152
 
153
153
  class TestLogCmd5 < HammerCLI::AbstractCommand
@@ -162,7 +162,7 @@ describe HammerCLI::AbstractCommand do
162
162
  HammerCLI::Settings.clear
163
163
  HammerCLI::Settings.load(:watch_plain => true)
164
164
  test_command.run []
165
- @log_output.read.must_include "DEBUG TestLogCmd5 : Test\n{\n :a => \"a\"\n}"
165
+ _(@log_output.read).must_include "DEBUG TestLogCmd5 : Test\n{\n :a => \"a\"\n}"
166
166
  end
167
167
 
168
168
  class TestLogCmd6 < HammerCLI::AbstractCommand
@@ -177,7 +177,7 @@ describe HammerCLI::AbstractCommand do
177
177
  HammerCLI::Settings.clear
178
178
  HammerCLI::Settings.load(:watch_plain => true)
179
179
  test_command.run []
180
- @log_output.read.must_include "DEBUG TestLogCmd6 : Test\n{\n :password => \"***\",\n \"password\" => \"***\"\n}"
180
+ _(@log_output.read).must_include "DEBUG TestLogCmd6 : Test\n{\n :password => \"***\",\n \"password\" => \"***\"\n}"
181
181
  end
182
182
 
183
183
  it "password parameters should be hidden in logs" do
@@ -185,7 +185,7 @@ describe HammerCLI::AbstractCommand do
185
185
  test_command_class.option(['--password'], 'PASSWORD', 'Password')
186
186
  test_command = test_command_class.new("")
187
187
  test_command.run ['--password=pass']
188
- @log_output.readline.strip.must_equal "INFO HammerCLI::AbstractCommand : Called with options: {\"option_password\"=>\"***\"}"
188
+ _(@log_output.readline.strip).must_equal "INFO HammerCLI::AbstractCommand : Called with options: {\"option_password\"=>\"***\"}"
189
189
  end
190
190
  end
191
191
 
@@ -209,24 +209,24 @@ describe HammerCLI::AbstractCommand do
209
209
 
210
210
  it "should replace commands with the same name" do
211
211
  main_cmd.subcommand!("ping", "description", Subcommand2)
212
- main_cmd.find_subcommand("some_command").wont_be_nil
213
- main_cmd.find_subcommand("ping").wont_be_nil
214
- main_cmd.find_subcommand("ping").subcommand_class.must_equal Subcommand2
215
- main_cmd.recognised_subcommands.count.must_equal 2
212
+ _(main_cmd.find_subcommand("some_command")).wont_be_nil
213
+ _(main_cmd.find_subcommand("ping")).wont_be_nil
214
+ _(main_cmd.find_subcommand("ping").subcommand_class).must_equal Subcommand2
215
+ _(main_cmd.recognised_subcommands.count).must_equal 2
216
216
  end
217
217
 
218
218
  it "should write a message to log when replacing subcommand" do
219
219
  main_cmd.subcommand!("ping", "description", Subcommand2)
220
- @log_output.readline.strip.must_equal "INFO Clamp::Command : subcommand ping (Subcommand1) was removed."
221
- @log_output.readline.strip.must_equal "INFO Clamp::Command : subcommand ping (Subcommand2) was created."
220
+ _(@log_output.readline.strip).must_equal "INFO Clamp::Command : subcommand ping (Subcommand1) was removed."
221
+ _(@log_output.readline.strip).must_equal "INFO Clamp::Command : subcommand ping (Subcommand2) was created."
222
222
  end
223
223
 
224
224
  it "should add the subcommand" do
225
225
  main_cmd.subcommand!("new_command", "description", Subcommand2)
226
- main_cmd.find_subcommand("new_command").wont_be_nil
227
- main_cmd.find_subcommand("some_command").wont_be_nil
228
- main_cmd.find_subcommand("ping").wont_be_nil
229
- main_cmd.recognised_subcommands.count.must_equal 3
226
+ _(main_cmd.find_subcommand("new_command")).wont_be_nil
227
+ _(main_cmd.find_subcommand("some_command")).wont_be_nil
228
+ _(main_cmd.find_subcommand("ping")).wont_be_nil
229
+ _(main_cmd.recognised_subcommands.count).must_equal 3
230
230
  end
231
231
 
232
232
  end
@@ -235,17 +235,17 @@ describe HammerCLI::AbstractCommand do
235
235
  describe "subcommand" do
236
236
 
237
237
  it "should throw an exception for conflicting commands" do
238
- proc do
238
+ _{
239
239
  main_cmd.subcommand("ping", "description", Subcommand2)
240
- end.must_raise HammerCLI::CommandConflict
240
+ }.must_raise HammerCLI::CommandConflict
241
241
  end
242
242
 
243
243
  it "should add the subcommand" do
244
244
  main_cmd.subcommand("new_command", "description", Subcommand2)
245
- main_cmd.find_subcommand("new_command").wont_be_nil
246
- main_cmd.find_subcommand("some_command").wont_be_nil
247
- main_cmd.find_subcommand("ping").wont_be_nil
248
- main_cmd.recognised_subcommands.count.must_equal 3
245
+ _(main_cmd.find_subcommand("new_command")).wont_be_nil
246
+ _(main_cmd.find_subcommand("some_command")).wont_be_nil
247
+ _(main_cmd.find_subcommand("ping")).wont_be_nil
248
+ _(main_cmd.recognised_subcommands.count).must_equal 3
249
249
  end
250
250
 
251
251
  end
@@ -253,34 +253,34 @@ describe HammerCLI::AbstractCommand do
253
253
  describe "remove_subcommand" do
254
254
  it "should remove the subcommand" do
255
255
  main_cmd.remove_subcommand('ping')
256
- main_cmd.find_subcommand("ping").must_be_nil
256
+ _(main_cmd.find_subcommand("ping")).must_be_nil
257
257
  end
258
258
 
259
259
  it "should write a message to log when removing subcommand" do
260
260
  main_cmd.remove_subcommand('ping')
261
- @log_output.readline.strip.must_equal "INFO Clamp::Command : subcommand ping (Subcommand1) was removed."
261
+ _(@log_output.readline.strip).must_equal "INFO Clamp::Command : subcommand ping (Subcommand1) was removed."
262
262
  end
263
263
 
264
264
  end
265
265
 
266
266
  describe 'find_subcommand' do
267
267
  it 'should find by full name' do
268
- main_cmd.find_subcommand('some_command').wont_be_nil
268
+ _(main_cmd.find_subcommand('some_command')).wont_be_nil
269
269
  end
270
270
 
271
271
  it 'should find by partial name' do
272
- main_cmd.find_subcommand('some_').wont_be_nil
272
+ _(main_cmd.find_subcommand('some_')).wont_be_nil
273
273
  end
274
274
 
275
275
  it 'should not find by wrong name' do
276
- main_cmd.find_subcommand('not_existing').must_be_nil
276
+ _(main_cmd.find_subcommand('not_existing')).must_be_nil
277
277
  end
278
278
 
279
279
  it 'should raise if more than one were found' do
280
280
  main_cmd.subcommand('pong', 'description', Subcommand2)
281
- proc do
281
+ _{
282
282
  main_cmd.find_subcommand('p')
283
- end.must_raise HammerCLI::CommandConflict
283
+ }.must_raise HammerCLI::CommandConflict
284
284
  end
285
285
  end
286
286
  end
@@ -296,22 +296,22 @@ describe HammerCLI::AbstractCommand do
296
296
 
297
297
  it "should create instances of hammer options" do
298
298
  opt = TestOptionCmd.find_option("--test")
299
- opt.kind_of?(HammerCLI::Options::OptionDefinition).must_equal true
299
+ _(opt.kind_of?(HammerCLI::Options::OptionDefinition)).must_equal true
300
300
  end
301
301
 
302
302
  it "should set options' formatters" do
303
303
  opt = TestOptionCmd.find_option("--test-format")
304
- opt.value_formatter.kind_of?(HammerCLI::Options::Normalizers::List).must_equal true
304
+ _(opt.value_formatter.kind_of?(HammerCLI::Options::Normalizers::List)).must_equal true
305
305
  end
306
306
 
307
307
  it 'should allow using of predefined options' do
308
308
  opt = TestOptionCmd.find_option('--fields')
309
- opt.is_a?(HammerCLI::Options::OptionDefinition).must_equal true
309
+ _(opt.is_a?(HammerCLI::Options::OptionDefinition)).must_equal true
310
310
  end
311
311
 
312
312
  it 'should add option type and accepted value' do
313
313
  help_str = TestOptionCmd.help('')
314
- help_str.must_match(
314
+ _(help_str).must_match(
315
315
  /LIST Comma separated list of values. Values containing comma should be quoted or escaped with backslash./
316
316
  )
317
317
  end
@@ -330,11 +330,11 @@ describe HammerCLI::AbstractCommand do
330
330
  describe "option builder" do
331
331
 
332
332
  it "uses builder container as default" do
333
- HammerCLI::AbstractCommand.option_builder.class.must_equal HammerCLI::OptionBuilderContainer
333
+ _(HammerCLI::AbstractCommand.option_builder.class).must_equal HammerCLI::OptionBuilderContainer
334
334
  end
335
335
 
336
336
  it "Default builder container is empty" do
337
- HammerCLI::AbstractCommand.option_builder.builders.empty?.must_equal true
337
+ _(HammerCLI::AbstractCommand.option_builder.builders.empty?).must_equal true
338
338
  end
339
339
 
340
340
  end
@@ -368,13 +368,13 @@ describe HammerCLI::AbstractCommand do
368
368
 
369
369
  it "should use option builder" do
370
370
  TestBuilderCmd.build_options
371
- TestBuilderCmd.recognised_options.map(&:switches).flatten.sort.must_equal ["--test", "--test2"].sort
371
+ _(TestBuilderCmd.recognised_options.map(&:switches).flatten.sort).must_equal ["--test", "--test2"].sort
372
372
  end
373
373
 
374
374
  it "should skip options that already exist" do
375
375
  TestBuilderCmd.option(["--test"], "TEST", "original_test")
376
376
  TestBuilderCmd.build_options
377
- TestBuilderCmd.recognised_options.map(&:description).flatten.sort.must_equal ["original_test", "test2"].sort
377
+ _(TestBuilderCmd.recognised_options.map(&:description).flatten.sort).must_equal ["original_test", "test2"].sort
378
378
  end
379
379
 
380
380
  it "passes params to the builders" do
@@ -441,7 +441,7 @@ describe HammerCLI::AbstractCommand do
441
441
  class CmdName2 < CmdName1
442
442
  end
443
443
 
444
- CmdName2.command_name.must_equal ['cmd']
444
+ _(CmdName2.command_name).must_equal ['cmd']
445
445
  end
446
446
 
447
447
  it "should inherit output definition" do
@@ -455,7 +455,7 @@ describe HammerCLI::AbstractCommand do
455
455
  class CmdOD2 < CmdOD1
456
456
  end
457
457
 
458
- CmdOD2.output_definition.fields.length.must_equal 1
458
+ _(CmdOD2.output_definition.fields.length).must_equal 1
459
459
  end
460
460
 
461
461
  describe 'validate_options' do
@@ -551,14 +551,14 @@ describe HammerCLI::AbstractCommand do
551
551
  it 'should extend command with option, output, help right away' do
552
552
  cmd.extend_with(extension)
553
553
  opt = cmd.find_option('--flag')
554
- opt.is_a?(HammerCLI::Options::OptionDefinition).must_equal true
555
- cmd.output_definition.empty?.must_equal false
556
- cmd.new('', {}).help.must_match(/.*text.*/)
554
+ _(opt.is_a?(HammerCLI::Options::OptionDefinition)).must_equal true
555
+ _(cmd.output_definition.empty?).must_equal false
556
+ _(cmd.new('', {}).help).must_match(/.*text.*/)
557
557
  end
558
558
 
559
559
  it 'should store more than one extension' do
560
560
  cmd.extend_with(extension, output_extension)
561
- cmd.command_extensions.size.must_equal 2
561
+ _(cmd.command_extensions.size).must_equal 2
562
562
  end
563
563
  end
564
564
  end
@@ -1,5 +1,4 @@
1
- require File.join(File.dirname(__FILE__), '../test_helper')
2
-
1
+ require_relative 'test_helper'
3
2
 
4
3
  describe HammerCLI::Apipie::Command do
5
4
 
@@ -34,15 +33,15 @@ describe HammerCLI::Apipie::Command do
34
33
  end
35
34
 
36
35
  let(:ctx) { { :adapter => :silent, :interactive => false } }
37
- let(:cmd_class) { HammerCLI::Apipie::Command.dup }
36
+ let(:cmd_class) { Class.new(HammerCLI::Apipie::Command) }
38
37
  let(:cmd) { cmd_class.new("", ctx) }
39
38
  let(:cmd_run) { cmd.run([]) }
40
39
 
41
40
  context "unsupported commands" do
42
- let(:cmd_class) { CommandUnsupp.dup }
41
+ let(:cmd_class) { Class.new(CommandUnsupp) }
43
42
  let(:cmd) { cmd_class.new("unsupported", ctx) }
44
43
  it "should print help for unsupported command" do
45
- assert_match /.*Unfortunately the server does not support such operation.*/, cmd.help
44
+ assert_match(/.*Unfortunately the server does not support such operation.*/, cmd.help)
46
45
  end
47
46
 
48
47
  end
@@ -52,63 +51,63 @@ describe HammerCLI::Apipie::Command do
52
51
  it "should set resource and action together" do
53
52
  cmd_class.resource :architectures, :index
54
53
 
55
- cmd.resource.name.must_equal :architectures
56
- cmd_class.resource.name.must_equal :architectures
54
+ _(cmd.resource.name).must_equal :architectures
55
+ _(cmd_class.resource.name).must_equal :architectures
57
56
 
58
- cmd.action.must_equal :index
59
- cmd_class.action.must_equal :index
57
+ _(cmd.action).must_equal :index
58
+ _(cmd_class.action).must_equal :index
60
59
  end
61
60
 
62
61
  it "should set resource alone" do
63
62
  cmd_class.resource :architectures
64
63
 
65
- cmd.resource.name.must_equal :architectures
66
- cmd_class.resource.name.must_equal :architectures
64
+ _(cmd.resource.name).must_equal :architectures
65
+ _(cmd_class.resource.name).must_equal :architectures
67
66
 
68
- cmd.action.must_equal nil
69
- cmd_class.action.must_equal nil
67
+ assert_nil cmd.action
68
+ assert_nil cmd_class.action
70
69
  end
71
70
 
72
71
  it "should set resource and action alone" do
73
72
  cmd_class.resource :architectures
74
73
  cmd_class.action :index
75
74
 
76
- cmd.resource.name.must_equal :architectures
77
- cmd_class.resource.name.must_equal :architectures
75
+ _(cmd.resource.name).must_equal :architectures
76
+ _(cmd_class.resource.name).must_equal :architectures
78
77
 
79
- cmd.action.must_equal :index
80
- cmd_class.action.must_equal :index
78
+ _(cmd.action).must_equal :index
79
+ _(cmd_class.action).must_equal :index
81
80
  end
82
81
 
83
82
  it "inherits action from a parent class" do
84
83
  cmd_b = CommandA::CommandB.new("", ctx)
85
- cmd_b.action.must_equal :show
86
- cmd_b.class.action.must_equal :show
84
+ _(cmd_b.action).must_equal :show
85
+ _(cmd_b.class.action).must_equal :show
87
86
  end
88
87
 
89
88
  it "looks up resource in the class' modules" do
90
89
  cmd_b = CommandA::CommandB.new("", ctx)
91
- cmd_b.resource.name.must_equal :architectures
92
- cmd_b.class.resource.name.must_equal :architectures
90
+ _(cmd_b.resource.name).must_equal :architectures
91
+ _(cmd_b.class.resource.name).must_equal :architectures
93
92
  end
94
93
 
95
94
  it "looks up resource in the superclass" do
96
95
  cmd_c = CommandC.new("", ctx)
97
- cmd_c.resource.name.must_equal :architectures
98
- cmd_c.class.resource.name.must_equal :architectures
96
+ _(cmd_c.resource.name).must_equal :architectures
97
+ _(cmd_c.class.resource.name).must_equal :architectures
99
98
  end
100
99
  end
101
100
 
102
101
  it "should raise exception when no action is defined" do
103
102
  cmd.stubs(:handle_exception).returns(HammerCLI::EX_SOFTWARE)
104
- cmd_run.must_equal HammerCLI::EX_SOFTWARE
103
+ _(cmd_run).must_equal HammerCLI::EX_SOFTWARE
105
104
  end
106
105
 
107
106
  context "resource defined" do
108
107
  it "should perform a call to api when resource is defined" do
109
108
  ApipieBindings::API.any_instance.expects(:call).returns([])
110
109
  cmd.class.resource :architectures, :index
111
- cmd_run.must_equal 0
110
+ _(cmd_run).must_equal 0
112
111
  end
113
112
  end
114
113
 
@@ -117,13 +116,13 @@ describe HammerCLI::Apipie::Command do
117
116
  it "should collect method options from given options" do
118
117
  cmd_opt = OptionCommand.new("", ctx)
119
118
  params = cmd_opt.class.resource.action(:create).params
120
- cmd_opt.method_options_for_params(params, {'option_name' => 'name'}).must_equal({"architecture" => {"name" => "name"}})
119
+ _(cmd_opt.method_options_for_params(params, {'option_name' => 'name'})).must_equal({"architecture" => {"name" => "name"}})
121
120
  end
122
121
 
123
122
  it "should collect method options from methods" do
124
123
  cmd_opt = OptionCommand.new("", ctx)
125
124
  params = cmd_opt.class.resource.action(:create).params
126
- cmd_opt.method_options_for_params(params, {}).must_equal({"architecture"=>{"name"=>"test_name"}})
125
+ _(cmd_opt.method_options_for_params(params, {})).must_equal({"architecture"=>{"name"=>"test_name"}})
127
126
  end
128
127
 
129
128
  end
@@ -148,7 +147,7 @@ describe HammerCLI::Apipie::Command do
148
147
  ''
149
148
  ].join("\n")
150
149
  expected_result = success_result(expected_messages)
151
- result = run_cmd([], { :verbosity => HammerCLI::V_QUIET }, MessagesCommand)
150
+ result = run_cmd([], { :verbosity => HammerCLI::V_QUIET }, Class.new(MessagesCommand))
152
151
  assert_cmd(expected_result, result)
153
152
  end
154
153