Sha256: a4800377947ab8f1cdef752d7a63f75b535066470b1664192276d3a81e0f35e7

Contents?: true

Size: 1.83 KB

Versions: 6

Compression:

Stored size: 1.83 KB

Contents

# frozen_string_literal: true

require 'spec_helper'
require 'image_optim/worker/pngquant'

describe ImageOptim::Worker::Pngquant do
  describe 'quality option' do
    describe 'default' do
      subject{ described_class::QUALITY_OPTION.default }

      it{ is_expected.to match(/100\.\.100.*0\.\.100/) }
    end

    describe 'value' do
      let(:subject){ described_class.new(ImageOptim.new, options).quality }

      context 'when lossy not allowed' do
        context 'by default' do
          let(:options){ {} }

          it{ is_expected.to eq(100..100) }
        end

        context 'when value is passed through options' do
          let(:options){ {quality: 10..90} }

          it 'warns and keeps default' do
            expect_any_instance_of(described_class).
              to receive(:warn).with(/ignored in lossless mode/)
            is_expected.to eq(100..100)
          end
        end
      end

      context 'when lossy allowed' do
        context 'by default' do
          let(:options){ {allow_lossy: true} }

          it{ is_expected.to eq(0..100) }
        end

        context 'when value is passed through options' do
          let(:options){ {allow_lossy: true, quality: 10..90} }

          it 'sets the value without warning' do
            expect_any_instance_of(described_class).not_to receive(:warn)
            is_expected.to eq(10..90)
          end
        end

        context 'when passed range begin is less than 0' do
          let(:options){ {allow_lossy: true, quality: -50..50} }

          it 'sets begin to 0' do
            is_expected.to eq(0..50)
          end
        end

        context 'when passed range end is more than 100' do
          let(:options){ {allow_lossy: true, quality: 50..150} }

          it 'sets end to 100' do
            is_expected.to eq(50..100)
          end
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
image_optim-0.31.4 spec/image_optim/worker/pngquant_spec.rb
image_optim-0.31.3 spec/image_optim/worker/pngquant_spec.rb
image_optim-0.31.2 spec/image_optim/worker/pngquant_spec.rb
image_optim-0.31.1 spec/image_optim/worker/pngquant_spec.rb
image_optim-0.31.0 spec/image_optim/worker/pngquant_spec.rb
image_optim-0.30.0 spec/image_optim/worker/pngquant_spec.rb