Sha256: c75754f87c0baf6d20a452fb41efb7fc5a0c265ae66b66a0770afd5a4805d5b7

Contents?: true

Size: 1.21 KB

Versions: 10

Compression:

Stored size: 1.21 KB

Contents

# frozen_string_literal: true

require 'helper'

module Cri
  class HelpRendererTestCase < Cri::TestCase
    # NOTE: Additional test cases are in test_command.rb

    def help_for(cmd)
      io = StringIO.new
      Cri::HelpRenderer.new(cmd, io: io).render
    end

    def test_simple
      expected = <<~HELP
        NAME
            help - show help

        USAGE
            help [command_name]

        DESCRIPTION
            Show help for the given command, or show general help. When no command is
            given, a list of available commands is displayed, as well as a list of
            global command-line options. When a command is given, a command
            description, as well as command-specific command-line options, are shown.

        OPTIONS
            -v --verbose      show more detailed help
      HELP

      cmd = Cri::Command.new_basic_help
      assert_equal(expected, help_for(cmd))
    end

    def test_with_defaults
      cmd = Cri::Command.define do
        name 'build'
        optional nil, :'with-animal', 'Add animal', default: 'giraffe'
      end

      help = help_for(cmd)

      assert_match(/^       --with-animal\[=<value>\]      Add animal \(default: giraffe\)$/, help)
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
cri-2.15.5 test/test_help_renderer.rb
cri-2.15.4 test/test_help_renderer.rb
cri-2.15.3 test/test_help_renderer.rb
cri-2.15.2 test/test_help_renderer.rb
cri-2.15.1 test/test_help_renderer.rb
cri-2.15.0 test/test_help_renderer.rb
cri-2.14.0 test/test_help_renderer.rb
cri-2.13.0 test/test_help_renderer.rb
cri-2.12.0 test/test_help_renderer.rb
cri-2.11.0 test/test_help_renderer.rb