capybara-screenshot-diff 0.14.2 → 0.15.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7d9914e53a8c3d8b2b2dbdf2d30395e5c4b69197a0c257d96c6325ada3d190b6
4
- data.tar.gz: 6f221ba0becc99ef9c84913f1f6ca3ab07948bc4193028930e0a5901aeee2933
3
+ metadata.gz: 79eb03ec72d66b7c8e8a1c2597238a0e4fed8d86c2f33150edb1d08c9d3a44b1
4
+ data.tar.gz: 6d50e7b3a58e317f43a534ab1fc27a953f46232a40473d58a86aac10d91db6d2
5
5
  SHA512:
6
- metadata.gz: 90d7916580c53a0d7c85265f67264699edbce9b1d21e6186bdf408ab98311c63d8f7658bc0b4e842525d72d8ce2ba849132d65729a6890e3f38409ae1f9b8b88
7
- data.tar.gz: 2a52e7d983d3d2a7307d00821dcbb44767e40e9e021d3ed42f079986eaa5f1350d1163c95a2385a9548d20517635f979f031bdbb24e5034f08c8a349a06907a0
6
+ metadata.gz: 7beaab007bfbae3db191271d312ba70ec1ab29b0ff1d519c8b79d4ca1f600d88d00222e1c6910adf9e66ece549c69f64bc5626dc2bfe4071bcaafa31d1c767ea
7
+ data.tar.gz: 9144c53f1a723a73ad6add946694775255132160affdc8308e84a9aa61d2b4ee32eeaa933bf471de648a8a124e8c7f359874e5fad92d844d5650d9d8607575b2
data/README.md CHANGED
@@ -391,6 +391,25 @@ Capybara::Screenshot::Diff.area_size_limit = 42
391
391
  ```
392
392
 
393
393
 
394
+ ### Skipping an area
395
+
396
+ Sometimes you have expected change that you want to ignore.
397
+ You can use the `skip_area` option to the `screenshot` method to ignore an area:
398
+
399
+ ```ruby
400
+ test 'unstable area' do
401
+ visit '/'
402
+ screenshot 'index', skip_area: [17, 6, 27, 16]
403
+ end
404
+ ```
405
+
406
+ The arguments are [x1, y1, x2, y2] for the area you want to ignore. You can also set this globally:
407
+
408
+ ```ruby
409
+ Capybara::Screenshot::Diff.skip_area = [0, 0, 64, 48]
410
+ ```
411
+
412
+
394
413
  ## Development
395
414
 
396
415
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -11,12 +11,13 @@ module Capybara
11
11
  attr_reader :annotated_new_file_name, :annotated_old_file_name, :new_file_name, :old_file_name
12
12
 
13
13
  def initialize(new_file_name, old_file_name = nil, dimensions: nil, color_distance_limit: nil,
14
- area_size_limit: nil, shift_distance_limit: nil)
14
+ area_size_limit: nil, shift_distance_limit: nil, skip_area: nil)
15
15
  @new_file_name = new_file_name
16
16
  @color_distance_limit = color_distance_limit
17
17
  @area_size_limit = area_size_limit
18
18
  @shift_distance_limit = shift_distance_limit
19
19
  @dimensions = dimensions
20
+ @skip_area = skip_area
20
21
  @old_file_name = old_file_name || "#{new_file_name}~"
21
22
  @annotated_old_file_name = "#{new_file_name.chomp('.png')}_0.png~"
22
23
  @annotated_new_file_name = "#{new_file_name.chomp('.png')}_1.png~"
@@ -274,6 +275,7 @@ module Capybara
274
275
  end
275
276
 
276
277
  def same_color?(old_img, new_img, x, y)
278
+ return true if @skip_area && @skip_area[0] <= x && x <= @skip_area[2] && @skip_area[1] <= y && y <= @skip_area[3]
277
279
  color_distance =
278
280
  color_distance_at(new_img, old_img, x, y, shift_distance_limit: @shift_distance_limit)
279
281
  if !@max_color_distance || color_distance > @max_color_distance
@@ -19,7 +19,7 @@ module Capybara
19
19
  JS
20
20
 
21
21
  def take_stable_screenshot(comparison, color_distance_limit:, shift_distance_limit:,
22
- area_size_limit:)
22
+ area_size_limit:, skip_area:)
23
23
  blurred_input = prepare_page_for_screenshot
24
24
  previous_file_name = comparison.old_file_name
25
25
  screenshot_started_at = last_image_change_at = Time.now
@@ -38,7 +38,7 @@ module Capybara
38
38
  stabilization_comparison =
39
39
  ImageCompare.new(comparison.new_file_name, previous_file_name,
40
40
  color_distance_limit: color_distance_limit, shift_distance_limit: shift_distance_limit,
41
- area_size_limit: area_size_limit)
41
+ area_size_limit: area_size_limit, skip_area: skip_area)
42
42
  if stabilization_comparison.quick_equal?
43
43
  if (Time.now - last_image_change_at) > Capybara::Screenshot.stability_time_limit
44
44
  clean_stabilization_images(comparison.new_file_name)
@@ -67,7 +67,8 @@ module Capybara
67
67
 
68
68
  # @return [Boolean] wether a screenshot was taken
69
69
  def screenshot(name, color_distance_limit: Diff.color_distance_limit,
70
- shift_distance_limit: Diff.shift_distance_limit, area_size_limit: Diff.area_size_limit)
70
+ shift_distance_limit: Diff.shift_distance_limit, area_size_limit: Diff.area_size_limit,
71
+ skip_area: nil)
71
72
  return unless Screenshot.active?
72
73
  return if window_size_is_wrong?
73
74
 
@@ -81,11 +82,13 @@ module Capybara
81
82
  FileUtils.mkdir_p File.dirname(file_name)
82
83
  comparison = ImageCompare.new(file_name,
83
84
  dimensions: Screenshot.window_size, color_distance_limit: color_distance_limit,
84
- area_size_limit: area_size_limit, shift_distance_limit: shift_distance_limit)
85
+ area_size_limit: area_size_limit, shift_distance_limit: shift_distance_limit,
86
+ skip_area: skip_area)
85
87
  checkout_vcs(name, comparison)
86
88
  take_stable_screenshot(comparison, color_distance_limit: color_distance_limit,
87
89
  shift_distance_limit: shift_distance_limit,
88
- area_size_limit: area_size_limit)
90
+ area_size_limit: area_size_limit,
91
+ skip_area: skip_area)
89
92
  return unless comparison.old_file_exists?
90
93
 
91
94
  (@test_screenshots ||= []) << [caller(1..1).first, name, comparison]
@@ -3,7 +3,7 @@
3
3
  module Capybara
4
4
  module Screenshot
5
5
  module Diff
6
- VERSION = '0.14.2'.freeze
6
+ VERSION = '0.15.0'.freeze
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: 0.14.2
4
+ version: 0.15.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: 2019-03-01 00:00:00.000000000 Z
11
+ date: 2019-04-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
@@ -200,7 +200,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
200
200
  - !ruby/object:Gem::Version
201
201
  version: '0'
202
202
  requirements: []
203
- rubygems_version: 3.0.1
203
+ rubygems_version: 3.0.3
204
204
  signing_key:
205
205
  specification_version: 4
206
206
  summary: Track your GUI changes with diff assertions