summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Roberts <Markus@reality.com>2009-09-18 16:12:08 -0700
committerJames Turnbull <james@lovedthanlost.net>2009-09-22 09:31:19 +1000
commita5950339f43e08516130ff0b7463dbe3fa925890 (patch)
tree3c1f4b60f2310e5133311433fe10f954e72e3d01
parenta951163d3d8a52fff4f0340b4ed1e827f2399147 (diff)
downloadpuppet-a5950339f43e08516130ff0b7463dbe3fa925890.tar.gz
puppet-a5950339f43e08516130ff0b7463dbe3fa925890.tar.xz
puppet-a5950339f43e08516130ff0b7463dbe3fa925890.zip
Fix for #2654 (error generating error message)
Since required_features can (and frequently does) return a single item instead of an Array, the error message needed to be more robust. The tests were not specific enough to catch the fact that an error was being raised in the generation of the error, so a more specific test was added and the required_features accessor test was beefed up a little. Signed-off-by: Markus Roberts <Markus@reality.com> Signed-off-by: Markus Roberts <Markus@reality.com>
-rw-r--r--lib/puppet/property.rb4
-rwxr-xr-xspec/unit/property.rb18
2 files changed, 16 insertions, 6 deletions
diff --git a/lib/puppet/property.rb b/lib/puppet/property.rb
index 1ed323f16..abbc71c6b 100644
--- a/lib/puppet/property.rb
+++ b/lib/puppet/property.rb
@@ -1,4 +1,4 @@
- # The virtual base class for properties, which are the self-contained building
+# The virtual base class for properties, which are the self-contained building
# blocks for actually doing work on the system.
require 'puppet'
@@ -384,7 +384,7 @@ class Puppet::Property < Puppet::Parameter
# Make sure that we've got all of the required features for a given value.
def validate_features_per_value(value)
if features = self.class.value_option(self.class.value_name(value), :required_features)
- raise ArgumentError, "Provider must have features '%s' to set '%s' to '%s'" % [features.collect { |f| f.to_s }.join(", "), self.class.name, value] unless provider.satisfies?(features)
+ raise ArgumentError, "Provider must have features '%s' to set '%s' to '%s'" % [[features].flatten.join(", "), self.class.name, value] unless provider.satisfies?(features)
end
end
diff --git a/spec/unit/property.rb b/spec/unit/property.rb
index 07ab9c319..26a5765a2 100755
--- a/spec/unit/property.rb
+++ b/spec/unit/property.rb
@@ -34,10 +34,12 @@ describe Puppet::Property do
@class.should respond_to(:required_features=)
end
- it "should always convert required features into an array of symbols" do
- @class.required_features = %w{one two}
- @class.required_features.should == [:one, :two]
- end
+ {"one" => [:one],:one => [:one],%w{a} => [:a],[:b] => [:b],%w{one two} => [:one,:two],[:a,:b] => [:a,:b]}.each { |in_value,out_value|
+ it "should always convert required features into an array of symbols (e.g. #{in_value.inspect} --> #{out_value.inspect})" do
+ @class.required_features = in_value
+ @class.required_features.should == out_value
+ end
+ }
it "should be able to shadow metaparameters" do
@property.must respond_to(:shadow)
@@ -200,6 +202,14 @@ describe Puppet::Property do
lambda { @property.should = :foo }.should raise_error(Puppet::Error)
end
+ it "should internally raise an ArgumentError if required features are missing" do
+ @class.newvalue(:foo, :required_features => [:a, :b])
+
+ @provider.expects(:satisfies?).with([:a, :b]).returns false
+
+ lambda { @property.validate_features_per_value :foo }.should raise_error(ArgumentError)
+ end
+
it "should validate that all required features are present for regexes" do
value = @class.newvalue(/./, :required_features => [:a, :b])