Skip to content

Commit

Permalink
raise when using generate_from_image without RMagick
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordan Stephens committed Jul 3, 2015
1 parent 338e66c commit 3ee38b7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/paleta.rb
Expand Up @@ -3,6 +3,8 @@
require 'paleta/palette'

module Paleta
class MissingDependencyError < StandardError; end

@rmagick_available = begin
require "rmagick"
rescue LoadError
Expand Down
2 changes: 1 addition & 1 deletion lib/paleta/palette.rb
Expand Up @@ -211,7 +211,7 @@ def fit

def self.generate_from_image(path, size = 5)
unless Paleta.rmagick_available?
return puts "You must install RMagick to use Palette.generate(:from => :image, ...)"
raise Paleta::MissingDependencyError, "You must install RMagick to use Palette.generate(:from => :image, ...)"
end

begin
Expand Down
11 changes: 11 additions & 0 deletions spec/models/palette_spec.rb
Expand Up @@ -231,6 +231,17 @@
palette.size.should == size
end

it "should raise when generating a Palette from an image without RMagick" do
# stub Paleta.rmagick_available? to return false
allow(Paleta).to receive(:rmagick_available?).and_return(false)

path = File.join(File.dirname(__FILE__), '..', 'images/test.jpg')
size = 5
expect do
Paleta::Palette.generate(:from => :image, :image => path, :size => size)
end.to raise_error(Paleta::MissingDependencyError)
end

it "should raise an error when generating a Palette from an invalid image" do
expect{ Paleta::Palette.generate(:from => :image, :image => "/no/image.here") }.to raise_error(RuntimeError)
end
Expand Down

0 comments on commit 3ee38b7

Please sign in to comment.