Permalink
Browse files

Clean up spurious JSON decoding test failure

  • Loading branch information...
1 parent 7d2add8 commit 053a0f6ac48d35fd39d385df5d810078e92c521e @jeremy jeremy committed Sep 13, 2009
View
5 activesupport/lib/active_support/json/backends/jsongem.rb
@@ -2,10 +2,9 @@
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 @@ def convert_dates_from(data)
end
end
end
-end
+end
View
6 activesupport/lib/active_support/json/backends/yaml.rb
@@ -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
# Parses a JSON string or IO and converts it into an object
View
2 activesupport/lib/active_support/json/decoding.rb
@@ -7,6 +7,7 @@ module ActiveSupport
module JSON
class << self
+ attr_reader :parse_error
delegate :decode, :to => :backend
def backend
@@ -21,6 +22,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)
View
10 activesupport/test/json/decoding_test.rb
@@ -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

0 comments on commit 053a0f6

Please sign in to comment.