image_optim 0.22.0 → 0.22.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NGEwM2UzY2VlZmU0OWJmNzg2YTAyMDZlNWM1MzM5ZWVhNDAyOTg3Mw==
4
+ MDRiNGJkYTQ0MDcxZGIyODc5YWJkMGZkNGVkYmQzNzRmYTk4N2Y4OQ==
5
5
  data.tar.gz: !binary |-
6
- YTE0YzA1YjQ2NzU3NDIxZjFjNzA4ZGVjOGFmNGY4YTgxMjhiODlhZA==
6
+ NDMyODhiNzkyZGIxZmVmNDdmODY3MWFkOTE0NWFkMTM5ZWY0YWY5OQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YjI3M2JhYmExNTg2OTg2OGI1NWU5YWEwM2Y4MjNmOWRhNjcwM2EwZmFjOTQz
10
- ZjI2MzBiZjcwZWIwMjQ0ZWUwOTFlODNjZjU0NThmMDhjYWUzMTE2ZTVmOGFm
11
- NGM1ZWMzMjYyODZmZTUzZjk2NzljMTY1MDg1M2Y4NmZmNTMwZTY=
9
+ NzdkYmVmNDRmYmYwODFmZjAyOWJhODBlZGE3NWEwZmJhNjllNjE5ZmJjM2Y2
10
+ ZTk1NDZiOWViNTZjMTI2MDE3YjgwNWQ3N2Y0Y2ZjNWQ0ODJjMGU1MjQ3NDkx
11
+ NTZjZjA4NjQ4MGM4YzNhMDkyYTQ3OTI3ZGYwZGMzMGRjNWU5ODQ=
12
12
  data.tar.gz: !binary |-
13
- NTQxYjc1MWI2OTgzNzNhOTliMGRjMjgwMTBlMDBjZDdjYmRlN2RjOTVhNTk0
14
- YjE0NzczOWE0NzZjMWMzOGM4NWFlZTg0ZjAzZWQ3NTNjZGRhYTVkNjc2ZjUx
15
- OWQ3ODZmZGE2MmMxMWM1YmU1NjI0NzljNDE4MjE4MDdjYzliOTU=
13
+ MDMwNzg5MDM4NWRmNzM5ZjI0MDJmZTgwNzRiMjBlZDI1ZTNmOTMzZWUwNGE0
14
+ ZTc0ZGIyNWVkMjExNTIyZGFkNTk1YWQ2MjU1NzU1ZjY3ZmZkNGUyNGVmZTk2
15
+ ZGMyMDZjNGVlY2M1NmRmY2EyNWRjNTY5ZTBjNGRiMmI5YWYxOTE=
data/.gitignore CHANGED
@@ -5,6 +5,7 @@
5
5
  /rdoc/
6
6
  /.yardoc/
7
7
  /coverage/
8
+ /vendor/
8
9
 
9
10
  Gemfile.lock
10
11
  Makefile
data/.rubocop.yml CHANGED
@@ -1,6 +1,7 @@
1
1
  AllCops:
2
2
  Exclude:
3
3
  - '*.gemspec'
4
+ - 'vendor/**/*'
4
5
 
5
6
  Lint/EndAlignment:
6
7
  AlignWith: variable
@@ -23,6 +24,9 @@ Metrics/PerceivedComplexity:
23
24
  Style/AccessModifierIndentation:
24
25
  EnforcedStyle: outdent
25
26
 
27
+ Style/Alias:
28
+ EnforcedStyle: prefer_alias_method
29
+
26
30
  Style/CaseIndentation:
27
31
  IndentWhenRelativeTo: end
28
32
 
@@ -41,6 +45,12 @@ Style/HashSyntax:
41
45
  Style/IfUnlessModifier:
42
46
  MaxLineLength: 40
43
47
 
48
+ Style/IndentArray:
49
+ EnforcedStyle: consistent
50
+
51
+ Style/IndentAssignment:
52
+ Enabled: false
53
+
44
54
  Style/IndentHash:
