Permalink
Browse files

Cleaned up tests

 * ensured that neither ::Yajl nor ::JSON is defined for the
   default_engine tests, even if they are run after other tests
 * broke the setup and teardown of the ok_json spec into
   before(:each) and after(:each) blocks
  • Loading branch information...
1 parent 9417df3 commit 0e72e90a1d86bc724cde3d2db6682ba6e4ac8bf9 James A. Rosen committed Sep 18, 2011
Showing with 17 additions and 6 deletions.
  1. +17 −6 spec/multi_json_spec.rb
View
@@ -3,17 +3,28 @@
describe "MultiJson" do
context 'engines' do
- it 'defaults to ok_json if no other json implementions are available' do
- old_map = MultiJson::REQUIREMENT_MAP
- begin
+ context 'when no other json implementations are available' do
+ before(:each) do
+ @old_map = MultiJson::REQUIREMENT_MAP
+ @old_yajl = Object.const_get :Yajl if Object.const_defined?(:Yajl)
+ @old_json = Object.const_get :JSON if Object.const_defined?(:JSON)
MultiJson::REQUIREMENT_MAP.each_with_index do |(library, engine), index|
MultiJson::REQUIREMENT_MAP[index] = ["foo/#{library}", engine]
end
- MultiJson.default_engine.should == :ok_json
- ensure
- old_map.each_with_index do |(library, engine), index|
+ Object.send :remove_const, :Yajl if @old_yajl
+ Object.send :remove_const, :JSON if @old_json
+ end
+
+ after(:each) do
+ @old_map.each_with_index do |(library, engine), index|
MultiJson::REQUIREMENT_MAP[index] = [library, engine]
end
+ Object.const_set :Yajl, @old_yajl if @old_yajl
+ Object.const_set :JSON, @old_json if @old_json
+ end
+
+ it 'defaults to ok_json if no other json implementions are available' do
+ MultiJson.default_engine.should == :ok_json
end
end

0 comments on commit 0e72e90

Please sign in to comment.