Sha256: 9c051b7c4ff34b088f6371124f3902f3b1b95363805b92e8dc0cc8d29439eed6

Contents?: true

Size: 1.48 KB

Versions: 6

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

6 entries across 6 versions & 1 rubygems

Version Path
middleman-webp-0.4.1 spec/unit/options_spec.rb
middleman-webp-0.4.0 spec/unit/options_spec.rb
middleman-webp-0.3.2 spec/unit/options_spec.rb
middleman-webp-0.3.1 spec/unit/options_spec.rb
middleman-webp-0.3.0 spec/unit/options_spec.rb
middleman-webp-0.2.7 spec/unit/options_spec.rb