Skip to content
Browse files

Feature-detect MultiJson in order to avoid deprecation warnings for v…

…ersions < 1.3
  • Loading branch information...
1 parent d638ec3 commit 5052d19b61ff802f99e68e6c53e3e1b95341cead @laserlemon laserlemon committed Apr 22, 2012
Showing with 6 additions and 2 deletions.
  1. +6 −2 lib/json_spec/helpers.rb
View
8 lib/json_spec/helpers.rb
@@ -5,10 +5,10 @@ module Helpers
extend self
def parse_json(json, path = nil)
- ruby = MultiJson.load(%([#{json}])).first
+ ruby = multi_json_load("[#{json}]").first
value_at_json_path(ruby, path)
rescue MultiJson::DecodeError
- MultiJson.load(json)
+ multi_json_load(json)
end
def normalize_json(json, path = nil)
@@ -31,6 +31,10 @@ def load_json(relative_path)
end
private
+ def multi_json_load(json)
+ MultiJson.respond_to?(:load) ? MultiJson.load(json) : MultiJson.decode(json)
+ end
+
def value_at_json_path(ruby, path)
return ruby unless path

0 comments on commit 5052d19

Please sign in to comment.
Something went wrong with that request. Please try again.