45
55
  EnforcedStyle: consistent
46
56
 
@@ -55,11 +65,17 @@ Style/PercentLiteralDelimiters:
55
65
  Style/Semicolon:
56
66
  AllowAsExpressionSeparator: true
57
67
 
68
+ Style/SignalException:
69
+ EnforcedStyle: semantic
70
+
58
71
  Style/SpaceBeforeBlockBraces:
59
72
  EnforcedStyle: no_space
60
73
 
61
74
  Style/SpaceInsideHashLiteralBraces:
62
75
  EnforcedStyle: no_space
63
76
 
64
- Style/TrailingComma:
77
+ Style/TrailingCommaInArguments:
78
+ EnforcedStyleForMultiline: no_comma
79
+
80
+ Style/TrailingCommaInLiteral:
65
81
  EnforcedStyleForMultiline: comma
data/.travis.yml CHANGED
@@ -1,9 +1,13 @@
1
1
  sudo: false
2
2
  language: ruby
3
+ cache:
4
+ bundler: true
5
+ directories:
6
+ - $(npm root)
7
+ - ~/bin
3
8
  rvm:
4
- - 1.8.7
5
- - 1.9.2
6
- - 1.9.3
9
+ - '1.8'
10
+ - '1.9'
7
11
  - '2.0'
8
12
  - '2.1'
9
13
  - '2.2'
@@ -21,17 +25,22 @@ script:
21
25
  ; fi
22
26
  before_install:
23
27
  if [ -z "$RUBOCOP" ]; then
24
- mkdir ~/bin
25
- && npm install -g svgo
26
- && curl -L "http://static.jonof.id.au/dl/kenutils/pngout-20130221-linux.tar.gz" | tar -xz -C ~/bin --strip-components 2 --wildcards '*/x86_64/pngout'
28
+ command -v svgo || npm install svgo
29
+ ;
30
+ command -v pngout || (
31
+ mkdir -p ~/bin
32
+ && curl -L "http://static.jonof.id.au/dl/kenutils/pngout-20130221-linux.tar.gz" | tar -xz -C ~/bin --strip-components 2 --wildcards '*/x86_64/pngout'
33
+ )
27
34
  ; fi
28
- env:
29
- - PATH=~/bin:$PATH
30
35
  matrix:
31
36
  fast_finish: true
32
37
  include:
38
+ - env: RAILS_VERSION='~> 3.2' SPROCKETS_VERSION='~> 2.0'
39
+ rvm: default
33
40
  - env: RAILS_VERSION='~> 3.2'
34
41
  rvm: default
42
+ - env: RAILS_VERSION='~> 4.0' SPROCKETS_RAILS_VERSION='~> 2.0'
43
+ rvm: default
35
44
  - env: RAILS_VERSION='~> 4.0'
36
45
  rvm: default
37
46
  - env: RUBOCOP=true
data/CHANGELOG.markdown CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  ## unreleased
4
4
 
