Sha256: 1c413912575b098733dcd18a9cb1c779c6e2a7e4b8e849fcb1d73ecb31251c73
Contents?: true
Size: 1.57 KB
Versions: 2
Compression:
Stored size: 1.57 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 flatten_command = %W[ convert #{image.to_s.shellescape} -coalesce -append #{flattened.to_s.shellescape} ].join(' ') expect(ImageOptim::Cmd.run(flatten_command)).to be_truthy flattened else image end end def nrmse(image_a, image_b) coalesce_a = flatten_animation(image_a) coalesce_b = flatten_animation(image_b) nrmse_command = %W[ compare -metric RMSE -alpha Background #{coalesce_a.to_s.shellescape} #{coalesce_b.to_s.shellescape} /dev/null 2>&1 ].join(' ') output = ImageOptim::Cmd.capture(nrmse_command) if [0, 1].include?($CHILD_STATUS.exitstatus) output[/\((\d+(\.\d+)?)\)/, 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 = nrmse(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 & 2 rubygems
Version | Path |
---|---|
openstreetmap-image_optim-0.21.0.1 | spec/spec_helper.rb |
image_optim-0.21.0 | spec/spec_helper.rb |