capybara-screenshot-diff 1.3.0 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6e4f48d95925d0da6d7b8afcb53b0179c0477fb034ea88e9e2dde8db02d4fb61
4
- data.tar.gz: 9c6c456601df79a02b4b647f3c0cca0c0439194534c73522054c87d39926b89c
3
+ metadata.gz: 60b85259abbdb45d903015705a59c40d376523f4987c0285a0534657a1f71c5a
4
+ data.tar.gz: 5e5f95c2f086a9ce774c54fae55d4b38fdd8cd401df2ab1912d34e4925952f3c
5
5
  SHA512:
6
- metadata.gz: 54f1f31ec364031eed15cadd22a3e2305874802480efb9ca0b0b2c35a6954293b31552971751f143fc2a6056a96d6d49df31f0c16c3d2785491ed7664f3b1f7c
7
- data.tar.gz: 872732c38c6f1822b68d56b94b27c5aeba37ffd1f39379a4e15f76b8ed248d62c787514daa724ed10f22cda1f56b4442dd0753889fc28b99d2fb8299be16c821
6
+ metadata.gz: 5684af40410133d5ed7c4364433e124af1a6164eb651fa2e3fcfadf171b9f56c0845f541774546c11c80adb18babd45034886241896f4435d61c90476238e92d
7
+ data.tar.gz: 8ccbadc67bb64ea977247cb5c501380b4c2c6aa70eb784c73d90e087f5e60875636c375c8ceba1e1367b2fed4d36fe80b20c8584510131878f9d69682ce26691
@@ -55,6 +55,9 @@ Style/Documentation:
55
55
  Style/DoubleNegation:
56
56
  Enabled: false
57
57
 
58
+ Style/FormatStringToken:
59
+ EnforcedStyle: unannotated
60
+
58
61
  Style/NumericPredicate:
59
62
  Enabled: false
60
63
 
@@ -19,7 +19,7 @@ Metrics/BlockLength:
19
19
  # Offense count: 1
20
20
  # Configuration parameters: CountComments.
21
21
  Metrics/ClassLength:
22
- Max: 304
22
+ Max: 309
23
23
 
24
24
  # Offense count: 5
25
25
  Metrics/CyclomaticComplexity:
@@ -33,7 +33,7 @@ Metrics/MethodLength:
33
33
  # Offense count: 1
34
34
  # Configuration parameters: CountComments.
35
35
  Metrics/ModuleLength:
36
- Max: 107
36
+ Max: 123
37
37
 
38
38
  # Offense count: 1
39
39
  # Configuration parameters: CountKeywordArgs.
@@ -6,7 +6,7 @@ rvm:
6
6
  - ruby-2.6.3
7
7
  - ruby-2.5.5
8
8
  - ruby-2.4.6
9
- - truffleruby-19.2.0
9
+ - truffleruby
10
10
 
11
11
  gemfile:
12
12
  - gemfiles/rails60.gemfile
data/README.md CHANGED
@@ -274,7 +274,7 @@ configuration options that that are relevant.
274
274
  The most likely one you'll want to modify is ...
275
275
 
276
276
  ```ruby
277
- Capybara::Screenshot::Diff.save_path = "other/path"
277
+ Capybara::Screenshot.save_path = "other/path"
278
278
  ```
279
279
 
280
280
  The `save_path` option is relative to `Capybara::Screenshot.root`.
@@ -5,12 +5,13 @@ require 'chunky_png'
5
5
  module Capybara
6
6
  module Screenshot
7
7
  module Diff
8
- # Compare two images and determine if they are equal, different, or within som comparison
8
+ # Compare two images and determine if they are equal, different, or within some comparison
9
9
  # range considering color values and difference area size.
10
10
  class ImageCompare
11
11
  include ChunkyPNG::Color
12
12
 
13
- attr_reader :annotated_new_file_name, :annotated_old_file_name, :new_file_name, :old_file_name
13
+ attr_reader :annotated_new_file_name, :annotated_old_file_name, :area_size_limit,
14
+ :color_distance_limit, :new_file_name, :old_file_name, :shift_distance_limit, :skip_area
14
15
 
15
16
  def initialize(new_file_name, old_file_name = nil, dimensions: nil, color_distance_limit: nil,
16
17
  area_size_limit: nil, shift_distance_limit: nil, skip_area: nil)
@@ -21,8 +22,8 @@ module Capybara
21
22
  @dimensions = dimensions
22
23
  @skip_area = skip_area
23
24
  @old_file_name = old_file_name || "#{new_file_name}~"
