Clean up spurious JSON decoding test failure

This commit is contained in:
Jeremy Kemper
2009-09-13 05:43:02 -07:00
parent 7d2add8c96
commit 053a0f6ac4
4 changed files with 7 additions and 16 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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)

View File

@@ -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