rspec-page-regression 0.3.0 → 0.4.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
  SHA1:
3
- metadata.gz: 989c90a06a9ad0ad6e5e69c61118c8960999019e
4
- data.tar.gz: a1ef462d3075a522528bc39fb7b076a84ed9ba30
3
+ metadata.gz: 16be31d2cd913d4f1c0e4d8e8cfe17236478aafe
4
+ data.tar.gz: 3cfc21083eb4dc17b28f4ba4496d9d437eb76401
5
5
  SHA512:
6
- metadata.gz: 07a4e7baeee04af73847b73030880baee7d6b06d81acc6edbad15f5a3ea65ae4c94e8da465ec4ed9584b81053038227430b4fcb053a22c7a6d77dcaa99714006
7
- data.tar.gz: 195e79f35b7e35511be05af0bb01a3a177a919f7f48197efe6ed3401b15f2373abc59901770e6977200c3762ef2c5172b9a3d17895d27f2174586d68e38333b2
6
+ metadata.gz: bbe34659c64d36c19ae203ea9ce0bbea48505009ec7cc9b984c45412a9e17e2602954eac59892b67e7582960a638e490b619217cf8985f275a865f46949eec75
7
+ data.tar.gz: 9a271da665070a549833b805294f5ddf8d6a8495d3c986debdd72d2d045f99a133bee974a00e3885ee9466ef63e1a705badde5e86ceb2ab9bd0769dcffac4576
data/Gemfile CHANGED
@@ -4,4 +4,4 @@ source 'https://rubygems.org'
4
4
  gemspec
5
5
 
6
6
  gem 'awesome_print'
7
- gem 'byebug'
7
+ gem 'byebug' if RUBY_VERSION >= "2.0.0"
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
 
