diff options
author | Luke Kanies <luke@madstop.com> | 2009-05-17 17:10:16 -0500 |
---|---|---|
committer | James Turnbull <james@lovedthanlost.net> | 2009-05-20 18:29:04 +1000 |
commit | d489a2b9e2806beefd41627adf7e20d23b0924d6 (patch) | |
tree | afdfa61e1bd6d2704826467abb5b022050494684 /spec/unit/util/autoload.rb | |
parent | 5f1c228767432591a7e4b77666e9b1c7d70a095c (diff) | |
download | puppet-d489a2b9e2806beefd41627adf7e20d23b0924d6.tar.gz puppet-d489a2b9e2806beefd41627adf7e20d23b0924d6.tar.xz puppet-d489a2b9e2806beefd41627adf7e20d23b0924d6.zip |
Adding modulepath caching to the Autoloader
There's more caching to add, but this simplifies
the interface to the list of paths and then caches
that list so we aren't constantly searching the
filesystem.
Signed-off-by: Luke Kanies <luke@madstop.com>
Diffstat (limited to 'spec/unit/util/autoload.rb')
-rwxr-xr-x | spec/unit/util/autoload.rb | 50 |
1 files changed, 48 insertions, 2 deletions
diff --git a/spec/unit/util/autoload.rb b/spec/unit/util/autoload.rb index ff717d6c5..53b90db69 100755 --- a/spec/unit/util/autoload.rb +++ b/spec/unit/util/autoload.rb @@ -11,20 +11,66 @@ describe Puppet::Util::Autoload do @autoload.stubs(:eachdir).yields "/my/dir" end + it "should use the Cacher module" do + Puppet::Util::Autoload.ancestors.should be_include(Puppet::Util::Cacher) + end + + it "should use a ttl of 15 for the search path" do + Puppet::Util::Autoload.attr_ttl(:searchpath).should == 15 + end + + describe "when building the search path" do + it "should collect all of the plugins and lib directories that exist in the current environment's module path" do + Puppet.settings.expects(:value).with(:environment).returns "foo" + Puppet.settings.expects(:value).with(:modulepath, "foo").returns %w{/a /b /c} + Dir.expects(:entries).with("/a").returns %w{/a/one /a/two} + Dir.expects(:entries).with("/b").returns %w{/b/one /b/two} + + FileTest.stubs(:directory?).returns false + FileTest.expects(:directory?).with("/a").returns true + FileTest.expects(:directory?).with("/b").returns true + %w{/a/one/plugins /a/two/lib /b/one/plugins /b/two/lib}.each do |d| + FileTest.expects(:directory?).with(d).returns true + end + + @autoload.module_directories.should == %w{/a/one/plugins /a/two/lib /b/one/plugins /b/two/lib} + end + + it "should include the module directories, the Puppet libdir, and all of the Ruby load directories" do + @autoload.expects(:module_directories).returns %w{/one /two} + @autoload.search_directories.should == ["/one", "/two", Puppet[:libdir], $:].flatten + end + + it "should include in its search path all of the search directories that have a subdirectory matching the autoload path" do + @autoload = Puppet::Util::Autoload.new("foo", "loaddir") + @autoload.expects(:search_directories).returns %w{/one /two /three} + FileTest.expects(:directory?).with("/one/loaddir").returns true + FileTest.expects(:directory?).with("/two/loaddir").returns false + FileTest.expects(:directory?).with("/three/loaddir").returns true + @autoload.searchpath.should == ["/one/loaddir", "/three/loaddir"] + end + end + describe "when loading a file" do + before do + @autoload.stubs(:searchpath).returns %w{/a} + end + [RuntimeError, LoadError, SyntaxError].each do |error| it "should not die an if a #{error.to_s} exception is thrown" do - FileTest.stubs(:exists?).returns true + FileTest.stubs(:directory?).returns true + FileTest.stubs(:exist?).returns true Kernel.expects(:load).raises error - lambda { @autoload.load("foo") }.should_not raise_error + @autoload.load("foo") end end end describe "when loading all files" do before do + @autoload.stubs(:searchpath).returns %w{/a} Dir.stubs(:glob).returns "file.rb" end |