summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/chef/environment.rb9
-rw-r--r--lib/chef/exceptions.rb3
-rw-r--r--spec/unit/environment_spec.rb18
-rw-r--r--spec/unit/exceptions_spec.rb4
4 files changed, 31 insertions, 3 deletions
diff --git a/lib/chef/environment.rb b/lib/chef/environment.rb
index 0e1b03c87f..5c719ca285 100644
--- a/lib/chef/environment.rb
+++ b/lib/chef/environment.rb
@@ -302,8 +302,13 @@ class Chef
def self.validate_cookbook_version(version)
begin
- Chef::VersionConstraint.new version
- true
+ if Chef::Config[:solo]
+ raise Chef::Exceptions::IllegalVersionConstraint,
+ "Environment cookbook version constraints not allowed in chef-solo"
+ else
+ Chef::VersionConstraint.new version
+ true
+ end
rescue ArgumentError
false
end
diff --git a/lib/chef/exceptions.rb b/lib/chef/exceptions.rb
index ec2abb0e0c..64609c5c04 100644
--- a/lib/chef/exceptions.rb
+++ b/lib/chef/exceptions.rb
@@ -115,6 +115,9 @@ class Chef
# match OP VERSION. ArgumentError?
class InvalidVersionConstraint < ArgumentError; end
+ # Version constraints are not allowed in chef-solo
+ class IllegalVersionConstraint < NotImplementedError; end
+
# File operation attempted but no permissions to perform it
class InsufficientPermissions < RuntimeError; end
diff --git a/spec/unit/environment_spec.rb b/spec/unit/environment_spec.rb
index 8bbf003e6a..5f9675a307 100644
--- a/spec/unit/environment_spec.rb
+++ b/spec/unit/environment_spec.rb
@@ -275,6 +275,24 @@ describe Chef::Environment do
Chef::Environment.validate_cookbook_version("= a").should == false
Chef::Environment.validate_cookbook_version("= 1.2.3.4").should == false
end
+
+ describe "in solo mode" do
+ before do
+ Chef::Config[:solo] = true
+ end
+
+ after do
+ Chef::Config[:solo] = false
+ end
+
+ it "should raise and exception" do
+ lambda {
+ Chef::Environment.validate_cookbook_version("= 1.2.3.4")
+ }.should raise_error Chef::Exceptions::IllegalVersionConstraint,
+ "Environment cookbook version constraints not allowed in chef-solo"
+ end
+ end
+
end
describe "when updating from a parameter hash" do
diff --git a/spec/unit/exceptions_spec.rb b/spec/unit/exceptions_spec.rb
index fdf515de54..3e7b1ba93f 100644
--- a/spec/unit/exceptions_spec.rb
+++ b/spec/unit/exceptions_spec.rb
@@ -65,7 +65,9 @@ describe Chef::Exceptions do
Chef::Exceptions::SolrConnectionError => RuntimeError,
Chef::Exceptions::InvalidDataBagPath => ArgumentError,
Chef::Exceptions::InvalidEnvironmentPath => ArgumentError,
- Chef::Exceptions::EnvironmentNotFound => RuntimeError
+ Chef::Exceptions::EnvironmentNotFound => RuntimeError,
+ Chef::Exceptions::InvalidVersionConstraint => ArgumentError,
+ Chef::Exceptions::IllegalVersionConstraint => NotImplementedError
}
exception_to_super_class.each do |exception, expected_super_class|