24
- @annotated_old_file_name = "#{new_file_name.chomp('.png')}_0.png~"
25
- @annotated_new_file_name = "#{new_file_name.chomp('.png')}_1.png~"
25
+ @annotated_old_file_name = "#{new_file_name.chomp('.png')}.committed.png"
26
+ @annotated_new_file_name = "#{new_file_name.chomp('.png')}.latest.png"
26
27
  reset
27
28
  end
28
29
 
@@ -97,10 +98,7 @@ module Capybara
97
98
  return not_different if @top.nil?
98
99
  return not_different if @area_size_limit && size <= @area_size_limit
99
100
 
100
- annotated_old_img, annotated_new_img = draw_rectangles(images, @bottom, @left, @right, @top)
101
-
102
- save_images(@annotated_new_file_name, annotated_new_img,
103
- @annotated_old_file_name, annotated_old_img)
101
+ save_annotated_images(images)
104
102
  true
105
103
  end
106
104
 
@@ -117,6 +115,8 @@ module Capybara
117
115
  end
118
116
 
119
117
  def dimensions
118
+ return unless @left || @top || @right || @bottom
119
+
120
120
  [@left, @top, @right, @bottom]
121
121
  end
122
122
 
@@ -136,6 +136,13 @@ module Capybara
136
136
 
137
137
  private
138
138
 
139
+ def save_annotated_images(images)
140
+ annotated_old_img, annotated_new_img = draw_rectangles(images, @bottom, @left, @right, @top)
141
+
142
+ save_images(@annotated_new_file_name, annotated_new_img,
143
+ @annotated_old_file_name, annotated_old_img)
144
+ end
145
+
139
146
  def calculate_metrics
140
147
  old_file, new_file = load_image_files(@old_file_name, @new_file_name)
141
148
  if old_file == new_file
@@ -52,7 +52,9 @@ module Capybara
52
52
  end
53
53
  end
54
54
 
55
- previous_file_name = "#{comparison.new_file_name.chomp('.png')}_x#{format('%02i', i)}.png~"
55
+ previous_file_name = "#{comparison.new_file_name.chomp('.png')}" \
56
+ "_x#{format('%02i', i)}_#{(Time.now - screenshot_started_at).round(1)}s" \
57
+ "_#{stabilization_comparison.dimensions&.to_s&.gsub(', ', '_') || :initial}.png~"
56
58
  FileUtils.mv comparison.new_file_name, previous_file_name
57
59
 
58
60
  check_max_wait_time(comparison, screenshot_started_at,
@@ -117,9 +119,25 @@ module Capybara
117
119
  def check_max_wait_time(comparison, screenshot_started_at, wait:, shift_distance_limit:)
118
120
  shift_factor = shift_distance_limit ? (shift_distance_limit * 2 + 1) ^ 2 : 1
119
121
  max_wait_time = wait * shift_factor
120
- assert((Time.now - screenshot_started_at) < max_wait_time,
121
- "Could not get stable screenshot within #{max_wait_time}s\n" \
122
- "#{stabilization_images(comparison.new_file_name).join("\n")}")
122
+ return if (Time.now - screenshot_started_at) < max_wait_time
123
+
124
+ # FIXME(uwe): Change to store the failure and only report if the test succeeds functionally.
125
+ previous_file = comparison.old_file_name
126
+ stabilization_images(comparison.new_file_name).each do |file_name|
127
+ if File.exist? previous_file
128
+ stabilization_comparison =
129
+ ImageCompare.new(file_name, previous_file,
130
+ color_distance_limit: comparison.color_distance_limit,
131
+ shift_distance_limit: comparison.shift_distance_limit,
132
+ area_size_limit: comparison.area_size_limit, skip_area: comparison.skip_area)
133
+ assert stabilization_comparison.different?
134
+ FileUtils.mv stabilization_comparison.annotated_new_file_name, file_name
135
+ FileUtils.rm stabilization_comparison.annotated_old_file_name
136
+ end
137
+ previous_file = file_name
138
+ end
139
+ fail("Could not get stable screenshot within #{max_wait_time}s\n" \
140
+ "#{stabilization_images(comparison.new_file_name).join("\n")}")
123
141
  end
124
142
 
125
143
  def assert_images_loaded(timeout:)
@@ -3,7 +3,7 @@
3
3
  module Capybara
4
4
  module Screenshot
5
5
  module Diff
6
- VERSION = '1.3.0'
6
+ VERSION = '1.3.1'
7
7
  end
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capybara-screenshot-diff
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Uwe Kubosch
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-09-27 00:00:00.000000000 Z
11
+ date: 2019-10-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack