summaryrefslogtreecommitdiff
path: root/spec/unit/cookbook
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2015-10-20 16:06:34 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2015-10-26 16:21:06 -0700
commit324fddbb0d2d6ecdd63c0044eaf07e18d1e2de7b (patch)
tree355abebb4787d40a90c6e9ee1f327df6978ba860 /spec/unit/cookbook
parent4e61b02930ac7b8db3fd040ced2b110bfce54c9f (diff)
downloadchef-324fddbb0d2d6ecdd63c0044eaf07e18d1e2de7b.tar.gz
improve error message, add more tests
Diffstat (limited to 'spec/unit/cookbook')
-rw-r--r--spec/unit/cookbook/metadata_spec.rb52
1 files changed, 51 insertions, 1 deletions
diff --git a/spec/unit/cookbook/metadata_spec.rb b/spec/unit/cookbook/metadata_spec.rb
index ce8fb1ff26..0215858180 100644
--- a/spec/unit/cookbook/metadata_spec.rb
+++ b/spec/unit/cookbook/metadata_spec.rb
@@ -1,7 +1,7 @@
#
# Author:: Adam Jacob (<adam@opscode.com>)
# Author:: Seth Falcon (<seth@opscode.com>)
-# Copyright:: Copyright 2008-2010 Opscode, Inc.
+# Copyright:: Copyright 2008-2015 Chef Software, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -351,6 +351,31 @@ describe Chef::Cookbook::Metadata do
it "should work with multiple complex constraints" do
expect_chef_version_works([">= 11.14.2", "< 11.18.10"],[">= 12.2.1", "< 12.5.1"])
end
+
+ it "should fail validation on a simple pessimistic constraint" do
+ expect_chef_version_works(["~> 999.0"])
+ expect { metadata.validate_chef_version! }.not_to raise_error(Chef::Exceptions::CookbookChefVersionMismatch)
+ end
+
+ it "should fail validation when that valid chef versions are too big" do
+ expect_chef_version_works([">= 999.0", "< 999.9"])
+ expect { metadata.validate_chef_version! }.to raise_error(Chef::Exceptions::CookbookChefVersionMismatch)
+ end
+
+ it "should fail validation when that valid chef versions are too small" do
+ expect_chef_version_works([">= 0.0.1", "< 0.0.9"])
+ expect { metadata.validate_chef_version! }.to raise_error(Chef::Exceptions::CookbookChefVersionMismatch)
+ end
+
+ it "should fail validation when all ranges fail" do
+ expect_chef_version_works([">= 999.0", "< 999.9"],[">= 0.0.1", "< 0.0.9"])
+ expect { metadata.validate_chef_version! }.to raise_error(Chef::Exceptions::CookbookChefVersionMismatch)
+ end
+
+ it "should pass validation when one constraint passes" do
+ expect_chef_version_works([">= 999.0", "< 999.9"],["= #{Chef::VERSION}"])
+ expect { metadata.validate_chef_version! }.not_to raise_error
+ end
end
describe "ohai_version" do
@@ -378,6 +403,31 @@ describe Chef::Cookbook::Metadata do
it "should work with multiple complex constraints" do
expect_ohai_version_works([">= 11.14.2", "< 11.18.10"],[">= 12.2.1", "< 12.5.1"])
end
+
+ it "should fail validation on a simple pessimistic constraint" do
+ expect_ohai_version_works(["~> 999.0"])
+ expect { metadata.validate_ohai_version! }.to raise_error(Chef::Exceptions::CookbookOhaiVersionMismatch)
+ end
+
+ it "should fail validation when that valid chef versions are too big" do
+ expect_ohai_version_works([">= 999.0", "< 999.9"])
+ expect { metadata.validate_ohai_version! }.to raise_error(Chef::Exceptions::CookbookOhaiVersionMismatch)
+ end
+
+ it "should fail validation when that valid chef versions are too small" do
+ expect_ohai_version_works([">= 0.0.1", "< 0.0.9"])
+ expect { metadata.validate_ohai_version! }.to raise_error(Chef::Exceptions::CookbookOhaiVersionMismatch)
+ end
+
+ it "should fail validation when all ranges fail" do
+ expect_ohai_version_works([">= 999.0", "< 999.9"],[">= 0.0.1", "< 0.0.9"])
+ expect { metadata.validate_ohai_version! }.to raise_error(Chef::Exceptions::CookbookOhaiVersionMismatch)
+ end
+
+ it "should pass validation when one constraint passes" do
+ expect_ohai_version_works([">= 999.0", "< 999.9"],["= #{Ohai::VERSION}"])
+ expect { metadata.validate_ohai_version! }.not_to raise_error
+ end
end
describe "attribute groupings" do