diff options
author | Stan Lo <stan001212@gmail.com> | 2023-04-24 15:10:32 +0100 |
---|---|---|
committer | git <svn-admin@ruby-lang.org> | 2023-04-24 14:10:36 +0000 |
commit | 73fc81199de5e567e38f7ea9067260eb6866cbf9 (patch) | |
tree | 3d98586fa270eb64e1a11164bf74227324b0bc44 /test/irb/test_cmd.rb | |
parent | 805899dda29e36a42ffd9e076b9296f3bf13af5a (diff) | |
download | ruby-73fc81199de5e567e38f7ea9067260eb6866cbf9.tar.gz |
[ruby/irb] Simplify the help command's implementation
(https://github.com/ruby/irb/pull/564)
The current method-redefining approach brings little benefit, makes it
harder to understand the code, and causes warnings like:
> warning: method redefined; discarding old execute
This patch simplifies it while displaying more helpful message when rdoc
couldn't be loaded.
Diffstat (limited to 'test/irb/test_cmd.rb')
-rw-r--r-- | test/irb/test_cmd.rb | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/test/irb/test_cmd.rb b/test/irb/test_cmd.rb index 5cbc5b4663..c069bedb51 100644 --- a/test/irb/test_cmd.rb +++ b/test/irb/test_cmd.rb @@ -785,7 +785,7 @@ module TestIRB class ShowDocTest < CommandTestCase def test_help_and_show_doc ["help", "show_doc"].each do |cmd| - out, _ = execute_lines( + out, err = execute_lines( "#{cmd} String#gsub\n", "\n", ) @@ -793,6 +793,7 @@ module TestIRB # 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_empty err assert(possible_rdoc_output.any? { |output| output.match?(out) }, "Expect the `#{cmd}` command to match one of the possible outputs. Got:\n#{out}") end ensure @@ -801,7 +802,7 @@ module TestIRB end def test_show_doc_without_rdoc - out, _ = without_rdoc do + out, err = without_rdoc do execute_lines( "show_doc String#gsub\n", "\n", @@ -809,7 +810,8 @@ module TestIRB end # if it fails to require rdoc, it only returns the command object - assert_match(/=> IRB::ExtendCommand::Help\n/, out) + assert_match(/=> nil\n/, out) + assert_include(err, "Can't display document because `rdoc` is not installed.\n") ensure # this is the only way to reset the redefined method without coupling the test with its implementation EnvUtil.suppress_warning { load "irb/cmd/help.rb" } |