Sha256: db29c7906a14dfc26fe3abf1e1d17d8befc0dd3c9c1ccdc65a71730b1ff903f1

Contents?: true

Size: 1.67 KB

Versions: 7

Compression:

Stored size: 1.67 KB

Contents

require 'spec_helper'
require_relative '../../lib/middleman-webp/pathname_matcher'

describe Middleman::WebP::PathnameMatcher do

  describe '#matches?' do
    it 'returns true when given file matches pattern' do
      patterns = ['**/*.jpg', /jpg$/, ->(path) { path.end_with?('jpg') }]
      files = [
        'images/sample.jpg',
        Pathname.new('images/another.jpg'),
        File.new('spec/fixtures/dummy-build/empty.jpg')
      ]

      patterns.each do |p|
        matcher = Middleman::WebP::PathnameMatcher.new(p)
        files.each do |f|
          matcher.matches?(f).must_equal true, "Pattern: #{p.inspect}, "\
          "file: #{f.inspect}"
        end
      end
    end

    it 'returns false when given file won\'t match pattern' do
      patterns = ['**/*.jpg', /jpg$/, ->(path) { path.end_with?('jpg') }]
      files = [
        'images/sample.png',
        Pathname.new('images/another.png'),
        File.new('spec/fixtures/dummy-build/empty.png')
      ]

      patterns.each do |p|
        matcher = Middleman::WebP::PathnameMatcher.new(p)
        files.each do |f|
          matcher.matches?(f).must_equal false, "Pattern: #{p.inspect}, "\
          "file: #{f.inspect}"
        end
      end
    end

    it 'defaults to pattern \'**/*\' and matches all when pattern is nil' do
      paths = [
        'something/anything.foo',
        Pathname.new('images/another.png'),
        'a/b/c/d/e/f/g'
      ]

      matcher = Middleman::WebP::PathnameMatcher.new
      paths.each do |p|
        matcher.matches?(p).must_equal true
      end
    end

    it 'handles nil path gracefully and returns false' do
      Middleman::WebP::PathnameMatcher.new('*.jpg').matches? nil
    end

  end

end

Version data entries

7 entries across 7 versions & 1 rubygems

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