5
+ ## v0.22.1 (2016-02-21)
6
+
7
+ * Fix missing old (1.x) `pngquant` version as it was output to stderr [#123](https://github.com/toy/image_optim/issues/123) [@toy](https://github.com/toy)
8
+ * Fix capturing wrong version of `pngcrush` when it complains about different png.h and png.c [#122](https://github.com/toy/image_optim/issues/122) [@toy](https://github.com/toy)
9
+ * Add support for `sprockets-rails` 3.x, kudos to [@iggant](https://github.com/iggant) and [@valff](https://github.com/valff) for initial PRs [#120](https://github.com/toy/image_optim/pull/120) [#121](https://github.com/toy/image_optim/pull/121) [#126](https://github.com/toy/image_optim/pull/126) [@toy](https://github.com/toy)
10
+ * Use rubocop ~> 0.37 [@toy](https://github.com/toy)
11
+
5
12
  ## v0.22.0 (2015-11-21)
6
13
 
7
14
  * Unify getting description of option default value using `default_description` [@toy](https://github.com/toy)
data/Gemfile CHANGED
@@ -6,4 +6,11 @@ if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('1.9')
6
6
  gem 'codeclimate-test-reporter', :group => :test, :require => nil
7
7
  end
8
8
 
9
- gem 'rails', ENV['RAILS_VERSION'] if ENV['RAILS_VERSION']
9
+ %w[
10
+ rails
11
+ sprockets
12
+ sprockets-rails
13
+ ].each do |gem_name|
14
+ version = ENV[gem_name.tr('-', '_').upcase + '_VERSION']
15
+ gem gem_name, version if version
16
+ end
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2012-2015 Ivan Kuchin
1
+ Copyright (c) 2012-2016 Ivan Kuchin
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.markdown CHANGED
@@ -341,4 +341,4 @@ In separate file [CHANGELOG.markdown](CHANGELOG.markdown).
341
341
 
342
342
  ## Copyright
343
343
 
344
- Copyright (c) 2012-2015 Ivan Kuchin. See [LICENSE.txt](LICENSE.txt) for details.
344
+ Copyright (c) 2012-2016 Ivan Kuchin. See [LICENSE.txt](LICENSE.txt) for details.
data/Vagrantfile CHANGED
@@ -1,6 +1,4 @@
1
- VAGRANTFILE_API_VERSION = '2'
2
-
3
- Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
1
+ Vagrant.configure('2') do |config|
4
2
  config.vm.box = 'ubuntu/precise64'
5
3
 
6
4
  config.vm.provision 'shell', :inline => <<-SH
data/image_optim.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'image_optim'
5
- s.version = '0.22.0'
5
+ s.version = '0.22.1'
6
6
  s.summary = %q{Optimize (lossless compress, optionally lossy) images (jpeg, png, gif, svg) using external utilities (advpng, gifsicle, jhead, jpeg-recompress, jpegoptim, jpegrescan, jpegtran, optipng, pngcrush, pngout, pngquant, svgo)}
7
7
  s.homepage = "http://github.com/toy/#{s.name}"
8
8
  s.authors = ['Ivan Kuchin']
@@ -24,6 +24,6 @@ Gem::Specification.new do |s|
24
24
  s.add_development_dependency 'image_optim_pack', '~> 0.2'
25
25
  s.add_development_dependency 'rspec', '~> 3.0'
26
26
  if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('1.9.3')
27
- s.add_development_dependency 'rubocop', '~> 0.35'
27
+ s.add_development_dependency 'rubocop', '~> 0.37'
28
28
  end
29
29
  end
data/lib/image_optim.rb CHANGED
@@ -212,7 +212,7 @@ private
212
212
  apply_threading(list).map do |item|
213
213
  result = send(method_name, item)
214
214
  if block
215
- block.call(item, result)
215
+ yield item, result
216
216
  else
217
217
  [item, result]
218
218
  end
@@ -44,11 +44,9 @@ class ImageOptim
44
44
  bin.check! if bin
45
45
  end
46
46
 
47
- if @bins[name]
48
- @bins[name].check_fail!
49
- else
50
- fail BinNotFound, "`#{name}` not found"
51
- end
47
+ fail BinNotFound, "`#{name}` not found" unless @bins[name]
48
+
49
+ @bins[name].check_fail!
52
50
 
53
51
  @bins[name]
54
52
  end
@@ -29,7 +29,7 @@ class ImageOptim
29
29
  'broken pngs'],
30
30
  [:pngcrush, is == '1.7.80', 'loses one color in indexed images'],
31
31
  [:pngquant, is < '2.0', 'is not supported'],
32
- ]
32
+ ].freeze
33
33
 
34
34
  WARN_CHECKS = [
35
35
  [:advpng, is < '1.17', 'does not use zopfli'],
@@ -37,7 +37,7 @@ class ImageOptim
37
37
  [:pngcrush, is < '1.7.38', 'does not have blacken flag'],
38
38
  [:pngquant, is < '2.1', 'may be lossy even with quality `100-`'],
39
39
  [:optipng, is < '0.7', 'does not support -strip option'],
40
- ]
40
+ ].freeze
41
41
 
42
42
  # Fail if version will not work properly
43
43
  def check_fail!
@@ -72,16 +72,16 @@ class ImageOptim
72
72
  # Getting version of bin, will fail for an unknown name
73
73
  def version_string
74
74
  case name
75
- when :advpng, :gifsicle, :jpegoptim, :optipng, :pngquant
76
- capture("#{escaped_path} --version 2> /dev/null")[/\d+(\.\d+){1,}/]
77
- when :svgo
78
- capture("#{escaped_path} --version 2>&1")[/\d+(\.\d+){1,}/]
75
+ when :advpng, :gifsicle, :jpegoptim, :optipng
76
+ capture("#{escaped_path} --version 2> /dev/null")[/\d+(\.\d+)+/]
77
+ when :svgo, :pngquant
78
+ capture("#{escaped_path} --version 2>&1")[/\d+(\.\d+)+/]
79
79
  when :jhead, :'jpeg-recompress'
80
- capture("#{escaped_path} -V 2> /dev/null")[/\d+(\.\d+){1,}/]
80
+ capture("#{escaped_path} -V 2> /dev/null")[/\d+(\.\d+)+/]
81
81
  when :jpegtran
82
82
  capture("#{escaped_path} -v - 2>&1")[/version (\d+\S*)/, 1]
83
83
  when :pngcrush
84
- capture("#{escaped_path} -version 2>&1")[/\d+(\.\d+){1,}/]
84
+ capture("#{escaped_path} -version 2>&1")[/pngcrush (\d+(\.\d+)+)/, 1]
85
85
  when :pngout
86
86
  date_regexp = /[A-Z][a-z]{2} (?: |\d)\d \d{4}/
87
87
  date_str = capture("#{escaped_path} 2>&1")[date_regexp]
@@ -18,7 +18,7 @@ class ImageOptim
18
18
  end
19
19
 
20
20
  # Local config path at `./.image_optim.yml`
21
- LOCAL_PATH = './.image_optim.yml'
21
+ LOCAL_PATH = './.image_optim.yml'.freeze
22
22
 
23
23
  class << self
24
24
  # Read options at path: expand path (warn on failure), return {} if file
@@ -192,10 +192,9 @@ class ImageOptim
192
192
  Cmd.capture 'sysctl -n hw.ncpu'
193
193
  when /mswin|mingw/
194
194
  require 'win32ole'
195
- WIN32OLE.
196
- connect('winmgmts://').
197
- ExecQuery('select NumberOfLogicalProcessors from Win32_Processor').
198
- to_enum.first.NumberOfLogicalProcessors
195
+ query = 'select NumberOfLogicalProcessors from Win32_Processor'
196
+ result = WIN32OLE.connect('winmgmts://').ExecQuery(query)
197
+ result.to_enum.first.NumberOfLogicalProcessors
199
198
  else
200
199
  warn "Unknown architecture (#{host_os}) assuming one processor."
201
200
  1
@@ -16,11 +16,11 @@ class ImageOptim
16
16
 
17
17
  # Returns a new hash with recursive merge of all keys
18
18
  def deep_merge(a, b)
19
- a.merge(b) do |_k, v_a, v_b|
20
- if v_a.is_a?(Hash) && v_b.is_a?(Hash)
21
- deep_merge(v_a, v_b)
19
+ a.merge(b) do |_key, value_a, value_b|
20
+ if value_a.is_a?(Hash) && value_b.is_a?(Hash)
21
+ deep_merge(value_a, value_b)
22
22
  else
23
- v_b
23
+ value_b
24
24
  end
25
25
  end
26
26
  end
@@ -31,11 +31,11 @@ class ImageOptim
31
31
  # provided block
32
32
  def deep_transform_keys(hash, &block)
33
33
  new_hash = {}
34
- hash.each do |k, v|
35
- new_hash[block.call(k)] = if v.is_a?(Hash)
36
- deep_transform_keys(v, &block)
34
+ hash.each do |key, value|
35
+ new_hash[yield key] = if value.is_a?(Hash)
36
+ deep_transform_keys(value, &block)
37
37
  else
38
- v
38
+ value
39
39
  end
40
40
  end
41
41
  new_hash
@@ -3,6 +3,13 @@ require 'image_optim'
3
3
  class ImageOptim
4
4
  # Adds image_optim as preprocessor for gif, jpeg, png and svg images
5
5
  class Railtie < Rails::Railtie
6
+ MIME_TYPES = %w[
7
+ image/gif
8
+ image/jpeg
9
+ image/png
10
+ image/svg+xml
11
+ ].freeze
12
+
6
13
  config.before_configuration do |app|
7
14
  worker_names = ImageOptim::Worker.klasses.map(&:bin_sym)
8
15
  app.config.assets.image_optim =
@@ -14,14 +21,22 @@ class ImageOptim
14
21
  end
15
22
 
16
23
  initializer 'image_optim.initializer' do |app|
17
- register_preprocessor(app) if register_preprocessor?(app)
18
- end
24
+ next if app.config.assets.compress == false
25
+ next if app.config.assets.image_optim == false
19
26
 
20
- def register_preprocessor?(app)
21
- return if app.config.assets.compress == false
22
- return if app.config.assets.image_optim == false
27
+ @image_optim = ImageOptim.new(options(app))
23
28
 
24
- app.assets
29
+ register_preprocessor(app) do |*args|
30
+ if args[1] # context and data arguments in sprockets 2
31
+ optimize_image_data(args[1])
32
+ else
33
+ input = args[0]
34
+ {
35
+ :data => optimize_image_data(input[:data]),
36
+ :charset => nil, # no gzipped version with rails/sprockets#228
37
+ }
38
+ end
39
+ end
25
40
  end
26
41
 
27
42
  def options(app)
@@ -32,17 +47,20 @@ class ImageOptim
32
47
  end
33
48
  end
34
49
 
35
- def register_preprocessor(app)
36
- image_optim = ImageOptim.new(options(app))
50
+ def optimize_image_data(data)
51
+ @image_optim.optimize_image_data(data) || data
52
+ end
37
53
 
38
- processor = proc do |_context, data|
39
- image_optim.optimize_image_data(data) || data
54
+ def register_preprocessor(app, &processor)
55
+ MIME_TYPES.each do |mime_type|
56
+ if app.assets
57
+ app.assets.register_preprocessor mime_type, :image_optim, &processor
58
+ else
59
+ app.config.assets.configure do |env|
60
+ env.register_preprocessor mime_type, :image_optim, &processor
61
+ end
62
+ end
40
63
  end
41
-
42
- app.assets.register_preprocessor 'image/gif', :image_optim, &processor
43
- app.assets.register_preprocessor 'image/jpeg', :image_optim, &processor
44
- app.assets.register_preprocessor 'image/png', :image_optim, &processor
45
- app.assets.register_preprocessor 'image/svg+xml', :image_optim, &processor
46
64
  end
47
65
  end
48
66
  end
@@ -7,6 +7,8 @@ class ImageOptim
7
7
  #
8
8
  # Jhead internally uses jpegtran which should be on path
9
9
  class Jhead < Worker
10
+ ORIENTED = 2..8 # not top-left
11
+
10
12
  # Works on jpegs
11
13
  def image_formats
12
14
  [:jpeg]
@@ -36,7 +38,7 @@ class ImageOptim
36
38
 
37
39
  def oriented?(image)
38
40
  exif = EXIFR::JPEG.new(image.to_s)
39
- (2..8).include?(exif.orientation.to_i)
41
+ ORIENTED.include?(exif.orientation.to_i)
40
42
  end
41
43
  end
42
44
  end
@@ -10,7 +10,7 @@ class ImageOptim
10
10
  super if options[:allow_lossy]
11
11
  end
12
12
 
13
- QUALITY_NAMES = [:low, :medium, :high, :veryhigh]
13
+ QUALITY_NAMES = [:low, :medium, :high, :veryhigh].freeze
14
14
 
15
15
  quality_names_desc = QUALITY_NAMES.each_with_index.map do |name, i|
16
16
  "`#{i}` - #{name}"
@@ -6,10 +6,8 @@ require 'bundler/setup'
6
6
  require 'image_optim'
7
7
 
8
8
  README_FILE = File.expand_path('../../README.markdown', __FILE__)
9
- BEGIN_MARKER = '<!---<worker-options>-->'
10
- END_MARKER = '<!---</worker-options>-->'
11
- GENERATED_NOTE = '<!-- markdown for worker options is generated by '\
12
- "`#{Pathname($PROGRAM_NAME).cleanpath}` -->"
9
+ BEGIN_MARKER = '<!---<worker-options>-->'.freeze
10
+ END_MARKER = '<!---</worker-options>-->'.freeze
13
11
 
14
12
  def write_worker_options(io, klass)
15
13
  io.puts "### #{klass.bin_sym}:"
@@ -29,7 +27,8 @@ end
29
27
 
30
28
  def write_marked(io)
31
29
  io.puts BEGIN_MARKER
32
- io.puts GENERATED_NOTE
30
+ io.puts '<!-- markdown for worker options is generated by '\
31
+ "`#{Pathname($PROGRAM_NAME).cleanpath}` -->"
33
32
  io.puts
34
33
 
35
34
  ImageOptim::Worker.klasses.sort_by(&:name).each do |klass|
@@ -12,7 +12,7 @@ require 'digest'
12
12
  require 'erb'
13
13
  require 'ostruct'
14
14
 
15
- DIR = 'tmp'
15
+ DIR = 'tmp'.freeze
16
16
  Pathname(DIR).mkpath
17
17
 
18
18
  Array.class_eval do
@@ -127,8 +127,8 @@ class Analyser
127
127
  entry[0]
128
128
  end
129
129
 
130
- def set!(key, etag, &block)
131
- value = block.call
130
+ def set!(key, etag, &_block)
131
+ value = yield
132
132
  DB[Marshal.dump(key)] = Marshal.dump([value, etag])
133
133
  value
134
134
  end
@@ -284,7 +284,7 @@ class Analyser
284
284
  chain_result = ChainResult.new(src.format, steps)
285
285
  chain_result.difference = difference_with(result_image)
286
286
 
287
- block.call(chain_result)
287
+ yield chain_result
288
288
 
289
289
  workers_left = workers.reject do |w|
290
290
  w.cons_id == worker.cons_id || w.run_order < worker.run_order
@@ -32,26 +32,26 @@ describe ImageOptim::BinResolver::SimpleVersion do
32
32
  1.0.0.0
33
33
  ].each do |variation|
