Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Handling invalid images

  • Loading branch information...
commit a0de4ca19d3ddd5caa7d77218dc4d8d41026f43e 1 parent cedf946
@redsquirrel redsquirrel authored
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
Please sign in to comment.
Something went wrong with that request. Please try again.