spec/unit/options_spec.rb in middleman-webp-0.2.3 vs spec/unit/options_spec.rb in middleman-webp-0.2.4

- old
+ new

@@ -1,23 +1,46 @@ -require "spec_helper" -require "pathname" -require_relative "../../lib/middleman-webp/options" +require 'spec_helper' +require 'pathname' +require_relative '../../lib/middleman-webp/options' describe Middleman::WebP::Options do - describe "#for" do - it "returns cwebp args when given file matches option file pattern" do - path = Pathname.new("test_image.jpg") - options = Middleman::WebP::Options.new("*.jpg" => {lossless: true, q: 85}) + 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") + 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