imgry 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -32,10 +32,12 @@ module Imgry
32
32
 
33
33
  def detect_image_format!(image_input_stream)
34
34
  @format = nil # reset..
35
- if (reader = ImageIO.get_image_readers(image_input_stream).first)
36
- @format = reader.format_name.downcase
37
- @format = 'jpg' if @format == 'jpeg' # prefer this way..
38
- end
35
+
36
+ reader = ImageIO.get_image_readers(image_input_stream).first
37
+ raise UnsupportedFormatError if reader.nil?
38
+
39
+ @format = reader.format_name.downcase
40
+ @format = 'jpg' if @format == 'jpeg' # prefer this way..
39
41
  end
40
42
 
41
43
  def self.supported_formats
data/lib/imgry/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Imgry
2
- VERSION = '0.1.6'
2
+ VERSION = '0.1.7'
3
3
  end
data/lib/imgry.rb CHANGED
@@ -28,8 +28,9 @@ module Imgry
28
28
  end
29
29
 
30
30
  class Error < StandardError
31
- def initialize(msg)
32
- super("#{self.class} #{msg}")
31
+ def initialize(msg=nil)
32
+ msg ||= "unspecified"
33
+ super("#{self.class}: #{msg}")
33
34
  # TODO... we can parse this out to be cleaner.. human readable
34
35
  # .. or we add the messages to a constant for each thing or something..
35
36
 
@@ -5,6 +5,14 @@ if RUBY_ENGINE == 'jruby'
5
5
 
6
6
  let (:img_data) { IO.read(SPEC_ROOT.join('support/335is.jpg')) }
7
7
  let (:transparent_img_data) { IO.read(SPEC_ROOT.join('support/transparent_background.png')) }
8
+ let (:broken_img_data) { IO.read(SPEC_ROOT.join('support/invalid_image.gif')) }
9
+
10
+ context "broken_image_blob_data" do
11
+ it "raises exception" do
12
+ lambda { Imgry::Processor::ImgScalr.with_bytes(broken_img_data) }
13
+ .should raise_error(Imgry::InvalidImageError)
14
+ end
15
+ end
8
16
 
9
17
  context "a pretty picture" do
10
18
 
data/spec/imgry_spec.rb CHANGED
@@ -30,6 +30,12 @@ describe Imgry do
30
30
  File.exists?(tmpfile).should == true
31
31
  File.unlink(tmpfile)
32
32
  end
33
+
34
+ it "accepts bad data" do
35
+ expect { Imgry.with_bytes("") }.to raise_error(Imgry::InvalidImageError)
36
+ expect { Imgry.with_bytes(nil) }.to raise_error(Imgry::InvalidImageError)
37
+ expect { Imgry.with_bytes("fsadfasf") }.to raise_error(Imgry::InvalidImageError)
38
+ end
33
39
 
34
40
  end
35
41
 
@@ -0,0 +1,5 @@
1
+ <html>
2
+ <body>
3
+ <p>I'm not a image</a>
4
+ </body>
5
+ </html>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: imgry
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-22 00:00:00.000000000 Z
12
+ date: 2013-01-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -55,6 +55,7 @@ files:
55
55
  - spec/support/335is.png
56
56
  - spec/support/335is_3.jpg
57
57
  - spec/support/cmyk.jpg
58
+ - spec/support/invalid_image.gif
58
59
  - spec/support/mexico-cmyk.jpg
59
60
  - spec/support/transparent_background.png
60
61
  - spec/support/transparent_background_saved.png
@@ -94,7 +95,7 @@ test_files:
94
95
  - spec/support/335is.png
95
96
  - spec/support/335is_3.jpg
96
97
  - spec/support/cmyk.jpg
98
+ - spec/support/invalid_image.gif
97
99
  - spec/support/mexico-cmyk.jpg
98
100
  - spec/support/transparent_background.png
99
101
  - spec/support/transparent_background_saved.png
100
- has_rdoc: