capybara-screenshot-diff 0.2.1 → 0.3.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
  SHA1:
3
- metadata.gz: d8c517212dfc9af8af735a354862dcaba9adc96a
4
- data.tar.gz: 7828ae0bfa1c9aea2e8814288989288c43c8f64e
3
+ metadata.gz: 18cb8f36eeb03d05da4cd3300a91e7f871724a77
4
+ data.tar.gz: 2bbdc4d01d53b5bad98f43b16cec3557a167811b
5
5
  SHA512:
6
- metadata.gz: 27179f167cc8d6b77850033dd0e5291ae89e7dd4182586e22269a66619fca6e02d891e257c6c7041e51adb13a4b7097e8017e7c6e543ef7f11a6cf02fefef2e9
7
- data.tar.gz: be58b147f1948e3136975f1320caa8cbfeeca7d5e5f27651bd8736fe31da35384d950165e8b560c0fdc4b2fe1975e382511ac565cc9f8314a2145982c11d3de0
6
+ metadata.gz: b46673760287a2ff760f261e089ef75ed469cc83c05148a7dc4ca2791d8d5967f862bbffb45bf670c0e5bde9b50cb2cd42598679814b9cac88920a3bf333b7d5
7
+ data.tar.gz: 4048618b8364260ba070a1a320d44adf494f1af02344ae26a9d2a21d9a38f90ae3c9d4800c878234e20b494ac0c2af9e8bfaff1ad9689d35cf6a173bed2bdaf0
@@ -13,6 +13,9 @@ Metrics/ClassLength:
13
13
  Metrics/LineLength:
14
14
  Max: 110
15
15
 
16
+ Style/Documentation:
17
+ Enabled: false
18
+
16
19
  Style/MultilineMethodCallIndentation:
17
20
  EnforcedStyle: indented
18
21
  IndentationWidth: 4
@@ -1,31 +1,23 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2016-04-22 14:35:36 +0200 using RuboCop version 0.39.0.
3
+ # on 2016-12-23 14:12:31 +0100 using RuboCop version 0.46.0.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
7
7
  # versions of RuboCop, may require this file to be generated again.
8
8
 
9
- Style/TrivialAccessors:
10
- Enabled: false
11
-
12
- # Offense count: 2
13
- Lint/AmbiguousRegexpLiteral:
14
- Exclude:
15
- - 'lib/capybara/screenshot/diff/capybara_setup.rb'
16
-
17
9
  # Offense count: 3
18
10
  Metrics/AbcSize:
19
- Max: 55
11
+ Max: 45
20
12
 
21
13
  # Offense count: 1
22
14
  Metrics/CyclomaticComplexity:
23
- Max: 15
15
+ Max: 12
24
16
 
25
- # Offense count: 3
17
+ # Offense count: 4
26
18
  # Configuration parameters: CountComments.
27
19
  Metrics/MethodLength:
28
- Max: 42
20
+ Max: 36
29
21
 
30
22
  # Offense count: 1
31
23
  # Configuration parameters: CountKeywordArgs.
@@ -34,22 +26,7 @@ Metrics/ParameterLists:
34
26
 
35
27
  # Offense count: 1
36
28
  Metrics/PerceivedComplexity:
37
- Max: 17
38
-
39
- # Offense count: 1
40
- # Configuration parameters: EnforcedStyle, SupportedStyles.
41
- # SupportedStyles: nested, compact
42
- Style/ClassAndModuleChildren:
43
- Exclude:
44
- - 'lib/capybara/screenshot/diff/capybara_setup.rb'
45
-
46
- # Offense count: 2
47
- Style/Documentation:
48
- Exclude:
49
- - 'spec/**/*'
50
- - 'test/**/*'
51
- - 'lib/capybara/screenshot/diff.rb'
52
- - 'lib/capybara/screenshot/diff/image_compare.rb'
29
+ Max: 14
53
30
 
54
31
  # Offense count: 1
55
32
  # Configuration parameters: EnforcedStyle, SupportedStyles.
@@ -57,23 +34,3 @@ Style/Documentation:
57
34
  Style/FormatString:
58
35
  Exclude:
59
36
  - 'lib/capybara/screenshot/diff/capybara_setup.rb'
60
-
61
- # Offense count: 1
62
- # Configuration parameters: MinBodyLength.
63
- Style/GuardClause:
64
- Exclude:
65
- - 'capybara-screenshot-diff.gemspec'
66
-
67
- # Offense count: 1
68
- # Cop supports --auto-correct.
69
- # Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth.
70
- # SupportedStyles: aligned, indented
71
- Style/MultilineMethodCallIndentation:
72
- Enabled: false
73
-
74
- # Offense count: 1
75
- # Cop supports --auto-correct.
76
- # Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth.
77
- # SupportedStyles: aligned, indented
78
- Style/MultilineOperationIndentation:
79
- Enabled: false
@@ -1,11 +1,10 @@
1
1
  language: ruby
2
2
  rvm:
3
+ - jruby-9.1.6.0
4
+ - 2.3.3
5
+ - 2.2.6
6
+ - 2.1.9
3
7
  - jruby-head
4
- - jruby-9.1.2.0
5
- - jruby-9.1.5.0
6
- - 2.3.1
7
- - 2.2.5
8
- - 2.1.8
9
8
  - ruby-head
10
9
  before_install: gem query -i -n ^bundler$ >/dev/null || gem install bundler
11
10
 
data/README.md CHANGED
@@ -251,7 +251,7 @@ To release a new version, update the version number in `lib/capybara/screenshot/
251
251
 
252
252
  ## Contributing
253
253
 
254
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/capybara-screenshot-diff. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
254
+ Bug reports and pull requests are welcome on GitHub at https://github.com/donv/capybara-screenshot-diff. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
255
255
 
256
256
 
257
257
  ## License
data/Rakefile CHANGED
@@ -1,8 +1,7 @@
1
1
  require 'bundler/gem_tasks'
2
2
  require 'rake/testtask'
3
- require 'rubocop/rake_task'
4
3
 
5
- task default: [:test, :rubocop]
4
+ task default: :test
6
5
 
7
6
  Rake::TestTask.new(:test) do |t|
8
7
  t.libs << 'test'
@@ -10,6 +9,6 @@ Rake::TestTask.new(:test) do |t|
10
9
  t.test_files = FileList['test/**/*_test.rb']
11
10
  end
12
11
 
12
+ require 'rubocop/rake_task'
13
13
  RuboCop::RakeTask.new
14
-
15
14
  Rake::Task[:test].enhance [:'rubocop:auto_correct']
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
19
  spec.require_paths = ['lib']
20
20
 
21
- spec.add_runtime_dependency 'actionpack', '~> 4.1'
21
+ spec.add_runtime_dependency 'actionpack', '>= 4.1', '<5.1'
22
22
  spec.add_runtime_dependency 'capybara', '~> 2.0'
23
23
  spec.add_runtime_dependency 'chunky_png', '~> 1.3'
24
24
 
@@ -7,132 +7,139 @@ require 'action_dispatch'
7
7
  # and use Module#prepend/include to insert.
8
8
  # Add the `screenshot` method to ActionDispatch::IntegrationTest
9
9
  # rubocop:disable Metrics/ClassLength
10
- class ActionDispatch::IntegrationTest
11
- ON_WINDOWS = RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/
12
- SILENCE_ERRORS = ON_WINDOWS ? '2>nul' : '2>/dev/null'
13
-
14
- def self.os_name
15
- case RbConfig::CONFIG['host_os']
16
- when /darwin/
17
- 'macos'
18
- when /mswin|mingw|cygwin/
19
- 'windows'
20
- when /linux/
21
- 'linux'
22
- else
23
- 'unknown'
10
+ module ActionDispatch
11
+ class IntegrationTest
12
+ ON_WINDOWS = RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/
13
+ SILENCE_ERRORS = ON_WINDOWS ? '2>nul' : '2>/dev/null'
14
+
15
+ def self.os_name
16
+ case RbConfig::CONFIG['host_os']
17
+ when /darwin/
18
+ 'macos'
19
+ when /mswin|mingw|cygwin/
20
+ 'windows'
21
+ when /linux/
22
+ 'linux'
23
+ else
24
+ 'unknown'
25
+ end
24
26
  end
25
- end
26
27
 
27
- def self.screenshot_root
28
- Capybara::Screenshot.screenshot_root ||
28
+ def self.screenshot_root
29
+ Capybara::Screenshot.screenshot_root ||
29
30
  (defined?(Rails.root) && Rails.root) || File.expand_path('.')
30
- end
31
+ end
31
32
 
32
- def self.screenshot_area
33
- parts = ['doc/screenshots']
34
- parts << Capybara.default_driver.to_s if Capybara::Screenshot.add_driver_path
35
- parts << os_name if Capybara::Screenshot.add_os_path
36
- File.join parts
37
- end
33
+ def self.screenshot_area
34
+ parts = ['doc/screenshots']
35
+ parts << Capybara.default_driver.to_s if Capybara::Screenshot.add_driver_path
36
+ parts << os_name if Capybara::Screenshot.add_os_path
37
+ File.join parts
38
+ end
38
39
 
39
- def self.screenshot_area_abs
40
- "#{screenshot_root}/#{screenshot_area}".freeze
41
- end
40
+ def self.screenshot_area_abs
41
+ "#{screenshot_root}/#{screenshot_area}".freeze
42
+ end
42
43
 
43
- def initialize(*)
44
- super
45
- @screenshot_counter = nil
46
- @screenshot_group = nil
47
- @screenshot_section = nil
48
- @test_screenshot_errors = nil
49
- @test_screenshots = nil
50
- end
44
+ def initialize(*)
45
+ super
46
+ @screenshot_counter = nil
47
+ @screenshot_group = nil
48
+ @screenshot_section = nil
49
+ @test_screenshot_errors = nil
50
+ @test_screenshots = nil
51
+ end
51
52
 
52
- def group_parts
53
- parts = []
54
- parts << @screenshot_section if @screenshot_section.present?
55
- parts << @screenshot_group if @screenshot_group.present?
56
- parts
57
- end
53
+ def group_parts
54
+ parts = []
55
+ parts << @screenshot_section if @screenshot_section.present?
56
+ parts << @screenshot_group if @screenshot_group.present?
57
+ parts
58
+ end
58
59
 
59
- def full_name(name)
60
- File.join group_parts.<<(name).map(&:to_s)
61
- end
60
+ def full_name(name)
61
+ File.join group_parts.<<(name).map(&:to_s)
62
+ end
62
63
 
63
- def screenshot_dir
64
- File.join [self.class.screenshot_area] + group_parts
65
- end
64
+ def screenshot_dir
65
+ File.join [self.class.screenshot_area] + group_parts
66
+ end
67
+
68
+ setup do
69
+ if Capybara::Screenshot.window_size
70
+ if Capybara.default_driver == :selenium
71
+ page.driver.browser.manage.window.resize_to(*Capybara::Screenshot.window_size)
72
+ elsif Capybara.default_driver == :poltergeist
73
+ page.driver.resize(*Capybara::Screenshot.window_size)
74
+ end
75
+ end
76
+ end
66
77
 
67
- setup do
68
- if Capybara::Screenshot.window_size
69
- if Capybara.default_driver == :selenium
70
- page.driver.browser.manage.window.resize_to(*Capybara::Screenshot.window_size)
71
- elsif Capybara.default_driver == :poltergeist
72
- page.driver.resize(*Capybara::Screenshot.window_size)
78
+ teardown do
79
+ if Capybara::Screenshot::Diff.enabled && @test_screenshots
80
+ @test_screenshots.each { |args| assert_image_not_changed(*args) }
73
81
  end
82
+ fail(@test_screenshot_errors.join("\n\n")) if @test_screenshot_errors
74
83
  end
75
- end
76
84
 
77
- teardown do
78
- if Capybara::Screenshot::Diff.enabled && @test_screenshots
79
- @test_screenshots.each { |args| assert_image_not_changed(*args) }
85
+ def screenshot_section(name)
86
+ @screenshot_section = name.to_s
80
87
  end
81
- fail(@test_screenshot_errors.join("\n\n")) if @test_screenshot_errors
82
- end
83
88
 
84
- def screenshot_section(name)
85
- @screenshot_section = name.to_s
86
- end
89
+ def screenshot_group(name)
90
+ @screenshot_group = name.to_s
91
+ @screenshot_counter = 0
92
+ return unless Capybara::Screenshot.active? && name.present?
93
+ FileUtils.rm_rf screenshot_dir
94
+ end
87
95
 
88
- def screenshot_group(name)
89
- @screenshot_group = name.to_s
90
- @screenshot_counter = 0
91
- return unless Capybara::Screenshot.active? && name.present?
92
- FileUtils.rm_rf screenshot_dir
93
- end
96
+ def screenshot(name)
97
+ return unless Capybara::Screenshot.active?
98
+ if Capybara.default_driver == :selenium && Capybara::Screenshot.window_size
99
+ return unless page.driver.browser.manage.window
100
+ .size == Selenium::WebDriver::Dimension.new(*Capybara::Screenshot.window_size)
101
+ end
102
+ if @screenshot_counter
103
+ name = "#{'%02i' % @screenshot_counter}_#{name}"
104
+ @screenshot_counter += 1
105
+ end
106
+ name = full_name(name)
107
+ file_name = "#{self.class.screenshot_area_abs}/#{name}.png"
108
+ org_name = "#{self.class.screenshot_area_abs}/#{name}_0.png~"
109
+ new_name = "#{self.class.screenshot_area_abs}/#{name}_1.png~"
110
+
111
+ FileUtils.mkdir_p File.dirname(file_name)
112
+ committed_file_name = check_vcs(name, file_name, org_name)
113
+ take_stable_screenshot(file_name)
114
+ return unless committed_file_name && File.exist?(committed_file_name)
115
+ (@test_screenshots ||= []) << [caller[0], name, file_name, committed_file_name, new_name, org_name]
116
+ end
94
117
 
95
- def screenshot(name)
96
- return unless Capybara::Screenshot.active?
97
- if Capybara.default_driver == :selenium && Capybara::Screenshot.window_size
98
- return unless page.driver.browser.manage.window
99
- .size == Selenium::WebDriver::Dimension.new(*Capybara::Screenshot.window_size)
100
- end
101
- if @screenshot_counter
102
- name = "#{'%02i' % @screenshot_counter}_#{name}"
103
- @screenshot_counter += 1
104
- end
105
- name = full_name(name)
106
- file_name = "#{self.class.screenshot_area_abs}/#{name}.png"
107
- org_name = "#{self.class.screenshot_area_abs}/#{name}_0.png~"
108
- new_name = "#{self.class.screenshot_area_abs}/#{name}_1.png~"
109
-
110
- FileUtils.mkdir_p File.dirname(file_name)
111
- svn_file_name = "#{self.class.screenshot_area_abs}/.svn/text-base/#{name}.png.svn-base"
112
- if File.exist?(svn_file_name)
113
- committed_file_name = svn_file_name
114
- else
115
- svn_info = `svn info #{file_name} #{SILENCE_ERRORS}`
116
- if svn_info.present?
117
- wc_root = svn_info.slice(/(?<=Working Copy Root Path: ).*$/)
118
- checksum = svn_info.slice(/(?<=Checksum: ).*$/)
119
- if checksum
120
- committed_file_name = "#{wc_root}/.svn/pristine/#{checksum[0..1]}/#{checksum}.svn-base"
121
- end
118
+ def check_vcs(name, file_name, org_name)
119
+ svn_file_name = "#{self.class.screenshot_area_abs}/.svn/text-base/#{name}.png.svn-base"
120
+ if File.exist?(svn_file_name)
121
+ committed_file_name = svn_file_name
122
122
  else
