summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/puppet/application.rb9
-rwxr-xr-xspec/unit/application_spec.rb4
2 files changed, 8 insertions, 5 deletions
diff --git a/lib/puppet/application.rb b/lib/puppet/application.rb
index 374dc850b..1e00bcce7 100644
--- a/lib/puppet/application.rb
+++ b/lib/puppet/application.rb
@@ -215,11 +215,10 @@ class Application
def find(name)
klass = name.to_s.capitalize
- # const_defined? is used before const_get since const_defined? will only
- # check within our namespace, whereas const_get will check ancestor
- # trees as well, resulting in unexpected behaviour.
- if !self.const_defined?(klass)
- puts "Unable to find application '#{name.to_s}'."
+ begin
+ require File.join('puppet', 'application', name.to_s)
+ rescue LoadError => e
+ puts "Unable to find application '#{name}'. #{e}"
Kernel::exit(1)
end
diff --git a/spec/unit/application_spec.rb b/spec/unit/application_spec.rb
index aed80e3e6..b56aa20b0 100755
--- a/spec/unit/application_spec.rb
+++ b/spec/unit/application_spec.rb
@@ -31,6 +31,10 @@ describe Puppet::Application do
end
it "should exit if it can't find a class" do
+ reg = "Unable to find application 'ThisShallNeverEverEverExist'. "
+ reg += "no such file to load -- puppet/application/ThisShallNeverEverEverExist"
+ @klass.expects(:puts).with(reg)
+
expect { @klass.find("ThisShallNeverEverEverExist") }.to exit_with 1
end
end