Skip to content

Commit 3dd36c6

Browse files
committed
Skip BigDecimal tests when it's missing to load
1 parent d88fea4 commit 3dd36c6

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

lib/json/add/bigdecimal.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
33
require 'json'
44
end
5-
defined?(::BigDecimal) or require 'bigdecimal'
5+
begin
6+
require 'bigdecimal'
7+
rescue LoadError
8+
end
69

710
class BigDecimal
811
# Import a JSON Marshalled object.
@@ -26,4 +29,4 @@ def as_json(*)
2629
def to_json(*args)
2730
as_json.to_json(*args)
2831
end
29-
end
32+
end if defined?(::BigDecimal)

tests/json_addition_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def test_rational_complex
183183
def test_bigdecimal
184184
assert_equal BigDecimal('3.141', 23), JSON(JSON(BigDecimal('3.141', 23)), :create_additions => true)
185185
assert_equal BigDecimal('3.141', 666), JSON(JSON(BigDecimal('3.141', 666)), :create_additions => true)
186-
end
186+
end if defined?(::BigDecimal)
187187

188188
def test_ostruct
189189
o = OpenStruct.new

tests/json_parser_test.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
require 'stringio'
55
require 'tempfile'
66
require 'ostruct'
7-
require 'bigdecimal'
7+
begin
8+
require 'bigdecimal'
9+
rescue LoadError
10+
end
811

912
class JSONParserTest < Test::Unit::TestCase
1013
include JSON
@@ -113,7 +116,7 @@ def test_parse_numbers
113116
def test_parse_bigdecimals
114117
assert_equal(BigDecimal, JSON.parse('{"foo": 9.01234567890123456789}', decimal_class: BigDecimal)["foo"].class)
115118
assert_equal(BigDecimal("0.901234567890123456789E1"),JSON.parse('{"foo": 9.01234567890123456789}', decimal_class: BigDecimal)["foo"] )
116-
end
119+
end if defined?(::BigDecimal)
117120

118121
def test_parse_string_mixed_unicode
119122
assert_equal(["éé"], JSON.parse("[\"\\u00e9é\"]"))

0 commit comments

Comments
 (0)