lib/capybara/screenshot/diff/image_compare.rb in capybara-screenshot-diff-1.3.0 vs lib/capybara/screenshot/diff/image_compare.rb in capybara-screenshot-diff-1.3.1

- old
+ new

@@ -3,28 +3,29 @@ require 'chunky_png' module Capybara module Screenshot module Diff - # Compare two images and determine if they are equal, different, or within som comparison + # Compare two images and determine if they are equal, different, or within some comparison # range considering color values and difference area size. class ImageCompare include ChunkyPNG::Color - attr_reader :annotated_new_file_name, :annotated_old_file_name, :new_file_name, :old_file_name + attr_reader :annotated_new_file_name, :annotated_old_file_name, :area_size_limit, + :color_distance_limit, :new_file_name, :old_file_name, :shift_distance_limit, :skip_area def initialize(new_file_name, old_file_name = nil, dimensions: nil, color_distance_limit: nil, area_size_limit: nil, shift_distance_limit: nil, skip_area: nil) @new_file_name = new_file_name @color_distance_limit = color_distance_limit @area_size_limit = area_size_limit @shift_distance_limit = shift_distance_limit @dimensions = dimensions @skip_area = skip_area @old_file_name = old_file_name || "#{new_file_name}~" - @annotated_old_file_name = "#{new_file_name.chomp('.png')}_0.png~" - @annotated_new_file_name = "#{new_file_name.chomp('.png')}_1.png~" + @annotated_old_file_name = "#{new_file_name.chomp('.png')}.committed.png" + @annotated_new_file_name = "#{new_file_name.chomp('.png')}.latest.png" reset end # Resets the calculated data about the comparison with regard to the "new_image". # Data about the original image is kept. @@ -95,14 +96,11 @@ @left, @top, @right, @bottom = find_diff_rectangle(old_img, new_img) return not_different if @top.nil? return not_different if @area_size_limit && size <= @area_size_limit - annotated_old_img, annotated_new_img = draw_rectangles(images, @bottom, @left, @right, @top) - - save_images(@annotated_new_file_name, annotated_new_img, - @annotated_old_file_name, annotated_old_img) + save_annotated_images(images) true end def old_file_exists? @old_file_name && File.exist?(@old_file_name) @@ -115,10 +113,12 @@ def new_file_size File.size(@new_file_name) end def dimensions + return unless @left || @top || @right || @bottom + [@left, @top, @right, @bottom] end def size (@right - @left + 1) * (@bottom - @top + 1) @@ -133,9 +133,16 @@ calculate_metrics unless @max_shift_distance || !@shift_distance_limit @max_shift_distance end private + + def save_annotated_images(images) + annotated_old_img, annotated_new_img = draw_rectangles(images, @bottom, @left, @right, @top) + + save_images(@annotated_new_file_name, annotated_new_img, + @annotated_old_file_name, annotated_old_img) + end def calculate_metrics old_file, new_file = load_image_files(@old_file_name, @new_file_name) if old_file == new_file @max_color_distance = 0