summaryrefslogtreecommitdiffstats
path: root/spec/unit/util/loader.rb
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2008-05-15 15:24:29 -0500
committerLuke Kanies <luke@madstop.com>2008-05-15 15:24:29 -0500
commitf1acbc0403068141c80b74c8585a1629fd45711b (patch)
tree346894daf9bad2228e2f8396e1303048cdc43a3a /spec/unit/util/loader.rb
parentbb92493c3868c54ef441a4f60c0b6a95ff742f88 (diff)
downloadfacter-f1acbc0403068141c80b74c8585a1629fd45711b.tar.gz
facter-f1acbc0403068141c80b74c8585a1629fd45711b.tar.xz
facter-f1acbc0403068141c80b74c8585a1629fd45711b.zip
Switching Facter to using the new loader.
This should make it possible to move all facts to separate files and only load them on demand.
Diffstat (limited to 'spec/unit/util/loader.rb')
-rwxr-xr-xspec/unit/util/loader.rb41
1 files changed, 41 insertions, 0 deletions
diff --git a/spec/unit/util/loader.rb b/spec/unit/util/loader.rb
index e6a7f17..690ec03 100755
--- a/spec/unit/util/loader.rb
+++ b/spec/unit/util/loader.rb
@@ -149,6 +149,18 @@ describe Facter::Util::Loader do
before do
@loader = Facter::Util::Loader.new
@loader.stubs(:search_path).returns []
+
+ FileTest.stubs(:directory?).returns true
+ end
+
+ it "should skip directories that do not exist" do
+ @loader.expects(:search_path).returns %w{/one/dir}
+
+ FileTest.expects(:directory?).with("/one/dir").returns false
+
+ Dir.expects(:entries).with("/one/dir").never
+
+ @loader.load_all
end
it "should load all files in all search paths" do
@@ -190,6 +202,29 @@ describe Facter::Util::Loader do
@loader.load_all
end
+ it "should not load files in a lib subdirectory" do
+ @loader.expects(:search_path).returns %w{/one/dir}
+
+ Dir.expects(:entries).with("/one/dir").returns %w{lib}
+
+ File.expects(:directory?).with("/one/dir/lib").returns true
+
+ Dir.expects(:entries).with("/one/dir/lib").never
+
+ @loader.load_all
+ end
+
+ it "should not load files in '.' or '..'" do
+ @loader.expects(:search_path).returns %w{/one/dir}
+
+ Dir.expects(:entries).with("/one/dir").returns %w{. ..}
+
+ File.expects(:entries).with("/one/dir/.").never
+ File.expects(:entries).with("/one/dir/..").never
+
+ @loader.load_all
+ end
+
it "should load all facts from the environment" do
Facter.expects(:add).with('one')
Facter.expects(:add).with('two')
@@ -198,5 +233,11 @@ describe Facter::Util::Loader do
@loader.load_all
end
end
+
+ it "should only load all facts one time" do
+ @loader.expects(:load_env).once
+ @loader.load_all
+ @loader.load_all
+ end
end
end