|
4 | 4 | require_relative "helper" |
5 | 5 |
|
6 | 6 | 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 | + |
7 | 16 | class CommandTestCase < TestCase |
8 | 17 | def setup |
9 | 18 | @pwd = Dir.pwd |
@@ -767,18 +776,33 @@ def test_ls_with_no_singleton_class |
767 | 776 | end |
768 | 777 |
|
769 | 778 | 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 |
782 | 806 |
|
783 | 807 | def test_show_doc_without_rdoc |
784 | 808 | _, err = without_rdoc do |
|
0 commit comments