34
34
  it "normalizes #{variation}" do
35
- expect(v variation).to eq(1)
35
+ expect(v(variation)).to eq(1)
36
36
  end
37
37
  end
38
38
  end
39
39
 
40
40
  describe 'conversion' do
41
41
  it 'converts Integer' do
42
- expect(v 117).to eq('117')
42
+ expect(v(117)).to eq('117')
43
43
  end
44
44
 
45
45
  it 'converts Float' do
46
- expect(v 1.17).to eq('1.17')
46
+ expect(v(1.17)).to eq('1.17')
47
47
  end
48
48
 
49
49
  it 'converts String' do
50
- expect(v '1.17').to eq('1.17')
50
+ expect(v('1.17')).to eq('1.17')
51
51
  end
52
52
 
53
53
  it 'converts self' do
54
- expect(v(v 1.17)).to eq('1.17')
54
+ expect(v(v(1.17))).to eq('1.17')
55
55
  end
56
56
  end
57
57
  end
@@ -209,7 +209,7 @@ describe ImageOptim::BinResolver do
209
209
  allow(bin).to receive(:check!).once
210
210
  allow(bin).to receive(:check_fail!){ mutex.synchronize{ count += 1 } }
211
211
 
212
- 10.times.map do
212
+ Array.new(10) do
213
213
  Thread.new do
