Sha256: 45bad408e6c7576d411a50c833b0ce58ddab36cb6da8a63aa96d30d2c0cf2b0c

Contents?: true

Size: 1.48 KB

Versions: 4

Compression:

Stored size: 1.48 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
      options.allow_skip.must_equal(true)
    end

    it 'should allow setting to true' do
      options = Middleman::WebP::Options.new(allow_skip: false)
      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)
      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)
      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)
      args.must_match(/^-q 85$/)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
middleman-webp-1.0.1 spec/unit/options_spec.rb
middleman-webp-1.0.0 spec/unit/options_spec.rb
middleman-webp-0.4.3 spec/unit/options_spec.rb
middleman-webp-0.4.2 spec/unit/options_spec.rb