diff options
author | tyler-ball <tyleraball@gmail.com> | 2014-10-08 10:52:51 -0700 |
---|---|---|
committer | tyler-ball <tyleraball@gmail.com> | 2014-10-08 10:52:51 -0700 |
commit | a349694218db2cb35ca2b4d14acdc6a92ba540da (patch) | |
tree | 51b6e93fc7fe3919c262f8f6ba4494897e08d567 | |
parent | 982d0137298b5a8592dad14eea025e46ee530794 (diff) | |
download | chef-a349694218db2cb35ca2b4d14acdc6a92ba540da.tar.gz |
Adding back to prevent breaking people who use Hash.to_jsontball/11-stable-yajl-replace-json
-rw-r--r-- | lib/chef/json_compat.rb | 2 | ||||
-rw-r--r-- | spec/spec_helper.rb | 7 | ||||
-rw-r--r-- | spec/unit/json_compat_spec.rb | 7 |
3 files changed, 6 insertions, 10 deletions
diff --git a/lib/chef/json_compat.rb b/lib/chef/json_compat.rb index bf8a9cff69..9db358b5b9 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 e0788f3d9c..475daff39e 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -183,12 +183,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 a756d2b459..2d10df874f 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 |