2
2
  [![Gem Version](https://badge.fury.io/rb/rspec-page-regression.png)](http://badge.fury.io/rb/rspec-page-regression)
3
- [![Build Status](https://secure.travis-ci.org/ronen/rspec-page-regression.png)](http://travis-ci.org/ronen/rspec-page-regression)
3
+ [![Build Status](https://secure.travis-ci.org/ronen/rspec-page-regression.png)](http://travis-ci.org/ronen/rspec-page-regression)
4
4
  [![Dependency Status](https://gemnasium.com/ronen/rspec-page-regression.png)](https://gemnasium.com/ronen/rspec-page-regression)
5
5
 
6
6
  # rspec-page-regression
@@ -27,7 +27,7 @@ And in your spec_helper:
27
27
 
28
28
  require 'rspec' # or 'rspec/rails' if you're using Rails
29
29
  require 'rspec/page-regression'
30
-
30
+
31
31
  require 'capybara/rspec'
32
32
  require 'capybara/poltergeist'
33
33
  Capybara.javascript_driver = :poltergeist
@@ -37,7 +37,7 @@ Rspec-page-regression presupposes the convention that your spec files are somwhe
37
37
  To install for use with Selenium, [see instructions below](#selenium).
38
38
 
39
39
  #### Note on versions:
40
- Rspec-page-regression has multiple versions that work in concert with the [significant changes in RSpec version 3](http://myronmars.to/n/dev-blog/2013/07/the-plan-for-rspec-3). If you're using bundler, the gem dependencies should automatically find the proper version of rspec-page-regression for your chosen version of RSpec.
40
+ Rspec-page-regression has multiple versions that work in concert with the [significant changes in RSpec version 3](http://myronmars.to/n/dev-blog/2013/07/the-plan-for-rspec-3). If you're using bundler, the gem dependencies should automatically find the proper version of rspec-page-regression for your chosen version of RSpec.
41
41
 
42
42
  | Rspec Version | Rspec-page-regression |
43
43
  | ------------- | --------------------- |
@@ -52,7 +52,7 @@ Rspec-page-regression provides a matcher that renders the page and compares
52
52
  the resulting image against an expected image. To use it, you need to enable Capybara and Poltergeist by specifying `:type => :feature` and `:js => true`:
53
53
 
54
54
  require 'spec_helper'
55
-
55
+
56
56
  describe "my page", :type => :feature, :js => true do
57
57
 
58
58
  before(:each) do
@@ -69,7 +69,7 @@ the resulting image against an expected image. To use it, you need to enable Ca
69
69
  it { expect(page).to match_expectation }
70
70
  end
71
71
  end
72
-
72
+
73
73
  The spec will pass if the test rendered image contains the exact same pixel values as the expectated image. Otherwise it will fail with an error message along the lines of:
74
74
 
75
75
  Test image does not match expected image
@@ -110,6 +110,8 @@ Everything will work normally, and the failure messages will refer to your path.
110
110
 
111
111
  ## Configuration
112
112
 
113
+ ### Window size
114
+
113
115
  The default window size for the renders is 1024 x 768 pixels. You can specify another size as `[height, width]` in pixels:
114
116
 
115
117
  # in spec_helper.rb:
@@ -119,9 +121,19 @@ The default window size for the renders is 1024 x 768 pixels. You can specify a
119
121
 
120
122
  Note that this specifies the size of the browser window viewport; but rspec-page-regression requests a render of the full page, which might extend beyond the window. So the rendered file dimensions may be larger than this configuration value.
121
123
 
124
+ ### Image difference threshold
125
+
126
+ By default, a test fails if only a single pixel in the screenshot differs from the expectation image. To account for minor rendering differences, you can set a threshold value that allows a certain amount of differences. The threshold value is the fraction of pixels that are allowed to differ before the test fails.
127
+
128
+ RSpec::PageRegression.configure do |config|
129
+ config.threshold = 0.01
130
+ end
131
+
132
+ This setting means that 1% of pixels are allowed to differ between the rendering result and the expectation image. For example, for an image size of 1024 x 768 and a threshold of 0.01, the maximum number of pixel differences between the images is 7864.
133
+
122
134
  ## [Using the selenium driver](id:selenium)
123
135
 
124
- You can also use the selenium driver with capybara. This offers the possiblity to visually test your pages against a range of real browsers.
136
+ You can also use the selenium driver with capybara. This offers the possiblity to visually test your pages against a range of real browsers.
125
137
 
126
138
  Add the [selenium-webdriver](https://rubygems.org/gems/selenium-webdriver) to your Gemfile:
127
139
 
@@ -156,6 +168,8 @@ Don't forget to include specs (`rake spec`) to verify your functionality. Code
156
168
 
157
169
  Release Notes:
158
170
 
171
+ * 0.4.0 - Add difference threshold. Thanks to [@abersager](https://github.com/abersager)
172
+
159
173
  * 0.3.0 - Compatibility with rspec 3.0
160
174
 
161
175
  * 0.2.99 - Compatibility with rspec 2.99
@@ -168,4 +182,3 @@ Release Notes:
168
182
 
169
183
 
170
184
  [![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/ronen/rspec-page-regression/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
171
-
@@ -16,4 +16,12 @@ module RSpec::PageRegression
16
16
  def self.page_size
17
17
  @@page_size ||= [1024, 768]
18
18
  end
19
+
20
+ def self.threshold= (threshold)
21
+ @@threshold = threshold
22
+ end
23
+
24
+ def self.threshold
25
+ @@threshold ||= 0.0
26
+ end
19
27
  end
@@ -40,8 +40,13 @@ module RSpec::PageRegression
40
40
  end
41
41
 
42
42
  def pixels_match?
43
+ max_count = RSpec::PageRegression.threshold * @itest.width * @itest.height
44
+ count = 0
43
45
  @itest.height.times do |y|
44
- return false if @itest.row(y) != @iexpected.row(y)
46
+ next if @itest.row(y) == @iexpected.row(y)
47
+ diff = @itest.row(y).zip(@iexpected.row(y)).select { |x, y| x != y }
48
+ count += diff.count
49
+ return false if count > max_count
45
50
  end
46
51
  return true
47
52
  end
@@ -1,5 +1,5 @@
1
1
  module RSpec
2
2
  module PageRegression
3
- VERSION = "0.3.0"
3
+ VERSION = "0.4.0"
4
4
  end
5
5
  end
@@ -62,6 +62,40 @@ describe "match_expectation" do
62
62
  Then { expect(difference_path.read).to eq fixture_image("ABdiff").read }
63
63
  end
64
64
 
65
+ context "when difference threshold is set" do
66
+ context "when difference threshold is configured below image difference" do
67
+ Given do
68
+ RSpec::PageRegression.configure do |config|
69
+ config.threshold = 0.01
70
+ end
71
+ end
72
+ Given { use_test_image "A" }
73
+ Given { use_expected_image "B" }
74
+
75
+ Then { expect(@error).to_not be_nil }
76
+ Then { expect(@error.message).to include "Test image does not match expected image" }
77
+ Then { expect(@error.message).to match viewer_pattern(test_path, expected_path, difference_path) }
78
+
79
+ Then { expect(difference_path.read).to eq fixture_image("ABdiff").read }
80
+ end
81
+
82
+ context "when difference threshold is configured above image difference" do
83
+ Given do
84
+ RSpec::PageRegression.configure do |config|
85
+ config.threshold = 0.02
86
+ end
87
+ end
88
+ Given { use_test_image "A" }
89
+ Given { use_expected_image "B" }
90
+
91
+ Then { expect(@error).to be_nil }
92
+ end
93
+
94
+ after :each do
95
+ RSpec::PageRegression.class_variable_set :@@threshold, nil
96
+ end
97
+ end
98
+
65
99
  context "when test image is missing" do
66
100
  Given { use_expected_image "A" }
67
101
 
@@ -1,3 +1,4 @@
1
+ require 'pathname'
1
2
  require 'simplecov'
2
3
  require 'simplecov-gem-adapter'
3
4
  SimpleCov.start "gem"
metadata CHANGED
@@ -1,181 +1,181 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-page-regression
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ronen barzel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-05 00:00:00.000000000 Z
11
+ date: 2015-07-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: oily_png
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: poltergeist
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ~>
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
61
  version: '3.0'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ~>
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '3.0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: which_works
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '>='
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: bourne
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - '>='
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - '>='
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: bundler
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ~>
101
+ - - "~>"
102
102
  - !ruby/object:Gem::Version
103
103
  version: '1.3'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ~>
108
+ - - "~>"
109
109
  - !ruby/object:Gem::Version
110
110
  version: '1.3'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: mocha
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - '>='
115
+ - - ">="
116
116
  - !ruby/object:Gem::Version
117
117
  version: '0'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - '>='
122
+ - - ">="
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: rake
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - '>='
129
+ - - ">="
130
130
  - !ruby/object:Gem::Version
131
131
  version: '0'
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - '>='
136
+ - - ">="
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: rspec-given
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
- - - '>='
143
+ - - ">="
144
144
  - !ruby/object:Gem::Version
145
145
  version: '0'
146
146
  type: :development
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
- - - '>='
150
+ - - ">="
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0'
153
153
  - !ruby/object:Gem::Dependency
154
154
  name: simplecov
155
155
  requirement: !ruby/object:Gem::Requirement
156
156
  requirements:
157
- - - '>='
157
+ - - ">="
158
158
  - !ruby/object:Gem::Version
159
159
  version: '0'
160
160
  type: :development
161
161
  prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
- - - '>='
164
+ - - ">="
165
165
  - !ruby/object:Gem::Version
166
166
  version: '0'
167
167
  - !ruby/object:Gem::Dependency
168
168
  name: simplecov-gem-adapter
169
169
  requirement: !ruby/object:Gem::Requirement
170
170
  requirements:
171
- - - '>='
171
+ - - ">="
172
172
  - !ruby/object:Gem::Version
173
173
  version: '0'
174
174
  type: :development
175
175
  prerelease: false
176
176
  version_requirements: !ruby/object:Gem::Requirement
177
177
  requirements:
178
- - - '>='
178
+ - - ">="
179
179
  - !ruby/object:Gem::Version
180
180
  version: '0'
181
181
  description: Rspec-page-regression provides a mechanism for headless regression testing
@@ -189,9 +189,9 @@ executables: []
189
189
  extensions: []
190
190
  extra_rdoc_files: []
191
191
  files:
192
- - .gitignore
193
- - .rspec
194
- - .travis.yml
192
+ - ".gitignore"
193
+ - ".rspec"
194
+ - ".travis.yml"
195
195
  - Gemfile
196
196
  - LICENSE.txt
197
197
  - README.md
@@ -221,17 +221,17 @@ require_paths:
221
221
  - lib
222
222
  required_ruby_version: !ruby/object:Gem::Requirement
223
223
  requirements:
224
- - - '>='
224
+ - - ">="
225
225
  - !ruby/object:Gem::Version
226
226
  version: '0'
227
227
  required_rubygems_version: !ruby/object:Gem::Requirement
228
228
  requirements:
229
- - - '>='
229
+ - - ">="
230
230
  - !ruby/object:Gem::Version
231
231
  version: '0'
232
232
  requirements: []
233
233
  rubyforge_project:
234
- rubygems_version: 2.0.3
234
+ rubygems_version: 2.4.5
235
235
  signing_key:
236
236
  specification_version: 4
237
237
  summary: Web page rendering (HTML, CSS, and JavasSript) regression for RSpec