[rubygems/rubygems] Extract a helper to temporarily modify internal encoding

https://github.com/rubygems/rubygems/commit/93051fd2aa
This commit is contained in:
David Rodríguez 2021-12-13 16:52:37 +01:00 коммит произвёл git
Родитель 890a6b432c
Коммит c2dbdf3067
2 изменённых файлов: 22 добавлений и 16 удалений

Просмотреть файл

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

Просмотреть файл

@ -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' }
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
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'))
spec = Gem::Specification.load full_path
spec2.files.clear
assert_equal spec2, spec
end
spec = Gem::Specification.load full_path
spec2.files.clear
assert_equal spec2, spec
ensure
silence_warnings { Encoding.default_internal = int_enc }
end
def test_self_load_legacy_ruby