Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip BigDecimal tests when it's missing to load #533

Merged
merged 1 commit into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/json/add/bigdecimal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
require 'json'
end
defined?(::BigDecimal) or require 'bigdecimal'
begin
require 'bigdecimal'
rescue LoadError
end

class BigDecimal
# Import a JSON Marshalled object.
Expand All @@ -26,4 +29,4 @@ def as_json(*)
def to_json(*args)
as_json.to_json(*args)
end
end
end if defined?(::BigDecimal)
2 changes: 1 addition & 1 deletion tests/json_addition_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def test_rational_complex
def test_bigdecimal
assert_equal BigDecimal('3.141', 23), JSON(JSON(BigDecimal('3.141', 23)), :create_additions => true)
assert_equal BigDecimal('3.141', 666), JSON(JSON(BigDecimal('3.141', 666)), :create_additions => true)
end
end if defined?(::BigDecimal)

def test_ostruct
o = OpenStruct.new
Expand Down
7 changes: 5 additions & 2 deletions tests/json_parser_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
require 'stringio'
require 'tempfile'
require 'ostruct'
require 'bigdecimal'
begin
require 'bigdecimal'
rescue LoadError
end

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

def test_parse_string_mixed_unicode
assert_equal(["éé"], JSON.parse("[\"\\u00e9é\"]"))
Expand Down