diff options
author | David RodrÃguez <deivid.rodriguez@riseup.net> | 2021-12-13 16:52:37 +0100 |
---|---|---|
committer | git <svn-admin@ruby-lang.org> | 2021-12-15 19:46:43 +0900 |
commit | c2dbdf3067c334e22946fbda74181d3a94afbf97 (patch) | |
tree | ce7da35bde4074e4cbf3024539b8029152a7a52d | |
parent | 890a6b432c7f9b7e3160af31cedb440e53e2d79b (diff) |
[rubygems/rubygems] Extract a helper to temporarily modify internal encoding
https://github.com/rubygems/rubygems/commit/93051fd2aa
-rw-r--r-- | test/rubygems/helper.rb | 9 | ||||
-rw-r--r-- | test/rubygems/test_gem_specification.rb | 27 |
2 files changed, 21 insertions, 15 deletions
diff --git a/test/rubygems/helper.rb b/test/rubygems/helper.rb index b0ad5aafcd..f321b02e48 100644 --- a/test/rubygems/helper.rb +++ b/test/rubygems/helper.rb @@ -1300,6 +1300,15 @@ Also, a list: Gem.instance_variable_set :@ruby, orig_ruby end + def with_internal_encoding(encoding) + int_enc = Encoding.default_internal + silence_warnings { Encoding.default_internal = encoding } + + yield + ensure + silence_warnings { Encoding.default_internal = int_enc } + end + def silence_warnings old_verbose, $VERBOSE = $VERBOSE, false yield diff --git a/test/rubygems/test_gem_specification.rb b/test/rubygems/test_gem_specification.rb index 3062b66bc6..b1d925bb57 100644 --- a/test/rubygems/test_gem_specification.rb +++ b/test/rubygems/test_gem_specification.rb @@ -873,24 +873,21 @@ dependencies: [] end def test_self_load_utf8_with_ascii_encoding - int_enc = Encoding.default_internal - silence_warnings { Encoding.default_internal = 'US-ASCII' } - - spec2 = @a2.dup - bin = "\u5678".dup - spec2.authors = [bin] - full_path = spec2.spec_file - write_file full_path do |io| - io.write spec2.to_ruby_for_cache.force_encoding('BINARY').sub("\\u{5678}", bin.force_encoding('BINARY')) - end + with_internal_encoding('US-ASCII') do + spec2 = @a2.dup + bin = "\u5678".dup + spec2.authors = [bin] + full_path = spec2.spec_file + write_file full_path do |io| + io.write spec2.to_ruby_for_cache.force_encoding('BINARY').sub("\\u{5678}", bin.force_encoding('BINARY')) + end - spec = Gem::Specification.load full_path + spec = Gem::Specification.load full_path - spec2.files.clear + spec2.files.clear - assert_equal spec2, spec - ensure - silence_warnings { Encoding.default_internal = int_enc } + assert_equal spec2, spec + end end def test_self_load_legacy_ruby |