Permalink
Browse files

Fail more gracefully when finding module files if no file is specified

Previously this would just complain about trying to call `nil.split`.
  • Loading branch information...
nicklewis committed Jun 22, 2012
1 parent 20ab0e9 commit d881b4b1cc7d3a744e5ef2d55fa0cde1792949de
Showing with 12 additions and 5 deletions.
  1. +4 −5 lib/puppet/file_serving/mount/modules.rb
  2. +8 −0 spec/unit/file_serving/mount/modules_spec.rb
@@ -5,18 +5,17 @@
class Puppet::FileServing::Mount::Modules < Puppet::FileServing::Mount
# Return an instance of the appropriate class.
def find(path, request)
+ raise "No module specified" if path.to_s.empty?
module_name, relative_path = path.split("/", 2)
return nil unless mod = request.environment.module(module_name)
mod.file(relative_path)
end
def search(path, request)
- module_name, relative_path = path.split("/", 2)
- return nil unless mod = request.environment.module(module_name)
-
- return nil unless path = mod.file(relative_path)
- [path]
+ if result = find(path, request)
+ [result]
+ end
end
def valid?
@@ -11,6 +11,10 @@
end
describe "when finding files" do
+ it "should fail if no module is specified" do
+ expect { @mount.find("", @request) }.to raise_error(/No module specified/)
+ end
+
it "should use the provided environment to find the module" do
@environment.expects(:module)
@@ -36,6 +40,10 @@
end
describe "when searching for files" do
+ it "should fail if no module is specified" do
+ expect { @mount.find("", @request) }.to raise_error(/No module specified/)
+ end
+
it "should use the node's environment to search the module" do
@environment.expects(:module)

0 comments on commit d881b4b

Please sign in to comment.