ruby/test/irb/command/test_help.rb
Stan Lo 07c774e85c [ruby/irb] Revamp help command
(https://github.com/ruby/irb/pull/877)

* Make help command display help for individual commands

Usage: `help [command]`

If the command is not specified, it will display a list of all available commands.

If the command is specified, it will display the banner OR description of the command.

If the command is not found, it will display a message saying that the command is not found.

* Rename test/irb/cmd to test/irb/command

* Add banner to edit and ls commands

* Promote help command in the help message

1. Make `show_cmds` an alias of `help` so it's not displayed in the help message
2. Update description of the help command to reflect `help <command>` syntax

* Rename banner to help_message

43a2c99f3f
2024-02-18 18:21:08 +00:00

66 lines
1.3 KiB
Ruby

require "tempfile"
require_relative "../helper"
module TestIRB
class HelpTest < IntegrationTestCase
def setup
super
write_rc <<~'RUBY'
IRB.conf[:USE_PAGER] = false
RUBY
write_ruby <<~'RUBY'
binding.irb
RUBY
end
def test_help
out = run_ruby_file do
type "help"
type "exit"
end
assert_match(/List all available commands/, out)
assert_match(/Start the debugger of debug\.gem/, out)
end
def test_command_help
out = run_ruby_file do
type "help ls"
type "exit"
end
assert_match(/Usage: ls \[obj\]/, out)
end
def test_command_help_not_found
out = run_ruby_file do
type "help foo"
type "exit"
end
assert_match(/Can't find command `foo`\. Please check the command name and try again\./, out)
end
def test_show_cmds
out = run_ruby_file do
type "help"
type "exit"
end
assert_match(/List all available commands/, out)
assert_match(/Start the debugger of debug\.gem/, out)
end
def test_help_lists_user_aliases
out = run_ruby_file do
type "help"
type "exit"
end
assert_match(/\$\s+Alias for `show_source`/, out)
assert_match(/@\s+Alias for `whereami`/, out)
end
end
end