imgkit 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -13,6 +13,15 @@ class IMGKit
13
13
  super("Improper Source: #{msg}")
14
14
  end
15
15
  end
16
+
17
+ class CommandFailedError < RuntimeError
18
+ attr_reader :command, :stderr
19
+ def initialize(command, stderr)
20
+ @command = command
21
+ @stderr = stderr
22
+ super("Command failed: #{command}: #{stderr}")
23
+ end
24
+ end
16
25
 
17
26
  attr_accessor :source, :stylesheets
18
27
  attr_reader :options
@@ -67,15 +76,17 @@ class IMGKit
67
76
  =end
68
77
 
69
78
  result = nil
79
+ stderr_output = nil
70
80
  Open3.popen3(*command) do |stdin,stdout,stderr|
71
81
  stdin << (@source.to_s) if @source.html?
72
82
  stdin.close
73
83
  result = stdout.gets(nil)
84
+ stderr_output = stderr.readlines.join
74
85
  stdout.close
75
86
  stderr.close
76
87
  end
77
88
 
78
- raise "command failed: #{command.join(' ')}" unless result
89
+ raise CommandFailedError.new(command.join(' '), stderr_output) unless result
79
90
  return result
80
91
  end
81
92
 
@@ -1,3 +1,3 @@
1
1
  class IMGKit
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
@@ -142,6 +142,11 @@ describe IMGKit do
142
142
  imgkit.stylesheets << css
143
143
  lambda { imgkit.to_img }.should raise_error(IMGKit::ImproperSourceError)
144
144
  end
145
+
146
+ it "should throw an error if the wkhtmltoimage command fails" do
147
+ imgkit = IMGKit.new('http://www.hopefully.this.site.never.exists.asjdhjkalshgflkahfsglkahfdlg11.com')
148
+ lambda { imgkit.to_img }.should raise_error(IMGKit::CommandFailedError)
149
+ end
145
150
  end
146
151
 
147
152
  context "#to_file" do
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 0
8
- - 1
9
- version: 1.0.1
8
+ - 2
9
+ version: 1.0.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - csquared
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-12-14 00:00:00 -06:00
17
+ date: 2011-04-12 00:00:00 -05:00
18
18
  default_executable:
19
19
  dependencies: []
20
20