Permalink
Browse files

Also give a CommandNotFoundError if backtick raises Errno::ENOENT.

  • Loading branch information...
1 parent 3f1390a commit 20e9559acf9538a41220e19e9b017d011f32db0f @jyurek jyurek committed Jun 7, 2010
Showing with 18 additions and 8 deletions.
  1. +11 −7 lib/paperclip.rb
  2. +7 −1 test/paperclip_test.rb
View
@@ -112,16 +112,20 @@ def run cmd, *params
command = "#{command} 2>#{bit_bucket}" if Paperclip.options[:swallow_stderr]
Paperclip.log(command) if Paperclip.options[:log_command]
- output = `#{command}`
+ begin
+ output = `#{command}`
- if $?.exitstatus == 127
+ raise CommandNotFoundError if $?.exitstatus == 127
+
+ unless expected_outcodes.include?($?.exitstatus)
+ raise PaperclipCommandLineError,
+ "Error while running #{cmd}. Expected return code to be #{expected_outcodes.join(", ")} but was #{$?.exitstatus}",
+ output
+ end
+ rescue Errno::ENOENT => e
raise CommandNotFoundError
end
- unless expected_outcodes.include?($?.exitstatus)
- raise PaperclipCommandLineError,
- "Error while running #{cmd}. Expected return code to be #{expected_outcodes.join(", ")} but was #{$?.exitstatus}",
- output
- end
+
output
end
@@ -63,7 +63,7 @@ class PaperclipTest < Test::Unit::TestCase
end
context "Calling Paperclip.run when the command is not found" do
- should "tell you the command isn't there" do
+ should "tell you the command isn't there if the shell returns 127" do
begin
assert_raises(Paperclip::CommandNotFoundError) do
`ruby -e 'exit 127'` # Stub $?.exitstatus to be 127, i.e. Command Not Found.
@@ -74,6 +74,12 @@ class PaperclipTest < Test::Unit::TestCase
`ruby -e 'exit 0'` # Unstub $?.exitstatus
end
end
+ should "tell you the command isn't there if an ENOENT is raised" do
+ assert_raises(Paperclip::CommandNotFoundError) do
+ Paperclip.stubs(:"`").raises(Errno::ENOENT)
+ Paperclip.run("command")
+ end
+ end
end
should "prevent dangerous characters in the command via quoting" do

0 comments on commit 20e9559

Please sign in to comment.