Skip to content

Commit

Permalink
[rubygems/rubygems] Extract a helper to temporarily modify internal e…
Browse files Browse the repository at this point in the history
  • Loading branch information
deivid-rodriguez authored and matzbot committed Dec 15, 2021
1 parent 890a6b4 commit c2dbdf3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
9 changes: 9 additions & 0 deletions test/rubygems/helper.rb
Expand Up @@ -1300,6 +1300,15 @@ def with_clean_path_to_ruby
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
Expand Down
27 changes: 12 additions & 15 deletions test/rubygems/test_gem_specification.rb
Expand Up @@ -873,24 +873,21 @@ def test_self_load_escape_quote
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
Expand Down

0 comments on commit c2dbdf3

Please sign in to comment.