Class: LookbookVisualTester::ImageComparator
- Inherits:
-
Object
- Object
- LookbookVisualTester::ImageComparator
- Defined in:
- lib/lookbook_visual_tester/image_comparator.rb
Instance Attribute Summary collapse
-
#baseline_dir ⇒ Object
readonly
Returns the value of attribute baseline_dir.
-
#current_dir ⇒ Object
readonly
Returns the value of attribute current_dir.
-
#diff_dir ⇒ Object
readonly
Returns the value of attribute diff_dir.
Instance Method Summary collapse
- #compare(scenario_run) ⇒ Object
-
#initialize ⇒ ImageComparator
constructor
A new instance of ImageComparator.
Constructor Details
#initialize ⇒ ImageComparator
Returns a new instance of ImageComparator.
7 8 9 10 11 |
# File 'lib/lookbook_visual_tester/image_comparator.rb', line 7 def initialize @baseline_dir = LookbookVisualTester.config.baseline_dir @current_dir = LookbookVisualTester.config.current_dir @diff_dir = LookbookVisualTester.config.diff_dir end |
Instance Attribute Details
#baseline_dir ⇒ Object (readonly)
Returns the value of attribute baseline_dir.
5 6 7 |
# File 'lib/lookbook_visual_tester/image_comparator.rb', line 5 def baseline_dir @baseline_dir end |
#current_dir ⇒ Object (readonly)
Returns the value of attribute current_dir.
5 6 7 |
# File 'lib/lookbook_visual_tester/image_comparator.rb', line 5 def current_dir @current_dir end |
#diff_dir ⇒ Object (readonly)
Returns the value of attribute diff_dir.
5 6 7 |
# File 'lib/lookbook_visual_tester/image_comparator.rb', line 5 def diff_dir @diff_dir end |
Instance Method Details
#compare(scenario_run) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/lookbook_visual_tester/image_comparator.rb', line 13 def compare(scenario_run) filename = scenario_run.filename current_path = current_dir.join(filename) baseline_path = baseline_dir.join(filename) diff_path = diff_dir.join(scenario_run.diff_filename) if baseline_path.exist? baseline_image = MiniMagick::Image.open(baseline_path) current_image = MiniMagick::Image.open(current_path) unless baseline_image.dimensions == current_image.dimensions puts ' Image dimensions do not match. Skipping comparison.' return end begin compare_command = "compare -metric AE \"#{baseline_path}\" \"#{current_path}\" \"#{diff_path}\" 2>&1" result = `#{compare_command}` distortion = result.strip.to_i if distortion > 0 puts " Differences found! Diff image saved to #{diff_path}" else puts ' No differences detected.' File.delete(diff_path) if diff_path.exist? end rescue StandardError => e puts " Error comparing images: #{e.}" end else FileUtils.cp(current_path, baseline_path) puts " Baseline image created at #{baseline_path}" end end |