214
214
  resolver.resolve!(:ls)
215
215
  end
@@ -7,7 +7,7 @@ describe 'ImageOptim::Railtie' do
7
7
  def init_rails_app
8
8
  Class.new(Rails::Application) do
9
9
  # Rails 4 requires application class to have name
10
- def self.name
10
+ define_singleton_method :name do
11
11
  'Dummy'
12
12
  end
13
13
 
@@ -6,6 +6,12 @@ describe ImageOptim::Runner::OptionParser do
6
6
  stub_const('OptionParser', ImageOptim::Runner::OptionParser)
7
7
  end
8
8
 
9
+ def exit_with_status(status)
10
+ raise_error(SystemExit) do |e|
11
+ expect(e.status).to eq(status)
12
+ end
13
+ end
14
+
9
15
  describe :parse! do
10
16
  it 'returns empty hash for arguments without options' do
11
17
  args = %w[foo bar]
@@ -65,8 +71,8 @@ describe ImageOptim::Runner::OptionParser do
65
71
 
66
72
  expect do
67
73
  OptionParser.parse!(%w[--help])
68
- end.to output("#{help}\n").to_stdout &
69
- raise_error(SystemExit){ |e| expect(e.status).to eq(0) }
74
+ end.to exit_with_status(0) &
75
+ output("#{help}\n").to_stdout
70
76
  end
