Browse files

Handling invalid images

  • Loading branch information...
1 parent cedf946 commit a0de4ca19d3ddd5caa7d77218dc4d8d41026f43e @redsquirrel redsquirrel committed Mar 23, 2011
Showing with 11 additions and 0 deletions.
  1. +4 −0 lib/css-spriter/image.rb
  2. +1 −0 spec/images/not_a.png
  3. +6 −0 spec/lib/css_spriter_image_spec.rb
View
4 lib/css-spriter/image.rb
@@ -8,6 +8,10 @@ def self.from_file( filename )
image = super
image.name = name
image
+ rescue => e
+ raise LoadingError, "Error loading #{filename}: #{e.message}"
end
+
+ class LoadingError < StandardError; end
end
end
View
1 spec/images/not_a.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
6 spec/lib/css_spriter_image_spec.rb
@@ -5,4 +5,10 @@
image = CssSpriter::Image.from_file( File.dirname(__FILE__) + '/../images/lightening.png')
image.name.should == 'lightening'
end
+
+ it "raises an error when the file is invalid" do
+ expect {
+ CssSpriter::Image.from_file( File.dirname(__FILE__) + '/../images/not_a.png')
+ }.to raise_error(CssSpriter::Image::LoadingError)
+ end
end

0 comments on commit a0de4ca

Please sign in to comment.