Sha256: 55ffe92af9044f3a449acf8237a8f3170c7970722c1ec0262633afd14a23338d

Contents?: true

Size: 1.96 KB

Versions: 2

Compression:

Stored size: 1.96 KB

Contents

require 'spec_helper'
require 'pathname'
require_relative '../../lib/middleman-webp/options'

describe Middleman::WebP::Options do
  describe '#allow_skip' do
    it 'should default to true' do
      options = Middleman::WebP::Options.new
      value(options.allow_skip).must_equal(true)
    end

    it 'should allow setting to true' do
      options = Middleman::WebP::Options.new(allow_skip: false)
      value(options.allow_skip).must_equal(false)
    end
  end

  describe '#for' do
    it 'returns cwebp args when given file matches option file pattern glob' do
      path = Pathname.new('test_image.jpg')
      options_hash = {
        conversion_options: {
          '*.jpg' => {
            lossless: true,
            q: 85
          }
        }
      }
      options = Middleman::WebP::Options.new options_hash

      args = options.for(path)
      value(args).must_match(/^(-q 85|-lossless) (-q 85|-lossless)$/)
    end

    it 'returns empty string when no options are defined' do
      path = Pathname.new('test_image.jpg')
      options = Middleman::WebP::Options.new

      args = options.for(path)
      value(args).must_be_empty
    end

    it 'returns cwebp args when given file matches option pattern regexp' do
      path = Pathname.new('test_image.jpg')
      options_hash = {
        conversion_options: {
          /jpg$/ => {
            q: 85
          }
        }
      }
      options = Middleman::WebP::Options.new options_hash

      args = options.for(path)
      value(args).must_match(/^-q 85$/)
    end

    it 'selects most precise file pattern to get file specific option overrides correctly' do
      path = Pathname.new('lizard.jpg')
      options_hash = {
        conversion_options: {
          '*.jpg' => {
            q: 85
          },
          'lizard.jpg' => {
            q: 100
          }
        }
      }
      options = Middleman::WebP::Options.new options_hash

      args = options.for(path)
      value(args).must_match(/^-q 100$/)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
middleman-webp-1.0.3 spec/unit/options_spec.rb
middleman-webp-1.0.2 spec/unit/options_spec.rb