summaryrefslogtreecommitdiffstats
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
parentda082d500e1f1192dbc987483d753d93b5698094 (diff)
downloadpuppet-29268f3fda3c6e29f60d05e5aa387ff0424e7b1e.tar.gz
puppet-29268f3fda3c6e29f60d05e5aa387ff0424e7b1e.tar.xz
puppet-29268f3fda3c6e29f60d05e5aa387ff0424e7b1e.zip
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>
-rw-r--r--lib/puppet/module.rb2
-rwxr-xr-xspec/unit/module_spec.rb39
2 files changed, 33 insertions, 8 deletions
diff --git a/lib/puppet/module.rb b/lib/puppet/module.rb
index 43266b2b5..059591ed8 100644
--- a/lib/puppet/module.rb
+++ b/lib/puppet/module.rb
@@ -138,7 +138,7 @@ class Puppet::Module
# Find this module in the modulepath.
def path
- environment.modulepath.collect { |path| File.join(path, name) }.find { |d| FileTest.exist?(d) }
+ environment.modulepath.collect { |path| File.join(path, name) }.find { |d| FileTest.directory?(d) }
end
# Find all plugin directories. This is used by the Plugins fileserving mount.
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