From 0e5700cfda77d5ccc25700d3c5a1fbe729d4eccd Mon Sep 17 00:00:00 2001 From: Earlopain <14981592+Earlopain@users.noreply.github.com> Date: Fri, 13 Feb 2026 10:32:32 +0100 Subject: [PATCH] Silence default_external warning in tests Some warnings appear in test output because of this pattern --- test/irb/helper.rb | 8 ++++++++ test/irb/test_completion.rb | 8 +------- test/irb/test_type_completor.rb | 8 +------- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/test/irb/helper.rb b/test/irb/helper.rb index 2c815bb7b..5555fc48c 100644 --- a/test/irb/helper.rb +++ b/test/irb/helper.rb @@ -76,6 +76,14 @@ def restore_encodings end end + def with_default_external(encoding) + original = Encoding.default_external + EnvUtil.suppress_warning { Encoding.default_external = encoding } + yield + ensure + EnvUtil.suppress_warning { Encoding.default_external = original } + end + def without_rdoc(&block) ::Kernel.send(:alias_method, :irb_original_require, :require) diff --git a/test/irb/test_completion.rb b/test/irb/test_completion.rb index 22db60375..1bb462736 100644 --- a/test/irb/test_completion.rb +++ b/test/irb/test_completion.rb @@ -327,11 +327,7 @@ def test_regexp_completor_handles_encoding_errors_gracefully test_obj.define_singleton_method(invalid_method_name) {} test_bind = test_obj.instance_eval { binding } - original_encoding = Encoding.default_external - - begin - Encoding.default_external = Encoding::UTF_8 - + with_default_external(Encoding::UTF_8) do completor = IRB::RegexpCompletor.new assert_nothing_raised do @@ -339,8 +335,6 @@ def test_regexp_completor_handles_encoding_errors_gracefully assert_include(result, 'block_given?') assert_not_include(result, nil) end - ensure - Encoding.default_external = original_encoding end end diff --git a/test/irb/test_type_completor.rb b/test/irb/test_type_completor.rb index 6389bf1f6..446be5ec4 100644 --- a/test/irb/test_type_completor.rb +++ b/test/irb/test_type_completor.rb @@ -88,18 +88,12 @@ def test_type_completor_handles_encoding_errors_gracefully test_obj.define_singleton_method(invalid_method_name) {} test_bind = test_obj.instance_eval { binding } - original_encoding = Encoding.default_external - - begin - Encoding.default_external = Encoding::UTF_8 - + with_default_external(Encoding::UTF_8) do assert_nothing_raised do result = @completor.completion_candidates('', 'b', '', bind: test_bind) assert_include(result, 'block_given?') assert_not_include(result, nil) end - ensure - Encoding.default_external = original_encoding end end end