diff options
66 files changed, 222 insertions, 99 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 452b1d331b..2daf841499 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -146,6 +146,7 @@ * Add escape_glob method to PathHelper, update glob operations. * Verify x509 properties of certificates in the :trusted_certs_dir during knife ssl check. * Disable unforked interval chef-client runs. +* Removed dependencies on the 'json' gem, replaced with ffi-yajl. Use Chef::JSONCompat library for parsing and printing. ## Last Release: 11.14.2 diff --git a/DOC_CHANGES.md b/DOC_CHANGES.md index ceccb77cd0..08c343809a 100644 --- a/DOC_CHANGES.md +++ b/DOC_CHANGES.md @@ -467,7 +467,6 @@ PathHelper = Chef::Util::PathHelper Dir.glob(File.join(PathHelper.escape_glob(path), "*")) # ["#{path}\\apache2", "#{path}\\apt", ...] Dir[PathHelper.escape_glob(path) + "/*"] # ["#{path}\\apache2", "#{path}\\apt", ...] ``` - ## Mac OS X default package provider is now Homebrew Per [Chef RFC 016](https://github.com/opscode/chef-rfc/blob/master/rfc016-homebrew-osx-package-provider.md), the default provider for the `package` resource on Mac OS X is now [Homebrew](http://brew.sh). The [homebrew cookbook's](https://supermarket.getchef.com/cookbooks/homebrew) default recipe, or some other method is still required for getting homebrew installed on the system. The cookbook won't be strictly required just to install packages from homebrew on OS X, though. To use this, simply use the `package` resource, or the `homebrew_package` shortcut resource: @@ -521,4 +520,4 @@ end ``` Chef will then execute the Homebrew command as that user. The `homebrew_user` attribute can only be provided to the -`homebrew_package` resource, not the `package` resource.
\ No newline at end of file +`homebrew_package` resource, not the `package` resource. @@ -2,6 +2,8 @@ source "https://rubygems.org" gemspec :name => "chef" gem "activesupport", "< 4.0.0", :group => :compat_testing, :platform => "ruby" +# TODO remove this when next version of ffi-yajl is released including this change +gem "ffi-yajl", :github => 'tyler-ball/ffi-yajl', :branch => 'tball/remove_to_json' group(:docgen) do gem "yard" diff --git a/chef.gemspec b/chef.gemspec index 481b120fe6..f970bb32f9 100644 --- a/chef.gemspec +++ b/chef.gemspec @@ -22,7 +22,7 @@ Gem::Specification.new do |s| s.add_dependency "mixlib-shellout", ">= 2.0.0.rc.0", "< 3.0" s.add_dependency "ohai", ">= 7.6.0.rc.0" - s.add_dependency "ffi-yajl", "~> 1.0", ">= 1.0.2" + s.add_dependency "ffi-yajl", "~> 1.1" s.add_dependency "net-ssh", "~> 2.6" s.add_dependency "net-ssh-multi", "~> 1.1" # CHEF-3027: The knife-cloud plugins require newer features from highline, core chef should not. @@ -30,7 +30,7 @@ Gem::Specification.new do |s| s.add_dependency "erubis", "~> 2.7" s.add_dependency "diff-lcs", "~> 1.2", ">= 1.2.4" - s.add_dependency "chef-zero", "~> 3.1" + s.add_dependency "chef-zero", "~> 3.2" s.add_dependency "pry", "~> 0.9" s.add_dependency 'plist', '~> 3.1.0' diff --git a/kitchen-tests/test/fixtures/serverspec_helper.rb b/kitchen-tests/test/fixtures/serverspec_helper.rb index 6e6d71e79b..48963dc45d 100644 --- a/kitchen-tests/test/fixtures/serverspec_helper.rb +++ b/kitchen-tests/test/fixtures/serverspec_helper.rb @@ -4,6 +4,7 @@ require 'serverspec' require 'json' +require 'ffi_yajl' set :backend, :exec @@ -21,7 +22,7 @@ def load_nodestub platform = 'centos' platform_version = os[:release].to_i end - JSON.parse(IO.read("#{ENV['BUSSER_ROOT']}/../kitchen/data/platforms/#{platform}/#{platform_version}.json"), :symbolize_names => true) + FFI_Yajl::Parser.parse(IO.read("#{ENV['BUSSER_ROOT']}/../kitchen/data/platforms/#{platform}/#{platform_version}.json"), :symbolize_names => true) end # centos-59 doesn't have /sbin in the default path, diff --git a/kitchen-tests/test/integration/webapp/serverspec/Gemfile b/kitchen-tests/test/integration/webapp/serverspec/Gemfile new file mode 100644 index 0000000000..0cb00ce354 --- /dev/null +++ b/kitchen-tests/test/integration/webapp/serverspec/Gemfile @@ -0,0 +1,4 @@ +# This Gemfile is only needed so that busser will install gems it needs for serverspec_helper.rb to work +source "https://rubygems.org" + +gem 'ffi-yajl', '~> 1.1' # Go away, JSON gem diff --git a/lib/chef/chef_fs/chef_fs_data_store.rb b/lib/chef/chef_fs/chef_fs_data_store.rb index 484ab07390..3813d0edb4 100644 --- a/lib/chef/chef_fs/chef_fs_data_store.rb +++ b/lib/chef/chef_fs/chef_fs_data_store.rb @@ -168,7 +168,7 @@ class Chef end end end - JSON.pretty_generate(result) + Chef::JSONCompat.to_json_pretty(result) else begin diff --git a/lib/chef/chef_fs/command_line.rb b/lib/chef/chef_fs/command_line.rb index 43e8b276e0..8a205eef78 100644 --- a/lib/chef/chef_fs/command_line.rb +++ b/lib/chef/chef_fs/command_line.rb @@ -253,7 +253,7 @@ class Chef def self.canonicalize_json(json_text) parsed_json = Chef::JSONCompat.parse(json_text) sorted_json = sort_keys(parsed_json) - JSON.pretty_generate(sorted_json) + Chef::JSONCompat.to_json_pretty(sorted_json) end def self.diff_text(old_path, new_path, old_value, new_value) diff --git a/lib/chef/chef_fs/file_system/organization_invites_entry.rb b/lib/chef/chef_fs/file_system/organization_invites_entry.rb index cb26326050..5df37085cb 100644 --- a/lib/chef/chef_fs/file_system/organization_invites_entry.rb +++ b/lib/chef/chef_fs/file_system/organization_invites_entry.rb @@ -1,5 +1,6 @@ require 'chef/chef_fs/file_system/rest_list_entry' require 'chef/chef_fs/data_handler/organization_invites_data_handler' +require 'chef/json_compat' class Chef module ChefFS @@ -34,7 +35,7 @@ class Chef end def write(contents) - desired_invites = minimize_value(JSON.parse(contents, :create_additions => false)) + desired_invites = minimize_value(Chef::JSONCompat.parse(contents, :create_additions => false)) actual_invites = _read_json.inject({}) { |h,val| h[val['username']] = val['id']; h } invites = actual_invites.keys (desired_invites - invites).each do |invite| diff --git a/lib/chef/chef_fs/file_system/organization_members_entry.rb b/lib/chef/chef_fs/file_system/organization_members_entry.rb index eb524d5ea2..94393b341f 100644 --- a/lib/chef/chef_fs/file_system/organization_members_entry.rb +++ b/lib/chef/chef_fs/file_system/organization_members_entry.rb @@ -1,5 +1,6 @@ require 'chef/chef_fs/file_system/rest_list_entry' require 'chef/chef_fs/data_handler/organization_members_data_handler' +require 'chef/json_compat' class Chef module ChefFS @@ -34,7 +35,7 @@ class Chef end def write(contents) - desired_members = minimize_value(JSON.parse(contents, :create_additions => false)) + desired_members = minimize_value(Chef::JSONCompat.parse(contents, :create_additions => false)) members = minimize_value(_read_json) (desired_members - members).each do |member| begin diff --git a/lib/chef/chef_fs/file_system/rest_list_entry.rb b/lib/chef/chef_fs/file_system/rest_list_entry.rb index ac47ff4f25..f68794cb0d 100644 --- a/lib/chef/chef_fs/file_system/rest_list_entry.rb +++ b/lib/chef/chef_fs/file_system/rest_list_entry.rb @@ -21,6 +21,7 @@ require 'chef/chef_fs/file_system/not_found_error' require 'chef/chef_fs/file_system/operation_failed_error' require 'chef/role' require 'chef/node' +require 'chef/json_compat' class Chef module ChefFS @@ -172,7 +173,7 @@ class Chef def api_error_text(response) begin - JSON.parse(response.body)['error'].join("\n") + Chef::JSONCompat.parse(response.body)['error'].join("\n") rescue response.body end diff --git a/lib/chef/cookbook_version.rb b/lib/chef/cookbook_version.rb index 40aaaf1191..95af94bdf7 100644 --- a/lib/chef/cookbook_version.rb +++ b/lib/chef/cookbook_version.rb @@ -479,7 +479,7 @@ class Chef cookbook_version.manifest = o # We don't need the following step when we decide to stop supporting deprecated operators in the metadata (e.g. <<, >>) - cookbook_version.manifest["metadata"] = Chef::JSONCompat.from_json(cookbook_version.metadata.to_json) + cookbook_version.manifest["metadata"] = Chef::JSONCompat.from_json(Chef::JSONCompat.to_json(cookbook_version.metadata)) cookbook_version.freeze_version if o["frozen?"] cookbook_version diff --git a/lib/chef/json_compat.rb b/lib/chef/json_compat.rb index e92d5c36ae..3350da0c13 100644 --- a/lib/chef/json_compat.rb +++ b/lib/chef/json_compat.rb @@ -18,9 +18,9 @@ # Wrapper class for interacting with JSON. require 'ffi_yajl' -require 'json' -require 'ffi_yajl/json_gem' # XXX: parts of chef require JSON gem's Hash#to_json monkeypatch require 'chef/exceptions' +# We're requiring this to prevent breaking consumers using Hash.to_json +require 'json' class Chef class JSONCompat diff --git a/lib/chef/knife/bootstrap/archlinux-gems.erb b/lib/chef/knife/bootstrap/archlinux-gems.erb index eb134b90d5..581293daa3 100644 --- a/lib/chef/knife/bootstrap/archlinux-gems.erb +++ b/lib/chef/knife/bootstrap/archlinux-gems.erb @@ -34,7 +34,7 @@ mkdir -p /etc/chef/ohai/hints <% @chef_config[:knife][:hints].each do |name, hash| -%> cat > /etc/chef/ohai/hints/<%= name %>.json <<'EOP' -<%= hash.to_json %> +<%= Chef::JSONCompat.to_json(hash) %> EOP <% end -%> <% end -%> @@ -61,7 +61,7 @@ https_proxy "<%= knife_config[:bootstrap_proxy] %>" EOP cat > /etc/chef/first-boot.json <<'EOP' -<%= first_boot.to_json %> +<%= Chef::JSONCompat.to_json(first_boot) %> EOP <%= start_chef %>' diff --git a/lib/chef/knife/bootstrap/chef-aix.erb b/lib/chef/knife/bootstrap/chef-aix.erb index 3a031ee738..013ad1decb 100644 --- a/lib/chef/knife/bootstrap/chef-aix.erb +++ b/lib/chef/knife/bootstrap/chef-aix.erb @@ -47,7 +47,7 @@ mkdir -p /etc/chef/ohai/hints <% @chef_config[:knife][:hints].each do |name, hash| -%> cat > /etc/chef/ohai/hints/<%= name %>.json <<'EOP' -<%= hash.to_json %> +<%= Chef::JSONCompat.to_json(hash) %> EOP <% end -%> <% end -%> @@ -57,7 +57,7 @@ cat > /etc/chef/client.rb <<'EOP' EOP cat > /etc/chef/first-boot.json <<'EOP' -<%= first_boot.to_json %> +<%= Chef::JSONCompat.to_json(first_boot) %> EOP <%= start_chef %>' diff --git a/lib/chef/knife/bootstrap/chef-full.erb b/lib/chef/knife/bootstrap/chef-full.erb index 6edb485f44..dfd5df0071 100644 --- a/lib/chef/knife/bootstrap/chef-full.erb +++ b/lib/chef/knife/bootstrap/chef-full.erb @@ -61,7 +61,7 @@ mkdir -p /etc/chef/ohai/hints <% @chef_config[:knife][:hints].each do |name, hash| -%> cat > /etc/chef/ohai/hints/<%= name %>.json <<'EOP' -<%= hash.to_json %> +<%= Chef::JSONCompat.to_json(hash) %> EOP <% end -%> <% end -%> @@ -71,7 +71,7 @@ cat > /etc/chef/client.rb <<'EOP' EOP cat > /etc/chef/first-boot.json <<'EOP' -<%= first_boot.to_json %> +<%= Chef::JSONCompat.to_json(first_boot) %> EOP echo "Starting first Chef Client run..." diff --git a/lib/chef/knife/core/ui.rb b/lib/chef/knife/core/ui.rb index 0007480ea2..f3ecfbcae8 100644 --- a/lib/chef/knife/core/ui.rb +++ b/lib/chef/knife/core/ui.rb @@ -113,7 +113,7 @@ class Chef # determined by the value of `config[:color]`. When output is not to a # terminal, colored output is never used def color? - Chef::Config[:color] && stdout.tty? && !Chef::Platform.windows? + Chef::Config[:color] && stdout.tty? end def ask(*args, &block) diff --git a/lib/chef/util/powershell/cmdlet_result.rb b/lib/chef/util/powershell/cmdlet_result.rb index af7b3607cd..246701a7bc 100644 --- a/lib/chef/util/powershell/cmdlet_result.rb +++ b/lib/chef/util/powershell/cmdlet_result.rb @@ -16,7 +16,7 @@ # limitations under the License. # -require 'json' +require 'chef/json_compat' class Chef::Util::Powershell class CmdletResult @@ -33,7 +33,7 @@ class Chef::Util::Powershell def return_value if output_format == :object - JSON.parse(@status.stdout) + Chef::JSONCompat.parse(@status.stdout) else @status.stdout end diff --git a/spec/data/bootstrap/test-hints.erb b/spec/data/bootstrap/test-hints.erb index 29ba710b42..7693fdc7c9 100644 --- a/spec/data/bootstrap/test-hints.erb +++ b/spec/data/bootstrap/test-hints.erb @@ -6,7 +6,7 @@ mkdir -p /etc/chef/ohai/hints <% @chef_config[:knife][:hints].each do |name, hash| -%> ( cat <<'EOP' -<%= hash.to_json %> +<%= Chef::JSONCompat.to_json(hash) %> EOP ) > /etc/chef/ohai/hints/<%= name %>.json <% end -%> diff --git a/spec/data/bootstrap/test.erb b/spec/data/bootstrap/test.erb index 7cdc7dfdd0..3a383b47d0 100644 --- a/spec/data/bootstrap/test.erb +++ b/spec/data/bootstrap/test.erb @@ -1 +1 @@ -<%= first_boot.to_json %>
\ No newline at end of file +<%= Chef::JSONCompat.to_json(first_boot) %> diff --git a/spec/functional/knife/cookbook_delete_spec.rb b/spec/functional/knife/cookbook_delete_spec.rb index ee620bf165..4773fd2185 100644 --- a/spec/functional/knife/cookbook_delete_spec.rb +++ b/spec/functional/knife/cookbook_delete_spec.rb @@ -47,7 +47,7 @@ describe Chef::Knife::CookbookDelete do Chef::Log.level = :debug @knife.name_args = %w{no-such-cookbook} - @api.get("/cookbooks/no-such-cookbook", 404, {'error'=>'dear Tim, no. -Sent from my iPad'}.to_json) + @api.get("/cookbooks/no-such-cookbook", 404, Chef::JSONCompat.to_json({'error'=>'dear Tim, no. -Sent from my iPad'})) end it "logs an error and exits" do @@ -62,7 +62,7 @@ describe Chef::Knife::CookbookDelete do before do @knife.name_args = %w{obsolete-cookbook} @cookbook_list = {'obsolete-cookbook' => { 'versions' => ['version' => '1.0.0']} } - @api.get("/cookbooks/obsolete-cookbook", 200, @cookbook_list.to_json) + @api.get("/cookbooks/obsolete-cookbook", 200, Chef::JSONCompat.to_json(@cookbook_list)) end it "asks for confirmation, then deletes the cookbook" do @@ -105,7 +105,7 @@ describe Chef::Knife::CookbookDelete do versions = ['1.0.0', '1.1.0', '1.2.0'] with_version = lambda { |version| { 'version' => version } } @cookbook_list = {'obsolete-cookbook' => { 'versions' => versions.map(&with_version) } } - @api.get("/cookbooks/obsolete-cookbook", 200, @cookbook_list.to_json) + @api.get("/cookbooks/obsolete-cookbook", 200, Chef::JSONCompat.to_json(@cookbook_list)) end it "deletes all versions of a cookbook when given the '-a' flag" do diff --git a/spec/functional/knife/exec_spec.rb b/spec/functional/knife/exec_spec.rb index 455160fd5c..7eb52d01df 100644 --- a/spec/functional/knife/exec_spec.rb +++ b/spec/functional/knife/exec_spec.rb @@ -47,7 +47,7 @@ describe Chef::Knife::Exec do @node = Chef::Node.new @node.name("ohai-world") response = {"rows" => [@node],"start" => 0,"total" => 1} - @api.get(%r{^/search/node}, 200, response.to_json) + @api.get(%r{^/search/node}, 200, Chef::JSONCompat.to_json(response)) code = "$output.puts nodes.all" @knife.config[:exec] = code @knife.run diff --git a/spec/functional/util/powershell/cmdlet_spec.rb b/spec/functional/util/powershell/cmdlet_spec.rb index 63d1ac09b5..b240a5ec12 100644 --- a/spec/functional/util/powershell/cmdlet_spec.rb +++ b/spec/functional/util/powershell/cmdlet_spec.rb @@ -16,7 +16,7 @@ # limitations under the License. # -require 'json' +require 'chef/json_compat' require File.expand_path('../../../../spec_helper', __FILE__) describe Chef::Util::Powershell::Cmdlet, :windows_only do @@ -91,7 +91,7 @@ describe Chef::Util::Powershell::Cmdlet, :windows_only do it "returns json format data", :windows_powershell_dsc_only do result = cmdlet_alias_requires_switch_or_argument.run({},{},'ls') expect(result.succeeded?).to eq(true) - expect(lambda{JSON.parse(result.return_value)}).not_to raise_error + expect(lambda{Chef::JSONCompat.parse(result.return_value)}).not_to raise_error end end diff --git a/spec/integration/knife/chef_fs_data_store_spec.rb b/spec/integration/knife/chef_fs_data_store_spec.rb index c6737e08cb..a4d62673de 100644 --- a/spec/integration/knife/chef_fs_data_store_spec.rb +++ b/spec/integration/knife/chef_fs_data_store_spec.rb @@ -22,7 +22,7 @@ require 'chef/knife/show' require 'chef/knife/raw' require 'chef/knife/cookbook_upload' -describe 'ChefFSDataStore tests' do +describe 'ChefFSDataStore tests', :workstation do include IntegrationSupport include KnifeSupport diff --git a/spec/integration/knife/chef_repo_path_spec.rb b/spec/integration/knife/chef_repo_path_spec.rb index 90455ed374..874b33901f 100644 --- a/spec/integration/knife/chef_repo_path_spec.rb +++ b/spec/integration/knife/chef_repo_path_spec.rb @@ -20,7 +20,7 @@ require 'support/shared/context/config' require 'chef/knife/list' require 'chef/knife/show' -describe 'chef_repo_path tests' do +describe 'chef_repo_path tests', :workstation do include IntegrationSupport include KnifeSupport diff --git a/spec/integration/knife/chef_repository_file_system_spec.rb b/spec/integration/knife/chef_repository_file_system_spec.rb index ff86924e22..34afd228f3 100644 --- a/spec/integration/knife/chef_repository_file_system_spec.rb +++ b/spec/integration/knife/chef_repository_file_system_spec.rb @@ -19,7 +19,7 @@ require 'support/shared/integration/integration_helper' require 'chef/knife/list' require 'chef/knife/show' -describe 'General chef_repo file system checks' do +describe 'General chef_repo file system checks', :workstation do include IntegrationSupport include KnifeSupport diff --git a/spec/integration/knife/chefignore_spec.rb b/spec/integration/knife/chefignore_spec.rb index b09959b581..34bf391f88 100644 --- a/spec/integration/knife/chefignore_spec.rb +++ b/spec/integration/knife/chefignore_spec.rb @@ -19,7 +19,7 @@ require 'support/shared/integration/integration_helper' require 'chef/knife/list' require 'chef/knife/show' -describe 'chefignore tests' do +describe 'chefignore tests', :workstation do include IntegrationSupport include KnifeSupport diff --git a/spec/integration/knife/common_options_spec.rb b/spec/integration/knife/common_options_spec.rb index 7a48f14ad3..dfc1e024f9 100644 --- a/spec/integration/knife/common_options_spec.rb +++ b/spec/integration/knife/common_options_spec.rb @@ -18,7 +18,7 @@ require 'support/shared/integration/integration_helper' require 'chef/knife/raw' -describe 'knife common options' do +describe 'knife common options', :workstation do include IntegrationSupport include KnifeSupport diff --git a/spec/integration/knife/cookbook_api_ipv6_spec.rb b/spec/integration/knife/cookbook_api_ipv6_spec.rb index c5b5b81abe..e59c8912bd 100644 --- a/spec/integration/knife/cookbook_api_ipv6_spec.rb +++ b/spec/integration/knife/cookbook_api_ipv6_spec.rb @@ -18,7 +18,7 @@ require 'support/shared/integration/integration_helper' require 'chef/mixin/shell_out' -describe "Knife cookbook API integration with IPv6" do +describe "Knife cookbook API integration with IPv6", :workstation do include IntegrationSupport include Chef::Mixin::ShellOut diff --git a/spec/integration/knife/delete_spec.rb b/spec/integration/knife/delete_spec.rb index e56469e102..733a7ef72b 100644 --- a/spec/integration/knife/delete_spec.rb +++ b/spec/integration/knife/delete_spec.rb @@ -20,7 +20,7 @@ require 'chef/knife/delete' require 'chef/knife/list' require 'chef/knife/raw' -describe 'knife delete' do +describe 'knife delete', :workstation do include IntegrationSupport include KnifeSupport diff --git a/spec/integration/knife/deps_spec.rb b/spec/integration/knife/deps_spec.rb index 2cbb7b8f74..8b4d71906b 100644 --- a/spec/integration/knife/deps_spec.rb +++ b/spec/integration/knife/deps_spec.rb @@ -19,7 +19,7 @@ require 'support/shared/integration/integration_helper' require 'support/shared/context/config' require 'chef/knife/deps' -describe 'knife deps' do +describe 'knife deps', :workstation do include IntegrationSupport include KnifeSupport diff --git a/spec/integration/knife/diff_spec.rb b/spec/integration/knife/diff_spec.rb index 62b491d6ef..c12ebbcf8f 100644 --- a/spec/integration/knife/diff_spec.rb +++ b/spec/integration/knife/diff_spec.rb @@ -18,7 +18,7 @@ require 'support/shared/integration/integration_helper' require 'chef/knife/diff' -describe 'knife diff' do +describe 'knife diff', :workstation do include IntegrationSupport include KnifeSupport diff --git a/spec/integration/knife/download_spec.rb b/spec/integration/knife/download_spec.rb index 17779d1f47..0c2b907f1e 100644 --- a/spec/integration/knife/download_spec.rb +++ b/spec/integration/knife/download_spec.rb @@ -19,7 +19,7 @@ require 'support/shared/integration/integration_helper' require 'chef/knife/download' require 'chef/knife/diff' -describe 'knife download' do +describe 'knife download', :workstation do include IntegrationSupport include KnifeSupport diff --git a/spec/integration/knife/list_spec.rb b/spec/integration/knife/list_spec.rb index c9632e146d..3d8b83001d 100644 --- a/spec/integration/knife/list_spec.rb +++ b/spec/integration/knife/list_spec.rb @@ -19,7 +19,7 @@ require 'support/shared/integration/integration_helper' require 'support/shared/context/config' require 'chef/knife/list' -describe 'knife list' do +describe 'knife list', :workstation do include IntegrationSupport include KnifeSupport diff --git a/spec/integration/knife/raw_spec.rb b/spec/integration/knife/raw_spec.rb index fad69e4e11..2b49d2ebb2 100644 --- a/spec/integration/knife/raw_spec.rb +++ b/spec/integration/knife/raw_spec.rb @@ -20,7 +20,7 @@ require 'support/shared/context/config' require 'chef/knife/raw' require 'chef/knife/show' -describe 'knife raw' do +describe 'knife raw', :workstation do include IntegrationSupport include KnifeSupport include AppServerSupport diff --git a/spec/integration/knife/redirection_spec.rb b/spec/integration/knife/redirection_spec.rb index 549a6f6df0..77bda99453 100644 --- a/spec/integration/knife/redirection_spec.rb +++ b/spec/integration/knife/redirection_spec.rb @@ -19,7 +19,7 @@ require 'support/shared/integration/integration_helper' require 'support/shared/context/config' require 'chef/knife/list' -describe 'redirection' do +describe 'redirection', :workstation do include IntegrationSupport include KnifeSupport include AppServerSupport diff --git a/spec/integration/knife/serve_spec.rb b/spec/integration/knife/serve_spec.rb index 32e633543d..3c859b794e 100644 --- a/spec/integration/knife/serve_spec.rb +++ b/spec/integration/knife/serve_spec.rb @@ -19,7 +19,7 @@ require 'support/shared/integration/integration_helper' require 'chef/knife/serve' require 'chef/server_api' -describe 'knife serve' do +describe 'knife serve', :workstation do include IntegrationSupport include KnifeSupport include AppServerSupport diff --git a/spec/integration/knife/show_spec.rb b/spec/integration/knife/show_spec.rb index 4a71499e87..bc7f1cf6d3 100644 --- a/spec/integration/knife/show_spec.rb +++ b/spec/integration/knife/show_spec.rb @@ -19,7 +19,7 @@ require 'support/shared/integration/integration_helper' require 'support/shared/context/config' require 'chef/knife/show' -describe 'knife show' do +describe 'knife show', :workstation do include IntegrationSupport include KnifeSupport diff --git a/spec/integration/knife/upload_spec.rb b/spec/integration/knife/upload_spec.rb index 05d33d1a17..dade476889 100644 --- a/spec/integration/knife/upload_spec.rb +++ b/spec/integration/knife/upload_spec.rb @@ -19,8 +19,9 @@ require 'support/shared/integration/integration_helper' require 'chef/knife/upload' require 'chef/knife/diff' require 'chef/knife/raw' +require 'chef/json_compat' -describe 'knife upload' do +describe 'knife upload', :workstation do include IntegrationSupport include KnifeSupport @@ -261,7 +262,7 @@ Created /data_bags/x/y.json EOM knife('diff --name-status /data_bags').should_succeed <<EOM EOM - JSON.parse(knife('raw /data/x/y').stdout, :create_additions => false).keys.sort.should == [ 'foo', 'id' ] + Chef::JSONCompat.parse(knife('raw /data/x/y').stdout, :create_additions => false).keys.sort.should == [ 'foo', 'id' ] end it 'knife upload /data_bags/x /data_bags/x/y.json uploads x once' do @@ -284,7 +285,7 @@ Created /data_bags/x Created /data_bags/x/y.json EOM knife('diff --name-status /data_bags').should_succeed '' - result = JSON.parse(knife('raw /data/x/y').stdout, :create_additions => false) + result = Chef::JSONCompat.parse(knife('raw /data/x/y').stdout, :create_additions => false) result.keys.sort.should == [ 'chef_type', 'data_bag', 'id' ] result['chef_type'].should == 'aaa' result['data_bag'].should == 'bbb' diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ed0a8f89f6..1760aab871 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -97,6 +97,9 @@ RSpec.configure do |config| config.filter_run :focus => true config.filter_run_excluding :external => true + # Only run these tests on platforms that are also chef workstations + config.filter_run_excluding :workstation if solaris? + # Tests that randomly fail, but may have value. config.filter_run_excluding :volatile => true config.filter_run_excluding :volatile_on_solaris => true if solaris? @@ -185,3 +188,6 @@ module WEBrick end end end + +# Enough stuff needs json serialization that I'm just adding it here for equality asserts +require 'chef/json_compat' diff --git a/spec/support/shared/integration/integration_helper.rb b/spec/support/shared/integration/integration_helper.rb index b42f7f69d9..e6942c62af 100644 --- a/spec/support/shared/integration/integration_helper.rb +++ b/spec/support/shared/integration/integration_helper.rb @@ -72,7 +72,7 @@ module IntegrationSupport File.open(filename, 'w') do |file| raw = case contents when Hash, Array - JSON.pretty_generate(contents) + Chef::JSONCompat.to_json_pretty(contents) else contents end diff --git a/spec/support/shared/shared_examples.rb b/spec/support/shared/shared_examples.rb new file mode 100644 index 0000000000..b20c65f8b6 --- /dev/null +++ b/spec/support/shared/shared_examples.rb @@ -0,0 +1,14 @@ +# For storing any examples shared between multiple tests + +# Any object which defines a .to_json should import this test +shared_examples "to_json equalivent to Chef::JSONCompat.to_json" do + + let(:jsonable) { + raise "You must define the subject when including this test" + } + + it "should allow consumers to call #to_json or Chef::JSONCompat.to_json" do + expect(jsonable.to_json).to eq(Chef::JSONCompat.to_json(jsonable)) + end + +end diff --git a/spec/tiny_server.rb b/spec/tiny_server.rb index 7e6ef3a809..a2cfe168d5 100644 --- a/spec/tiny_server.rb +++ b/spec/tiny_server.rb @@ -22,7 +22,6 @@ require 'webrick/https' require 'rack' #require 'thin' require 'singleton' -require 'chef/json_compat' require 'open-uri' require 'chef/config' @@ -152,7 +151,7 @@ module TinyServer :available_routes => @routes, :request => env} # Uncomment me for glorious debugging # pp :not_found => debug_info - [404, {'Content-Type' => 'application/json'}, [ debug_info.to_json ]] + [404, {'Content-Type' => 'application/json'}, [ Chef::JSONCompat.to_json(debug_info) ]] end end diff --git a/spec/unit/api_client_spec.rb b/spec/unit/api_client_spec.rb index 76fc4afb5c..bd6c5ef7fd 100644 --- a/spec/unit/api_client_spec.rb +++ b/spec/unit/api_client_spec.rb @@ -123,6 +123,10 @@ describe Chef::ApiClient do it "does not include the private key if not present" do @json.should_not include("private_key") end + + include_examples "to_json equalivent to Chef::JSONCompat.to_json" do + let(:jsonable) { @client } + end end describe "when deserializing from JSON" do @@ -135,7 +139,7 @@ describe Chef::ApiClient do "validator" => true, "json_class" => "Chef::ApiClient" } - @client = Chef::JSONCompat.from_json(client.to_json) + @client = Chef::JSONCompat.from_json(Chef::JSONCompat.to_json(client)) end it "should deserialize to a Chef::ApiClient object" do diff --git a/spec/unit/config_fetcher_spec.rb b/spec/unit/config_fetcher_spec.rb index f6d5436a11..31787a0909 100644 --- a/spec/unit/config_fetcher_spec.rb +++ b/spec/unit/config_fetcher_spec.rb @@ -1,7 +1,8 @@ require 'spec_helper' require 'chef/config_fetcher' + describe Chef::ConfigFetcher do - let(:valid_json) { {:a=>"b"}.to_json } + let(:valid_json) { Chef::JSONCompat.to_json({:a=>"b"}) } let(:invalid_json) { %q[{"syntax-error": "missing quote}] } let(:http) { double("Chef::HTTP::Simple") } diff --git a/spec/unit/cookbook/metadata_spec.rb b/spec/unit/cookbook/metadata_spec.rb index e61c85b42b..86be0d2390 100644 --- a/spec/unit/cookbook/metadata_spec.rb +++ b/spec/unit/cookbook/metadata_spec.rb @@ -623,9 +623,13 @@ describe Chef::Cookbook::Metadata do metadata.version "1.2.3" end + it "should produce the same output from to_json and Chef::JSONCompat" do + expect(metadata.to_json).to eq(Chef::JSONCompat.to_json(metadata)) + end + describe "serialize" do - let(:deserialized_metadata) { Chef::JSONCompat.from_json(metadata.to_json) } + let(:deserialized_metadata) { Chef::JSONCompat.from_json(Chef::JSONCompat.to_json(metadata)) } it "should serialize to a json hash" do deserialized_metadata.should be_a_kind_of(Hash) @@ -657,7 +661,7 @@ describe Chef::Cookbook::Metadata do describe "deserialize" do - let(:deserialized_metadata) { Chef::Cookbook::Metadata.from_json(metadata.to_json) } + let(:deserialized_metadata) { Chef::Cookbook::Metadata.from_json(Chef::JSONCompat.to_json(metadata)) } it "should deserialize to a Chef::Cookbook::Metadata object" do diff --git a/spec/unit/cookbook_loader_spec.rb b/spec/unit/cookbook_loader_spec.rb index f40bbd5696..deaf393d7a 100644 --- a/spec/unit/cookbook_loader_spec.rb +++ b/spec/unit/cookbook_loader_spec.rb @@ -210,7 +210,7 @@ describe Chef::CookbookLoader do aa.to_hash["metadata"].recipes.keys.should include("openldap") expected_desc = "Main Open LDAP configuration" aa.to_hash["metadata"].recipes["openldap"].should == expected_desc - raw = aa.to_hash["metadata"].recipes.to_json + raw = Chef::JSONCompat.to_json(aa.to_hash["metadata"].recipes) search_str = "\"openldap\":\"" key_idx = raw.index(search_str) key_idx.should be > 0 diff --git a/spec/unit/cookbook_version_spec.rb b/spec/unit/cookbook_version_spec.rb index f20bc3766a..25bc936569 100644 --- a/spec/unit/cookbook_version_spec.rb +++ b/spec/unit/cookbook_version_spec.rb @@ -422,4 +422,8 @@ describe Chef::CookbookVersion do end + include_examples "to_json equalivent to Chef::JSONCompat.to_json" do + let(:jsonable) { Chef::CookbookVersion.new("tatft", '/tmp/blah') } + end + end diff --git a/spec/unit/data_bag_item_spec.rb b/spec/unit/data_bag_item_spec.rb index ead0dadfa2..5972d8a239 100644 --- a/spec/unit/data_bag_item_spec.rb +++ b/spec/unit/data_bag_item_spec.rb @@ -166,7 +166,7 @@ describe Chef::DataBagItem do before(:each) do @data_bag_item.data_bag('mars_volta') @data_bag_item.raw_data = { "id" => "octahedron", "snooze" => { "finally" => :world_will }} - @deserial = Chef::JSONCompat.from_json(@data_bag_item.to_json) + @deserial = Chef::JSONCompat.from_json(Chef::JSONCompat.to_json(@data_bag_item)) end it "should deserialize to a Chef::DataBagItem object" do @@ -184,6 +184,10 @@ describe Chef::DataBagItem do it "should have a matching 'snooze' key" do @deserial["snooze"].should == { "finally" => "world_will" } end + + include_examples "to_json equalivent to Chef::JSONCompat.to_json" do + let(:jsonable) { @data_bag_item } + end end describe "when converting to a string" do diff --git a/spec/unit/data_bag_spec.rb b/spec/unit/data_bag_spec.rb index c905277b7c..ff323902eb 100644 --- a/spec/unit/data_bag_spec.rb +++ b/spec/unit/data_bag_spec.rb @@ -59,7 +59,7 @@ describe Chef::DataBag do describe "deserialize" do before(:each) do @data_bag.name('mars_volta') - @deserial = Chef::JSONCompat.from_json(@data_bag.to_json) + @deserial = Chef::JSONCompat.from_json(Chef::JSONCompat.to_json(@data_bag)) end it "should deserialize to a Chef::DataBag object" do @@ -72,6 +72,10 @@ describe Chef::DataBag do it "should match '#{t}'" do @deserial.send(t.to_sym).should == @data_bag.send(t.to_sym) end + + include_examples "to_json equalivent to Chef::JSONCompat.to_json" do + let(:jsonable) { @data_bag } + end end end diff --git a/spec/unit/encrypted_data_bag_item_spec.rb b/spec/unit/encrypted_data_bag_item_spec.rb index 5ee245b9bc..9335889ef3 100644 --- a/spec/unit/encrypted_data_bag_item_spec.rb +++ b/spec/unit/encrypted_data_bag_item_spec.rb @@ -168,6 +168,17 @@ describe Chef::EncryptedDataBagItem::Decryptor do let(:plaintext_data) { {"foo" => "bar"} } let(:encryption_key) { "passwd" } let(:decryption_key) { encryption_key } + let(:json_wrapped_data) { Chef::JSONCompat.to_json({"json_wrapper" => plaintext_data}) } + + shared_examples "decryption examples" do + it "decrypts the encrypted value" do + decryptor.decrypted_data.should eq(json_wrapped_data) + end + + it "unwraps the encrypted data and returns it" do + decryptor.for_decrypted_item.should eq plaintext_data + end + end context "when decrypting a version 3 (JSON+aes-256-gcm+random iv+auth tag) encrypted value" do @@ -179,13 +190,7 @@ describe Chef::EncryptedDataBagItem::Decryptor do let(:bogus_auth_tag) { "bogus_auth_tag" } - it "decrypts the encrypted value" do - decryptor.decrypted_data.should eq({"json_wrapper" => plaintext_data}.to_json) - end - - it "unwraps the encrypted data and returns it" do - decryptor.for_decrypted_item.should eq plaintext_data - end + include_examples "decryption examples" it "rejects the data if the authentication tag is wrong" do encrypted_value["auth_tag"] = bogus_auth_tag @@ -240,13 +245,7 @@ describe Chef::EncryptedDataBagItem::Decryptor do Base64.encode64(raw_hmac) end - it "decrypts the encrypted value" do - decryptor.decrypted_data.should eq({"json_wrapper" => plaintext_data}.to_json) - end - - it "unwraps the encrypted data and returns it" do - decryptor.for_decrypted_item.should eq plaintext_data - end + include_examples "decryption examples" it "rejects the data if the hmac is wrong" do encrypted_value["hmac"] = bogus_hmac @@ -270,13 +269,7 @@ describe Chef::EncryptedDataBagItem::Decryptor do decryptor.should be_a_instance_of Chef::EncryptedDataBagItem::Decryptor::Version1Decryptor end - it "decrypts the encrypted value" do - decryptor.decrypted_data.should eq({"json_wrapper" => plaintext_data}.to_json) - end - - it "unwraps the encrypted data and returns it" do - decryptor.for_decrypted_item.should eq plaintext_data - end + include_examples "decryption examples" describe "and the decryption step returns invalid data" do it "raises a decryption failure error" do diff --git a/spec/unit/environment_spec.rb b/spec/unit/environment_spec.rb index 5a2c400d3c..ffb8fbfeaf 100644 --- a/spec/unit/environment_spec.rb +++ b/spec/unit/environment_spec.rb @@ -196,7 +196,7 @@ describe Chef::Environment do %w{name description cookbook_versions}.each do |t| it "should include '#{t}'" do - @json.should =~ /"#{t}":#{Regexp.escape(@environment.send(t.to_sym).to_json)}/ + @json.should =~ /"#{t}":#{Regexp.escape(Chef::JSONCompat.to_json(@environment.send(t.to_sym)))}/ end end @@ -207,6 +207,10 @@ describe Chef::Environment do it "should include 'chef_type'" do @json.should =~ /"chef_type":"environment"/ end + + include_examples "to_json equalivent to Chef::JSONCompat.to_json" do + let(:jsonable) { @environment } + end end describe "from_json" do @@ -222,7 +226,7 @@ describe Chef::Environment do "json_class" => "Chef::Environment", "chef_type" => "environment" } - @environment = Chef::JSONCompat.from_json(@data.to_json) + @environment = Chef::JSONCompat.from_json(Chef::JSONCompat.to_json(@data)) end it "should return a Chef::Environment" do diff --git a/spec/unit/exceptions_spec.rb b/spec/unit/exceptions_spec.rb index 3e7b1ba93f..21b0abb9bf 100644 --- a/spec/unit/exceptions_spec.rb +++ b/spec/unit/exceptions_spec.rb @@ -74,5 +74,11 @@ describe Chef::Exceptions do it "should have an exception class of #{exception} which inherits from #{expected_super_class}" do lambda{ raise exception }.should raise_error(expected_super_class) end + + if exception.methods.include?(:to_json) + include_examples "to_json equalivent to Chef::JSONCompat.to_json" do + let(:jsonable) { exception } + end + end end end diff --git a/spec/unit/json_compat_spec.rb b/spec/unit/json_compat_spec.rb index e355a47faa..65d931df70 100644 --- a/spec/unit/json_compat_spec.rb +++ b/spec/unit/json_compat_spec.rb @@ -58,13 +58,17 @@ describe Chef::JSONCompat do describe "when pretty printing an object that defines #to_json" do class Foo def to_json(*a) - {'foo' => 1234}.to_json(*a) + Chef::JSONCompat.to_json({'foo' => 1234, 'bar' => {'baz' => 5678}}, *a) end end it "should work" do f = Foo.new - expect(Chef::JSONCompat.to_json_pretty(f)).to eql("{\n \"foo\": 1234\n}\n") + expect(Chef::JSONCompat.to_json_pretty(f)).to eql("{\n \"foo\": 1234,\n \"bar\": {\n \"baz\": 5678\n }\n}\n") + end + + include_examples "to_json equalivent to Chef::JSONCompat.to_json" do + let(:jsonable) { Foo.new } end end @@ -97,4 +101,10 @@ describe Chef::JSONCompat do end end end + + it "should define .to_json on all classes" do + class SomeClass; end + + expect(SomeClass.new.respond_to?(:to_json)).to eq(true) + end end diff --git a/spec/unit/knife/cookbook_site_share_spec.rb b/spec/unit/knife/cookbook_site_share_spec.rb index 902e5f6115..ad3f32fecc 100644 --- a/spec/unit/knife/cookbook_site_share_spec.rb +++ b/spec/unit/knife/cookbook_site_share_spec.rb @@ -109,7 +109,7 @@ describe Chef::Knife::CookbookSiteShare do end it 'should post the cookbook to "https://supermarket.getchef.com"' do - response_text = {:uri => 'https://supermarket.getchef.com/cookbooks/cookbook_name'}.to_json + response_text = Chef::JSONCompat.to_json({:uri => 'https://supermarket.getchef.com/cookbooks/cookbook_name'}) @upload_response.stub(:body).and_return(response_text) @upload_response.stub(:code).and_return(201) Chef::CookbookSiteStreamingUploader.should_receive(:post).with(/supermarket\.getchef\.com/, anything(), anything(), anything()) @@ -117,7 +117,7 @@ describe Chef::Knife::CookbookSiteShare do end it 'should alert the user when a version already exists' do - response_text = {:error_messages => ['Version already exists']}.to_json + response_text = Chef::JSONCompat.to_json({:error_messages => ['Version already exists']}) @upload_response.stub(:body).and_return(response_text) @upload_response.stub(:code).and_return(409) lambda { @knife.run }.should raise_error(SystemExit) @@ -125,7 +125,7 @@ describe Chef::Knife::CookbookSiteShare do end it 'should pass any errors on to the user' do - response_text = {:error_messages => ["You're holding it wrong"]}.to_json + response_text = Chef::JSONCompat.to_json({:error_messages => ["You're holding it wrong"]}) @upload_response.stub(:body).and_return(response_text) @upload_response.stub(:code).and_return(403) lambda { @knife.run }.should raise_error(SystemExit) @@ -133,7 +133,7 @@ describe Chef::Knife::CookbookSiteShare do end it 'should print the body if no errors are exposed on failure' do - response_text = {:system_error => "Your call was dropped", :reason => "There's a map for that"}.to_json + response_text = Chef::JSONCompat.to_json({:system_error => "Your call was dropped", :reason => "There's a map for that"}) @upload_response.stub(:body).and_return(response_text) @upload_response.stub(:code).and_return(500) @knife.ui.should_receive(:error).with(/#{Regexp.escape(response_text)}/)#.ordered diff --git a/spec/unit/knife/core/bootstrap_context_spec.rb b/spec/unit/knife/core/bootstrap_context_spec.rb index 266991a7dd..cd53088419 100644 --- a/spec/unit/knife/core/bootstrap_context_spec.rb +++ b/spec/unit/knife/core/bootstrap_context_spec.rb @@ -95,13 +95,13 @@ EXPECTED describe "when JSON attributes are given" do let(:config) { {:first_boot_attributes => {:baz => :quux}} } it "adds the attributes to first_boot" do - bootstrap_context.first_boot.to_json.should eq({:baz => :quux, :run_list => run_list}.to_json) + Chef::JSONCompat.to_json(bootstrap_context.first_boot).should eq(Chef::JSONCompat.to_json({:baz => :quux, :run_list => run_list})) end end describe "when JSON attributes are NOT given" do it "sets first_boot equal to run_list" do - bootstrap_context.first_boot.to_json.should eq({:run_list => run_list}.to_json) + Chef::JSONCompat.to_json(bootstrap_context.first_boot).should eq(Chef::JSONCompat.to_json({:run_list => run_list})) end end diff --git a/spec/unit/knife/core/ui_spec.rb b/spec/unit/knife/core/ui_spec.rb index 9044bc2f2f..ed1037ebd5 100644 --- a/spec/unit/knife/core/ui_spec.rb +++ b/spec/unit/knife/core/ui_spec.rb @@ -403,6 +403,34 @@ EOM @ui.format_cookbook_list_for_display(@item).should == response end end + + context "when running on Windows" do + before(:each) do + stdout = double('StringIO', :tty? => true) + @ui.stub(:stdout).and_return(stdout) + Chef::Platform.stub(:windows?) { true } + Chef::Config.reset + end + + after(:each) do + Chef::Config.reset + end + + it "should have color set to true if knife config has color explicitly set to true" do + Chef::Config[:color] = true + @ui.config[:color] = true + expect(@ui.color?).to eql(true) + end + + it "should have color set to false if knife config has color explicitly set to false" do + Chef::Config[:color] = false + expect(@ui.color?).to eql(false) + end + + it "should not have color set to false by default" do + expect(@ui.color?).to eql(false) + end + end end describe "confirm" do diff --git a/spec/unit/knife/data_bag_from_file_spec.rb b/spec/unit/knife/data_bag_from_file_spec.rb index dba5cc282b..8de046e7a4 100644 --- a/spec/unit/knife/data_bag_from_file_spec.rb +++ b/spec/unit/knife/data_bag_from_file_spec.rb @@ -29,7 +29,7 @@ describe Chef::Knife::DataBagFromFile do Chef::Platform.stub(:windows?) { false } Chef::Config[:node_name] = "webmonkey.example.com" FileUtils.mkdir_p([db_folder, db_folder2]) - db_file.write(plain_data.to_json) + db_file.write(Chef::JSONCompat.to_json(plain_data)) db_file.flush allow(knife).to receive(:config).and_return(config) allow(Chef::Knife::Core::ObjectLoader).to receive(:new).and_return(loader) diff --git a/spec/unit/node_spec.rb b/spec/unit/node_spec.rb index 21a978a9c9..00879dcb13 100644 --- a/spec/unit/node_spec.rb +++ b/spec/unit/node_spec.rb @@ -762,6 +762,13 @@ describe Chef::Node do end serialized_node.run_list.should == node.run_list end + + include_examples "to_json equalivent to Chef::JSONCompat.to_json" do + let(:jsonable) { + node.from_file(File.expand_path("nodes/test.example.com.rb", CHEF_SPEC_DATA)) + node + } + end end describe "to_s" do diff --git a/spec/unit/provider/remote_file/cache_control_data_spec.rb b/spec/unit/provider/remote_file/cache_control_data_spec.rb index 8e396b1b40..8a849d9d7d 100644 --- a/spec/unit/provider/remote_file/cache_control_data_spec.rb +++ b/spec/unit/provider/remote_file/cache_control_data_spec.rb @@ -85,7 +85,7 @@ describe Chef::Provider::RemoteFile::CacheControlData do cache["etag"] = etag cache["mtime"] = mtime cache["checksum"] = last_fetched_checksum - cache.to_json + Chef::JSONCompat.to_json(cache) end before do diff --git a/spec/unit/resource_collection_spec.rb b/spec/unit/resource_collection_spec.rb index eddd92e098..cf119f1ab0 100644 --- a/spec/unit/resource_collection_spec.rb +++ b/spec/unit/resource_collection_spec.rb @@ -278,12 +278,20 @@ describe Chef::ResourceCollection do json.should =~ /json_class/ json.should =~ /instance_vars/ end + + include_examples "to_json equalivent to Chef::JSONCompat.to_json" do + let(:jsonable) { @rc } + end end describe "self.from_json" do - it "should deserialize itself from json" do + it "should not respond to this method" do + expect(@rc.respond_to?(:from_json)).to eq(false) + end + + it "should convert from json using the CHEF::JSONCompat library" do @rc << @resource - json = @rc.to_json + json = Chef::JSONCompat.to_json(@rc) s_rc = Chef::JSONCompat.from_json(json) s_rc.should be_a_kind_of(Chef::ResourceCollection) s_rc[0].name.should eql(@resource.name) diff --git a/spec/unit/resource_reporter_spec.rb b/spec/unit/resource_reporter_spec.rb index fe6a895b5a..1a89cbdce1 100644 --- a/spec/unit/resource_reporter_spec.rb +++ b/spec/unit/resource_reporter_spec.rb @@ -421,7 +421,7 @@ describe Chef::ResourceReporter do it "includes the run_list" do @report.should have_key("run_list") - @report["run_list"].should == @run_status.node.run_list.to_json + @report["run_list"].should == Chef::JSONCompat.to_json(@run_status.node.run_list) end it "includes the end_time" do @@ -484,7 +484,7 @@ describe Chef::ResourceReporter do it "includes the exception trace in the event data" do @report["data"]["exception"].should have_key("backtrace") - @report["data"]["exception"]["backtrace"].should == @backtrace.to_json + @report["data"]["exception"]["backtrace"].should == Chef::JSONCompat.to_json(@backtrace) end it "includes the error inspector output in the event data" do @@ -701,7 +701,7 @@ describe Chef::ResourceReporter do }) data_stream = Zlib::GzipReader.new(StringIO.new(data)) data = data_stream.read - data.should eq(@expected_data.to_json) + data.should eq(Chef::JSONCompat.to_json(@expected_data)) response end diff --git a/spec/unit/resource_spec.rb b/spec/unit/resource_spec.rb index e85633eaab..692345c943 100644 --- a/spec/unit/resource_spec.rb +++ b/spec/unit/resource_spec.rb @@ -336,6 +336,10 @@ describe Chef::Resource do json.should =~ /json_class/ json.should =~ /instance_vars/ end + + include_examples "to_json equalivent to Chef::JSONCompat.to_json" do + let(:jsonable) { @resource } + end end describe "to_hash" do @@ -354,7 +358,7 @@ describe Chef::Resource do describe "self.json_create" do it "should deserialize itself from json" do - json = @resource.to_json + json = Chef::JSONCompat.to_json(@resource) serialized_node = Chef::JSONCompat.from_json(json) serialized_node.should be_a_kind_of(Chef::Resource) serialized_node.name.should eql(@resource.name) diff --git a/spec/unit/role_spec.rb b/spec/unit/role_spec.rb index f3fa7e1868..1a108c4247 100644 --- a/spec/unit/role_spec.rb +++ b/spec/unit/role_spec.rb @@ -216,6 +216,10 @@ describe Chef::Role do end end + + include_examples "to_json equalivent to Chef::JSONCompat.to_json" do + let(:jsonable) { @role } + end end describe "when created from JSON", :json => true do diff --git a/spec/unit/run_list_spec.rb b/spec/unit/run_list_spec.rb index 220e4ea4a6..cc7e29af0f 100644 --- a/spec/unit/run_list_spec.rb +++ b/spec/unit/run_list_spec.rb @@ -304,7 +304,11 @@ describe Chef::RunList do end it "converts to json by converting its array form" do - @run_list.to_json.should == ["recipe[nagios::client]", "role[production]", "recipe[apache2]"].to_json + Chef::JSONCompat.to_json(@run_list).should == Chef::JSONCompat.to_json(["recipe[nagios::client]", "role[production]", "recipe[apache2]"]) + end + + include_examples "to_json equalivent to Chef::JSONCompat.to_json" do + let(:jsonable) { @run_list } end end diff --git a/spec/unit/user_spec.rb b/spec/unit/user_spec.rb index 08bde33d7b..2f2299c5bd 100644 --- a/spec/unit/user_spec.rb +++ b/spec/unit/user_spec.rb @@ -154,6 +154,10 @@ describe Chef::User do it "does not include the password if not present" do @json.should_not include("password") end + + include_examples "to_json equalivent to Chef::JSONCompat.to_json" do + let(:jsonable) { @user } + end end describe "when deserializing from JSON" do @@ -163,7 +167,7 @@ describe Chef::User do "private_key" => "pandas", "password" => "password", "admin" => true } - @user = Chef::User.from_json(user.to_json) + @user = Chef::User.from_json(Chef::JSONCompat.to_json(user)) end it "should deserialize to a Chef::User object" do |