Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Kill process on error. Throw CommandFailed if command returns nonzero.

  • Loading branch information...
commit ec92710d8ab90c63dfc0886f193cecf49748e555 1 parent bce2b3e
@topfunky authored
Showing with 15 additions and 3 deletions.
  1. +5 −3 lib/osxscreenshot.rb
  2. +10 −0 test/test_osxscreenshot.rb
View
8 lib/osxscreenshot.rb
@@ -3,7 +3,9 @@
module OSX
class Screenshot
VERSION = '0.0.3'
-
+
+ class CommandFailed < StandardError; end
+
##
# Takes a screenshot of a website, optionally resizes it, and writes
# it to a temporary directory. Returns the file path to the
@@ -109,9 +111,9 @@ def run_command(cmd, &block)
end
# Error
- system "kill -9 #{pid}"
- raise "Command failed: #{cmd}"
+ raise CommandFailed, "Command failed: #{cmd}"
rescue Timeout::Error => e
+ Process.kill "KILL", pid
return nil
end
View
10 test/test_osxscreenshot.rb
@@ -1,3 +1,4 @@
+# $: << File.dirname(__FILE__) + "/../lib"
require "test/unit"
require "osxscreenshot"
@@ -30,6 +31,15 @@ def test_handles_timeout
assert_nil @tmpfile
end
+ def test_handles_error_when_exiting
+ @tmpfile = nil
+ assert_raise OSX::Screenshot::CommandFailed do
+ OSX::Screenshot.capture("http://example.com", {
+ :webkit2png => "exit 1;"
+ })
+ end
+ end
+
def teardown
if @tmpfile
FileUtils.rm @tmpfile
Please sign in to comment.
Something went wrong with that request. Please try again.