summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordanielsdeleo <dan@getchef.com>2015-02-06 15:40:27 -0800
committerdanielsdeleo <dan@getchef.com>2015-02-11 10:52:49 -0800
commita164ceb6cac2808088920e36e35b5e9c16a8496b (patch)
treeb993a8b68ecf2817e800d3c5fd5fb9b39cf84a95
parent6c9f246b04c23906dd5297d178a423c96bc7b369 (diff)
downloadchef-a164ceb6cac2808088920e36e35b5e9c16a8496b.tar.gz
Change hard errors to warnings for deprecated methods
-rw-r--r--lib/chef/cookbook_version.rb33
-rw-r--r--spec/unit/cookbook_version_spec.rb39
2 files changed, 55 insertions, 17 deletions
diff --git a/lib/chef/cookbook_version.rb b/lib/chef/cookbook_version.rb
index 4e3e8069a6..1f55ff8b72 100644
--- a/lib/chef/cookbook_version.rb
+++ b/lib/chef/cookbook_version.rb
@@ -63,47 +63,48 @@ class Chef
cookbook_manifest.update_from(new_manifest)
end
+ private def deprecated!(message)
+ if Chef::Config[:treat_deprecation_warnings_as_errors]
+ raise Exceptions::DeprecatedFeatureError, message
+ else
+ Chef::Log.warn(message)
+ end
+ end
+
def save_url
# TODO: double check this code suggestion
- msg = <<-WARNING
+ deprecated!(<<-DEPRECATED)
Cookbooks now have multiple save URLs based on the capabilities of the Chef Server.
To get the default save URL, use code like `Chef::CookbookManifest.new(cookbook_version).save_url`
-WARNING
- raise msg
- # TODO: change to warning
+DEPRECATED
+
cookbook_manifest.save_url
end
def force_save_url
# TODO: double check this code suggestion
- msg = <<-WARNING
+ deprecated!(<<-DEPRECATED)
Cookbooks now have multiple save URLs based on the capabilities of the Chef Server.
To get the default save URL, use code like `Chef::CookbookManifest.new(cookbook_version).force_save_url`
-WARNING
- raise msg
- # TODO: change to warning
+DEPRECATED
cookbook_manifest.force_save_url
end
def to_hash
# TODO: double check this code suggestion
- msg = <<-WARNING
+ deprecated!(<<-DEPRECATED)
Cookbooks now have multiple JSON representations based on the capabilities of the Chef Server.
To get the Hash representation, use code like `Chef::CookbookManifest.new(cookbook_version).to_hash`
-WARNING
- raise msg
- # TODO: change to warning
+DEPRECATED
cookbook_manifest.to_hash
end
def to_json(*a)
# TODO: double check this code suggestion
- msg = <<-WARNING
+ deprecated!(<<-DEPRECATED)
Cookbooks now have multiple JSON representations based on the capabilities of the Chef Server.
To get the JSON representation, use code like `Chef::CookbookManifest.new(cookbook_version).to_json`
-WARNING
- raise msg
- # TODO: change to warning
+DEPRECATED
cookbook_manifest.to_json
end
diff --git a/spec/unit/cookbook_version_spec.rb b/spec/unit/cookbook_version_spec.rb
index 95f0d68efc..1a3ec76840 100644
--- a/spec/unit/cookbook_version_spec.rb
+++ b/spec/unit/cookbook_version_spec.rb
@@ -498,7 +498,44 @@ describe Chef::CookbookVersion do
end
end
- pending "These should work when deprecation errors are changed back to warning" do
+
+ describe "when deprecation warnings are errors" do
+
+ subject(:cbv) { Chef::CookbookVersion.new("version validation", '/tmp/blah') }
+
+ it "errors on #save_url" do
+ expect { cbv.save_url }.to raise_error(Chef::Exceptions::DeprecatedFeatureError)
+ end
+
+ it "errors on #force_save_url" do
+ expect { cbv.force_save_url }.to raise_error(Chef::Exceptions::DeprecatedFeatureError)
+ end
+
+ it "errors on #to_hash" do
+ expect { cbv.to_hash }.to raise_error(Chef::Exceptions::DeprecatedFeatureError)
+ end
+
+ it "errors on #to_json" do
+ expect { cbv.to_json }.to raise_error(Chef::Exceptions::DeprecatedFeatureError)
+ end
+
+ end
+
+ describe "deprecated features" do
+
+ subject(:cbv) { Chef::CookbookVersion.new("tatft", '/tmp/blah').tap { |c| c.version = "1.2.3" } }
+
+ before do
+ Chef::Config[:treat_deprecation_warnings_as_errors] = false
+ end
+
+ it "gives a save URL for the standard cookbook API" do
+ expect(cbv.save_url).to eq("cookbooks/tatft/1.2.3")
+ end
+
+ it "gives a force save URL for the standard cookbook API" do
+ expect(cbv.force_save_url).to eq("cookbooks/tatft/1.2.3?force=true")
+ end
include_examples "to_json equalivent to Chef::JSONCompat.to_json" do
let(:jsonable) { Chef::CookbookVersion.new("tatft", '/tmp/blah') }