capybara-screenshot-diff 0.11.3 → 0.12.0
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 +5 -5
- data/.rubocop_todo.yml +3 -3
- data/README.md +3 -0
- data/lib/capybara/screenshot/diff/image_compare.rb +32 -12
- data/lib/capybara/screenshot/diff/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 0b1699ff683e2c3cb5b32b32ae60bbb05bf15c7480c85f931d5276dec9712fb0
|
4
|
+
data.tar.gz: c315dcb091a812a01b2c2f2fe0690a07814dc3b87c632668f3355d2c4c994a59
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bb6b91c2e92fdce32245fa82fefc1ba48ab29f92645cdcc1513c28f2c79635c5c184ed16d81207268e3384ca04b199f2aeea98bc9f915c3faf91299cb9879e24
|
7
|
+
data.tar.gz: 19a7ef21e19844f845cb396bd3c8db4d24402d87f44da571a554d91ec504eb9a3326d6b31c012d2c19790c53e99e91a9514ac2bf3e9b28fd9ea16f141b2cd1d4
|
data/.rubocop_todo.yml
CHANGED
@@ -13,12 +13,12 @@ Metrics/AbcSize:
|
|
13
13
|
# Offense count: 1
|
14
14
|
# Configuration parameters: CountComments, ExcludedMethods.
|
15
15
|
Metrics/BlockLength:
|
16
|
-
Max:
|
16
|
+
Max: 44
|
17
17
|
|
18
18
|
# Offense count: 1
|
19
19
|
# Configuration parameters: CountComments.
|
20
20
|
Metrics/ClassLength:
|
21
|
-
Max:
|
21
|
+
Max: 302
|
22
22
|
|
23
23
|
# Offense count: 6
|
24
24
|
Metrics/CyclomaticComplexity:
|
@@ -27,7 +27,7 @@ Metrics/CyclomaticComplexity:
|
|
27
27
|
# Offense count: 16
|
28
28
|
# Configuration parameters: CountComments.
|
29
29
|
Metrics/MethodLength:
|
30
|
-
Max:
|
30
|
+
Max: 49
|
31
31
|
|
32
32
|
# Offense count: 1
|
33
33
|
# Configuration parameters: CountComments.
|
data/README.md
CHANGED
@@ -16,6 +16,7 @@ Add this line to your application's Gemfile:
|
|
16
16
|
|
17
17
|
```ruby
|
18
18
|
gem 'capybara-screenshot-diff'
|
19
|
+
gem 'oily_png', platform :ruby
|
19
20
|
```
|
20
21
|
|
21
22
|
And then execute:
|
@@ -93,6 +94,8 @@ doc
|
|
93
94
|
|
94
95
|
To store the screen shot history, add the `doc/screenshots` directory to your
|
95
96
|
version control system (git, svn, etc).
|
97
|
+
|
98
|
+
Screen shots are compared to the previously COMMITTED version of the same screen shot.
|
96
99
|
|
97
100
|
### Screenshot groups
|
98
101
|
|
@@ -8,8 +8,7 @@ module Capybara
|
|
8
8
|
class ImageCompare
|
9
9
|
include ChunkyPNG::Color
|
10
10
|
|
11
|
-
attr_reader :annotated_new_file_name, :annotated_old_file_name, :new_file_name,
|
12
|
-
:old_file_name
|
11
|
+
attr_reader :annotated_new_file_name, :annotated_old_file_name, :new_file_name, :old_file_name
|
13
12
|
|
14
13
|
def initialize(new_file_name, old_file_name = nil, dimensions: nil, color_distance_limit: nil,
|
15
14
|
area_size_limit: nil, shift_distance_limit: nil)
|
@@ -134,18 +133,34 @@ module Capybara
|
|
134
133
|
|
135
134
|
def calculate_metrics
|
136
135
|
old_file, new_file = load_image_files(@old_file_name, @new_file_name)
|
137
|
-
|
136
|
+
if old_file == new_file
|
137
|
+
@max_color_distance = 0
|
138
|
+
@max_shift_distance = 0
|
139
|
+
return
|
140
|
+
end
|
138
141
|
|
139
142
|
old_image, new_image = load_images(old_file, new_file)
|
143
|
+
calculate_max_color_distance(new_image, old_image)
|
144
|
+
calculate_max_shift_limit(new_image, old_image)
|
145
|
+
end
|
140
146
|
|
147
|
+
def calculate_max_color_distance(new_image, old_image)
|
141
148
|
pixel_pairs = old_image.pixels.zip(new_image.pixels)
|
142
149
|
@max_color_distance = pixel_pairs.inject(0) do |max, (p1, p2)|
|
143
150
|
d = ChunkyPNG::Color.euclidean_distance_rgba(p1, p2)
|
144
151
|
[max, d].max
|
145
152
|
end
|
153
|
+
end
|
146
154
|
|
147
|
-
|
148
|
-
|
155
|
+
def calculate_max_shift_limit(new_img, old_img)
|
156
|
+
(0...new_img.width).each do |x|
|
157
|
+
(0...new_img.height).each do |y|
|
158
|
+
shift_distance =
|
159
|
+
shift_distance_at(new_img, old_img, x, y, color_distance_limit: @color_distance_limit)
|
160
|
+
if shift_distance && (@max_shift_distance.nil? || shift_distance > @max_shift_distance)
|
161
|
+
@max_shift_distance = shift_distance
|
162
|
+
return if @max_shift_distance == Float::INFINITY # rubocop: disable Lint/NonLocalExitFromIterator
|
163
|
+
end
|
149
164
|
end
|
150
165
|
end
|
151
166
|
end
|
@@ -259,9 +274,13 @@ module Capybara
|
|
259
274
|
end
|
260
275
|
color_matches = color_distance == 0 || (@color_distance_limit && @color_distance_limit > 0 &&
|
261
276
|
color_distance <= @color_distance_limit)
|
262
|
-
return color_matches
|
277
|
+
return color_matches if !@shift_distance_limit || @max_shift_distance == Float::INFINITY
|
263
278
|
shift_distance =
|
264
|
-
|
279
|
+
if color_matches
|
280
|
+
0
|
281
|
+
else
|
282
|
+
shift_distance_at(new_img, old_img, x, y, color_distance_limit: @color_distance_limit)
|
283
|
+
end
|
265
284
|
if shift_distance && (@max_shift_distance.nil? || shift_distance > @max_shift_distance)
|
266
285
|
@max_shift_distance = shift_distance
|
267
286
|
end
|
@@ -293,9 +312,10 @@ module Capybara
|
|
293
312
|
shift_distance = 0
|
294
313
|
loop do
|
295
314
|
bounds_breached = 0
|
296
|
-
|
315
|
+
top_row = y - shift_distance
|
316
|
+
if top_row >= 0 # top
|
297
317
|
([0, x - shift_distance].max..[x + shift_distance, new_img.width - 1].min).each do |dx|
|
298
|
-
if color_matches(new_img, org_color, dx,
|
318
|
+
if color_matches(new_img, org_color, dx, top_row, color_distance_limit)
|
299
319
|
return shift_distance
|
300
320
|
end
|
301
321
|
end
|
@@ -304,7 +324,7 @@ module Capybara
|
|
304
324
|
end
|
305
325
|
if shift_distance > 0
|
306
326
|
if (x - shift_distance) >= 0 # left
|
307
|
-
([0,
|
327
|
+
([0, top_row + 1].max..[y + shift_distance, new_img.height - 2].min)
|
308
328
|
.each do |dy|
|
309
329
|
if color_matches(new_img, org_color, x - shift_distance, dy, color_distance_limit)
|
310
330
|
return shift_distance
|
@@ -323,7 +343,7 @@ module Capybara
|
|
323
343
|
bounds_breached += 1
|
324
344
|
end
|
325
345
|
if (x + shift_distance) < new_img.width # right
|
326
|
-
([0,
|
346
|
+
([0, top_row + 1].max..[y + shift_distance, new_img.height - 2].min)
|
327
347
|
.each do |dy|
|
328
348
|
if color_matches(new_img, org_color, x + shift_distance, dy, color_distance_limit)
|
329
349
|
return shift_distance
|
@@ -336,7 +356,7 @@ module Capybara
|
|
336
356
|
break if bounds_breached == 4
|
337
357
|
shift_distance += 1
|
338
358
|
end
|
339
|
-
|
359
|
+
Float::INFINITY
|
340
360
|
end
|
341
361
|
|
342
362
|
def color_matches(new_img, org_color, dx, dy, color_distance_limit)
|
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: 0.
|
4
|
+
version: 0.12.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Uwe Kubosch
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-09-
|
11
|
+
date: 2018-09-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|
@@ -194,7 +194,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
194
194
|
version: '0'
|
195
195
|
requirements: []
|
196
196
|
rubyforge_project:
|
197
|
-
rubygems_version: 2.6
|
197
|
+
rubygems_version: 2.7.6
|
198
198
|
signing_key:
|
199
199
|
specification_version: 4
|
200
200
|
summary: Track your GUI changes with diff assertions
|