diff options
Diffstat (limited to 'test/irb/helper.rb')
-rw-r--r-- | test/irb/helper.rb | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/test/irb/helper.rb b/test/irb/helper.rb index 19c39a4a59..15d5dafc57 100644 --- a/test/irb/helper.rb +++ b/test/irb/helper.rb @@ -1,6 +1,22 @@ -module IRB - module TestHelper - def self.without_rdoc(&block) +require "test/unit" + +module TestIRB + class TestCase < Test::Unit::TestCase + def save_encodings + @default_encoding = [Encoding.default_external, Encoding.default_internal] + @stdio_encodings = [STDIN, STDOUT, STDERR].map {|io| [io.external_encoding, io.internal_encoding] } + end + + def restore_encodings + EnvUtil.suppress_warning do + Encoding.default_external, Encoding.default_internal = *@default_encoding + [STDIN, STDOUT, STDERR].zip(@stdio_encodings) do |io, encs| + io.set_encoding(*encs) + end + end + end + + def without_rdoc(&block) ::Kernel.send(:alias_method, :old_require, :require) ::Kernel.define_method(:require) do |name| |