Skip to content

Commit 609a555

Browse files
st0012matzbot
authored andcommitted
[ruby/irb] Add ri an alias to the show_doc command
(ruby/irb#1054) ruby/irb@52e77dd113
1 parent e4ec212 commit 609a555

File tree

2 files changed

+38
-13
lines changed

2 files changed

+38
-13
lines changed

lib/irb/default_commands.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,8 @@ def load_command(command)
218218
)
219219

220220
_register_with_aliases(:irb_show_doc, Command::ShowDoc,
221-
[:show_doc, NO_OVERRIDE]
221+
[:show_doc, NO_OVERRIDE],
222+
[:ri, NO_OVERRIDE]
222223
)
223224

224225
_register_with_aliases(:irb_info, Command::IrbInfo)

test/irb/test_command.rb

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@
44
require_relative "helper"
55

66
module TestIRB
7+
# In case when RDoc becomes a bundled gem, we may not be able to load it when running tests
8+
# in ruby/ruby
9+
HAS_RDOC = begin
10+
require "rdoc"
11+
true
12+
rescue LoadError
13+
false
14+
end
15+
716
class CommandTestCase < TestCase
817
def setup
918
@pwd = Dir.pwd
@@ -767,18 +776,33 @@ def test_ls_with_no_singleton_class
767776
end
768777

769778
class ShowDocTest < CommandTestCase
770-
def test_show_doc
771-
out, err = execute_lines("show_doc String#gsub")
772-
773-
# the former is what we'd get without document content installed, like on CI
774-
# the latter is what we may get locally
775-
possible_rdoc_output = [/Nothing known about String#gsub/, /gsub\(pattern\)/]
776-
assert_not_include err, "[Deprecation]"
777-
assert(possible_rdoc_output.any? { |output| output.match?(out) }, "Expect the `show_doc` command to match one of the possible outputs. Got:\n#{out}")
778-
ensure
779-
# this is the only way to reset the redefined method without coupling the test with its implementation
780-
EnvUtil.suppress_warning { load "irb/command/help.rb" }
781-
end if defined?(RDoc)
779+
if HAS_RDOC
780+
def test_show_doc
781+
out, err = execute_lines("show_doc String#gsub")
782+
783+
# the former is what we'd get without document content installed, like on CI
784+
# the latter is what we may get locally
785+
possible_rdoc_output = [/Nothing known about String#gsub/, /gsub\(pattern\)/]
786+
assert_not_include err, "[Deprecation]"
787+
assert(possible_rdoc_output.any? { |output| output.match?(out) }, "Expect the `show_doc` command to match one of the possible outputs. Got:\n#{out}")
788+
ensure
789+
# this is the only way to reset the redefined method without coupling the test with its implementation
790+
EnvUtil.suppress_warning { load "irb/command/help.rb" }
791+
end
792+
793+
def test_ri
794+
out, err = execute_lines("ri String#gsub")
795+
796+
# the former is what we'd get without document content installed, like on CI
797+
# the latter is what we may get locally
798+
possible_rdoc_output = [/Nothing known about String#gsub/, /gsub\(pattern\)/]
799+
assert_not_include err, "[Deprecation]"
800+
assert(possible_rdoc_output.any? { |output| output.match?(out) }, "Expect the `ri` command to match one of the possible outputs. Got:\n#{out}")
801+
ensure
802+
# this is the only way to reset the redefined method without coupling the test with its implementation
803+
EnvUtil.suppress_warning { load "irb/command/help.rb" }
804+
end
805+
end
782806

783807
def test_show_doc_without_rdoc
784808
_, err = without_rdoc do

0 commit comments

Comments
 (0)