test/unit/abstract_test.rb in hammer_cli-2.0.0 vs test/unit/abstract_test.rb in hammer_cli-2.1.0
- old
+ new
@@ -260,10 +260,31 @@
main_cmd.remove_subcommand('ping')
@log_output.readline.strip.must_equal "INFO Clamp::Command : subcommand ping (Subcommand1) was removed."
end
end
+
+ describe 'find_subcommand' do
+ it 'should find by full name' do
+ main_cmd.find_subcommand('some_command').wont_be_nil
+ end
+
+ it 'should find by partial name' do
+ main_cmd.find_subcommand('some_').wont_be_nil
+ end
+
+ it 'should not find by wrong name' do
+ main_cmd.find_subcommand('not_existing').must_be_nil
+ end
+
+ it 'should raise if more than one were found' do
+ main_cmd.subcommand('pong', 'description', Subcommand2)
+ proc do
+ main_cmd.find_subcommand('p')
+ end.must_raise HammerCLI::CommandConflict
+ end
+ end
end
describe "options" do
class TestOptionCmd < HammerCLI::AbstractCommand
@@ -411,11 +432,11 @@
end
class CmdName2 < CmdName1
end
- CmdName2.command_name.must_equal 'cmd'
+ CmdName2.command_name.must_equal ['cmd']
end
it "should inherit output definition" do
class CmdOD1 < HammerCLI::AbstractCommand
output do
@@ -523,10 +544,10 @@
it 'should extend command with option, output, help right away' do
cmd.extend_with(extension)
opt = cmd.find_option('--flag')
opt.is_a?(HammerCLI::Options::OptionDefinition).must_equal true
cmd.output_definition.empty?.must_equal false
- cmd.new({}).help.must_match(/.*text.*/)
+ cmd.new('', {}).help.must_match(/.*text.*/)
end
it 'should store more than one extension' do
cmd.extend_with(extension, output_extension)
cmd.command_extensions.size.must_equal 2