1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[ruby/irb] Don't insert new methods to Test::Unit::TestCase

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.
This commit is contained in:
st0012 2022-10-26 12:40:48 +01:00 committed by Peter Zhu
parent 2022470a95
commit cb95d834cc
3 changed files with 22 additions and 2 deletions

View file

@ -3,6 +3,8 @@ require "test/unit"
require "irb" require "irb"
require "irb/extend-command" require "irb/extend-command"
require_relative "test_helper"
module TestIRB module TestIRB
class ExtendCommand < Test::Unit::TestCase class ExtendCommand < Test::Unit::TestCase
class TestInputMethod < ::IRB::InputMethod class TestInputMethod < ::IRB::InputMethod
@ -443,7 +445,7 @@ module TestIRB
irb = IRB::Irb.new(IRB::WorkSpace.new(self), input) irb = IRB::Irb.new(IRB::WorkSpace.new(self), input)
IRB.conf[:MAIN_CONTEXT] = irb.context IRB.conf[:MAIN_CONTEXT] = irb.context
out, err = capture_output do out, err = capture_output do
without_rdoc do IRB::TestHelper.without_rdoc do
irb.eval_input irb.eval_input
end end
end end

16
test/irb/test_helper.rb Normal file
View file

@ -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

View file

@ -3,6 +3,8 @@
require "test/unit" require "test/unit"
require "irb" require "irb"
require_relative "test_helper"
module TestIRB module TestIRB
class TestRelineInputMethod < Test::Unit::TestCase class TestRelineInputMethod < Test::Unit::TestCase
def setup def setup
@ -76,7 +78,7 @@ module TestIRB
IRB.conf[:USE_AUTOCOMPLETE] = true IRB.conf[:USE_AUTOCOMPLETE] = true
without_rdoc do IRB::TestHelper.without_rdoc do
IRB::RelineInputMethod.new IRB::RelineInputMethod.new
end end