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:
parent
2022470a95
commit
cb95d834cc
3 changed files with 22 additions and 2 deletions
|
@ -3,6 +3,8 @@ require "test/unit"
|
|||
require "irb"
|
||||
require "irb/extend-command"
|
||||
|
||||
require_relative "test_helper"
|
||||
|
||||
module TestIRB
|
||||
class ExtendCommand < Test::Unit::TestCase
|
||||
class TestInputMethod < ::IRB::InputMethod
|
||||
|
@ -443,7 +445,7 @@ module TestIRB
|
|||
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
|
||||
|
|
16
test/irb/test_helper.rb
Normal file
16
test/irb/test_helper.rb
Normal 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
|
|
@ -3,6 +3,8 @@
|
|||
require "test/unit"
|
||||
require "irb"
|
||||
|
||||
require_relative "test_helper"
|
||||
|
||||
module TestIRB
|
||||
class TestRelineInputMethod < Test::Unit::TestCase
|
||||
def setup
|
||||
|
@ -76,7 +78,7 @@ module TestIRB
|
|||
|
||||
IRB.conf[:USE_AUTOCOMPLETE] = true
|
||||
|
||||
without_rdoc do
|
||||
IRB::TestHelper.without_rdoc do
|
||||
IRB::RelineInputMethod.new
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue