From 78954672f97112f47c8abf6a575db59e8533448f Mon Sep 17 00:00:00 2001 From: Joffrey JAFFEUX Date: Mon, 5 Nov 2018 10:12:52 +0100 Subject: [PATCH] FIX: uses hex to compare images It prevents some terminals from crashing in case of errors and dumping the whole file content into the terminal. --- spec/models/optimized_image_spec.rb | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/spec/models/optimized_image_spec.rb b/spec/models/optimized_image_spec.rb index 40d12b5cbf2..caef6150f11 100644 --- a/spec/models/optimized_image_spec.rb +++ b/spec/models/optimized_image_spec.rb @@ -17,9 +17,12 @@ describe OptimizedImage do 5 ) - expect(File.read(tmp_path)).to eq( - File.read("#{Rails.root}/spec/fixtures/images/cropped.png") - ) + fixture_path = "#{Rails.root}/spec/fixtures/images/cropped.png" + fixture_hex = Digest::MD5.hexdigest(File.read(fixture_path)) + + cropped_hex = Digest::MD5.hexdigest(File.read(tmp_path)) + + expect(cropped_hex).to eq(fixture_hex) ensure File.delete(tmp_path) if File.exists?(tmp_path) end @@ -120,9 +123,12 @@ describe OptimizedImage do "100x100\>" ) - expect(File.read(tmp_path)).to eq( - File.read("#{Rails.root}/spec/fixtures/images/downsized.png") - ) + fixture_path = "#{Rails.root}/spec/fixtures/images/downsized.png" + fixture_hex = Digest::MD5.hexdigest(File.read(fixture_path)) + + downsized_hex = Digest::MD5.hexdigest(File.read(tmp_path)) + + expect(downsized_hex).to eq(fixture_hex) ensure File.delete(tmp_path) if File.exists?(tmp_path) end