Skip to content

Commit

Permalink
[ruby/irb] Don't insert new methods to Test::Unit::TestCase
Browse files Browse the repository at this point in the history
Ruby CI runs irb and other Ruby core/stdlib tests in the same process.
So adding irb-specific helper to Test::Unit::TestCase could potentially
pollute other components' tests and should be avoided.
  • Loading branch information
st0012 authored and peterzhu2118 committed Oct 26, 2022
1 parent 2022470 commit cb95d83
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
4 changes: 3 additions & 1 deletion test/irb/test_cmd.rb
Expand Up @@ -3,6 +3,8 @@
require "irb"
require "irb/extend-command"

require_relative "test_helper"

module TestIRB
class ExtendCommand < Test::Unit::TestCase
class TestInputMethod < ::IRB::InputMethod
Expand Down Expand Up @@ -443,7 +445,7 @@ def test_help_without_rdoc
irb = IRB::Irb.new(IRB::WorkSpace.new(self), input)
IRB.conf[:MAIN_CONTEXT] = irb.context
out, err = capture_output do
without_rdoc do
IRB::TestHelper.without_rdoc do
irb.eval_input
end
end
Expand Down
16 changes: 16 additions & 0 deletions test/irb/test_helper.rb
@@ -0,0 +1,16 @@
module IRB
module TestHelper
def self.without_rdoc(&block)
::Kernel.send(:alias_method, :old_require, :require)

::Kernel.define_method(:require) do |name|
raise LoadError, "cannot load such file -- rdoc (test)" if name.match?("rdoc") || name.match?(/^rdoc\/.*/)
::Kernel.send(:old_require, name)
end

yield
ensure
EnvUtil.suppress_warning { ::Kernel.send(:alias_method, :require, :old_require) }
end
end
end
4 changes: 3 additions & 1 deletion test/irb/test_input_method.rb
Expand Up @@ -3,6 +3,8 @@
require "test/unit"
require "irb"

require_relative "test_helper"

module TestIRB
class TestRelineInputMethod < Test::Unit::TestCase
def setup
Expand Down Expand Up @@ -76,7 +78,7 @@ def test_initialization_with_use_autocomplete_but_without_rdoc

IRB.conf[:USE_AUTOCOMPLETE] = true

without_rdoc do
IRB::TestHelper.without_rdoc do
IRB::RelineInputMethod.new
end

Expand Down

0 comments on commit cb95d83

Please sign in to comment.