|
1 | 1 | require 'spec_helper'
|
| 2 | +require 'open3' |
2 | 3 |
|
3 | 4 | describe CarrierWave::MiniMagick do
|
4 | 5 | let(:klass) { Class.new(CarrierWave::Uploader::Base) { include CarrierWave::MiniMagick } }
|
|
270 | 271 |
|
271 | 272 | context "of failing to find ImageMagick/GraphicsMagick" do
|
272 | 273 | before do
|
273 |
| - MiniMagick.remove_instance_variable(:@processor) if MiniMagick.instance_variable_defined?(:@processor) |
274 |
| - MiniMagick.remove_instance_variable(:@cli) if MiniMagick.instance_variable_defined?(:@cli) |
| 274 | + allow(MiniMagick).to receive(:cli_prefix).and_return('invalid') |
275 | 275 | allow(MiniMagick::Utilities).to receive(:which).and_return(nil)
|
276 | 276 | end
|
277 | 277 |
|
|
283 | 283 | context "of being configured to use ImageMagick but failing to execute" do
|
284 | 284 | before do
|
285 | 285 | allow(MiniMagick).to receive(:processor).and_return(:magick)
|
| 286 | + allow(Open3).to receive(:capture3).and_raise(Errno::ENOENT) |
286 | 287 | allow_any_instance_of(MiniMagick::Shell).to receive(:execute_open3).and_raise(Errno::ENOENT)
|
287 | 288 | end
|
288 | 289 |
|
|
293 | 294 | end
|
294 | 295 |
|
295 | 296 | describe "#manipulate!" do
|
| 297 | + let(:minimagick_error) do |
| 298 | + # MiniMagick >= 5.0 does not call #validate! on Image.create, hence the error changes |
| 299 | + MiniMagick::VERSION::MAJOR >= 5 ? MiniMagick::Error : MiniMagick::Invalid |
| 300 | + end |
| 301 | + |
296 | 302 | it "performs manipulation using the given block" do
|
297 | 303 | instance.manipulate! do |image|
|
298 | 304 | image.format('png')
|
|
310 | 316 |
|
311 | 317 | context "on failing to find ImageMagick/GraphicsMagick" do
|
312 | 318 | before do
|
313 |
| - MiniMagick.remove_instance_variable(:@processor) if MiniMagick.instance_variable_defined?(:@processor) |
314 |
| - MiniMagick.remove_instance_variable(:@cli) if MiniMagick.instance_variable_defined?(:@cli) |
| 319 | + allow(MiniMagick).to receive(:cli_prefix).and_return('invalid') |
315 | 320 | allow(MiniMagick::Utilities).to receive(:which).and_return(nil)
|
316 | 321 | end
|
317 | 322 |
|
|
320 | 325 | instance.manipulate! do |image|
|
321 | 326 | image.format('png')
|
322 | 327 | end
|
323 |
| - end.to raise_exception(MiniMagick::Invalid) |
| 328 | + end.to raise_exception(minimagick_error) |
324 | 329 | end
|
325 | 330 | end
|
326 | 331 |
|
327 | 332 | context "on being configured to use ImageMagick but failing to execute" do
|
328 | 333 | before do
|
329 | 334 | allow(MiniMagick).to receive(:processor).and_return(:magick)
|
| 335 | + allow(Open3).to receive(:capture3).and_raise(Errno::ENOENT) |
330 | 336 | allow_any_instance_of(MiniMagick::Shell).to receive(:execute_open3).and_raise(Errno::ENOENT)
|
331 | 337 | end
|
332 |
| - after { MiniMagick.remove_instance_variable(:@processor) } |
| 338 | + after { MiniMagick.remove_instance_variable(:@processor) if MiniMagick.instance_variable_defined?(:@processor) } |
333 | 339 |
|
334 | 340 | it "raises MiniMagick::Invalid" do
|
335 | 341 | expect do
|
336 | 342 | instance.manipulate! do |image|
|
337 | 343 | image.format('png')
|
338 | 344 | end
|
339 |
| - end.to raise_exception(MiniMagick::Invalid) |
| 345 | + end.to raise_exception(minimagick_error) |
340 | 346 | end
|
341 | 347 | end
|
342 | 348 | end
|
|
0 commit comments