Skip to content

Commit ec64ecb

Browse files
committed
Avoid method redefinition warnings in test_broken_bignum
1 parent 6eb95b9 commit ec64ecb

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

test/json/json_generator_test.rb

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -493,20 +493,20 @@ 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
503-
end
504-
assert_raise(TypeError) do
505-
JSON::Ext::Generator::State.new.generate(bignum)
496+
def test_broken_bignum # [Bug #5173]
497+
bignum = 1 << 64
498+
original_to_s = bignum.class.instance_method(:to_s)
499+
bignum.class.class_eval do
500+
def to_s
501+
nil
506502
end
507-
ensure
508-
bignum.class.define_method(:to_s, original_to_s) if original_to_s
503+
alias_method :to_s, :to_s
504+
end
505+
assert_raise(TypeError) do
506+
JSON::Ext::Generator::State.new.generate(bignum)
509507
end
508+
ensure
509+
bignum.class.define_method(:to_s, original_to_s) if original_to_s
510510
end
511511

512512
def test_hash_likeness_set_symbol

0 commit comments

Comments
 (0)