123
- committed_file_name = org_name
124
- `git show HEAD~0:#{self.class.screenshot_area}/#{name}.png > #{committed_file_name} #{SILENCE_ERRORS}`
125
- if File.size(committed_file_name) == 0
126
- FileUtils.rm_f committed_file_name
123
+ svn_info = `svn info #{file_name} #{SILENCE_ERRORS}`
124
+ if svn_info.present?
125
+ wc_root = svn_info.slice(/(?<=Working Copy Root Path: ).*$/)
126
+ checksum = svn_info.slice(/(?<=Checksum: ).*$/)
127
+ if checksum
128
+ committed_file_name = "#{wc_root}/.svn/pristine/#{checksum[0..1]}/#{checksum}.svn-base"
129
+ end
130
+ else
131
+ committed_file_name = org_name
132
+ redirect_target = "#{committed_file_name} #{SILENCE_ERRORS}"
133
+ `git show HEAD~0:#{self.class.screenshot_area}/#{name}.png > #{redirect_target}`
134
+ if File.size(committed_file_name) == 0
135
+ FileUtils.rm_f committed_file_name
136
+ end
127
137
  end
128
138
  end
139
+ committed_file_name
129
140
  end
130
- take_stable_screenshot(file_name)
131
- return unless committed_file_name && File.exist?(committed_file_name)
132
- (@test_screenshots ||= []) << [caller[0], name, file_name, committed_file_name, new_name, org_name]
133
- end
134
141
 
