summaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorLuke Kanies <luke@puppetlabs.com>2011-03-25 12:39:13 -0700
committerLuke Kanies <luke@puppetlabs.com>2011-03-25 14:32:03 -0700
commit29268f3fda3c6e29f60d05e5aa387ff0424e7b1e (patch)
tree618a97d95f843f59091f33645b976d7e1417c8c6 /spec
parentda082d500e1f1192dbc987483d753d93b5698094 (diff)
Fixing Module#path detection
For some reason FileTest.exist? was returning false, and FileTest.directory? returns true. I've also added much better tests for this behavior. Signed-off-by: Luke Kanies <luke@puppetlabs.com> Reviewed-by: Daniel Pittman <daniel@puppetlabs.com>
Diffstat (limited to 'spec')
-rwxr-xr-xspec/unit/module_spec.rb39
1 files changed, 32 insertions, 7 deletions
diff --git a/spec/unit/module_spec.rb b/spec/unit/module_spec.rb
index 54f5444ee..f3120e16b 100755
--- a/spec/unit/module_spec.rb
+++ b/spec/unit/module_spec.rb
@@ -1,8 +1,11 @@
#!/usr/bin/env ruby
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
+require 'puppet_spec/files'
describe Puppet::Module do
+ include PuppetSpec::Files
+
before do
# This is necessary because of the extra checks we have for the deprecated
# 'plugins' directory
@@ -267,17 +270,39 @@ describe Puppet::Module do
end
it "should return the path to the first found instance in its environment's module paths as its path" do
+ dir = tmpdir("deep_path")
+ first = File.join(dir, "first")
+ second = File.join(dir, "second")
+
+ FileUtils.mkdir_p(first)
+ FileUtils.mkdir_p(second)
+ Puppet[:modulepath] = "#{first}:#{second}"
+
+ modpath = File.join(first, "foo")
+ FileUtils.mkdir_p(modpath)
+
+ # Make a second one, which we shouldn't find
+ FileUtils.mkdir_p(File.join(second, "foo"))
+
mod = Puppet::Module.new("foo")
- env = mock 'environment'
- mod.stubs(:environment).returns env
+ mod.path.should == modpath
+ end
+
+ it "should be able to find itself in a directory other than the first directory in the module path" do
+ dir = tmpdir("deep_path")
+ first = File.join(dir, "first")
+ second = File.join(dir, "second")
- env.expects(:modulepath).returns %w{/a /b /c}
+ FileUtils.mkdir_p(first)
+ FileUtils.mkdir_p(second)
+ Puppet[:modulepath] = "#{first}:#{second}"
- FileTest.expects(:exist?).with("/a/foo").returns false
- FileTest.expects(:exist?).with("/b/foo").returns true
- FileTest.expects(:exist?).with("/c/foo").never
+ modpath = File.join(second, "foo")
+ FileUtils.mkdir_p(modpath)
- mod.path.should == "/b/foo"
+ mod = Puppet::Module.new("foo")
+ mod.should be_exist
+ mod.path.should == modpath
end
it "should be considered existent if it exists in at least one module path" do