multi_json 1.10.1 → 1.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/CHANGELOG.md +6 -1
- data/lib/multi_json/adapter.rb +1 -0
- data/lib/multi_json/adapters/gson.rb +0 -1
- data/lib/multi_json/adapters/json_common.rb +0 -2
- data/lib/multi_json/adapters/nsjsonserialization.rb +0 -1
- data/lib/multi_json/adapters/ok_json.rb +0 -1
- data/lib/multi_json/version.rb +2 -2
- data/multi_json.gemspec +13 -15
- metadata +20 -51
- metadata.gz.sig +0 -0
- data/.document +0 -5
- data/.rspec +0 -2
- data/.travis.yml +0 -19
- data/.yardopts +0 -6
- data/Gemfile +0 -29
- data/Rakefile +0 -25
- data/spec/gson_adapter_spec.rb +0 -10
- data/spec/jr_jackson_adapter_spec.rb +0 -10
- data/spec/json_gem_adapter_spec.rb +0 -9
- data/spec/json_pure_adapter_spec.rb +0 -9
- data/spec/multi_json_spec.rb +0 -200
- data/spec/nsjsonserialization_adapter_spec.rb +0 -10
- data/spec/oj_adapter_spec.rb +0 -20
- data/spec/ok_json_adapter_spec.rb +0 -7
- data/spec/shared/adapter.rb +0 -236
- data/spec/shared/json_common_adapter.rb +0 -30
- data/spec/shared/options.rb +0 -119
- data/spec/spec_helper.rb +0 -77
- data/spec/yajl_adapter_spec.rb +0 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c98a15d47cdde07463c5cd6ee853d0eb6e17d27b
|
4
|
+
data.tar.gz: fe66e81cb3aaf716037b48e438c602cb405cb0d0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 853be4c2d237e50d0fc9156fe1f8cc4fadf19c55480aff5b02b7daca5cc7b08f923468291244f9706a40968d38fadaf44557af23a40aa0c232a84246dfffe220
|
7
|
+
data.tar.gz: b1851d3dc40055a6c8572dbc1eb0752e3dd7b97fb8519de0027b41413a9c1b6d68650df53927c86dfec9039a074505758421822d5a9f7b1866c82fac198c3cc2
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,12 @@
|
|
1
|
+
1.11.0
|
2
|
+
------
|
3
|
+
|
4
|
+
* [Make all adapters read IO object before load](https://github.com/intridea/multi_json/commit/167f559e18d4efee05e1f160a2661d16dbb215d4)
|
5
|
+
|
1
6
|
1.10.1
|
2
7
|
------
|
3
8
|
* [Explicitly require stringio for Gson adapter](https://github.com/intridea/multi_json/commit/623ec8142d4a212fa0db763bb71295789a119929)
|
4
|
-
* [Do not read
|
9
|
+
* [Do not read StringIO object before passing it to JrJackson](https://github.com/intridea/multi_json/commit/a6dc935df08e7b3d5d701fbb9298384c96df0fde)
|
5
10
|
|
6
11
|
1.10.0
|
7
12
|
------
|
data/lib/multi_json/adapter.rb
CHANGED
@@ -6,8 +6,6 @@ module MultiJson
|
|
6
6
|
defaults :load, :create_additions => false, :quirks_mode => true
|
7
7
|
|
8
8
|
def load(string, options={})
|
9
|
-
string = string.read if string.respond_to?(:read)
|
10
|
-
|
11
9
|
if string.respond_to?(:force_encoding)
|
12
10
|
string = string.dup.force_encoding(::Encoding::ASCII_8BIT)
|
13
11
|
end
|
@@ -7,7 +7,6 @@ module MultiJson
|
|
7
7
|
ParseError = ::MultiJson::OkJson::Error
|
8
8
|
|
9
9
|
def load(string, options={})
|
10
|
-
string = string.read if string.respond_to?(:read)
|
11
10
|
data = string.dataUsingEncoding(NSUTF8StringEncoding)
|
12
11
|
object = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingMutableContainers | NSJSONReadingMutableLeaves, error: nil)
|
13
12
|
if object
|
@@ -9,7 +9,6 @@ module MultiJson
|
|
9
9
|
ParseError = ::MultiJson::OkJson::Error
|
10
10
|
|
11
11
|
def load(string, options={})
|
12
|
-
string = string.read if string.respond_to?(:read)
|
13
12
|
result = ::MultiJson::OkJson.decode("[#{string}]").first
|
14
13
|
options[:symbolize_keys] ? symbolize_keys(result) : result
|
15
14
|
rescue ArgumentError # invalid byte sequence in UTF-8
|
data/lib/multi_json/version.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
module MultiJson
|
2
2
|
class Version
|
3
3
|
MAJOR = 1 unless defined? MultiJson::Version::MAJOR
|
4
|
-
MINOR =
|
5
|
-
PATCH =
|
4
|
+
MINOR = 11 unless defined? MultiJson::Version::MINOR
|
5
|
+
PATCH = 0 unless defined? MultiJson::Version::PATCH
|
6
6
|
PRE = nil unless defined? MultiJson::Version::PRE
|
7
7
|
|
8
8
|
class << self
|
data/multi_json.gemspec
CHANGED
@@ -1,22 +1,20 @@
|
|
1
1
|
# coding: utf-8
|
2
|
-
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'multi_json/version'
|
2
|
+
require File.expand_path("../lib/multi_json/version.rb", __FILE__)
|
5
3
|
|
6
4
|
Gem::Specification.new do |spec|
|
7
|
-
spec.add_development_dependency 'bundler', '~> 1.0'
|
8
5
|
spec.authors = ["Michael Bleigh", "Josh Kalderimis", "Erik Michaels-Ober", "Pavel Pravosud"]
|
9
|
-
spec.cert_chain = %w
|
10
|
-
spec.
|
11
|
-
spec.
|
12
|
-
spec.
|
13
|
-
spec.
|
14
|
-
spec.
|
15
|
-
spec.
|
16
|
-
spec.
|
17
|
-
spec.
|
6
|
+
spec.cert_chain = %w[certs/rwz.pem]
|
7
|
+
spec.summary = "A common interface to multiple JSON libraries."
|
8
|
+
spec.description = "A common interface to multiple JSON libraries, including Oj, Yajl, the JSON gem (with C-extensions), the pure-Ruby JSON gem, NSJSONSerialization, gson.rb, JrJackson, and OkJson."
|
9
|
+
spec.email = %w[michael@intridea.com josh.kalderimis@gmail.com sferik@gmail.com pavel@pravosud.com]
|
10
|
+
spec.files = Dir["CHANGELOG.md", "CONTRIBUTING.md", "LICENSE.md", "README.md", "multi_json.gemspec", "lib/**/*"]
|
11
|
+
spec.homepage = "http://github.com/intridea/multi_json"
|
12
|
+
spec.license = "MIT"
|
13
|
+
spec.name = "multi_json"
|
14
|
+
spec.require_path = "lib"
|
18
15
|
spec.signing_key = File.expand_path("~/.gem/private_key.pem") if $0 =~ /gem\z/
|
19
|
-
spec.summary = %q{A common interface to multiple JSON libraries.}
|
20
|
-
spec.test_files = Dir['spec/**/*']
|
21
16
|
spec.version = MultiJson::Version
|
17
|
+
|
18
|
+
spec.required_rubygems_version = ">= 1.3.5"
|
19
|
+
spec.add_development_dependency "bundler", "~> 1.0"
|
22
20
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: multi_json
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Bleigh
|
@@ -15,25 +15,25 @@ cert_chain:
|
|
15
15
|
-----BEGIN CERTIFICATE-----
|
16
16
|
MIIDcDCCAligAwIBAgIBATANBgkqhkiG9w0BAQUFADA/MQ4wDAYDVQQDDAVwYXZl
|
17
17
|
bDEYMBYGCgmSJomT8ixkARkWCHByYXZvc3VkMRMwEQYKCZImiZPyLGQBGRYDY29t
|
18
|
-
|
18
|
+
MB4XDTE1MDMwNDA0MTAzNVoXDTE2MDMwMzA0MTAzNVowPzEOMAwGA1UEAwwFcGF2
|
19
19
|
ZWwxGDAWBgoJkiaJk/IsZAEZFghwcmF2b3N1ZDETMBEGCgmSJomT8ixkARkWA2Nv
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
20
|
+
bTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAKgJODgg1dH3weeyKtQF
|
21
|
+
mhC3C8gleHSTZYAt1pMBZQ6QmRD7/kLIfLTJB/zgFUVoNoHVZ8qyFmx89reqk5Z4
|
22
|
+
x/rIVskzpB76MushyaEJhw5UrxEZvoCK0b+nSUR8NT0YcznkjSbALBBagny5NWHn
|
23
|
+
98LbVtIQYXdJTgC8xvV1u2Bix1JI/Qv1wuDKCw14XF2AFmT4nPt40FEUk4zWwbGI
|
24
|
+
rdKjssA43TGDjzKmzdOpJ4aOble+Zq6N7jBacMdlsqQAvQ0bbGLokp8W7Ci/UNWC
|
25
|
+
Q8DwDrjlbURMu729T70yuswrQHyxmh7SISMmjp44+C5ElwVbfcCQQxiwsdAcE3zD
|
26
|
+
ST0CAwEAAaN3MHUwCQYDVR0TBAIwADALBgNVHQ8EBAMCBLAwHQYDVR0OBBYEFJ7X
|
27
|
+
Ly29ycziHHerLL3NCavLRSv5MB0GA1UdEQQWMBSBEnBhdmVsQHByYXZvc3VkLmNv
|
28
28
|
bTAdBgNVHRIEFjAUgRJwYXZlbEBwcmF2b3N1ZC5jb20wDQYJKoZIhvcNAQEFBQAD
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
29
|
+
ggEBAJM/D4S0IHFerw9xcEKR2sehNn9deQKsS7auR3wAtxEitrPzKZb+8Uy3KVqP
|
30
|
+
Jt/z5WABxO2Bjd7IM+s445lZF6kDsGsYYydlEkf9yzOYrtVmISTJYrsApU8BZQfL
|
31
|
+
bWJg8zt1qjAKmmwULsCiYOfIGhUIhKVdVKrlkdXFFCB5v8R124FZXjo43WXZ2OCp
|
32
|
+
4W7nHEaaaZLxrPnZCAiaryoFUL06d78sxq9F4MYfSD4CLdwJjNb5TOrwVAXK9uE9
|
33
|
+
88AJhXqiqrY/cm2sh/xcGvGkhy9YOMyMZZrCAq4ruaXAB+tAkMrJ1paJDJRgErvJ
|
34
|
+
8Vss1khfU5E/Xig1ytdFyNPPkCA=
|
35
35
|
-----END CERTIFICATE-----
|
36
|
-
date:
|
36
|
+
date: 2015-03-04 00:00:00.000000000 Z
|
37
37
|
dependencies:
|
38
38
|
- !ruby/object:Gem::Dependency
|
39
39
|
name: bundler
|
@@ -56,20 +56,15 @@ email:
|
|
56
56
|
- michael@intridea.com
|
57
57
|
- josh.kalderimis@gmail.com
|
58
58
|
- sferik@gmail.com
|
59
|
+
- pavel@pravosud.com
|
59
60
|
executables: []
|
60
61
|
extensions: []
|
61
62
|
extra_rdoc_files: []
|
62
63
|
files:
|
63
|
-
- ".document"
|
64
|
-
- ".rspec"
|
65
|
-
- ".travis.yml"
|
66
|
-
- ".yardopts"
|
67
64
|
- CHANGELOG.md
|
68
65
|
- CONTRIBUTING.md
|
69
|
-
- Gemfile
|
70
66
|
- LICENSE.md
|
71
67
|
- README.md
|
72
|
-
- Rakefile
|
73
68
|
- lib/multi_json.rb
|
74
69
|
- lib/multi_json/adapter.rb
|
75
70
|
- lib/multi_json/adapter_error.rb
|
@@ -88,19 +83,6 @@ files:
|
|
88
83
|
- lib/multi_json/vendor/okjson.rb
|
89
84
|
- lib/multi_json/version.rb
|
90
85
|
- multi_json.gemspec
|
91
|
-
- spec/gson_adapter_spec.rb
|
92
|
-
- spec/jr_jackson_adapter_spec.rb
|
93
|
-
- spec/json_gem_adapter_spec.rb
|
94
|
-
- spec/json_pure_adapter_spec.rb
|
95
|
-
- spec/multi_json_spec.rb
|
96
|
-
- spec/nsjsonserialization_adapter_spec.rb
|
97
|
-
- spec/oj_adapter_spec.rb
|
98
|
-
- spec/ok_json_adapter_spec.rb
|
99
|
-
- spec/shared/adapter.rb
|
100
|
-
- spec/shared/json_common_adapter.rb
|
101
|
-
- spec/shared/options.rb
|
102
|
-
- spec/spec_helper.rb
|
103
|
-
- spec/yajl_adapter_spec.rb
|
104
86
|
homepage: http://github.com/intridea/multi_json
|
105
87
|
licenses:
|
106
88
|
- MIT
|
@@ -121,22 +103,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
121
103
|
version: 1.3.5
|
122
104
|
requirements: []
|
123
105
|
rubyforge_project:
|
124
|
-
rubygems_version: 2.
|
106
|
+
rubygems_version: 2.4.6
|
125
107
|
signing_key:
|
126
108
|
specification_version: 4
|
127
109
|
summary: A common interface to multiple JSON libraries.
|
128
|
-
test_files:
|
129
|
-
- spec/gson_adapter_spec.rb
|
130
|
-
- spec/jr_jackson_adapter_spec.rb
|
131
|
-
- spec/json_gem_adapter_spec.rb
|
132
|
-
- spec/json_pure_adapter_spec.rb
|
133
|
-
- spec/multi_json_spec.rb
|
134
|
-
- spec/nsjsonserialization_adapter_spec.rb
|
135
|
-
- spec/oj_adapter_spec.rb
|
136
|
-
- spec/ok_json_adapter_spec.rb
|
137
|
-
- spec/shared/adapter.rb
|
138
|
-
- spec/shared/json_common_adapter.rb
|
139
|
-
- spec/shared/options.rb
|
140
|
-
- spec/spec_helper.rb
|
141
|
-
- spec/yajl_adapter_spec.rb
|
110
|
+
test_files: []
|
142
111
|
has_rdoc:
|
metadata.gz.sig
CHANGED
Binary file
|
data/.document
DELETED
data/.rspec
DELETED
data/.travis.yml
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
bundler_args: --without development
|
2
|
-
language: ruby
|
3
|
-
rvm:
|
4
|
-
- 1.8.7-p374
|
5
|
-
- 1.9.2
|
6
|
-
- 1.9.3
|
7
|
-
- 2.0.0
|
8
|
-
- 2.1.1
|
9
|
-
- jruby-18mode
|
10
|
-
- jruby-19mode
|
11
|
-
- jruby-head
|
12
|
-
- rbx-2
|
13
|
-
- ruby-head
|
14
|
-
matrix:
|
15
|
-
allow_failures:
|
16
|
-
- rvm: rbx-2
|
17
|
-
- rvm: jruby-head
|
18
|
-
- rvm: ruby-head
|
19
|
-
fast_finish: true
|
data/.yardopts
DELETED
data/Gemfile
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
source 'https://rubygems.org'
|
2
|
-
|
3
|
-
gem 'rake', '>= 0.9'
|
4
|
-
gem 'yard', '>= 0.8'
|
5
|
-
|
6
|
-
gem 'json', '~> 1.4', :require => nil
|
7
|
-
gem 'json_pure', '~> 1.4', :require => nil
|
8
|
-
|
9
|
-
group :development do
|
10
|
-
gem 'kramdown', '>= 0.14'
|
11
|
-
gem 'pry'
|
12
|
-
gem 'pry-debugger', :platforms => :mri
|
13
|
-
end
|
14
|
-
|
15
|
-
group :test do
|
16
|
-
gem 'rspec', '>= 2.14'
|
17
|
-
end
|
18
|
-
|
19
|
-
platforms :jruby do
|
20
|
-
gem 'gson', '>= 0.6', :require => nil
|
21
|
-
gem 'jrjackson', '~> 0.2.2', :require => nil
|
22
|
-
end
|
23
|
-
|
24
|
-
platforms :mingw, :mswin, :ruby do
|
25
|
-
gem 'oj', '~> 2.9', :require => nil
|
26
|
-
gem 'yajl-ruby', '~> 1.0', :require => nil
|
27
|
-
end
|
28
|
-
|
29
|
-
gemspec
|
data/Rakefile
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
require 'bundler'
|
2
|
-
Bundler::GemHelper.install_tasks
|
3
|
-
|
4
|
-
require 'rspec/core/rake_task'
|
5
|
-
RSpec::Core::RakeTask.new(:base_spec) do |task|
|
6
|
-
task.pattern = 'spec/multi_json_spec.rb'
|
7
|
-
end
|
8
|
-
|
9
|
-
namespace :adapters do
|
10
|
-
Dir['spec/*_adapter_spec.rb'].each do |adapter_spec|
|
11
|
-
adapter_name = adapter_spec[/(\w+)_adapter_spec/, 1]
|
12
|
-
desc "Run #{adapter_name} adapter specs"
|
13
|
-
RSpec::Core::RakeTask.new(adapter_name) do |task|
|
14
|
-
task.pattern = adapter_spec
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
task :spec => %w[base_spec adapters:oj adapters:yajl adapters:json_gem adapters:json_pure adapters:ok_json adapters:gson adapters:jr_jackson adapters:nsjsonserialization]
|
20
|
-
|
21
|
-
task :default => :spec
|
22
|
-
task :test => :spec
|
23
|
-
|
24
|
-
require 'yard'
|
25
|
-
YARD::Rake::YardocTask.new
|
data/spec/gson_adapter_spec.rb
DELETED
@@ -1,9 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'shared/adapter'
|
3
|
-
require 'shared/json_common_adapter'
|
4
|
-
require 'multi_json/adapters/json_gem'
|
5
|
-
|
6
|
-
describe MultiJson::Adapters::JsonGem do
|
7
|
-
it_behaves_like 'an adapter', described_class
|
8
|
-
it_behaves_like 'JSON-like adapter', described_class
|
9
|
-
end
|
@@ -1,9 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'shared/adapter'
|
3
|
-
require 'shared/json_common_adapter'
|
4
|
-
require 'multi_json/adapters/json_pure'
|
5
|
-
|
6
|
-
describe MultiJson::Adapters::JsonPure do
|
7
|
-
it_behaves_like 'an adapter', described_class
|
8
|
-
it_behaves_like 'JSON-like adapter', described_class
|
9
|
-
end
|
data/spec/multi_json_spec.rb
DELETED
@@ -1,200 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'shared/options'
|
3
|
-
|
4
|
-
describe MultiJson do
|
5
|
-
before(:all) do
|
6
|
-
# make sure all available libs are required
|
7
|
-
MultiJson::REQUIREMENT_MAP.each do |library, adapter|
|
8
|
-
begin
|
9
|
-
require library
|
10
|
-
rescue ::LoadError
|
11
|
-
next
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
context 'when no other json implementations are available' do
|
17
|
-
around do |example|
|
18
|
-
simulate_no_adapters{ example.call }
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'defaults to ok_json if no other json implementions are available' do
|
22
|
-
silence_warnings do
|
23
|
-
expect(MultiJson.default_adapter).to eq(:ok_json)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'prints a warning' do
|
28
|
-
expect(Kernel).to receive(:warn).with(/warning/i)
|
29
|
-
MultiJson.default_adapter
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
context 'caching' do
|
34
|
-
before{ MultiJson.use adapter }
|
35
|
-
let(:adapter){ MultiJson::Adapters::JsonGem }
|
36
|
-
let(:json_string){ '{"abc":"def"}' }
|
37
|
-
|
38
|
-
it 'busts caches on global options change' do
|
39
|
-
MultiJson.load_options = { :symbolize_keys => true }
|
40
|
-
expect(MultiJson.load(json_string)).to eq(:abc => 'def')
|
41
|
-
MultiJson.load_options = nil
|
42
|
-
expect(MultiJson.load(json_string)).to eq('abc' => 'def')
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'busts caches on per-adapter options change' do
|
46
|
-
adapter.load_options = { :symbolize_keys => true }
|
47
|
-
expect(MultiJson.load(json_string)).to eq(:abc => 'def')
|
48
|
-
adapter.load_options = nil
|
49
|
-
expect(MultiJson.load(json_string)).to eq('abc' => 'def')
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
it 'defaults to the best available gem' do
|
54
|
-
# Clear cache variable already set by previous tests
|
55
|
-
MultiJson.send(:remove_instance_variable, :@adapter) if MultiJson.instance_variable_defined?(:@adapter)
|
56
|
-
|
57
|
-
if jruby?
|
58
|
-
expect(MultiJson.adapter.to_s).to eq('MultiJson::Adapters::JrJackson')
|
59
|
-
else
|
60
|
-
expect(MultiJson.adapter.to_s).to eq('MultiJson::Adapters::Oj')
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
it 'looks for adapter even if @adapter variable is nil' do
|
65
|
-
MultiJson.send(:instance_variable_set, :@adapter, nil)
|
66
|
-
expect(MultiJson).to receive(:default_adapter).and_return(:ok_json)
|
67
|
-
expect(MultiJson.adapter).to eq(MultiJson::Adapters::OkJson)
|
68
|
-
end
|
69
|
-
|
70
|
-
it 'is settable via a symbol' do
|
71
|
-
MultiJson.use :json_gem
|
72
|
-
expect(MultiJson.adapter).to eq(MultiJson::Adapters::JsonGem)
|
73
|
-
end
|
74
|
-
|
75
|
-
it 'is settable via a case-insensitive string' do
|
76
|
-
MultiJson.use 'Json_Gem'
|
77
|
-
expect(MultiJson.adapter).to eq(MultiJson::Adapters::JsonGem)
|
78
|
-
end
|
79
|
-
|
80
|
-
it 'is settable via a class' do
|
81
|
-
adapter = Class.new
|
82
|
-
MultiJson.use adapter
|
83
|
-
expect(MultiJson.adapter).to eq(adapter)
|
84
|
-
end
|
85
|
-
|
86
|
-
it 'is settable via a module' do
|
87
|
-
adapter = Module.new
|
88
|
-
MultiJson.use adapter
|
89
|
-
expect(MultiJson.adapter).to eq(adapter)
|
90
|
-
end
|
91
|
-
|
92
|
-
it 'throws AdapterError on bad input' do
|
93
|
-
expect{ MultiJson.use 'bad adapter' }.to raise_error(MultiJson::AdapterError, /bad adapter/)
|
94
|
-
end
|
95
|
-
|
96
|
-
it 'gives access to original error when raising AdapterError' do
|
97
|
-
exception = get_exception(MultiJson::AdapterError){ MultiJson.use 'foobar' }
|
98
|
-
expect(exception.cause).to be_instance_of(::LoadError)
|
99
|
-
expect(exception.message).to include("-- multi_json/adapters/foobar")
|
100
|
-
expect(exception.message).to include("Did not recognize your adapter specification")
|
101
|
-
end
|
102
|
-
|
103
|
-
context 'using one-shot parser' do
|
104
|
-
before do
|
105
|
-
expect(MultiJson::Adapters::JsonPure).to receive(:dump).once.and_return('dump_something')
|
106
|
-
expect(MultiJson::Adapters::JsonPure).to receive(:load).once.and_return('load_something')
|
107
|
-
end
|
108
|
-
|
109
|
-
it 'should use the defined parser just for the call' do
|
110
|
-
MultiJson.use :json_gem
|
111
|
-
expect(MultiJson.dump('', :adapter => :json_pure)).to eq('dump_something')
|
112
|
-
expect(MultiJson.load('', :adapter => :json_pure)).to eq('load_something')
|
113
|
-
expect(MultiJson.adapter).to eq(MultiJson::Adapters::JsonGem)
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
it 'can set adapter for a block' do
|
118
|
-
MultiJson.use :ok_json
|
119
|
-
MultiJson.with_adapter(:json_pure) do
|
120
|
-
MultiJson.with_engine(:json_gem) do
|
121
|
-
expect(MultiJson.adapter).to eq(MultiJson::Adapters::JsonGem)
|
122
|
-
end
|
123
|
-
expect(MultiJson.adapter).to eq(MultiJson::Adapters::JsonPure)
|
124
|
-
end
|
125
|
-
expect(MultiJson.adapter).to eq(MultiJson::Adapters::OkJson)
|
126
|
-
end
|
127
|
-
|
128
|
-
it 'JSON gem does not create symbols on parse' do
|
129
|
-
MultiJson.with_engine(:json_gem) do
|
130
|
-
MultiJson.load('{"json_class":"ZOMG"}') rescue nil
|
131
|
-
|
132
|
-
expect{
|
133
|
-
MultiJson.load('{"json_class":"OMG"}') rescue nil
|
134
|
-
}.to_not change{Symbol.all_symbols.count}
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
unless jruby?
|
139
|
-
it 'Oj does not create symbols on parse' do
|
140
|
-
MultiJson.with_engine(:oj) do
|
141
|
-
MultiJson.load('{"json_class":"ZOMG"}') rescue nil
|
142
|
-
|
143
|
-
expect{
|
144
|
-
MultiJson.load('{"json_class":"OMG"}') rescue nil
|
145
|
-
}.to_not change{Symbol.all_symbols.count}
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
context 'with Oj.default_settings' do
|
150
|
-
around do |example|
|
151
|
-
options = Oj.default_options
|
152
|
-
Oj.default_options = { :symbol_keys => true }
|
153
|
-
MultiJson.with_engine(:oj){ example.call }
|
154
|
-
Oj.default_options = options
|
155
|
-
end
|
156
|
-
|
157
|
-
it 'ignores global settings' do
|
158
|
-
MultiJson.with_engine(:oj) do
|
159
|
-
example = '{"a": 1, "b": 2}'
|
160
|
-
expected = { 'a' => 1, 'b' => 2 }
|
161
|
-
expect(MultiJson.load(example)).to eq(expected)
|
162
|
-
end
|
163
|
-
end
|
164
|
-
end
|
165
|
-
end
|
166
|
-
|
167
|
-
describe 'default options' do
|
168
|
-
after(:all){ MultiJson.load_options = MultiJson.dump_options = nil }
|
169
|
-
|
170
|
-
it 'is deprecated' do
|
171
|
-
expect(Kernel).to receive(:warn).with(/deprecated/i)
|
172
|
-
silence_warnings{ MultiJson.default_options = {:foo => 'bar'} }
|
173
|
-
end
|
174
|
-
|
175
|
-
it 'sets both load and dump options' do
|
176
|
-
expect(MultiJson).to receive(:dump_options=).with(:foo => 'bar')
|
177
|
-
expect(MultiJson).to receive(:load_options=).with(:foo => 'bar')
|
178
|
-
silence_warnings{ MultiJson.default_options = {:foo => 'bar'} }
|
179
|
-
end
|
180
|
-
end
|
181
|
-
|
182
|
-
it_behaves_like 'has options', MultiJson
|
183
|
-
|
184
|
-
describe 'aliases' do
|
185
|
-
if jruby?
|
186
|
-
describe 'jrjackson' do
|
187
|
-
after{ expect(MultiJson.adapter).to eq(MultiJson::Adapters::JrJackson) }
|
188
|
-
|
189
|
-
it 'allows jrjackson alias as symbol' do
|
190
|
-
expect{ MultiJson.use :jrjackson }.not_to raise_error
|
191
|
-
end
|
192
|
-
|
193
|
-
it 'allows jrjackson alias as string' do
|
194
|
-
expect{ MultiJson.use 'jrjackson' }.not_to raise_error
|
195
|
-
end
|
196
|
-
|
197
|
-
end
|
198
|
-
end
|
199
|
-
end
|
200
|
-
end
|
data/spec/oj_adapter_spec.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
exit true if jruby?
|
4
|
-
|
5
|
-
require 'shared/adapter'
|
6
|
-
require 'multi_json/adapters/oj'
|
7
|
-
|
8
|
-
describe MultiJson::Adapters::Oj do
|
9
|
-
it_behaves_like 'an adapter', described_class
|
10
|
-
|
11
|
-
describe '.dump' do
|
12
|
-
describe '#dump_options' do
|
13
|
-
around{ |example| with_default_options(&example) }
|
14
|
-
|
15
|
-
it 'ensures indent is a Fixnum' do
|
16
|
-
expect{ MultiJson.dump(42, :indent => '')}.not_to raise_error
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
data/spec/shared/adapter.rb
DELETED
@@ -1,236 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require 'shared/options'
|
4
|
-
|
5
|
-
shared_examples_for 'an adapter' do |adapter|
|
6
|
-
|
7
|
-
before{ MultiJson.use adapter }
|
8
|
-
|
9
|
-
it_behaves_like 'has options', adapter
|
10
|
-
|
11
|
-
it 'does not modify argument hashes' do
|
12
|
-
options = { :symbolize_keys => true, :pretty => false, :adapter => :ok_json }
|
13
|
-
expect{MultiJson.load('{}', options)}.to_not change{options}
|
14
|
-
expect{MultiJson.dump([42], options)}.to_not change{options}
|
15
|
-
end
|
16
|
-
|
17
|
-
describe '.dump' do
|
18
|
-
describe '#dump_options' do
|
19
|
-
before{ MultiJson.dump_options = MultiJson.adapter.dump_options = {} }
|
20
|
-
|
21
|
-
after do
|
22
|
-
expect(MultiJson.adapter.instance).to receive(:dump).with(1, :foo => 'bar', :fizz => 'buzz')
|
23
|
-
MultiJson.dump(1, :fizz => 'buzz')
|
24
|
-
MultiJson.dump_options = MultiJson.adapter.dump_options = nil
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'respects global dump options' do
|
28
|
-
MultiJson.dump_options = {:foo => 'bar'}
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'respects per-adapter dump options' do
|
32
|
-
MultiJson.adapter.dump_options = {:foo => 'bar'}
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'adapter-specific are overridden by global options' do
|
36
|
-
MultiJson.adapter.dump_options = {:foo => 'foo'}
|
37
|
-
MultiJson.dump_options = {:foo => 'bar'}
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'writes decodable JSON' do
|
42
|
-
[
|
43
|
-
{'abc' => 'def'},
|
44
|
-
[1, 2, 3, '4', true, false, nil]
|
45
|
-
].each do |example|
|
46
|
-
expect(MultiJson.load(MultiJson.dump(example))).to eq(example)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
unless 'json_pure' == adapter || 'json_gem' == adapter
|
51
|
-
it 'dumps time in correct format' do
|
52
|
-
time = Time.at(1355218745).utc
|
53
|
-
|
54
|
-
dumped_json = MultiJson.dump(time)
|
55
|
-
expected = if RUBY_VERSION > '1.9'
|
56
|
-
'2012-12-11 09:39:05 UTC'
|
57
|
-
else
|
58
|
-
'Tue Dec 11 09:39:05 UTC 2012'
|
59
|
-
end
|
60
|
-
expect(MultiJson.load(dumped_json)).to eq(expected)
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
it 'dumps symbol and fixnum keys as strings' do
|
65
|
-
[
|
66
|
-
[
|
67
|
-
{:foo => {:bar => 'baz'}},
|
68
|
-
{'foo' => {'bar' => 'baz'}},
|
69
|
-
],
|
70
|
-
[
|
71
|
-
[{:foo => {:bar => 'baz'}}],
|
72
|
-
[{'foo' => {'bar' => 'baz'}}],
|
73
|
-
],
|
74
|
-
[
|
75
|
-
{:foo => [{:bar => 'baz'}]},
|
76
|
-
{'foo' => [{'bar' => 'baz'}]},
|
77
|
-
],
|
78
|
-
[
|
79
|
-
{1 => {2 => {3 => 'bar'}}},
|
80
|
-
{'1' => {'2' => {'3' => 'bar'}}}
|
81
|
-
]
|
82
|
-
].each do |example, expected|
|
83
|
-
dumped_json = MultiJson.dump(example)
|
84
|
-
expect(MultiJson.load(dumped_json)).to eq(expected)
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
it 'dumps rootless JSON' do
|
89
|
-
expect(MultiJson.dump('random rootless string')).to eq('"random rootless string"')
|
90
|
-
expect(MultiJson.dump(123)).to eq('123')
|
91
|
-
end
|
92
|
-
|
93
|
-
it 'passes options to the adapter' do
|
94
|
-
expect(MultiJson.adapter).to receive(:dump).with('foo', {:bar => :baz})
|
95
|
-
MultiJson.dump('foo', :bar => :baz)
|
96
|
-
end
|
97
|
-
|
98
|
-
it 'dumps custom objects that implement to_json' do
|
99
|
-
pending 'not supported' if adapter.name == 'MultiJson::Adapters::Gson'
|
100
|
-
klass = Class.new do
|
101
|
-
def to_json(*)
|
102
|
-
'"foobar"'
|
103
|
-
end
|
104
|
-
end
|
105
|
-
expect(MultiJson.dump(klass.new)).to eq('"foobar"')
|
106
|
-
end
|
107
|
-
|
108
|
-
it 'allows to dump JSON values' do
|
109
|
-
expect(MultiJson.dump(42)).to eq('42')
|
110
|
-
end
|
111
|
-
|
112
|
-
it 'allows to dump JSON with UTF-8 characters' do
|
113
|
-
expect(MultiJson.dump('color' => 'żółć')).to eq('{"color":"żółć"}')
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
describe '.load' do
|
118
|
-
describe '#load_options' do
|
119
|
-
before{ MultiJson.load_options = MultiJson.adapter.load_options = {} }
|
120
|
-
|
121
|
-
after do
|
122
|
-
expect(MultiJson.adapter.instance).to receive(:load).with('1', :foo => 'bar', :fizz => 'buzz')
|
123
|
-
MultiJson.load('1', :fizz => 'buzz')
|
124
|
-
MultiJson.load_options = MultiJson.adapter.load_options = nil
|
125
|
-
end
|
126
|
-
|
127
|
-
it 'respects global load options' do
|
128
|
-
MultiJson.load_options = {:foo => 'bar'}
|
129
|
-
end
|
130
|
-
|
131
|
-
it 'respects per-adapter load options' do
|
132
|
-
MultiJson.adapter.load_options = {:foo => 'bar'}
|
133
|
-
end
|
134
|
-
|
135
|
-
it 'adapter-specific are overridden by global options' do
|
136
|
-
MultiJson.adapter.load_options = {:foo => 'foo'}
|
137
|
-
MultiJson.load_options = {:foo => 'bar'}
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
it 'does not modify input' do
|
142
|
-
input = %Q{\n\n {"foo":"bar"} \n\n\t}
|
143
|
-
expect{
|
144
|
-
MultiJson.load(input)
|
145
|
-
}.to_not change{ input }
|
146
|
-
end
|
147
|
-
|
148
|
-
# Ruby 1.8 doesn't support String encodings
|
149
|
-
if RUBY_VERSION > '1.9'
|
150
|
-
it 'does not modify input encoding' do
|
151
|
-
|
152
|
-
input = '[123]'
|
153
|
-
input.force_encoding('iso-8859-1')
|
154
|
-
|
155
|
-
expect{
|
156
|
-
MultiJson.load(input)
|
157
|
-
}.to_not change{ input.encoding }
|
158
|
-
end
|
159
|
-
end
|
160
|
-
|
161
|
-
it 'properly loads valid JSON' do
|
162
|
-
expect(MultiJson.load('{"abc":"def"}')).to eq('abc' => 'def')
|
163
|
-
end
|
164
|
-
|
165
|
-
it 'raises MultiJson::ParseError on blank input or invalid input' do
|
166
|
-
[nil, '{"abc"}', ' ', "\t\t\t", "\n", "\x82\xAC\xEF"].each do |input|
|
167
|
-
if input == "\x82\xAC\xEF"
|
168
|
-
pending 'GSON bug: https://github.com/avsej/gson.rb/issues/3' if adapter.name =~ /Gson/
|
169
|
-
pending 'JrJackson bug: https://github.com/guyboertje/jrjackson/issues/21' if adapter.name =~ /JrJackson/
|
170
|
-
end
|
171
|
-
|
172
|
-
expect{MultiJson.load(input)}.to raise_error(MultiJson::ParseError)
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
it 'raises MultiJson::ParseError with data on invalid JSON' do
|
177
|
-
data = '{invalid}'
|
178
|
-
exception = get_exception(MultiJson::ParseError){ MultiJson.load data }
|
179
|
-
expect(exception.data).to eq(data)
|
180
|
-
expect(exception.cause).to be_kind_of(MultiJson.adapter::ParseError)
|
181
|
-
end
|
182
|
-
|
183
|
-
it 'catches MultiJson::DecodeError for legacy support' do
|
184
|
-
data = '{invalid}'
|
185
|
-
exception = get_exception(MultiJson::DecodeError){ MultiJson.load data }
|
186
|
-
expect(exception.data).to eq(data)
|
187
|
-
expect(exception.cause).to be_kind_of(MultiJson.adapter::ParseError)
|
188
|
-
end
|
189
|
-
|
190
|
-
it 'catches MultiJson::LoadError for legacy support' do
|
191
|
-
data = '{invalid}'
|
192
|
-
exception = get_exception(MultiJson::LoadError){ MultiJson.load data }
|
193
|
-
expect(exception.data).to eq(data)
|
194
|
-
expect(exception.cause).to be_kind_of(MultiJson.adapter::ParseError)
|
195
|
-
end
|
196
|
-
|
197
|
-
|
198
|
-
it 'stringifys symbol keys when encoding' do
|
199
|
-
dumped_json = MultiJson.dump(:a => 1, :b => {:c => 2})
|
200
|
-
loaded_json = MultiJson.load(dumped_json)
|
201
|
-
expect(loaded_json).to eq('a' => 1, 'b' => {'c' => 2})
|
202
|
-
end
|
203
|
-
|
204
|
-
it 'properly loads valid JSON in StringIOs' do
|
205
|
-
json = StringIO.new('{"abc":"def"}')
|
206
|
-
expect(MultiJson.load(json)).to eq('abc' => 'def')
|
207
|
-
end
|
208
|
-
|
209
|
-
it 'allows for symbolization of keys' do
|
210
|
-
[
|
211
|
-
[
|
212
|
-
'{"abc":{"def":"hgi"}}',
|
213
|
-
{:abc => {:def => 'hgi'}},
|
214
|
-
],
|
215
|
-
[
|
216
|
-
'[{"abc":{"def":"hgi"}}]',
|
217
|
-
[{:abc => {:def => 'hgi'}}],
|
218
|
-
],
|
219
|
-
[
|
220
|
-
'{"abc":[{"def":"hgi"}]}',
|
221
|
-
{:abc => [{:def => 'hgi'}]},
|
222
|
-
]
|
223
|
-
].each do |example, expected|
|
224
|
-
expect(MultiJson.load(example, :symbolize_keys => true)).to eq(expected)
|
225
|
-
end
|
226
|
-
end
|
227
|
-
|
228
|
-
it 'allows to load JSON values' do
|
229
|
-
expect(MultiJson.load('42')).to eq(42)
|
230
|
-
end
|
231
|
-
|
232
|
-
it 'allows to load JSON with UTF-8 characters' do
|
233
|
-
expect(MultiJson.load('{"color":"żółć"}')).to eq('color' => 'żółć')
|
234
|
-
end
|
235
|
-
end
|
236
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
shared_examples_for 'JSON-like adapter' do |adapter|
|
2
|
-
before{ MultiJson.use adapter }
|
3
|
-
|
4
|
-
describe '.dump' do
|
5
|
-
before{ MultiJson.dump_options = MultiJson.adapter.dump_options = nil }
|
6
|
-
|
7
|
-
describe 'with :pretty option set to true' do
|
8
|
-
it 'passes default pretty options' do
|
9
|
-
object = 'foo'
|
10
|
-
expect(object).to receive(:to_json).with(JSON::PRETTY_STATE_PROTOTYPE.to_h)
|
11
|
-
MultiJson.dump(object, :pretty => true)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
describe 'with :indent option' do
|
16
|
-
it 'passes it on dump' do
|
17
|
-
object = 'foo'
|
18
|
-
expect(object).to receive(:to_json).with(:indent => "\t")
|
19
|
-
MultiJson.dump(object, :indent => "\t")
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
describe '.load' do
|
25
|
-
it 'passes :quirks_mode option' do
|
26
|
-
expect(::JSON).to receive(:parse).with('[123]', {:quirks_mode => false, :create_additions => false})
|
27
|
-
MultiJson.load('[123]', :quirks_mode => false)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
data/spec/shared/options.rb
DELETED
@@ -1,119 +0,0 @@
|
|
1
|
-
shared_examples_for 'has options' do |object|
|
2
|
-
|
3
|
-
if object.respond_to?(:call)
|
4
|
-
subject{ object.call }
|
5
|
-
else
|
6
|
-
subject{ object }
|
7
|
-
end
|
8
|
-
|
9
|
-
describe "dump options" do
|
10
|
-
|
11
|
-
before do
|
12
|
-
subject.dump_options = nil
|
13
|
-
end
|
14
|
-
|
15
|
-
after do
|
16
|
-
subject.dump_options = nil
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'returns default options if not set' do
|
20
|
-
expect(subject.dump_options).to eq(subject.default_dump_options)
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'allows hashes' do
|
24
|
-
subject.dump_options = {:foo => 'bar'}
|
25
|
-
expect(subject.dump_options).to eq(:foo => 'bar')
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'allows objects that implement #to_hash' do
|
29
|
-
value = Class.new do
|
30
|
-
def to_hash
|
31
|
-
{:foo => 'bar'}
|
32
|
-
end
|
33
|
-
end.new
|
34
|
-
|
35
|
-
subject.dump_options = value
|
36
|
-
expect(subject.dump_options).to eq(:foo => 'bar')
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'evaluates lambda returning options (with args)' do
|
40
|
-
subject.dump_options = lambda{ |a1, a2| { a1 => a2 }}
|
41
|
-
expect(subject.dump_options('1', '2')).to eq('1' => '2')
|
42
|
-
end
|
43
|
-
|
44
|
-
it 'evaluates lambda returning options (with no args)' do
|
45
|
-
subject.dump_options = lambda{{:foo => 'bar'}}
|
46
|
-
expect(subject.dump_options).to eq(:foo => 'bar')
|
47
|
-
end
|
48
|
-
|
49
|
-
it 'returns empty hash in all other cases' do
|
50
|
-
subject.dump_options = true
|
51
|
-
expect(subject.dump_options).to eq(subject.default_dump_options)
|
52
|
-
|
53
|
-
subject.dump_options = false
|
54
|
-
expect(subject.dump_options).to eq(subject.default_dump_options)
|
55
|
-
|
56
|
-
subject.dump_options = 10
|
57
|
-
expect(subject.dump_options).to eq(subject.default_dump_options)
|
58
|
-
|
59
|
-
subject.dump_options = nil
|
60
|
-
expect(subject.dump_options).to eq(subject.default_dump_options)
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
describe "load options" do
|
65
|
-
|
66
|
-
before do
|
67
|
-
subject.load_options = nil
|
68
|
-
end
|
69
|
-
|
70
|
-
after do
|
71
|
-
subject.load_options = nil
|
72
|
-
end
|
73
|
-
|
74
|
-
it 'returns default options if not set' do
|
75
|
-
expect(subject.load_options).to eq(subject.default_load_options)
|
76
|
-
end
|
77
|
-
|
78
|
-
it 'allows hashes' do
|
79
|
-
subject.load_options = {:foo => 'bar'}
|
80
|
-
expect(subject.load_options).to eq(:foo => 'bar')
|
81
|
-
end
|
82
|
-
|
83
|
-
it 'allows objects that implement #to_hash' do
|
84
|
-
value = Class.new do
|
85
|
-
def to_hash
|
86
|
-
{:foo => 'bar'}
|
87
|
-
end
|
88
|
-
end.new
|
89
|
-
|
90
|
-
subject.load_options = value
|
91
|
-
expect(subject.load_options).to eq(:foo => 'bar')
|
92
|
-
end
|
93
|
-
|
94
|
-
it 'evaluates lambda returning options (with args)' do
|
95
|
-
subject.load_options = lambda{ |a1, a2| { a1 => a2 }}
|
96
|
-
expect(subject.load_options('1', '2')).to eq('1' => '2')
|
97
|
-
end
|
98
|
-
|
99
|
-
it 'evaluates lambda returning options (with no args)' do
|
100
|
-
subject.load_options = lambda{{:foo => 'bar'}}
|
101
|
-
expect(subject.load_options).to eq(:foo => 'bar')
|
102
|
-
end
|
103
|
-
|
104
|
-
it 'returns empty hash in all other cases' do
|
105
|
-
subject.load_options = true
|
106
|
-
expect(subject.load_options).to eq(subject.default_load_options)
|
107
|
-
|
108
|
-
subject.load_options = false
|
109
|
-
expect(subject.load_options).to eq(subject.default_load_options)
|
110
|
-
|
111
|
-
subject.load_options = 10
|
112
|
-
expect(subject.load_options).to eq(subject.default_load_options)
|
113
|
-
|
114
|
-
subject.load_options = nil
|
115
|
-
expect(subject.load_options).to eq(subject.default_load_options)
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,77 +0,0 @@
|
|
1
|
-
require 'multi_json'
|
2
|
-
require 'rspec'
|
3
|
-
|
4
|
-
RSpec.configure do |config|
|
5
|
-
config.expect_with :rspec do |c|
|
6
|
-
c.syntax = :expect
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
def silence_warnings
|
11
|
-
old_verbose, $VERBOSE = $VERBOSE, nil
|
12
|
-
yield
|
13
|
-
ensure
|
14
|
-
$VERBOSE = old_verbose
|
15
|
-
end
|
16
|
-
|
17
|
-
def macruby?
|
18
|
-
defined?(RUBY_ENGINE) && RUBY_ENGINE == 'macruby'
|
19
|
-
end
|
20
|
-
|
21
|
-
def jruby?
|
22
|
-
defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby'
|
23
|
-
end
|
24
|
-
|
25
|
-
def undefine_constants(*consts)
|
26
|
-
values = {}
|
27
|
-
consts.each do |const|
|
28
|
-
if Object.const_defined?(const)
|
29
|
-
values[const] = Object.const_get(const)
|
30
|
-
Object.send :remove_const, const
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
yield
|
35
|
-
|
36
|
-
ensure
|
37
|
-
values.each do |const, value|
|
38
|
-
Object.const_set const, value
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def break_requirements
|
43
|
-
requirements = MultiJson::REQUIREMENT_MAP
|
44
|
-
MultiJson::REQUIREMENT_MAP.each_with_index do |(library, adapter), index|
|
45
|
-
MultiJson::REQUIREMENT_MAP[index] = ["foo/#{library}", adapter]
|
46
|
-
end
|
47
|
-
|
48
|
-
yield
|
49
|
-
ensure
|
50
|
-
requirements.each_with_index do |(library, adapter), index|
|
51
|
-
MultiJson::REQUIREMENT_MAP[index] = [library, adapter]
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
def simulate_no_adapters
|
56
|
-
break_requirements do
|
57
|
-
undefine_constants :JSON, :Oj, :Yajl, :Gson, :JrJackson do
|
58
|
-
yield
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
def get_exception(exception_class = StandardError)
|
64
|
-
begin
|
65
|
-
yield
|
66
|
-
rescue exception_class => exception
|
67
|
-
exception
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
def with_default_options
|
72
|
-
adapter = MultiJson.adapter
|
73
|
-
adapter.load_options = adapter.dump_options = MultiJson.load_options = MultiJson.dump_options = nil
|
74
|
-
yield
|
75
|
-
ensure
|
76
|
-
adapter.load_options = adapter.dump_options = MultiJson.load_options = MultiJson.dump_options = nil
|
77
|
-
end
|