+1 On Sep 18, 2009, at 10:40 PM, Markus Roberts wrote:
> > 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 <[email protected]> > > Signed-off-by: Markus Roberts <[email protected]> > --- > lib/puppet/property.rb | 4 ++-- > spec/unit/property.rb | 18 ++++++++++++++---- > 2 files changed, 16 insertions(+), 6 deletions(-) > > diff --git a/lib/puppet/property.rb b/lib/puppet/property.rb > index 1ed323f..abbc71c 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 07ab9c3..26a5765 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]) > > -- > 1.6.4 > > > > -- "They called me mad, and I called them mad, and damn them, they outvoted me." -- Nathaniel Lee, on being consigned to a mental institution, circa 17th c. --------------------------------------------------------------------- Luke Kanies | http://reductivelabs.com | http://madstop.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Puppet Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en -~----------~----~----~----~------~----~------~--~---
