test/test_command.rb in cri-2.7.0 vs test/test_command.rb in cri-2.7.1
- old
+ new
@@ -1,17 +1,15 @@
-# encoding: utf-8
-
module Cri
class CommandTestCase < Cri::TestCase
def simple_cmd
Cri::Command.define do
name 'moo'
usage 'moo [options] arg1 arg2 ...'
summary 'does stuff'
description 'This command does a lot of stuff.'
- option :a, :aaa, 'opt a', :argument => :optional do |value, cmd|
+ option :a, :aaa, 'opt a', argument: :optional do |value, cmd|
$stdout.puts "#{cmd.name}:#{value}"
end
required :b, :bbb, 'opt b'
optional :c, :ccc, 'opt c'
flag :d, :ddd, 'opt d'
@@ -29,11 +27,11 @@
end
end
def bare_cmd
Cri::Command.define do
- name 'moo'
+ name 'moo'
run do |_opts, _args|
end
end
end
@@ -43,11 +41,11 @@
name 'super'
usage 'super [command] [options] [arguments]'
summary 'does super stuff'
description 'This command does super stuff.'
- option :a, :aaa, 'opt a', :argument => :optional do |value, cmd|
+ option :a, :aaa, 'opt a', argument: :optional do |value, cmd|
$stdout.puts "#{cmd.name}:#{value}"
end
required :b, :bbb, 'opt b'
optional :c, :ccc, 'opt c'
flag :d, :ddd, 'opt d'
@@ -59,11 +57,11 @@
aliases 'sup'
usage 'sub [options]'
summary 'does subby stuff'
description 'This command does subby stuff.'
- option :m, :mmm, 'opt m', :argument => :optional
+ option :m, :mmm, 'opt m', argument: :optional
required :n, :nnn, 'opt n'
optional :o, :ooo, 'opt o'
flag :p, :ppp, 'opt p'
forbidden :q, :qqq, 'opt q'
@@ -146,32 +144,32 @@
end
def test_invoke_simple_with_missing_opt_arg
out, err = capture_io_while do
assert_raises SystemExit do
- simple_cmd.run(%w( -b ))
+ simple_cmd.run(%w(-b))
end
end
assert_equal [], lines(out)
assert_equal ['moo: option requires an argument -- b'], lines(err)
end
def test_invoke_simple_with_illegal_opt
out, err = capture_io_while do
assert_raises SystemExit do
- simple_cmd.run(%w( -z ))
+ simple_cmd.run(%w(-z))
end
end
assert_equal [], lines(out)
assert_equal ['moo: illegal option -- z'], lines(err)
end
def test_invoke_simple_with_opt_with_block
out, err = capture_io_while do
- simple_cmd.run(%w( -a 123 ))
+ simple_cmd.run(%w(-a 123))
end
assert_equal ['moo:123', 'Awesome moo!', '', 'aaa=123'], lines(out)
assert_equal [], lines(err)
end
@@ -187,51 +185,51 @@
assert_equal ['super: no command given'], lines(err)
end
def test_invoke_nested_with_correct_command_name
out, err = capture_io_while do
- nested_cmd.run(%w( sub ))
+ nested_cmd.run(%w(sub))
end
assert_equal ['Sub-awesome!', '', ''], lines(out)
assert_equal [], lines(err)
end
def test_invoke_nested_with_incorrect_command_name
out, err = capture_io_while do
assert_raises SystemExit do
- nested_cmd.run(%w( oogabooga ))
+ nested_cmd.run(%w(oogabooga))
end
end
assert_equal [], lines(out)
assert_equal ["super: unknown command 'oogabooga'"], lines(err)
end
def test_invoke_nested_with_ambiguous_command_name
out, err = capture_io_while do
assert_raises SystemExit do
- nested_cmd.run(%w( s ))
+ nested_cmd.run(%w(s))
end
end
assert_equal [], lines(out)
assert_equal ["super: 's' is ambiguous:", ' sink sub'], lines(err)
end
def test_invoke_nested_with_alias
out, err = capture_io_while do
- nested_cmd.run(%w( sup ))
+ nested_cmd.run(%w(sup))
end
assert_equal ['Sub-awesome!', '', ''], lines(out)
assert_equal [], lines(err)
end
def test_invoke_nested_with_options_before_command
out, err = capture_io_while do
- nested_cmd.run(%w( -a 666 sub ))
+ nested_cmd.run(%w(-a 666 sub))
end
assert_equal ['super:666', 'Sub-awesome!', '', 'aaa=666'], lines(out)
assert_equal [], lines(err)
end
@@ -243,11 +241,11 @@
assert_equal ['super'], lines(out)
assert_equal [], lines(err)
out, err = capture_io_while do
- nested_cmd_with_run_block.run(%w( sub ))
+ nested_cmd_with_run_block.run(%w(sub))
end
assert_equal ['sub'], lines(out)
assert_equal [], lines(err)
end
@@ -352,11 +350,11 @@
end
def test_help_with_multiple_groups
help = nested_cmd.subcommands.find { |cmd| cmd.name == 'sub' }.help
- assert_match(/OPTIONS.*OPTIONS FOR SUPER/m, help)
+ assert_match(/OPTIONS.*OPTIONS FOR SUPER/m, help)
end
def test_modify_with_block_argument
cmd = Cri::Command.define do |c|
c.name 'build'
@@ -375,11 +373,11 @@
true
end
cmd = Cri::Command.define do
name 'build'
- flag nil, :longflag, 'This is an option with a very long description that should be wrapped'
+ flag nil, :longflag, 'This is an option with a very long description that should be wrapped'
end
help = cmd.help
assert_match(/^ \e\[33m--longflag\e\[0m This is an option with a very long description that$/, help)
assert_match(/^ should be wrapped$/, help)
@@ -467,13 +465,13 @@
refute cmd.help.include?('hidden commands omitted')
assert cmd.help.include?('hidden command omitted')
refute cmd.help.include?('old-and-deprecated')
- refute cmd.help(:verbose => true).include?('hidden commands omitted')
- refute cmd.help(:verbose => true).include?('hidden command omitted')
- assert cmd.help(:verbose => true).include?('old-and-deprecated')
+ refute cmd.help(verbose: true).include?('hidden commands omitted')
+ refute cmd.help(verbose: true).include?('hidden command omitted')
+ assert cmd.help(verbose: true).include?('old-and-deprecated')
end
def test_hidden_commands_multiple
cmd = nested_cmd
@@ -503,17 +501,17 @@
assert cmd.help.include?('hidden commands omitted')
refute cmd.help.include?('hidden command omitted')
refute cmd.help.include?('old-and-deprecated')
refute cmd.help.include?('ancient-and-deprecated')
- refute cmd.help(:verbose => true).include?('hidden commands omitted')
- refute cmd.help(:verbose => true).include?('hidden command omitted')
- assert cmd.help(:verbose => true).include?('old-and-deprecated')
- assert cmd.help(:verbose => true).include?('ancient-and-deprecated')
+ refute cmd.help(verbose: true).include?('hidden commands omitted')
+ refute cmd.help(verbose: true).include?('hidden command omitted')
+ assert cmd.help(verbose: true).include?('old-and-deprecated')
+ assert cmd.help(verbose: true).include?('ancient-and-deprecated')
pattern = /ancient-and-deprecated.*first.*old-and-deprecated/m
- assert_match(pattern, cmd.help(:verbose => true))
+ assert_match(pattern, cmd.help(verbose: true))
end
def test_run_with_raw_args
cmd = Cri::Command.define do
name 'moo'
@@ -521,11 +519,11 @@
puts "args=#{args.join(',')} args.raw=#{args.raw.join(',')}"
end
end
out, _err = capture_io_while do
- cmd.run(%w( foo -- bar ))
+ cmd.run(%w(foo -- bar))
end
assert_equal "args=foo,bar args.raw=foo,--,bar\n", out
end
def test_run_without_block
@@ -547,10 +545,10 @@
end
end)
end
out, _err = capture_io_while do
- cmd.run(%w( foo -- bar ))
+ cmd.run(%w(foo -- bar))
end
assert_equal "args=foo,bar args.raw=foo,--,bar\n", out
end
def test_compare