135
- IMAGE_WAIT_SCRIPT = <<EOF.freeze
142
+ IMAGE_WAIT_SCRIPT = <<EOF.freeze
136
143
  function pending_image() {
137
144
  var images = document.images;
138
145
  for (var i = 0; i < images.length; i++) {
@@ -144,36 +151,37 @@ function pending_image() {
144
151
  }()
145
152
  EOF
146
153
 
147
- def assert_images_loaded(timeout: Capybara.default_max_wait_time)
148
- return unless respond_to? :evaluate_script
149
- start = Time.now
150
- loop do
151
- pending_image = evaluate_script IMAGE_WAIT_SCRIPT
152
- break unless pending_image
153
- assert (Time.now - start) < timeout,
154
- "Image not loaded after #{timeout}s: #{pending_image.inspect}"
155
- sleep 0.1
154
+ def assert_images_loaded(timeout: Capybara.default_max_wait_time)
155
+ return unless respond_to? :evaluate_script
156
+ start = Time.now
157
+ loop do
158
+ pending_image = evaluate_script IMAGE_WAIT_SCRIPT
159
+ break unless pending_image
160
+ assert (Time.now - start) < timeout,
161
+ "Image not loaded after #{timeout}s: #{pending_image.inspect}"
162
+ sleep 0.1
163
+ end
156
164
  end
157
- end
158
165
 
159
- def take_stable_screenshot(file_name)
160
- assert_images_loaded
161
- old_file_size = nil
162
- loop do
163
- save_screenshot(file_name)
164
- break unless Capybara::Screenshot.stability_time_limit
165
- new_file_size = File.size(file_name)
166
- break if new_file_size == old_file_size
167
- old_file_size = new_file_size
168
- sleep Capybara::Screenshot.stability_time_limit
166
+ def take_stable_screenshot(file_name)
167
+ assert_images_loaded
168
+ old_file_size = nil
169
+ loop do
170
+ save_screenshot(file_name)
171
+ break unless Capybara::Screenshot.stability_time_limit
172
+ new_file_size = File.size(file_name)
173
+ break if new_file_size == old_file_size
174
+ old_file_size = new_file_size
175
+ sleep Capybara::Screenshot.stability_time_limit
176
+ end
169
177
  end
170
- end
171
178
 
172
- def assert_image_not_changed(caller, name, file_name, committed_file_name, new_name, org_name)
173
- if Capybara::Screenshot::Diff::ImageCompare.compare(committed_file_name, file_name,
174
- Capybara::Screenshot.window_size)
175
- (@test_screenshot_errors ||= []) <<
179
+ def assert_image_not_changed(caller, name, file_name, committed_file_name, new_name, org_name)
180
+ if Capybara::Screenshot::Diff::ImageCompare.compare(committed_file_name, file_name,
181
+ Capybara::Screenshot.window_size)
182
+ (@test_screenshot_errors ||= []) <<
176
183
  "Screenshot does not match for '#{name}'\n#{file_name}\n#{org_name}\n#{new_name}\nat #{caller}"
184
+ end
177
185
  end
178
186
  end
179
187
  end
@@ -2,7 +2,7 @@
2
2
  module Capybara
3
3
  module Screenshot
4
4
  module Diff
5
- VERSION = '0.2.1'.freeze
5
+ VERSION = '0.3.0'.freeze
6
6
  end
7
7
  end
8
8
  end
metadata CHANGED
@@ -1,29 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capybara-screenshot-diff
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.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: 2016-12-20 00:00:00.000000000 Z
11
+ date: 2016-12-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '4.1'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '5.1'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - "~>"
27
+ - - ">="
25
28
  - !ruby/object:Gem::Version
26
29
  version: '4.1'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '5.1'
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: capybara
29
35
  requirement: !ruby/object:Gem::Requirement