Skip to content

Commit 742ec35

Browse files
byrootmatzbot
authored andcommitted
[ruby/json] Avoid method redefinition warnings in test_broken_bignum
ruby/json@d0b47b0011
1 parent 95b6f2c commit 742ec35

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

test/json/json_generator_test.rb

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -493,20 +493,27 @@ def foo.to_h
493493
assert_equal '2', state.indent
494494
end
495495

496-
if defined?(JSON::Ext::Generator) and RUBY_PLATFORM != "java"
497-
def test_broken_bignum # [ruby-core:38867]
498-
bignum = 1 << 64
499-
original_to_s = bignum.class.instance_method(:to_s)
500-
bignum.class.class_eval do
501-
def to_s
502-
end
496+
def test_broken_bignum # [Bug #5173]
497+
bignum = 1 << 64
498+
bignum_to_s = bignum.to_s
499+
500+
original_to_s = bignum.class.instance_method(:to_s)
501+
bignum.class.class_eval do
502+
def to_s
503+
nil
503504
end
505+
alias_method :to_s, :to_s
506+
end
507+
case RUBY_PLATFORM
508+
when "java"
509+
assert_equal bignum_to_s, JSON.generate(bignum)
510+
else
504511
assert_raise(TypeError) do
505-
JSON::Ext::Generator::State.new.generate(bignum)
512+
JSON.generate(bignum)
506513
end
507-
ensure
508-
bignum.class.define_method(:to_s, original_to_s) if original_to_s
509514
end
515+
ensure
516+
bignum.class.define_method(:to_s, original_to_s) if original_to_s
510517
end
511518

512519
def test_hash_likeness_set_symbol

0 commit comments

Comments
 (0)