capybara-screenshot-diff 1.0.2 → 1.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cbd81a7aa63a3fcfada0a1fd3544d83bf807ac00dd2240233dfe23ecfd105591
4
- data.tar.gz: '085af6073a2a6908ca4dfa8cb4ef674b0be391f241cea5816e4179bbdcb9e142'
3
+ metadata.gz: c4b74b3421312a6837944115244ae03eb5b59b65b28dd21fed17ad9f13672b32
4
+ data.tar.gz: 9d60292db9261447214601ff3e498adb81cb5ce51899db8c19f18ac66ea53d6c
5
5
  SHA512:
6
- metadata.gz: db56bcc2c8a2cac4be1190994cd481fe91258e9d6991ec2890f793b8d269ee7f7075ed3604603c501ad5412ab12b95124c4814a372e76b42486341f0e7e57e1f
7
- data.tar.gz: 421a21ecfb59711a95591a839fa23a1954664b021a634f78801e5b19aaf22520b69741dd4776d1a2a418de803b026487718fb4d05ac9f12c9fde2d6aa5d5d8ad
6
+ metadata.gz: c529cfbf50e5b11251d4c44115713a99aac84c712dc62770d6cdc735adeba814ffc62e68acaa2fdf8e77fc6171b37269b37fbb2d669915a80a44c4d9ef7a523a
7
+ data.tar.gz: 9b6f02f0c296a53fca5acba02b36b838bc83ac8616606029f44122a08537b930e122ce1398ec152f2dfc02e65b207042ba24c37f899cb7d6586c2588c6cd60f6
data/.rubocop_todo.yml CHANGED
@@ -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: 109
37
37
 
38
38
  # Offense count: 1
39
39
  # Configuration parameters: CountKeywordArgs.
data/README.md CHANGED
@@ -409,6 +409,12 @@ The arguments are [x1, y1, x2, y2] for the area you want to ignore. You can als
409
409
  Capybara::Screenshot::Diff.skip_area = [0, 0, 64, 48]
410
410
  ```
411
411
 
412
+ If you need to ignore multiple areas, you can supply an array of arrays:
413
+
414
+ ```ruby
415
+ screenshot 'index', skip_area: [[0, 0, 64, 48], [17, 6, 27, 16]]
416
+ ```
417
+
412
418
 
413
419
  ## Development
414
420
 
@@ -44,6 +44,7 @@ module Capybara
44
44
  mattr_accessor :color_distance_limit
45
45
  mattr_accessor(:enabled) { true }
46
46
  mattr_accessor :shift_distance_limit
47
+ mattr_accessor :skip_area
47
48
 
48
49
  def self.included(clas)
49
50
  clas.include TestMethods
@@ -277,9 +277,8 @@ module Capybara
277
277
  end
278
278
 
279
279
  def same_color?(old_img, new_img, x, y)
280
- if @skip_area && @skip_area[0] <= x && x <= @skip_area[2] &&
281
- @skip_area[1] <= y && y <= @skip_area[3]
282
- return true
280
+ @skip_area&.each do |skip_start_x, skip_start_y, skip_end_x, skip_end_y|
281
+ return true if skip_start_x <= x && x <= skip_end_x && skip_start_y <= y && y <= skip_end_y
283
282
  end
284
283
 
285
284
  color_distance =
@@ -25,7 +25,7 @@ module Capybara
25
25
  blurred_input = prepare_page_for_screenshot
26
26
  previous_file_name = comparison.old_file_name
27
27
  screenshot_started_at = last_image_change_at = Time.now
28
- loop.with_index do |_x, i|
28
+ 1.step do |i|
29
29
  take_right_size_screenshot(comparison)
30
30
 
31
31
  break unless Capybara::Screenshot.stability_time_limit
@@ -118,9 +118,9 @@ module Capybara
118
118
  def check_max_wait_time(comparison, screenshot_started_at, shift_distance_limit:)
119
119
  shift_factor = shift_distance_limit ? (shift_distance_limit * 2 + 1) ^ 2 : 1
120
120
  max_wait_time = Capybara.default_max_wait_time * shift_factor
121
- assert (Time.now - screenshot_started_at) < max_wait_time,
121
+ assert((Time.now - screenshot_started_at) < max_wait_time,
122
122
  "Could not get stable screenshot within #{max_wait_time}s\n" \
123
- "#{stabilization_images(comparison.new_file_name).join("\n")}"
123
+ "#{stabilization_images(comparison.new_file_name).join("\n")}")
124
124
  end
125
125
 
126
126
  def assert_images_loaded(timeout: Capybara.default_max_wait_time)
@@ -131,8 +131,8 @@ module Capybara
131
131
  pending_image = evaluate_script IMAGE_WAIT_SCRIPT
132
132
  break unless pending_image
133
133
 
134
- assert (Time.now - start) < timeout,
135
- "Images not loaded after #{timeout}s: #{pending_image.inspect}"
134
+ assert((Time.now - start) < timeout,
135
+ "Images not loaded after #{timeout}s: #{pending_image.inspect}")
136
136
  sleep 0.1
137
137
  end
138
138
  end
@@ -70,10 +70,12 @@ module Capybara
70
70
  # @return [Boolean] wether a screenshot was taken
71
71
  def screenshot(name, color_distance_limit: Diff.color_distance_limit,
72
72
  shift_distance_limit: Diff.shift_distance_limit, area_size_limit: Diff.area_size_limit,
73
- skip_area: nil)
73
+ skip_area: Diff.skip_area)
74
74
  return unless Screenshot.active?
75
75
  return if window_size_is_wrong?
76
76
 
77
+ skip_area = skip_area&.flatten&.each_cons(4)&.to_a # Allow nil or single or multiple areas
78
+
77
79
  if @screenshot_counter
78
80
  name = "#{format('%02i', @screenshot_counter)}_#{name}"
79
81
  @screenshot_counter += 1
@@ -3,7 +3,7 @@
3
3
  module Capybara
4
4
  module Screenshot
5
5
  module Diff
6
- VERSION = '1.0.2'
6
+ VERSION = '1.1.0'
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.0.2
4
+ version: 1.1.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-05-27 00:00:00.000000000 Z
11
+ date: 2019-08-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack