From 609a555ee00e7501d52bc4155cd2f8ee980cee2f Mon Sep 17 00:00:00 2001 From: Stan Lo Date: Sat, 28 Dec 2024 23:55:20 +0800 Subject: [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 --- lib/irb/default_commands.rb | 3 ++- test/irb/test_command.rb | 48 +++++++++++++++++++++++++++++++++------------ 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 -- cgit v1.2.3