diff options
| author | Luke Kanies <luke@madstop.com> | 2009-08-01 23:11:37 -0700 |
|---|---|---|
| committer | James Turnbull <james@lovedthanlost.net> | 2009-08-02 16:38:48 +1000 |
| commit | cc3f56a68b04ba26c0234e1434abe7f58e6c7218 (patch) | |
| tree | f7f4582ecd48611f894ba0c7ecba8e39acecc91e /spec/integration/util/feature.rb | |
| parent | 21d1d257a804e472607989ef63fb7d7ce1ddee77 (diff) | |
| download | puppet-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 'spec/integration/util/feature.rb')
| -rwxr-xr-x | spec/integration/util/feature.rb | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/spec/integration/util/feature.rb b/spec/integration/util/feature.rb new file mode 100755 index 000000000..f1ddd5d43 --- /dev/null +++ b/spec/integration/util/feature.rb @@ -0,0 +1,54 @@ +#!/usr/bin/env ruby + +Dir.chdir(File.dirname(__FILE__)) { (s = lambda { |f| File.exist?(f) ? require(f) : Dir.chdir("..") { s.call(f) } }).call("spec/spec_helper.rb") } + +require 'puppet/util/feature' +require 'puppet_spec/files' + +describe Puppet::Util::Feature do + include PuppetSpec::Files + + it "should be able to load features from disk" do + libdir = tmpfile("feature_lib") + Dir.mkdir(libdir) + + $: << libdir + + $features = Puppet::Util::Feature.new("feature_lib") + + Dir.mkdir(File.join(libdir, "feature_lib")) + + File.open(File.join(libdir, "feature_lib", "able_to_load.rb"), "w") do |f| + f.puts "$features.add(:able_to_load) { true }" + end + + $features.should be_able_to_load + end + + + def test_dynamic_loading + $features = @features + cleanup { $features = nil } + # Now create a feature and make sure it loads. + FileUtils.mkdir_p(@path) + nope = File.join(@path, "nope.rb") + File.open(nope, "w") { |f| + f.puts "$features.add(:nope, :libs => %w{nosuchlib})" + } + assert_nothing_raised("Failed to autoload features") do + assert(! @features.nope?, "'nope' returned true") + end + + # First make sure "yep?" returns false + assert_nothing_raised("Missing feature threw an exception") do + assert(! @features.notyep?, "'notyep' returned true before definition") + end + + yep = File.join(@path, "yep.rb") + File.open(yep, "w") { |f| + f.puts "$features.add(:yep, :libs => %w{puppet})" + } + + assert(@features.yep?, "false 'yep' is apparently cached or feature could not be loaded") + end +end |
