summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStan Lo <stan001212@gmail.com>2024-12-28 23:55:20 +0800
committergit <svn-admin@ruby-lang.org>2024-12-28 15:55:27 +0000
commit609a555ee00e7501d52bc4155cd2f8ee980cee2f (patch)
tree3d66b5f249fdef4e9db4b7e54aef2e8385615a4a
parente4ec2128ae9c5c2a43cd599759f19db21fc0238f (diff)
[ruby/irb] Add `ri` an alias to the `show_doc` command
(https://github.com/ruby/irb/pull/1054) https://github.com/ruby/irb/commit/52e77dd113
-rw-r--r--lib/irb/default_commands.rb3
-rw-r--r--test/irb/test_command.rb48
2 files changed, 38 insertions, 13 deletions
diff --git a/lib/irb/default_commands.rb b/lib/irb/default_commands.rb
index 768fbee9d7..533bdfc875 100644
--- a/lib/irb/default_commands.rb
+++ b/lib/irb/default_commands.rb
@@ -218,7 +218,8 @@ module IRB
)
_register_with_aliases(:irb_show_doc, Command::ShowDoc,
- [:show_doc, NO_OVERRIDE]
+ [:show_doc, NO_OVERRIDE],
+ [:ri, NO_OVERRIDE]
)
_register_with_aliases(:irb_info, Command::IrbInfo)
diff --git a/test/irb/test_command.rb b/test/irb/test_command.rb
index 21e05752b9..286fe04769 100644
--- a/test/irb/test_command.rb
+++ b/test/irb/test_command.rb
@@ -4,6 +4,15 @@ require "irb"
require_relative "helper"
module TestIRB
+ # In case when RDoc becomes a bundled gem, we may not be able to load it when running tests
+ # in ruby/ruby
+ HAS_RDOC = begin
+ require "rdoc"
+ true
+ rescue LoadError
+ false
+ end
+
class CommandTestCase < TestCase
def setup
@pwd = Dir.pwd
@@ -767,18 +776,33 @@ module TestIRB
end
class ShowDocTest < CommandTestCase
- def test_show_doc
- out, err = execute_lines("show_doc String#gsub")
-
- # the former is what we'd get without document content installed, like on CI
- # the latter is what we may get locally
- possible_rdoc_output = [/Nothing known about String#gsub/, /gsub\(pattern\)/]
- assert_not_include err, "[Deprecation]"
- assert(possible_rdoc_output.any? { |output| output.match?(out) }, "Expect the `show_doc` command to match one of the possible outputs. Got:\n#{out}")
- ensure
- # this is the only way to reset the redefined method without coupling the test with its implementation
- EnvUtil.suppress_warning { load "irb/command/help.rb" }
- end if defined?(RDoc)
+ if HAS_RDOC
+ def test_show_doc
+ out, err = execute_lines("show_doc String#gsub")
+
+ # the former is what we'd get without document content installed, like on CI
+ # the latter is what we may get locally
+ possible_rdoc_output = [/Nothing known about String#gsub/, /gsub\(pattern\)/]
+ assert_not_include err, "[Deprecation]"
+ assert(possible_rdoc_output.any? { |output| output.match?(out) }, "Expect the `show_doc` command to match one of the possible outputs. Got:\n#{out}")
+ ensure
+ # this is the only way to reset the redefined method without coupling the test with its implementation
+ EnvUtil.suppress_warning { load "irb/command/help.rb" }
+ end
+
+ def test_ri
+ out, err = execute_lines("ri String#gsub")
+
+ # the former is what we'd get without document content installed, like on CI
+ # the latter is what we may get locally
+ possible_rdoc_output = [/Nothing known about String#gsub/, /gsub\(pattern\)/]
+ assert_not_include err, "[Deprecation]"
+ assert(possible_rdoc_output.any? { |output| output.match?(out) }, "Expect the `ri` command to match one of the possible outputs. Got:\n#{out}")
+ ensure
+ # this is the only way to reset the redefined method without coupling the test with its implementation
+ EnvUtil.suppress_warning { load "irb/command/help.rb" }
+ end
+ end
def test_show_doc_without_rdoc
_, err = without_rdoc do