Sha256: 06961c3e5c9947edd52ef224771e6e5de21f74742cdcafdd61e24c705beaf875

Contents?: true

Size: 1.39 KB

Versions: 9

Compression:

Stored size: 1.39 KB

Contents

$:.unshift File.expand_path('../../../lib', __FILE__)
require 'rspec'
require 'image_optim/handler'

describe ImageOptim::Handler do
  it "should use original as source for first conversion and two temp files for further conversions" do
    original = double(:original)
    original.stub(:temp_path){ raise 'temp_path called unexpectedly' }

    handler = ImageOptim::Handler.new(original)

    original.should_receive(:temp_path).once.and_return(temp_a = double(:temp_a))
    handler.process do |src, dst|
      [src, dst].should == [original, temp_a]; false
    end
    handler.result.should == nil

    handler.process do |src, dst|
      [src, dst].should == [original, temp_a]; true
    end
    handler.result.should == temp_a

    original.should_receive(:temp_path).once.and_return(temp_b = double(:temp_b))
    handler.process do |src, dst|
      [src, dst].should == [temp_a, temp_b]; false
    end
    handler.result.should == temp_a

    handler.process do |src, dst|
      [src, dst].should == [temp_a, temp_b]; true
    end
    handler.result.should == temp_b

    handler.process do |src, dst|
      [src, dst].should == [temp_b, temp_a]; true
    end
    handler.result.should == temp_a

    handler.process do |src, dst|
      [src, dst].should == [temp_a, temp_b]; true
    end
    handler.result.should == temp_b

    temp_a.should_receive(:unlink).once
    handler.cleanup
    handler.cleanup
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
image_optim-0.13.3 spec/image_optim/handler_spec.rb
image_optim-0.13.2 spec/image_optim/handler_spec.rb
image_optim-0.13.1 spec/image_optim/handler_spec.rb
image_optim-0.13.0 spec/image_optim/handler_spec.rb
image_optim-0.12.1 spec/image_optim/handler_spec.rb
image_optim-0.12.0 spec/image_optim/handler_spec.rb
image_optim-0.11.2 spec/image_optim/handler_spec.rb
image_optim-0.11.1 spec/image_optim/handler_spec.rb
image_optim-0.11.0 spec/image_optim/handler_spec.rb