diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/irb/test_command.rb | 48 |
1 files changed, 36 insertions, 12 deletions
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 |
