mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Clean up spurious JSON decoding test failure
This commit is contained in:
@@ -2,10 +2,9 @@ require 'json' unless defined?(JSON)
|
||||
|
||||
module ActiveSupport
|
||||
module JSON
|
||||
ParseError = ::JSON::ParserError unless const_defined?(:ParseError)
|
||||
|
||||
module Backends
|
||||
module JSONGem
|
||||
ParseError = ::JSON::ParserError
|
||||
extend self
|
||||
|
||||
# Parses a JSON string or IO and convert it into an object
|
||||
@@ -38,4 +37,4 @@ module ActiveSupport
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2,13 +2,9 @@ require 'active_support/core_ext/string/starts_ends_with'
|
||||
|
||||
module ActiveSupport
|
||||
module JSON
|
||||
unless const_defined?(:ParseError)
|
||||
class ParseError < StandardError
|
||||
end
|
||||
end
|
||||
|
||||
module Backends
|
||||
module Yaml
|
||||
ParseError = ::StandardError
|
||||
extend self
|
||||
|
||||
# Parses a JSON string or IO and converts it into an object
|
||||
|
||||
@@ -7,6 +7,7 @@ module ActiveSupport
|
||||
|
||||
module JSON
|
||||
class << self
|
||||
attr_reader :parse_error
|
||||
delegate :decode, :to => :backend
|
||||
|
||||
def backend
|
||||
@@ -21,6 +22,7 @@ module ActiveSupport
|
||||
require "active_support/json/backends/#{name.to_s.downcase}.rb"
|
||||
@backend = ActiveSupport::JSON::Backends::const_get(name)
|
||||
end
|
||||
@parse_error = @backend::ParseError
|
||||
end
|
||||
|
||||
def with_backend(name)
|
||||
|
||||
@@ -47,13 +47,7 @@ class TestJSONDecoding < ActiveSupport::TestCase
|
||||
ActiveSupport::JSON.backend
|
||||
|
||||
backends = %w(Yaml)
|
||||
begin
|
||||
gem 'json', '>= 1.1'
|
||||
require 'json'
|
||||
backends << "JSONGem"
|
||||
rescue Gem::LoadError
|
||||
# Skip JSON gem tests
|
||||
end
|
||||
backends << "JSONGem" if defined?(::JSON)
|
||||
|
||||
backends.each do |backend|
|
||||
TESTS.each do |json, expected|
|
||||
@@ -81,7 +75,7 @@ class TestJSONDecoding < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
def test_failed_json_decoding
|
||||
assert_raise(ActiveSupport::JSON::ParseError) { ActiveSupport::JSON.decode(%({: 1})) }
|
||||
assert_raise(ActiveSupport::JSON.parse_error) { ActiveSupport::JSON.decode(%({: 1})) }
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user