71
77
  end
72
78
 
@@ -80,8 +86,8 @@ describe ImageOptim::Runner::OptionParser do
80
86
 
81
87
  expect do
82
88
  OptionParser.parse!(%w[--unknown-option])
83
- end.to output("invalid option: --unknown-option\n\n#{help}\n").
84
- to_stderr & raise_error(SystemExit){ |e| expect(e.status).to eq(1) }
89
+ end.to exit_with_status(1) &
90
+ output("invalid option: --unknown-option\n\n#{help}\n").to_stderr
85
91
  end
86
92
  end
87
93
  end
@@ -28,16 +28,15 @@ describe ImageOptim do
28
28
  allow(ImageOptim::Config).to receive(:local).and_return({})
29
29
  end
30
30
 
31
- disable_all_workers = Hash[ImageOptim::Worker.klasses.map do |klass|
32
- [klass.bin_sym, false]
33
- end]
31
+ isolated_options_base = {:skip_missing_workers => false}
32
+ ImageOptim::Worker.klasses.each do |klass|
33
+ isolated_options_base[klass.bin_sym] = false
34
+ end
34
35
 
35
36
  ImageOptim::Worker.klasses.each do |worker_klass|
36
37
  describe "#{worker_klass.bin_sym} worker" do
37
38
  it 'optimizes at least one test image' do
38
- options = disable_all_workers.dup
39
- options.merge!(worker_klass.bin_sym => true)
40
- options.merge!(:skip_missing_workers => false)
39
+ options = isolated_options_base.merge(worker_klass.bin_sym => true)
41
40
 
42
41
  image_optim = ImageOptim.new(options)
43
42
  if Array(worker_klass.init(image_optim)).empty?
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: image_optim
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.22.0
4
+ version: 0.22.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivan Kuchin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-21 00:00:00.000000000 Z
11
+ date: 2016-02-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fspath
@@ -126,14 +126,14 @@ dependencies:
126
126
  requirements:
127
127
  - - ~>
128
128
  - !ruby/object:Gem::Version
129
- version: '0.35'
129
+ version: '0.37'
130
130
  type: :development
131
131
  prerelease: false
132
132
  version_requirements: !ruby/object:Gem::Requirement
133
133
  requirements:
134
134
  - - ~>
135
135
  - !ruby/object:Gem::Version
136
- version: '0.35'
136
+ version: '0.37'
137
137
  description:
138
138
  email:
139
139
  executables: