-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #39.
- Loading branch information
Showing
12 changed files
with
97 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
lib/multi_json/engines/json_common.rb → lib/multi_json/adapters/json_common.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
module MultiJson | ||
module Engines | ||
module Adapters | ||
module JsonCommon | ||
|
||
def load(string, options={}) | ||
|
4 changes: 2 additions & 2 deletions
4
lib/multi_json/engines/json_gem.rb → lib/multi_json/adapters/json_gem.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
lib/multi_json/engines/json_pure.rb → lib/multi_json/adapters/json_pure.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
...multi_json/engines/nsjsonserialization.rb → ...ulti_json/adapters/nsjsonserialization.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
lib/multi_json/engines/ok_json.rb → lib/multi_json/adapters/ok_json.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
lib/multi_json/engines/yajl.rb → lib/multi_json/adapters/yajl.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,72 @@ | ||
require 'helper' | ||
require 'engine_shared_example' | ||
require 'adapter_shared_example' | ||
require 'stringio' | ||
|
||
describe 'MultiJson' do | ||
context 'engines' do | ||
context 'adapters' do | ||
before do | ||
MultiJson.engine = nil | ||
MultiJson.use nil | ||
end | ||
context 'when no other json implementations are available' do | ||
before do | ||
@old_map = MultiJson::REQUIREMENT_MAP | ||
@old_json = Object.const_get :JSON if Object.const_defined?(:JSON) | ||
@old_oj = Object.const_get :Oj if Object.const_defined?(:Oj) | ||
@old_yajl = Object.const_get :Yajl if Object.const_defined?(:Yajl) | ||
MultiJson::REQUIREMENT_MAP.each_with_index do |(library, engine), index| | ||
MultiJson::REQUIREMENT_MAP[index] = ["foo/#{library}", engine] | ||
MultiJson::REQUIREMENT_MAP.each_with_index do |(library, adapter), index| | ||
MultiJson::REQUIREMENT_MAP[index] = ["foo/#{library}", adapter] | ||
end | ||
Object.send :remove_const, :JSON if @old_json | ||
Object.send :remove_const, :Oj if @old_oj | ||
Object.send :remove_const, :Yajl if @old_yajl | ||
end | ||
|
||
after do | ||
@old_map.each_with_index do |(library, engine), index| | ||
MultiJson::REQUIREMENT_MAP[index] = [library, engine] | ||
@old_map.each_with_index do |(library, adapter), index| | ||
MultiJson::REQUIREMENT_MAP[index] = [library, adapter] | ||
end | ||
Object.const_set :JSON, @old_json if @old_json | ||
Object.const_set :Oj, @old_oj if @old_oj | ||
Object.const_set :Yajl, @old_yajl if @old_yajl | ||
end | ||
|
||
it 'defaults to ok_json if no other json implementions are available' do | ||
MultiJson.default_engine.should == :ok_json | ||
MultiJson.default_adapter.should == :ok_json | ||
end | ||
|
||
it 'prints a warning' do | ||
Kernel.should_receive(:warn).with(/warning/i) | ||
MultiJson.default_engine | ||
MultiJson.default_adapter | ||
end | ||
end | ||
|
||
it 'defaults to the best available gem' do | ||
unless jruby? | ||
require 'oj' | ||
MultiJson.engine.name.should == 'MultiJson::Engines::Oj' | ||
MultiJson.adapter.name.should == 'MultiJson::Adapters::Oj' | ||
else | ||
require 'json' | ||
MultiJson.engine.name.should == 'MultiJson::Engines::JsonGem' | ||
MultiJson.adapter.name.should == 'MultiJson::Adapters::JsonGem' | ||
end | ||
end | ||
|
||
it 'is settable via a symbol' do | ||
MultiJson.engine = :json_gem | ||
MultiJson.engine.name.should == 'MultiJson::Engines::JsonGem' | ||
MultiJson.use :json_gem | ||
MultiJson.adapter.name.should == 'MultiJson::Adapters::JsonGem' | ||
end | ||
|
||
it 'is settable via a class' do | ||
MultiJson.engine = MockDecoder | ||
MultiJson.engine.name.should == 'MockDecoder' | ||
MultiJson.use MockDecoder | ||
MultiJson.adapter.name.should == 'MockDecoder' | ||
end | ||
end | ||
|
||
%w(json_gem json_pure nsjsonserialization oj ok_json yajl).each do |engine| | ||
next if !macruby? && engine == 'nsjsonserialization' | ||
next if jruby? && (engine == 'oj' || engine == 'yajl') | ||
%w(json_gem json_pure nsjsonserialization oj ok_json yajl).each do |adapter| | ||
next if !macruby? && adapter == 'nsjsonserialization' | ||
next if jruby? && (adapter == 'oj' || adapter == 'yajl') | ||
|
||
context engine do | ||
it_should_behave_like "an engine", engine | ||
context adapter do | ||
it_should_behave_like "an adapter", adapter | ||
end | ||
end | ||
end |