Permalink
Browse files

fix and test for a case where the format method tries to raise an exc…

…eption that is not defined

- trying to raise MiniMagickError when should be raising MiniMagick::Error
- see: http://github.com/probablycorey/mini_magick/blob/da0c128a253b1c0725cad022e1e12d8f14fac98e/lib/mini_magick.rb#L225
  • Loading branch information...
1 parent da0c128 commit aec70c30a64cc0a195569a3ce4fd157815b1c635 @kellyredding kellyredding committed Oct 27, 2010
Showing with 25 additions and 11 deletions.
  1. +7 −7 lib/mini_magick.rb
  2. +3 −2 mini_magick.gemspec
  3. +15 −2 test/image_test.rb
View
@@ -5,8 +5,8 @@ module MiniMagick
class << self
attr_accessor :processor
attr_accessor :timeout
-
-
+
+
# Experimental method for automatically selecting a processor
# such as gm. Only works on *nix.
#
@@ -119,7 +119,7 @@ def create(ext = nil, &block)
# Create a new MiniMagick::Image object
#
- # _DANGER_: The file location passed in here is the *working copy*. That is, it gets *modified*.
+ # _DANGER_: The file location passed in here is the *working copy*. That is, it gets *modified*.
# you can either copy it yourself or use the MiniMagick::Image.open(path) method which creates a
# temporary file for you and protects your original!
#
@@ -222,7 +222,7 @@ def format(format, page = 0)
begin
FileUtils.copy_file(@path.sub(".#{format}", "-#{page}.#{format}"), @path)
rescue => ex
- raise MiniMagickError, "Unable to format to #{format}; #{ex}" unless File.exist?(@path)
+ raise MiniMagick::Error, "Unable to format to #{format}; #{ex}" unless File.exist?(@path)
end
end
ensure
@@ -237,7 +237,7 @@ def collapse!
run_command("mogrify", "-quality", "100", "#{path}[0]")
end
- # Writes the temporary file out to either a file location (by passing in a String) or by
+ # Writes the temporary file out to either a file location (by passing in a String) or by
# passing in a Stream that you can #write(chunk) to repeatedly
#
# @param output_to [IOStream, String] Some kind of stream object that needs to be read or a file path as a String
@@ -278,14 +278,14 @@ def method_missing(symbol, *args)
# You can use multiple commands together using this method. Very easy to use!
#
- # @example
+ # @example
# image.combine_options do |c|
# c.draw "image Over 0,0 10,10 '#{MINUS_IMAGE_PATH}'"
# c.thumbnail "300x500>"
# c.background background
# end
#
- # @yieldparam command [CommandBuilder]
+ # @yieldparam command [CommandBuilder]
def combine_options(&block)
c = CommandBuilder.new('mogrify')
block.call(c)
View
@@ -6,14 +6,15 @@ Gem::Specification.new do |s|
s.platform = Gem::Platform::RUBY
s.summary = "Manipulate images with minimal use of memory via ImageMagick / GraphicsMagick"
s.description = ""
-
+
s.authors = ["Corey Johnson", "Hampton Catlin", "Peter Kieltyka"]
s.email = ["probablycorey@gmail.com", "hcatlin@gmail.com", "peter@nulayer.com"]
s.homepage = "http://github.com/probablycorey/mini_magick"
s.files = Dir['README.rdoc', 'VERSION', 'MIT-LICENSE', 'Rakefile', 'lib/**/*']
s.test_files = Dir['test/**/*']
s.require_path = 'lib'
-
+
s.add_runtime_dependency('subexec', ['~> 0.0.4'])
+ s.add_development_dependency('mocha', ['~> 0.9.9'])
end
View
@@ -1,5 +1,6 @@
require 'rubygems'
require 'test/unit'
+require 'mocha'
require 'pathname'
require 'stringio'
require File.expand_path('../../lib/mini_magick', __FILE__)
@@ -50,7 +51,7 @@ def test_image_new
image = Image.new(SIMPLE_IMAGE_PATH)
image.destroy!
end
-
+
def test_remote_image
image = Image.open("http://www.google.com/images/logos/logo.png")
image.valid?
@@ -229,7 +230,7 @@ def test_issue_8
end
image.destroy!
end
-
+
# http://github.com/probablycorey/mini_magick/issues#issue/15
def test_issue_15
image = Image.open(Pathname.new(SIMPLE_IMAGE_PATH))
@@ -248,4 +249,16 @@ def test_throw_format_error
end
image.destroy!
end
+
+ # testing that if copying files formatted from an animation fails,
+ # it raises an appropriate error
+ def test_throw_animation_copy_after_format_error
+ image = Image.open(ANIMATION_PATH)
+ FileUtils.stubs(:copy_file).raises(Errno::ENOENT)
+ assert_raises MiniMagick::Error do
+ image.format('png')
+ end
+ end
+
+
end

0 comments on commit aec70c3

Please sign in to comment.