multi_json 1.5.0 → 1.15.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.
data/spec/helper.rb DELETED
@@ -1,39 +0,0 @@
1
- def jruby?
2
- defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby'
3
- end
4
-
5
- def macruby?
6
- defined?(RUBY_ENGINE) && RUBY_ENGINE == 'macruby'
7
- end
8
-
9
- unless ENV['CI'] || macruby?
10
- require 'simplecov'
11
- SimpleCov.start do
12
- add_filter 'spec'
13
- end
14
- end
15
-
16
- require 'multi_json'
17
- require 'rspec'
18
-
19
- RSpec.configure do |config|
20
- config.expect_with :rspec do |c|
21
- c.syntax = :expect
22
- end
23
- end
24
-
25
- class MockDecoder
26
- def self.load(string, options={})
27
- {'abc' => 'def'}
28
- end
29
-
30
- def self.dump(string)
31
- '{"abc":"def"}'
32
- end
33
- end
34
-
35
- class TimeWithZone
36
- def to_json(options={})
37
- "\"2005-02-01T15:15:10Z\""
38
- end
39
- end
@@ -1,100 +0,0 @@
1
- require 'helper'
2
- require 'adapter_shared_example'
3
- require 'stringio'
4
-
5
- describe 'MultiJson' do
6
- context 'adapters' do
7
- before do
8
- MultiJson.use nil
9
- end
10
- context 'when no other json implementations are available' do
11
- before do
12
- @old_map = MultiJson::REQUIREMENT_MAP
13
- @old_json = Object.const_get :JSON if Object.const_defined?(:JSON)
14
- @old_oj = Object.const_get :Oj if Object.const_defined?(:Oj)
15
- @old_yajl = Object.const_get :Yajl if Object.const_defined?(:Yajl)
16
- MultiJson::REQUIREMENT_MAP.each_with_index do |(library, adapter), index|
17
- MultiJson::REQUIREMENT_MAP[index] = ["foo/#{library}", adapter]
18
- end
19
- Object.send :remove_const, :JSON if @old_json
20
- Object.send :remove_const, :Oj if @old_oj
21
- Object.send :remove_const, :Yajl if @old_yajl
22
- end
23
-
24
- after do
25
- @old_map.each_with_index do |(library, adapter), index|
26
- MultiJson::REQUIREMENT_MAP[index] = [library, adapter]
27
- end
28
- Object.const_set :JSON, @old_json if @old_json
29
- Object.const_set :Oj, @old_oj if @old_oj
30
- Object.const_set :Yajl, @old_yajl if @old_yajl
31
- end
32
-
33
- it 'defaults to ok_json if no other json implementions are available' do
34
- expect(MultiJson.default_adapter).to eq :ok_json
35
- end
36
-
37
- it 'prints a warning' do
38
- Kernel.should_receive(:warn).with(/warning/i)
39
- MultiJson.default_adapter
40
- end
41
- end
42
-
43
- it 'defaults to the best available gem' do
44
- # Clear cache variable already set by previous tests
45
- MultiJson.send(:remove_instance_variable, :@adapter)
46
- unless jruby?
47
- require 'oj'
48
- expect(MultiJson.adapter.name).to eq 'MultiJson::Adapters::Oj'
49
- else
50
- require 'json'
51
- expect(MultiJson.adapter.name).to eq 'MultiJson::Adapters::JsonGem'
52
- end
53
- end
54
-
55
- it 'is settable via a symbol' do
56
- MultiJson.use :json_gem
57
- expect(MultiJson.adapter.name).to eq 'MultiJson::Adapters::JsonGem'
58
- end
59
-
60
- it 'is settable via a class' do
61
- MultiJson.use MockDecoder
62
- expect(MultiJson.adapter.name).to eq 'MockDecoder'
63
- end
64
-
65
- context "using one-shot parser" do
66
- before(:each) do
67
- require 'multi_json/adapters/json_pure'
68
- MultiJson::Adapters::JsonPure.should_receive(:dump).exactly(1).times.and_return('dump_something')
69
- MultiJson::Adapters::JsonPure.should_receive(:load).exactly(1).times.and_return('load_something')
70
- end
71
-
72
- it "should use the defined parser just for the call" do
73
- MultiJson.use :json_gem
74
- expect(MultiJson.dump('', :adapter => :json_pure)).to eq 'dump_something'
75
- expect(MultiJson.load('', :adapter => :json_pure)).to eq 'load_something'
76
- expect(MultiJson.adapter.name).to eq "MultiJson::Adapters::JsonGem"
77
- end
78
- end
79
- end
80
-
81
- it 'can set adapter for a block' do
82
- MultiJson.use :ok_json
83
- MultiJson.with_adapter(:json_pure) do
84
- expect(MultiJson.adapter.name).to eq 'MultiJson::Adapters::JsonPure'
85
- end
86
- MultiJson.with_engine(:yajl) do
87
- expect(MultiJson.adapter.name).to eq 'MultiJson::Adapters::Yajl'
88
- end
89
- expect(MultiJson.adapter.name).to eq 'MultiJson::Adapters::OkJson'
90
- end
91
-
92
- %w(json_gem json_pure nsjsonserialization oj ok_json yajl).each do |adapter|
93
- next if !macruby? && adapter == 'nsjsonserialization'
94
- next if jruby? && (adapter == 'oj' || adapter == 'yajl')
95
-
96
- context adapter do
97
- it_behaves_like "an adapter", adapter
98
- end
99
- end
100
- end