Permalink
Browse files

Clean up spurious JSON decoding test failure

  • Loading branch information...
jeremy committed Sep 13, 2009
1 parent 09b197f commit abd7bd311ae9935bfba5657a4f7d5d637c830d62
@@ -2,10 +2,9 @@
module ActiveSupport
module JSON
- ParseError = ::JSON::ParserError unless const_defined?(:ParseError)
-
module Backends
module JSONGem
+ ParseError = ::JSON::ParserError
extend self
# Converts a JSON string into a Ruby object.
@@ -35,4 +34,4 @@ def convert_dates_from(data)
end
end
end
-end
+end
@@ -2,13 +2,9 @@
module ActiveSupport
module JSON
- unless const_defined?(:ParseError)
- class ParseError < StandardError
- end
- end
-
module Backends
module Yaml
+ ParseError = ::StandardError
extend self
# Converts a JSON string into a Ruby object.
@@ -6,6 +6,7 @@ module ActiveSupport
module JSON
class << self
+ attr_reader :parse_error
delegate :decode, :to => :backend
def backend
@@ -20,6 +21,7 @@ def backend=(name)
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)
@@ -39,13 +39,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|
@@ -73,7 +67,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

0 comments on commit abd7bd3

Please sign in to comment.