From cc3f56a68b04ba26c0234e1434abe7f58e6c7218 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Sat, 1 Aug 2009 23:11:37 -0700 Subject: Migrating Feature tests to spec This was to fix a failing test/unit test. Test coverage is now a bit better, more maintainable, and I refactored the code just slightly to make it a bit cleaner. Signed-off-by: Luke Kanies --- lib/puppet/util/feature.rb | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) (limited to 'lib') diff --git a/lib/puppet/util/feature.rb b/lib/puppet/util/feature.rb index 94ee3be8b..102bca778 100644 --- a/lib/puppet/util/feature.rb +++ b/lib/puppet/util/feature.rb @@ -63,23 +63,29 @@ class Puppet::Util::Feature # someone asks for the feature, so we don't unnecessarily load # files. def test(name, options) - result = true - if ary = options[:libs] - ary = [ary] unless ary.is_a?(Array) + return true unless ary = options[:libs] + ary = [ary] unless ary.is_a?(Array) - ary.each do |lib| - unless lib.is_a?(String) - raise ArgumentError, "Libraries must be passed as strings not %s" % lib.class - end + ary.each do |lib| + load_library(lib) + end - begin - require lib - rescue Exception - Puppet.debug "Failed to load library '%s' for feature '%s'" % [lib, name] - result = false - end - end + # We loaded all of the required libraries + return true + end + + private + + def load_library(lib) + unless lib.is_a?(String) + raise ArgumentError, "Libraries must be passed as strings not %s" % lib.class + end + + begin + require lib + rescue Exception + Puppet.debug "Failed to load library '%s' for feature '%s'" % [lib, name] + result = false end - result end end -- cgit