Browse files

Allow the user to decide which json library to use by using MultiJson

  • Loading branch information...
1 parent 8f62027 commit 53baed9156228121c12299ea0b6d70f7c9f6eb69 @jeroenvandijk jeroenvandijk committed Aug 1, 2011
Showing with 7 additions and 5 deletions.
  1. +1 −1 json_spec.gemspec
  2. +5 −3 lib/json_spec/helpers.rb
  3. +1 −1 spec/json_spec/helpers_spec.rb
View
2 json_spec.gemspec
@@ -18,7 +18,7 @@ Gem::Specification.new do |s|
s.executables = `git ls-files -- bin/*`.split("\n").map{|f| File.basename(f) }
s.require_paths = ["lib"]
- s.add_dependency "json", "~> 1.0"
+ s.add_dependency "multi_json", "~> 1.0.0"
s.add_dependency "rspec", "~> 2.0"
s.add_development_dependency "rake", "~> 0.9"
View
8 lib/json_spec/helpers.rb
@@ -1,12 +1,14 @@
+require 'multi_json'
+
module JsonSpec
module Helpers
extend self
def parse_json(json, path = nil)
- ruby = JSON.parse(%([#{json}])).first
+ ruby = MultiJson.decode(%([#{json}])).first
value_at_json_path(ruby, path)
- rescue JSON::ParserError
- JSON.parse(json)
+ rescue MultiJson::DecodeError
+ MultiJson.decode(json)
end
def normalize_json(json, path = nil)
View
2 spec/json_spec/helpers_spec.rb
@@ -13,7 +13,7 @@
end
it "raises a parser error for invalid JSON" do
- expect{ parse_json("json_spec") }.to raise_error(JSON::ParserError)
+ expect{ parse_json("json_spec") }.to raise_error(MultiJson::DecodeError)
end
it "parses at a path if given" do

0 comments on commit 53baed9

Please sign in to comment.