summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortyler-ball <tyleraball@gmail.com>2014-10-08 10:48:18 -0700
committertyler-ball <tyleraball@gmail.com>2014-10-08 10:48:18 -0700
commit9f44841df63fac60e773917bb3240d8d64e6ed2e (patch)
treede5ff40308d6dc590a500eb3e7ec8d83e1a896df
parentb92978dd22f734f33044ec62c605b6eedb43bb6e (diff)
downloadchef-tball/yajl-replace-json.tar.gz
Adding back `require 'json'` to prevent breaking consumers who currently use Hash.to_json in their cookbookstball/yajl-replace-json
-rw-r--r--lib/chef/json_compat.rb2
-rw-r--r--spec/spec_helper.rb7
-rw-r--r--spec/unit/json_compat_spec.rb7
3 files changed, 6 insertions, 10 deletions
diff --git a/lib/chef/json_compat.rb b/lib/chef/json_compat.rb
index 843b87b25c..3350da0c13 100644
--- a/lib/chef/json_compat.rb
+++ b/lib/chef/json_compat.rb
@@ -19,6 +19,8 @@
require 'ffi_yajl'
require 'chef/exceptions'
+# We're requiring this to prevent breaking consumers using Hash.to_json
+require 'json'
class Chef
class JSONCompat
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 9d629da226..8abd5f59af 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -186,12 +186,5 @@ module WEBrick
end
end
-# We are no longer using the 'json' gem - deny all access to it!
-orig_require = Kernel.send(:instance_method, :require)
-Kernel.send(:remove_method, :require)
-Kernel.send(:define_method, :require) { |path|
- raise LoadError, 'JSON gem is no longer allowed - use Chef::JSONCompat.to_json' if path == 'json'
- orig_require.bind(Kernel).call(path)
-}
# Enough stuff needs json serialization that I'm just adding it here for equality asserts
require 'chef/json_compat'
diff --git a/spec/unit/json_compat_spec.rb b/spec/unit/json_compat_spec.rb
index 17beba5492..65d931df70 100644
--- a/spec/unit/json_compat_spec.rb
+++ b/spec/unit/json_compat_spec.rb
@@ -102,8 +102,9 @@ describe Chef::JSONCompat do
end
end
- it "should not allow the json gem to be required because of the spec_helper" do
- # We want to prevent ourselves from writing code that requires 'json'
- expect { require 'json' }.to raise_error(LoadError)
+ it "should define .to_json on all classes" do
+ class SomeClass; end
+
+ expect(SomeClass.new.respond_to?(:to_json)).to eq(true)
end
end