Sha256: 3ef9cc4b822462f6dc57f99ad9dc5bf01e1f64b6c54cb93fbf54444dd4f40d2a

Contents?: true

Size: 1.51 KB

Versions: 4

Compression:

Stored size: 1.51 KB

Contents

require_relative "test_helper"

class CommandFinderTest < MiniTest::Test
  include TestHelper

  def setup
    @app = CLIApp.new
    [:status, :deployable, :some_command, :some_similar_command].each do |command|
      @app.commands[command] = GLI::Command.new(:names => command)
    end
  end

  def teardown
  end

  def test_unknown_command_name
    assert_raises(GLI::UnknownCommand) do
      GLI::CommandFinder.new(@app.commands, :default_command => :status).find_command(:unfindable_command)
    end
  end

  def test_no_command_name_without_default
    assert_raises(GLI::UnknownCommand) do
      GLI::CommandFinder.new(@app.commands).find_command(nil)
    end
  end

  def test_no_command_name_with_default
    actual = GLI::CommandFinder.new(@app.commands, :default_command => :status).find_command(nil)
    expected = @app.commands[:status]

    assert_equal(actual, expected)
  end

  def test_ambigous_command
    assert_raises(GLI::AmbiguousCommand) do
      GLI::CommandFinder.new(@app.commands, :default_command => :status).find_command(:some)
    end
  end

  def test_partial_name_with_autocorrect_enabled
    actual = GLI::CommandFinder.new(@app.commands, :default_command => :status).find_command(:deploy)
    expected = @app.commands[:deployable]

    assert_equal(actual, expected)
  end

  def test_partial_name_with_autocorrect_disabled
    assert_raises(GLI::UnknownCommand) do
      GLI::CommandFinder.new(@app.commands, :default_command => :status, :autocomplete => false)
        .find_command(:deploy)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
gli-2.21.1 test/unit/command_finder_test.rb
gli-2.21.0 test/unit/command_finder_test.rb
gli-2.20.1 test/unit/command_finder_test.rb
gli-2.20.0 test/unit/command_finder_test.rb