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

Backport ruby core #450

Merged
merged 10 commits into from
Nov 13, 2020
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ language: ruby

# Specify which ruby versions you wish to run your tests on, each version will be used
rvm:
- 2.0.0
- 2.1
- 2.2
- 2.3
Expand Down
1 change: 0 additions & 1 deletion lib/json/add/complex.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
require 'json'
end
defined?(::Complex) or require 'complex'

class Complex

Expand Down
1 change: 0 additions & 1 deletion lib/json/add/rational.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
require 'json'
end
defined?(::Rational) or require 'rational'

class Rational
# Deserializes JSON string by converting numerator value <tt>n</tt>,
Expand Down
27 changes: 7 additions & 20 deletions tests/json_common_interface_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,31 +152,18 @@ def test_load_file_with_option_shared(method_name)
temp_file_containing(@json) do |filespec|
parsed_object = JSON.public_send(method_name, filespec, symbolize_names: true)
key_classes = parsed_object.keys.map(&:class)
assert_true key_classes.include?(Symbol) && (! key_classes.include?(String))
assert_include(key_classes, Symbol)
assert_not_include(key_classes, String)
end
end

# Copied and slightly modified from https://github.com/keithrbennett/trick_bag
# (https://github.com/keithrbennett/trick_bag/blob/master/lib/trick_bag/io/temp_files.rb).
#
# For the easy creation and deletion of a temp file populated with text,
# wrapped around the code block you provide.
#
# @param text the text to write to the temporary file
# @param file_prefix optional prefix for the temporary file's name
# @yield filespec of the temporary file
def temp_file_containing(text, file_prefix = '')
raise "This method must be called with a code block." unless block_given?

filespec = nil
begin
Tempfile.open(file_prefix) do |file|
file << text
filespec = file.path
end
yield(filespec)
ensure
File.delete(filespec) if filespec && File.exist?(filespec)
end
Tempfile.create(file_prefix) do |file|
file << text
file.close
yield file.path
end
end
end
Empty file modified tests/json_generator_test.rb
100755 → 100644
Empty file.
6 changes: 3 additions & 3 deletions tests/json_parser_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,10 @@ def test_freeze
assert_predicate parse('{}', :freeze => true), :frozen?
assert_predicate parse('[]', :freeze => true), :frozen?
assert_predicate parse('"foo"', :freeze => true), :frozen?

if string_deduplication_available?
assert_same -'foo', parse('"foo"', :freeze => true)
assert_same -'foo', parse('{"foo": 1}', :freeze => true).keys.first
assert_same(-'foo', parse('"foo"', :freeze => true))
assert_same(-'foo', parse('{"foo": 1}', :freeze => true).keys.first)
end
end

Expand Down