summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2009-08-01 23:11:37 -0700
committerJames Turnbull <james@lovedthanlost.net>2009-08-02 16:38:48 +1000
commitcc3f56a68b04ba26c0234e1434abe7f58e6c7218 (patch)
treef7f4582ecd48611f894ba0c7ecba8e39acecc91e /lib
parent21d1d257a804e472607989ef63fb7d7ce1ddee77 (diff)
downloadpuppet-cc3f56a68b04ba26c0234e1434abe7f58e6c7218.tar.gz
puppet-cc3f56a68b04ba26c0234e1434abe7f58e6c7218.tar.xz
puppet-cc3f56a68b04ba26c0234e1434abe7f58e6c7218.zip
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 <luke@madstop.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/puppet/util/feature.rb36
1 files changed, 21 insertions, 15 deletions
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