Sha256: 5168a49615f84942a7fdb21551807480bf6408567adc1817dbc693b8cb080c35
Contents?: true
Size: 1.59 KB
Versions: 2
Compression:
Stored size: 1.59 KB
Contents
if ENV['CODECLIMATE_REPO_TOKEN'] begin require 'codeclimate-test-reporter' CodeClimate::TestReporter.start rescue LoadError => e $stderr.puts "Got following while loading codeclimate-test-reporter: #{e}" end end RSpec.configure do |c| c.alias_example_to :they end def flatten_animation(image) if image.format == :gif flattened = image.temp_path command = %W[ convert #{image.to_s.shellescape} -coalesce -append #{flattened.to_s.shellescape} ].join(' ') expect(ImageOptim::Cmd.run(command)).to be_truthy flattened else image end end def mepp(image_a, image_b) coalesce_a = flatten_animation(image_a) coalesce_b = flatten_animation(image_b) command = %W[ compare -metric MEPP -alpha Background #{coalesce_a.to_s.shellescape} #{coalesce_b.to_s.shellescape} /dev/null 2>&1 ].join(' ') output = ImageOptim::Cmd.capture(command) if [0, 1].include?($CHILD_STATUS.exitstatus) num_r = '\d+(?:\.\d+(?:[eE][-+]?\d+)?)?' output[/\((#{num_r}), #{num_r}\)/, 1].to_f else fail "compare #{image_a} with #{image_b} failed with `#{output}`" end end RSpec::Matchers.define :be_smaller_than do |expected| match{ |actual| actual.size < expected.size } end RSpec::Matchers.define :be_similar_to do |expected, max_difference| match do |actual| @diff = mepp(actual, expected) @diff <= max_difference end failure_message do |actual| "expected #{actual} to have at most #{max_difference} difference from "\ "#{expected}, got normalized root-mean-square error of #{@diff}" end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
image_optim-0.22.1 | spec/spec_helper.rb |
image_optim-0.22.0 | spec/spec_helper.rb |