test/util/autoload.rb in puppet-0.23.2 vs test/util/autoload.rb in puppet-0.24.0

- old
+ new

@@ -1,8 +1,8 @@ #!/usr/bin/env ruby -$:.unshift("../lib").unshift("../../lib") if __FILE__ =~ /\.rb$/ +require File.dirname(__FILE__) + '/../lib/puppettest' require 'puppet' require 'puppet/util/autoload' require 'puppettest' @@ -48,15 +48,10 @@ loader = Puppet::Util::Autoload.new(self.class, name) } return rbdir, loader end - def teardown - super - Puppet::Util::Autoload.clear - end - def test_load dir, loader = mk_loader(:yayness) assert_equal(loader.object_id, Puppet::Util::Autoload[self.class].object_id, "Did not retrieve loader object by class") @@ -82,40 +77,22 @@ assert(loader.loaded?(:mything), "Not considered loaded") assert(self.class.thing?(:mything), "Did not get loaded thing") - # Now clear everything, and test loadall - assert_nothing_raised { - Puppet::Util::Autoload.clear - } - self.class.clear - assert_nothing_raised { - loader.loadall - } - [:mything, :othing].each do |thing| + loader.load(thing) assert(loader.loaded?(thing), "#{thing.to_s} not considered loaded") assert(loader.loaded?("%s.rb" % thing), "#{thing.to_s} not considered loaded with .rb") assert(Puppet::Util::Autoload.loaded?("yayness/%s" % thing), "%s not considered loaded by the main class" % thing) assert(Puppet::Util::Autoload.loaded?("yayness/%s.rb" % thing), "%s not considered loaded by the main class with .rb" % thing) - loaded = Puppet::Util::Autoload.loaded?("yayness/%s.rb" % thing) - assert_equal("%s/%s.rb" % [dir, thing], loaded[:file], "File path was not set correctly in loaded store") - assert_equal(self.class, loaded[:autoloader], "Loader was not set correctly in loaded store") - assert(self.class.thing?(thing), "Did not get loaded #{thing.to_s}") end - - Puppet::Util::Autoload.clear - [:mything, :othing].each do |thing| - assert(! loader.loaded?(thing), "#{thing.to_s} considered loaded after clear") - assert(! Puppet::Util::Autoload.loaded?("yayness/%s" % thing), "%s considered loaded by the main class after clear" % thing) - end end # Make sure that autoload dynamically modifies $: with the libdir as # appropriate. def test_searchpath @@ -123,8 +100,27 @@ loader = Puppet::Util::Autoload.new(self, "testing") assert(loader.send(:searchpath).include?(dir), "searchpath does not include the libdir") end -end -# $Id: autoload.rb 2668 2007-07-10 04:00:28Z luke $ + # This causes very strange behaviour in the tests. We need to make sure we + # require the same path that a user would use, otherwise we'll result in + # a reload of the + def test_require_does_not_cause_reload + loadname = "testing" + loader = Puppet::Util::Autoload.new(self.class, loadname) + + basedir = "/some/dir" + dir = File.join(basedir, loadname) + loader.expects(:eachdir).yields(dir) + + subname = "instance" + + file = File.join(dir, subname) + ".rb" + + Dir.expects(:glob).with("#{dir}/*.rb").returns(file) + + Kernel.expects(:require).with(File.join(loadname, subname)) + loader.loadall + end +end