summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThom May <thom@chef.io>2016-01-18 15:14:54 +0000
committerThom May <thom@chef.io>2016-01-18 15:14:54 +0000
commit832505aaa7e029ad76287c1d37c1ebc146869dd4 (patch)
treeb254006a56d4eb042dbaa429804bfd791ae3ebbd
parent0ef0ab07531ae78cb4052242037227b0fb5365dc (diff)
downloadchef-832505aaa7e029ad76287c1d37c1ebc146869dd4.tar.gz
ensure unit tests are correct
-rw-r--r--spec/unit/api_client_spec.rb2
-rw-r--r--spec/unit/data_bag_item_spec.rb2
-rw-r--r--spec/unit/data_bag_spec.rb2
-rw-r--r--spec/unit/environment_spec.rb2
-rw-r--r--spec/unit/handler/json_file_spec.rb2
-rw-r--r--spec/unit/json_compat_spec.rb7
-rw-r--r--spec/unit/node_spec.rb4
-rw-r--r--spec/unit/rest_spec.rb7
8 files changed, 21 insertions, 7 deletions
diff --git a/spec/unit/api_client_spec.rb b/spec/unit/api_client_spec.rb
index 1f313d7447..0451541f14 100644
--- a/spec/unit/api_client_spec.rb
+++ b/spec/unit/api_client_spec.rb
@@ -181,7 +181,7 @@ describe Chef::ApiClient do
end
let(:client) do
- Chef::JSONCompat.from_json(Chef::JSONCompat.to_json(client_hash))
+ Chef::ApiClient.from_hash(Chef::JSONCompat.parse(Chef::JSONCompat.to_json(client_hash)))
end
it "should deserialize to a Chef::ApiClient object" do
diff --git a/spec/unit/data_bag_item_spec.rb b/spec/unit/data_bag_item_spec.rb
index 0329264718..5605763806 100644
--- a/spec/unit/data_bag_item_spec.rb
+++ b/spec/unit/data_bag_item_spec.rb
@@ -174,7 +174,7 @@ describe Chef::DataBagItem do
data_bag_item
}
- let(:deserial) { Chef::JSONCompat.from_json(Chef::JSONCompat.to_json(data_bag_item)) }
+ let(:deserial) { Chef::DataBagItem.from_hash(Chef::JSONCompat.parse(Chef::JSONCompat.to_json(data_bag_item))) }
it "should deserialize to a Chef::DataBagItem object" do
diff --git a/spec/unit/data_bag_spec.rb b/spec/unit/data_bag_spec.rb
index 4e06a31911..8dc716460b 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(Chef::JSONCompat.to_json(@data_bag))
+ @deserial = Chef::DataBag.from_hash(Chef::JSONCompat.parse(Chef::JSONCompat.to_json(@data_bag)))
end
it "should deserialize to a Chef::DataBag object" do
diff --git a/spec/unit/environment_spec.rb b/spec/unit/environment_spec.rb
index 0f3ee17872..f5c5c3953d 100644
--- a/spec/unit/environment_spec.rb
+++ b/spec/unit/environment_spec.rb
@@ -226,7 +226,7 @@ describe Chef::Environment do
"json_class" => "Chef::Environment",
"chef_type" => "environment",
}
- @environment = Chef::JSONCompat.from_json(Chef::JSONCompat.to_json(@data))
+ @environment = Chef::Environment.from_hash(Chef::JSONCompat.parse(Chef::JSONCompat.to_json(@data)))
end
it "should return a Chef::Environment" do
diff --git a/spec/unit/handler/json_file_spec.rb b/spec/unit/handler/json_file_spec.rb
index 76098e2522..d66c3ef120 100644
--- a/spec/unit/handler/json_file_spec.rb
+++ b/spec/unit/handler/json_file_spec.rb
@@ -53,7 +53,7 @@ describe Chef::Handler::JsonFile do
it "saves run status data to a file as JSON" do
expect(@handler).to receive(:build_report_dir)
@handler.run_report_unsafe(@run_status)
- reported_data = Chef::JSONCompat.from_json(@file_mock.string)
+ reported_data = Chef::JSONCompat.parse(@file_mock.string)
expect(reported_data["exception"]).to eq("Exception: Boy howdy!")
expect(reported_data["start_time"]).to eq(@expected_time.to_s)
expect(reported_data["end_time"]).to eq((@expected_time + 5).to_s)
diff --git a/spec/unit/json_compat_spec.rb b/spec/unit/json_compat_spec.rb
index 524b71f09a..042ac09069 100644
--- a/spec/unit/json_compat_spec.rb
+++ b/spec/unit/json_compat_spec.rb
@@ -20,10 +20,17 @@ require File.expand_path("../../spec_helper", __FILE__)
require "chef/json_compat"
describe Chef::JSONCompat do
+ before { Chef::Config[:treat_deprecation_warnings_as_errors] = false }
describe "#from_json with JSON containing an existing class" do
let(:json) { '{"json_class": "Chef::Role"}' }
+ it "emits a deprecation warning" do
+ Chef::Config[:treat_deprecation_warnings_as_errors] = true
+ expect { Chef::JSONCompat.from_json(json) }.to raise_error Chef::Exceptions::DeprecatedFeatureError,
+ /Auto inflation of JSON data is deprecated. Please use Chef::Role#from_hash/
+ end
+
it "returns an instance of the class instead of a Hash" do
expect(Chef::JSONCompat.from_json(json).class).to eq Chef::Role
end
diff --git a/spec/unit/node_spec.rb b/spec/unit/node_spec.rb
index dcee5f8eb5..59bd1a1081 100644
--- a/spec/unit/node_spec.rb
+++ b/spec/unit/node_spec.rb
@@ -1207,7 +1207,7 @@ describe Chef::Node do
it "should deserialize itself from json", :json => true do
node.from_file(File.expand_path("nodes/test.example.com.rb", CHEF_SPEC_DATA))
json = Chef::JSONCompat.to_json(node)
- serialized_node = Chef::JSONCompat.from_json(json)
+ serialized_node = Chef::Node.from_hash(Chef::JSONCompat.parse(json))
expect(serialized_node).to be_a_kind_of(Chef::Node)
expect(serialized_node.name).to eql(node.name)
expect(serialized_node.chef_environment).to eql(node.chef_environment)
@@ -1246,7 +1246,7 @@ describe Chef::Node do
end
it "parses policyfile attributes from JSON" do
- round_tripped_node = Chef::Node.json_create(node.for_json)
+ round_tripped_node = Chef::Node.from_hash(node.for_json)
expect(round_tripped_node.policy_name).to eq("my-application")
expect(round_tripped_node.policy_group).to eq("staging")
diff --git a/spec/unit/rest_spec.rb b/spec/unit/rest_spec.rb
index ba5f837c07..b7d1c1d8c1 100644
--- a/spec/unit/rest_spec.rb
+++ b/spec/unit/rest_spec.rb
@@ -74,6 +74,7 @@ describe Chef::REST do
before(:each) do
Chef::Log.init(log_stringio)
+ Chef::Config[:treat_deprecation_warnings_as_errors] = false
end
it "should have content length validation middleware after compressor middleware" do
@@ -92,6 +93,12 @@ describe Chef::REST do
Chef::REST.new(base_url, nil, nil, options)
end
+ it "emits a deprecation warning" do
+ Chef::Config[:treat_deprecation_warnings_as_errors] = true
+ expect { Chef::REST.new(base_url) }.to raise_error Chef::Exceptions::DeprecatedFeatureError,
+ /Chef::REST is deprecated. Please use Chef::ServerAPI, or investigate Ridley or ChefAPI./
+ end
+
context "when created with a chef zero URL" do
let(:url) { "chefzero://localhost:1" }