Sha256: af633e57892bf50820fb45e244e0f02d33eed85fd230126b58be3a1783a2af77

Contents?: true

Size: 1.55 KB

Versions: 14

Compression:

Stored size: 1.55 KB

Contents

require 'image_optim/image_meta'

describe ImageOptim::ImageMeta do
  let(:image_path){ 'spec/images/lena.jpg' }
  let(:non_image_path){ __FILE__ }
  let(:broken_image_path){ 'spec/images/broken_jpeg' }

  describe '.format_for_path' do
    context 'for an image' do
      it 'returns format' do
        expect(described_class.format_for_path(image_path)).
          to eq(:jpeg)
      end
    end

    context 'for broken image' do
      it 'warns and returns nil' do
        expect(described_class).to receive(:warn)

        expect(described_class.format_for_path(broken_image_path)).
          to eq(nil)
      end
    end

    context 'for not an image' do
      it 'does not warn and returns nil' do
        expect(described_class).not_to receive(:warn)

        expect(described_class.format_for_path(non_image_path)).
          to eq(nil)
      end
    end
  end

  describe '.format_for_data' do
    context 'for image data' do
      it 'returns format' do
        expect(described_class.format_for_data(File.read(image_path))).
          to eq(:jpeg)
      end
    end

    context 'for broken image data' do
      it 'warns and returns nil' do
        expect(described_class).to receive(:warn)

        expect(described_class.format_for_data(File.read(broken_image_path))).
          to eq(nil)
      end
    end

    context 'for not an image data' do
      it 'does not warn and returns nil' do
        expect(described_class).not_to receive(:warn)

        expect(described_class.format_for_data(File.read(non_image_path))).
          to eq(nil)
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
image_optim-0.26.3 spec/image_optim/image_meta_spec.rb
image_optim-0.26.2 spec/image_optim/image_meta_spec.rb
discourse_image_optim-0.26.2 spec/image_optim/image_meta_spec.rb
discourse_image_optim-0.26.1 spec/image_optim/image_meta_spec.rb
image_optim-0.26.1 spec/image_optim/image_meta_spec.rb
image_optim-0.26.0 spec/image_optim/image_meta_spec.rb
image_optim-0.25.0 spec/image_optim/image_meta_spec.rb
discourse_image_optim-0.24.5 spec/image_optim/image_meta_spec.rb
image_optim-0.24.3 spec/image_optim/image_meta_spec.rb
discourse_image_optim-0.24.4 spec/image_optim/image_meta_spec.rb
image_optim-0.24.2 spec/image_optim/image_meta_spec.rb
image_optim-0.24.1 spec/image_optim/image_meta_spec.rb
image_optim-0.24.0 spec/image_optim/image_meta_spec.rb
image_optim-0.23.0 spec/image_optim/image_meta_spec.rb