percy-capybara 1.2.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +5 -1
- data/lib/percy/capybara/client.rb +3 -2
- data/lib/percy/capybara/client/snapshots.rb +7 -29
- data/lib/percy/capybara/loaders/sprockets_loader.rb +1 -1
- data/lib/percy/capybara/version.rb +1 -1
- data/percy-capybara.gemspec +2 -1
- data/spec/lib/percy/capybara/client/snapshots_spec.rb +33 -39
- data/spec/lib/percy/capybara/client_spec.rb +10 -2
- metadata +21 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5c84f5ed6c72de98416d621dfd3ab46867ea78d2
|
4
|
+
data.tar.gz: 7977a4ed7022626bbdb14ca3323b6def95c5e9d8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3958fb07643023624bd6e38a6541b806e80355c749245b5c8c4d0b76944b9c8e66985428ad80e386224da8886f68c9cd2a18fa107a7faf354e4771422a92cd4f
|
7
|
+
data.tar.gz: 6ac2f13f3775fc18fe1289ce982fb1758e774b4cc5522161e40f4faf82f493704c4e2fe4b2435c51f7aac7051f93ddf7cb633252a98b33ebea5271e3a9be8b48
|
data/.travis.yml
CHANGED
@@ -42,8 +42,9 @@ module Percy
|
|
42
42
|
raise ArgumentError.new('block is requried') if !block_given?
|
43
43
|
begin
|
44
44
|
block.call
|
45
|
-
rescue Percy::Client::
|
46
|
-
Percy::Client::
|
45
|
+
rescue Percy::Client::ServerError, # Rescue server errors.
|
46
|
+
Percy::Client::PaymentRequiredError, # Rescue quota exceeded errors.
|
47
|
+
Percy::Client::ConnectionFailed, # Rescue some networking errors.
|
47
48
|
Percy::Client::TimeoutError => e
|
48
49
|
Percy.logger.error(e)
|
49
50
|
@enabled = false
|
@@ -1,10 +1,4 @@
|
|
1
|
-
require 'set'
|
2
|
-
require 'faraday'
|
3
|
-
require 'httpclient'
|
4
|
-
require 'digest'
|
5
|
-
require 'uri'
|
6
1
|
require 'time'
|
7
|
-
require 'pathname'
|
8
2
|
|
9
3
|
module Percy
|
10
4
|
module Capybara
|
@@ -21,31 +15,10 @@ module Percy
|
|
21
15
|
return if !enabled? # Silently skip if the client is disabled.
|
22
16
|
|
23
17
|
name = options[:name]
|
18
|
+
widths = options[:widths]
|
24
19
|
loader = initialize_loader(page: page)
|
25
20
|
|
26
21
|
Percy.logger.debug { "Snapshot started (name: #{name.inspect})" }
|
27
|
-
|
28
|
-
# If this is the first snapshot, create the build and upload build resources.
|
29
|
-
# DEPRECATED: this flow is for the pre-parallel world.
|
30
|
-
if !build_initialized?
|
31
|
-
Percy.logger.warn do
|
32
|
-
"DEPRECATED: percy-capybara will remove implicitly created builds. You should " +
|
33
|
-
"update your usage to call initialize_build explicitly at the start of a test " +
|
34
|
-
"suite, or to use the Percy RSpec setup to do it for you."
|
35
|
-
end
|
36
|
-
|
37
|
-
start = Time.now
|
38
|
-
build_resources = loader.build_resources
|
39
|
-
if Percy.config.debug
|
40
|
-
build_resources.each do |build_resource|
|
41
|
-
Percy.logger.debug { "Build resource: #{build_resource.resource_url}" }
|
42
|
-
end
|
43
|
-
end
|
44
|
-
Percy.logger.debug { "All build resources loaded (#{Time.now - start}s)" }
|
45
|
-
initialize_build(resources: build_resources)
|
46
|
-
_upload_missing_build_resources(build_resources)
|
47
|
-
end
|
48
|
-
|
49
22
|
start = Time.now
|
50
23
|
current_build_id = current_build['data']['id']
|
51
24
|
resources = loader.snapshot_resources
|
@@ -59,7 +32,12 @@ module Percy
|
|
59
32
|
# Create the snapshot and upload any missing snapshot resources.
|
60
33
|
start = Time.now
|
61
34
|
rescue_connection_failures do
|
62
|
-
snapshot = client.create_snapshot(
|
35
|
+
snapshot = client.create_snapshot(
|
36
|
+
current_build_id,
|
37
|
+
resources,
|
38
|
+
name: name,
|
39
|
+
widths: widths,
|
40
|
+
)
|
63
41
|
snapshot['data']['relationships']['missing-resources']['data'].each do |missing_resource|
|
64
42
|
sha = missing_resource['id']
|
65
43
|
client.upload_resource(current_build_id, resource_map[sha].content)
|
data/percy-capybara.gemspec
CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ['lib']
|
20
20
|
|
21
|
-
spec.add_dependency 'percy-client', '
|
21
|
+
spec.add_dependency 'percy-client', '~> 1.4'
|
22
22
|
|
23
23
|
spec.add_development_dependency 'bundler', '~> 1.7'
|
24
24
|
spec.add_development_dependency 'rake', '~> 10.0'
|
@@ -27,6 +27,7 @@ Gem::Specification.new do |spec|
|
|
27
27
|
spec.add_development_dependency 'capybara-webkit', '>= 1.6'
|
28
28
|
spec.add_development_dependency 'selenium-webdriver'
|
29
29
|
spec.add_development_dependency 'webmock', '~> 1'
|
30
|
+
spec.add_development_dependency 'mime-types', '< 3' # For Ruby 1.9 testing support.
|
30
31
|
spec.add_development_dependency 'faraday', '>= 0.8'
|
31
32
|
spec.add_development_dependency 'sprockets', '>= 3.2.0'
|
32
33
|
end
|
@@ -9,35 +9,23 @@ RSpec.describe Percy::Capybara::Client::Snapshots, type: :feature do
|
|
9
9
|
describe '#snapshot', type: :feature, js: true do
|
10
10
|
context 'simple page with no resources' do
|
11
11
|
before(:each) { setup_sprockets(capybara_client) }
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
build_resource_sha = loader.build_resources.first.sha
|
18
|
-
snapshot_resource_sha = loader.snapshot_resources.first.sha
|
19
|
-
|
20
|
-
mock_response = {
|
12
|
+
let(:loader) { capybara_client.initialize_loader(page: page) }
|
13
|
+
let(:build_resource_sha) { loader.build_resources.first.sha }
|
14
|
+
let(:snapshot_resource_sha) { loader.snapshot_resources.first.sha }
|
15
|
+
let(:mock_build_response) do
|
16
|
+
{
|
21
17
|
'data' => {
|
22
18
|
'id' => '123',
|
23
19
|
'type' => 'builds',
|
24
20
|
'relationships' => {
|
25
21
|
'self' => "/api/v1/snapshots/123",
|
26
|
-
'missing-resources' => {
|
27
|
-
'data' => [
|
28
|
-
{
|
29
|
-
'type' => 'resources',
|
30
|
-
'id' => build_resource_sha,
|
31
|
-
},
|
32
|
-
],
|
33
|
-
},
|
22
|
+
'missing-resources' => {},
|
34
23
|
},
|
35
24
|
},
|
36
25
|
}
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
mock_response = {
|
26
|
+
end
|
27
|
+
let(:mock_snapshot_response) do
|
28
|
+
{
|
41
29
|
'data' => {
|
42
30
|
'id' => '256',
|
43
31
|
'type' => 'snapshots',
|
@@ -54,31 +42,37 @@ RSpec.describe Percy::Capybara::Client::Snapshots, type: :feature do
|
|
54
42
|
},
|
55
43
|
},
|
56
44
|
}
|
45
|
+
end
|
46
|
+
before :each do
|
47
|
+
visit '/'
|
48
|
+
loader # Force evaluation now.
|
49
|
+
stub_request(:post, 'https://percy.io/api/v1/repos/percy/percy-capybara/builds/')
|
50
|
+
.to_return(status: 201, body: mock_build_response.to_json)
|
57
51
|
stub_request(:post, 'https://percy.io/api/v1/builds/123/snapshots/')
|
58
|
-
.to_return(status: 201, body:
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
stub_request(:post, "https://percy.io/api/v1/builds/123/resources/")
|
63
|
-
.with(body: /#{snapshot_resource_sha}/)
|
64
|
-
.to_return(status: 201, body: {success: true}.to_json)
|
52
|
+
.to_return(status: 201, body: mock_snapshot_response.to_json)
|
53
|
+
stub_request(:post, "https://percy.io/api/v1/builds/123/resources/")
|
54
|
+
.with(body: /#{snapshot_resource_sha}/)
|
55
|
+
.to_return(status: 201, body: {success: true}.to_json)
|
65
56
|
stub_request(:post, "https://percy.io/api/v1/snapshots/256/finalize")
|
66
|
-
.to_return(status: 200, body:
|
57
|
+
.to_return(status: 200, body: {success: true}.to_json)
|
58
|
+
capybara_client.initialize_build
|
59
|
+
end
|
67
60
|
|
68
|
-
|
61
|
+
it 'creates a snapshot' do
|
62
|
+
expect(capybara_client.client).to receive(:create_snapshot)
|
63
|
+
.with(anything, anything, {name: nil, widths: nil})
|
64
|
+
.and_call_original
|
69
65
|
expect(capybara_client.snapshot(page)).to eq(true)
|
70
|
-
|
66
|
+
end
|
67
|
+
it 'passes through name and width options to the percy client if given' do
|
68
|
+
expect(capybara_client.client).to receive(:create_snapshot)
|
69
|
+
.with(anything, anything, {name: 'foo', widths: [320, 1024]})
|
70
|
+
.and_call_original
|
71
71
|
|
72
|
-
|
73
|
-
|
74
|
-
expect(capybara_client.snapshot(page)).to eq(true)
|
72
|
+
expect(capybara_client.snapshot(page, name: 'foo', widths: [320, 1024])).to eq(true)
|
73
|
+
expect(capybara_client.failed?).to eq(false)
|
75
74
|
end
|
76
75
|
it 'safely handles connection errors' do
|
77
|
-
visit '/'
|
78
|
-
build_data = {'data' => {'id' => 123}}
|
79
|
-
expect(capybara_client.client).to receive(:create_build).and_return(build_data)
|
80
|
-
capybara_client.initialize_build
|
81
|
-
|
82
76
|
expect(capybara_client.client).to receive(:create_snapshot)
|
83
77
|
.and_raise(Percy::Client::ConnectionFailed)
|
84
78
|
expect(capybara_client.snapshot(page)).to eq(nil)
|
@@ -43,9 +43,17 @@ RSpec.describe Percy::Capybara::Client do
|
|
43
43
|
expect(capybara_client.enabled?).to eq(true)
|
44
44
|
expect(capybara_client.failed?).to eq(false)
|
45
45
|
end
|
46
|
-
it 'makes block safe from
|
46
|
+
it 'makes block safe from server errors' do
|
47
47
|
result = capybara_client.rescue_connection_failures do
|
48
|
-
raise Percy::Client::
|
48
|
+
raise Percy::Client::ServerError.new(500, 'POST', '', '')
|
49
|
+
end
|
50
|
+
expect(result).to eq(nil)
|
51
|
+
expect(capybara_client.enabled?).to eq(false)
|
52
|
+
expect(capybara_client.failed?).to eq(true)
|
53
|
+
end
|
54
|
+
it 'makes block safe from quota exceeded errors' do
|
55
|
+
result = capybara_client.rescue_connection_failures do
|
56
|
+
raise Percy::Client::PaymentRequiredError.new(409, 'POST', '', '')
|
49
57
|
end
|
50
58
|
expect(result).to eq(nil)
|
51
59
|
expect(capybara_client.enabled?).to eq(false)
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: percy-capybara
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Perceptual Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-02-
|
11
|
+
date: 2016-02-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: percy-client
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 1.
|
19
|
+
version: '1.4'
|
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
|
-
version: 1.
|
26
|
+
version: '1.4'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -122,6 +122,20 @@ dependencies:
|
|
122
122
|
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '1'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: mime-types
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "<"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '3'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "<"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '3'
|
125
139
|
- !ruby/object:Gem::Dependency
|
126
140
|
name: faraday
|
127
141
|
requirement: !ruby/object:Gem::Requirement
|
@@ -227,7 +241,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
227
241
|
version: '0'
|
228
242
|
requirements: []
|
229
243
|
rubyforge_project:
|
230
|
-
rubygems_version: 2.
|
244
|
+
rubygems_version: 2.2.2
|
231
245
|
signing_key:
|
232
246
|
specification_version: 4
|
233
247
|
summary: Percy::Capybara
|
@@ -262,4 +276,3 @@ test_files:
|
|
262
276
|
- spec/lib/percy/capybara_spec.rb
|
263
277
|
- spec/spec_helper.rb
|
264
278
|
- spec/support/test_helpers.rb
|
265
|
-
has_rdoc:
|