percy-capybara 3.2.0 → 4.0.0.pre.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.circleci/config.yml +39 -0
- data/.gitignore +1 -0
- data/DEVELOPING.md +26 -0
- data/README.md +2 -2
- data/lib/environment.rb +31 -0
- data/lib/percy.rb +119 -0
- data/lib/version.rb +3 -0
- data/package-lock.json +2155 -0
- data/package.json +6 -0
- data/percy-capybara.gemspec +3 -12
- data/spec/lib/percy/environment_spec.rb +31 -0
- data/spec/lib/percy/percy_spec.rb +55 -0
- data/spec/spec_helper.rb +4 -44
- metadata +17 -233
- data/.travis.yml +0 -17
- data/lib/percy/capybara.rb +0 -60
- data/lib/percy/capybara/anywhere.rb +0 -37
- data/lib/percy/capybara/client.rb +0 -127
- data/lib/percy/capybara/client/builds.rb +0 -81
- data/lib/percy/capybara/client/snapshots.rb +0 -66
- data/lib/percy/capybara/client/user_agent.rb +0 -37
- data/lib/percy/capybara/httpfetcher.rb +0 -36
- data/lib/percy/capybara/loaders/base_loader.rb +0 -161
- data/lib/percy/capybara/loaders/ember_cli_rails_loader.rb +0 -52
- data/lib/percy/capybara/loaders/filesystem_loader.rb +0 -37
- data/lib/percy/capybara/loaders/native_loader.rb +0 -287
- data/lib/percy/capybara/loaders/sprockets_loader.rb +0 -99
- data/lib/percy/capybara/rspec.rb +0 -8
- data/lib/percy/capybara/version.rb +0 -5
- data/spec/lib/percy/capybara/client/builds_spec.rb +0 -171
- data/spec/lib/percy/capybara/client/ember_test_data/ember-cli/admin/assets/percy-admin.svg +0 -34
- data/spec/lib/percy/capybara/client/ember_test_data/ember-cli/admin/index.html +0 -1
- data/spec/lib/percy/capybara/client/ember_test_data/ember-cli/admin/percy-admin-public.svg +0 -34
- data/spec/lib/percy/capybara/client/ember_test_data/ember-cli/frontend/assets/percy-frontend.svg +0 -34
- data/spec/lib/percy/capybara/client/ember_test_data/ember-cli/frontend/index.html +0 -1
- data/spec/lib/percy/capybara/client/ember_test_data/ember-cli/frontend/percy-frontend-public.svg +0 -34
- data/spec/lib/percy/capybara/client/rails_public_test_data/large-file-skipped.png +0 -0
- data/spec/lib/percy/capybara/client/rails_public_test_data/percy-from-public.svg +0 -34
- data/spec/lib/percy/capybara/client/rails_public_test_data/symlink_to_images +0 -1
- data/spec/lib/percy/capybara/client/snapshots_spec.rb +0 -97
- data/spec/lib/percy/capybara/client/symlink_test_data/test.png +0 -0
- data/spec/lib/percy/capybara/client/test_data/assets/css/digested-f3420c6aee71c137a3ca39727052811bae84b2f37d898f4db242e20656a1579e.css +0 -1
- data/spec/lib/percy/capybara/client/test_data/assets/images/large-file-skipped.png +0 -0
- data/spec/lib/percy/capybara/client/test_data/css/base.css +0 -1
- data/spec/lib/percy/capybara/client/test_data/css/digested.css +0 -1
- data/spec/lib/percy/capybara/client/test_data/css/font.css +0 -8
- data/spec/lib/percy/capybara/client/test_data/css/imports.css +0 -1
- data/spec/lib/percy/capybara/client/test_data/css/level0-imports.css +0 -2
- data/spec/lib/percy/capybara/client/test_data/css/level1-imports.css +0 -2
- data/spec/lib/percy/capybara/client/test_data/css/level2-imports.css +0 -1
- data/spec/lib/percy/capybara/client/test_data/css/simple-imports.css +0 -1
- data/spec/lib/percy/capybara/client/test_data/css/source.css.map +0 -2
- data/spec/lib/percy/capybara/client/test_data/iframe.html +0 -7
- data/spec/lib/percy/capybara/client/test_data/images/bg-relative-to-root.png +0 -0
- data/spec/lib/percy/capybara/client/test_data/images/bg-relative.png +0 -0
- data/spec/lib/percy/capybara/client/test_data/images/bg-stacked.png +0 -0
- data/spec/lib/percy/capybara/client/test_data/images/img-relative-to-root.png +0 -0
- data/spec/lib/percy/capybara/client/test_data/images/img-relative.png +0 -0
- data/spec/lib/percy/capybara/client/test_data/images/percy.svg +0 -34
- data/spec/lib/percy/capybara/client/test_data/images/srcset-base.png +0 -0
- data/spec/lib/percy/capybara/client/test_data/images/srcset-first.png +0 -0
- data/spec/lib/percy/capybara/client/test_data/images/srcset-second.png +0 -0
- data/spec/lib/percy/capybara/client/test_data/index.html +0 -1
- data/spec/lib/percy/capybara/client/test_data/js/base.js +0 -1
- data/spec/lib/percy/capybara/client/test_data/test-css.html +0 -20
- data/spec/lib/percy/capybara/client/test_data/test-font.html +0 -9
- data/spec/lib/percy/capybara/client/test_data/test-iframe.html +0 -8
- data/spec/lib/percy/capybara/client/test_data/test-images.html +0 -51
- data/spec/lib/percy/capybara/client/test_data/test-localtest-me-images.html +0 -8
- data/spec/lib/percy/capybara/client/user_agent_spec.rb +0 -45
- data/spec/lib/percy/capybara/client_spec.rb +0 -232
- data/spec/lib/percy/capybara/http_fetcher_spec.rb +0 -17
- data/spec/lib/percy/capybara/loaders/base_loader_spec.rb +0 -122
- data/spec/lib/percy/capybara/loaders/ember_cli_rails_loader_spec.rb +0 -86
- data/spec/lib/percy/capybara/loaders/filesystem_loader_spec.rb +0 -166
- data/spec/lib/percy/capybara/loaders/native_loader_spec.rb +0 -300
- data/spec/lib/percy/capybara/loaders/sprockets_loader_spec.rb +0 -119
- data/spec/lib/percy/capybara_spec.rb +0 -101
- data/spec/support/test_helpers.rb +0 -60
@@ -1 +0,0 @@
|
|
1
|
-
../symlink_test_data
|
@@ -1,97 +0,0 @@
|
|
1
|
-
require 'json'
|
2
|
-
require 'digest'
|
3
|
-
require 'capybara'
|
4
|
-
|
5
|
-
RSpec.describe Percy::Capybara::Client::Snapshots, type: :feature do
|
6
|
-
let(:capybara_client) { Percy::Capybara::Client.new(enabled: true) }
|
7
|
-
|
8
|
-
describe '#snapshot', type: :feature, js: true do
|
9
|
-
context 'simple page with no resources' do
|
10
|
-
let(:loader) { capybara_client.initialize_loader(page: page) }
|
11
|
-
let(:build_resource_sha) { loader.build_resources.first.sha }
|
12
|
-
let(:snapshot_resource_sha) { loader.snapshot_resources.first.sha }
|
13
|
-
let(:mock_build_response) do
|
14
|
-
{
|
15
|
-
'data' => {
|
16
|
-
'id' => '123',
|
17
|
-
'type' => 'builds',
|
18
|
-
'relationships' => {
|
19
|
-
'self' => '/api/v1/snapshots/123',
|
20
|
-
'missing-resources' => {},
|
21
|
-
},
|
22
|
-
},
|
23
|
-
}
|
24
|
-
end
|
25
|
-
let(:mock_snapshot_response) do
|
26
|
-
{
|
27
|
-
'data' => {
|
28
|
-
'id' => '256',
|
29
|
-
'type' => 'snapshots',
|
30
|
-
'relationships' => {
|
31
|
-
'self' => '/api/v1/snapshots/123',
|
32
|
-
'missing-resources' => {
|
33
|
-
'data' => [
|
34
|
-
{
|
35
|
-
'type' => 'resources',
|
36
|
-
'id' => snapshot_resource_sha,
|
37
|
-
},
|
38
|
-
],
|
39
|
-
},
|
40
|
-
},
|
41
|
-
},
|
42
|
-
}
|
43
|
-
end
|
44
|
-
|
45
|
-
before(:each) do
|
46
|
-
setup_sprockets(capybara_client)
|
47
|
-
|
48
|
-
visit '/'
|
49
|
-
loader # Force evaluation now.
|
50
|
-
stub_request(:post, "https://percy.io/api/v1/builds/")
|
51
|
-
.to_return(status: 201, body: mock_build_response.to_json)
|
52
|
-
stub_request(:post, 'https://percy.io/api/v1/builds/123/snapshots/')
|
53
|
-
.to_return(status: 201, body: mock_snapshot_response.to_json)
|
54
|
-
stub_request(:post, 'https://percy.io/api/v1/builds/123/resources/')
|
55
|
-
.with(body: /#{snapshot_resource_sha}/)
|
56
|
-
.to_return(status: 201, body: {success: true}.to_json)
|
57
|
-
stub_request(:post, 'https://percy.io/api/v1/snapshots/256/finalize')
|
58
|
-
.to_return(status: 200, body: {success: true}.to_json)
|
59
|
-
capybara_client.initialize_build
|
60
|
-
end
|
61
|
-
|
62
|
-
it 'creates a snapshot' do
|
63
|
-
expect(capybara_client.client).to receive(:create_snapshot)
|
64
|
-
.with(anything, anything, {})
|
65
|
-
.and_call_original
|
66
|
-
expect(capybara_client.snapshot(page)).to eq(true)
|
67
|
-
end
|
68
|
-
it 'errors if build is not created' do
|
69
|
-
capybara_client = Percy::Capybara::Client.new(enabled: true)
|
70
|
-
expect { capybara_client.snapshot(page) }.to raise_error(RuntimeError)
|
71
|
-
end
|
72
|
-
it 'passes through options to the percy client if given' do
|
73
|
-
expect(capybara_client.client).to receive(:create_snapshot)
|
74
|
-
.with(anything, anything, name: 'foo', widths: [320, 1024], enable_javascript: true)
|
75
|
-
.and_call_original
|
76
|
-
|
77
|
-
result = capybara_client.snapshot(
|
78
|
-
page, name: 'foo', widths: [320, 1024], enable_javascript: true,
|
79
|
-
)
|
80
|
-
expect(result).to eq(true)
|
81
|
-
expect(capybara_client.failed?).to eq(false)
|
82
|
-
end
|
83
|
-
it 'safely handles snapshot bad request errors' do
|
84
|
-
error = Percy::Client::BadRequestError.new(400, '', '', '', 'snapshot error msg')
|
85
|
-
expect(capybara_client.client).to receive(:create_snapshot).and_raise(error)
|
86
|
-
expect(capybara_client.snapshot(page)).to eq(nil)
|
87
|
-
expect(capybara_client.failed?).to eq(false) # Build is not failed.
|
88
|
-
end
|
89
|
-
it 'safely handles connection errors' do
|
90
|
-
expect(capybara_client.client).to receive(:create_snapshot)
|
91
|
-
.and_raise(Percy::Client::ConnectionFailed)
|
92
|
-
expect(capybara_client.snapshot(page)).to eq(nil)
|
93
|
-
expect(capybara_client.failed?).to eq(true)
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
Binary file
|
@@ -1 +0,0 @@
|
|
1
|
-
--
|
Binary file
|
@@ -1 +0,0 @@
|
|
1
|
-
.colored-by-base { color: red; }
|
@@ -1 +0,0 @@
|
|
1
|
-
-- Do not change this, these contents generate a specific digested filename for testing. --
|
@@ -1 +0,0 @@
|
|
1
|
-
.colored-by-imports { color: red; }
|
@@ -1 +0,0 @@
|
|
1
|
-
.colored-by-level2-imports { color: red; }
|
@@ -1 +0,0 @@
|
|
1
|
-
@import url('imports.css');
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -1,34 +0,0 @@
|
|
1
|
-
<?xml version="1.0" encoding="utf-8"?>
|
2
|
-
<!-- Generator: Adobe Illustrator 18.1.1, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
|
3
|
-
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
|
4
|
-
viewBox="0 0 170 110" enable-background="new 0 0 170 110" xml:space="preserve">
|
5
|
-
<g>
|
6
|
-
<g>
|
7
|
-
<polyline fill="#1F0924" points="49.2,97.6 9.4,103.4 46,86.8 6.2,81.2 46,75.6 9.4,59 49.2,64.9 18.7,38.6 55.2,55.4 33.4,21.7
|
8
|
-
63.7,48.1 52.2,9.6 73.9,43.4 73.7,3.2 85,41.8 96.2,3.2 96.1,43.4 117.7,9.5 106.3,48.1 136.5,21.6 114.7,55.4 151.2,38.6
|
9
|
-
120.8,64.8 160.6,59 124,75.6 163.8,81.1 124,86.8 160.6,103.3 120.8,97.5 "/>
|
10
|
-
<polyline fill="#EDDDC2" points="52.8,90.2 18.5,90.3 51.4,80.7 18.5,71.2 52.8,71.3 23.9,52.8 56.8,62.6 63,55.4 48.7,24.2
|
11
|
-
71.1,50.2 66.1,16.3 80.2,47.5 85,13.5 89.8,47.5 103.9,16.3 98.9,50.2 121.3,24.2 107,55.4 113.2,62.6 146.1,52.8 117.2,71.3
|
12
|
-
151.5,71.2 118.6,80.7 151.5,90.3 117.2,90.2 "/>
|
13
|
-
</g>
|
14
|
-
<polygon fill="#EDDDC2" points="108.3,45.7 134.4,39.1 127.9,65.2 "/>
|
15
|
-
<polygon fill="#1F0924" points="114.2,48.6 128.5,45 124.9,59.3 114.2,59.3 "/>
|
16
|
-
<polygon fill="#EDDDC2" points="61.7,45.7 35.6,39.1 42.1,65.2 "/>
|
17
|
-
<polygon fill="#1F0924" points="55.8,48.6 41.5,45 45.1,59.3 55.8,59.3 "/>
|
18
|
-
<polyline fill="#B157B5" points="38.3,101.1 131.7,101.1 166.8,88.5 131.5,76 155.8,47.6 119,54.5 125.9,17.7 97.5,42 85,6.7
|
19
|
-
72.5,42 44.1,17.7 51,54.5 14.2,47.6 38.5,76 3.2,88.5 "/>
|
20
|
-
<circle fill="#EDDDC2" cx="61.4" cy="78.7" r="12.1"/>
|
21
|
-
<circle fill="#1F0924" cx="61.4" cy="78.7" r="9.5"/>
|
22
|
-
<circle fill="#EDDDC2" cx="58.2" cy="75.5" r="4.2"/>
|
23
|
-
<circle fill="#EDDDC2" cx="108.6" cy="78.7" r="12.1"/>
|
24
|
-
<circle fill="#1F0924" cx="108.6" cy="78.7" r="9.5"/>
|
25
|
-
<circle fill="#EDDDC2" cx="105.3" cy="75.5" r="4.2"/>
|
26
|
-
<path fill="#EDDDC2" d="M62.9,97.6c0-12.2,9.9-22.1,22.1-22.1s22.1,9.9,22.1,22.1S62.9,109.8,62.9,97.6z"/>
|
27
|
-
<path fill="#1F0924" d="M89.8,96.5c-2,0-3.7-1-4.8-2.5c-1,1.5-2.8,2.5-4.8,2.5c-3.2,0-5.8-2.6-5.8-5.8c0-0.6,0.4-1,1-1s1,0.4,1,1
|
28
|
-
c0,2.1,1.7,3.8,3.8,3.8s3.8-1.7,3.8-3.8h2c0,2.1,1.7,3.8,3.8,3.8s3.8-1.7,3.8-3.8c0-0.6,0.4-1,1-1s1,0.4,1,1
|
29
|
-
C95.5,93.9,93,96.5,89.8,96.5z"/>
|
30
|
-
<path fill="#1F0924" d="M92.8,83.6c0,4.3-3.5,7.8-7.8,7.8s-7.8-3.5-7.8-7.8C77.2,79.3,92.8,79.3,92.8,83.6z"/>
|
31
|
-
<path fill="#EDDDC2" d="M47,101.3c0-4,3.2-7.3,7.3-7.3s7.3,3.2,7.3,7.3S47,105.3,47,101.3z"/>
|
32
|
-
<path fill="#EDDDC2" d="M108.4,101.3c0-4,3.2-7.3,7.3-7.3c4,0,7.3,3.2,7.3,7.3S108.4,105.3,108.4,101.3z"/>
|
33
|
-
</g>
|
34
|
-
</svg>
|
Binary file
|
Binary file
|
Binary file
|
@@ -1 +0,0 @@
|
|
1
|
-
<html><head></head><body>Hello World!</body></html>
|
@@ -1 +0,0 @@
|
|
1
|
-
// Nothing to see here.
|
@@ -1,20 +0,0 @@
|
|
1
|
-
<!DOCTYPE html>
|
2
|
-
<html>
|
3
|
-
<title>Test Percy::Capybara</title>
|
4
|
-
<link href="../css/base.css" rel="stylesheet" type="text/css">
|
5
|
-
<link href="/css/simple-imports.css" rel="stylesheet" type="text/css">
|
6
|
-
<link href="/css/level0-imports.css" rel="stylesheet" type="text/css">
|
7
|
-
|
8
|
-
<!-- remote resource, ignored -->
|
9
|
-
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet" type="text/css">
|
10
|
-
<style>
|
11
|
-
.colored-by-inline { color: red; }
|
12
|
-
</style>
|
13
|
-
<h1>Hello World!</h1>
|
14
|
-
<div class="colored-by-inline">This should be red</div>
|
15
|
-
<div class="colored-by-base">This should be red</div>
|
16
|
-
<div class="colored-by-imports">This should be red</div>
|
17
|
-
<div class="colored-by-level0-imports">This should be red</div>
|
18
|
-
<div class="colored-by-level1-imports">This should be red</div>
|
19
|
-
<div class="colored-by-level2-imports">This should be red</div>
|
20
|
-
</html>
|
@@ -1,51 +0,0 @@
|
|
1
|
-
<!DOCTYPE html>
|
2
|
-
<html>
|
3
|
-
<title>Test Percy::Capybara</title>
|
4
|
-
<h1>Test images</h1>
|
5
|
-
|
6
|
-
<h2>img local PNG (relative)</h2>
|
7
|
-
<img src="images/img-relative.png">
|
8
|
-
|
9
|
-
<h2>img local PNG (relative to root)</h2>
|
10
|
-
<img src="/images/img-relative-to-root.png">
|
11
|
-
|
12
|
-
<h2>img PNG (remote, ignored)</h2>
|
13
|
-
<img src="http://i.imgur.com/Umkjdao.png">
|
14
|
-
|
15
|
-
<h2>img SVG (relative)</h2>
|
16
|
-
<img src="../../../images/percy.svg" width="300">
|
17
|
-
|
18
|
-
<h2>CSS background-image (relative)</h2>
|
19
|
-
<div style="background-image: url(images/bg-relative.png); width: 200px; height: 200px;"></div>
|
20
|
-
|
21
|
-
<h2>CSS background-image (relative to root)</h2>
|
22
|
-
<div style="background-image: url(/images/bg-relative-to-root.png); width: 200px; height: 200px;"></div>
|
23
|
-
|
24
|
-
<h2>CSS background-image (remote, ignored)</h2>
|
25
|
-
<div style="background-image: url(http://i.imgur.com/5mLoBs1.png); width: 408px; height: 376px;"></div>
|
26
|
-
|
27
|
-
<h2>img data-uri (ignored)</h2>
|
28
|
-
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAMAAABHPGVmAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAAZQTFRFVyxjAAAAmU4baAAAACNJREFUeNrswYEAAAAAw6D5U1/hAFUBAAAAAAAAAAAAjwkwACd0AAGLtJfaAAAAAElFTkSuQmCC">
|
29
|
-
|
30
|
-
<h2>CSS background-image data-uri (ignored)</h2>
|
31
|
-
<div style="background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAMAAABHPGVmAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAAZQTFRFVyxjAAAAmU4baAAAACNJREFUeNrswYEAAAAAw6D5U1/hAFUBAAAAAAAAAAAAjwkwACd0AAGLtJfaAAAAAElFTkSuQmCC); width: 100px; height: 100px;"></div>
|
32
|
-
|
33
|
-
<h2>CSS background stacked (local and remote, remote ignored)</h2>
|
34
|
-
<div style="background: url(/images/bg-stacked.png) 200px 200px no-repeat, url('http://i.imgur.com/61AQuplb.jpg'); width: 100px; height: 100px;"></div>
|
35
|
-
|
36
|
-
<h2>img srcset</h2>
|
37
|
-
<img width="200" src="/images/srcset-base.png" srcset="/images/srcset-first.png 200w, /images/srcset-second.png 400w">
|
38
|
-
|
39
|
-
<h2>blank image src (not included)</h2>
|
40
|
-
<img src=""></div>
|
41
|
-
|
42
|
-
<h2>empty background-image url (uses current page url, should not be included)</h2>
|
43
|
-
<div style="background: url() 200px 200px no-repeat"></div>
|
44
|
-
|
45
|
-
<h2>Duplicates of some of the above images, to verify they are not duplicated in resources:</h2>
|
46
|
-
<img src="images/img-relative.png">
|
47
|
-
<img src="/images/img-relative-to-root.png">
|
48
|
-
<img src="http://i.imgur.com/Umkjdao.png">
|
49
|
-
<div style="background-image: url(/images/bg-relative-to-root.png); width: 200px; height: 200px;"></div>
|
50
|
-
<div style="background-image: url(http://i.imgur.com/5mLoBs1.png); width: 408px; height: 376px;"></div>
|
51
|
-
</html>
|
@@ -1,45 +0,0 @@
|
|
1
|
-
RSpec.describe Percy::Capybara::Client::UserAgent do
|
2
|
-
subject(:client) do
|
3
|
-
Percy::Capybara::Client.new(
|
4
|
-
enabled: true,
|
5
|
-
sprockets_environment: 'test',
|
6
|
-
sprockets_options: 'test',
|
7
|
-
)
|
8
|
-
end
|
9
|
-
|
10
|
-
describe '#_environment_info' do
|
11
|
-
subject(:environment_info) { client._environment_info }
|
12
|
-
|
13
|
-
context 'an app with Rails, Sinatra and Ember Cli Rails' do
|
14
|
-
it 'returns full environment information' do
|
15
|
-
expect(client).to receive(:_rails_version).at_least(:once).times.and_return('4.2')
|
16
|
-
expect(client).to receive(:_sinatra_version).at_least(:once).and_return('2.0.0')
|
17
|
-
expect(client).to receive(:_ember_cli_rails_version).at_least(:once).and_return('0.9')
|
18
|
-
|
19
|
-
expect(environment_info).to eq('rails/4.2; sinatra/2.0.0; ember-cli-rails/0.9')
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
context 'an app with no known frameworks being used' do
|
24
|
-
it 'returns no environment information' do
|
25
|
-
expect(environment_info).to be_empty
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
context 'a loader is configured' do
|
30
|
-
before(:each) { client.loader = :sprockets_loader }
|
31
|
-
|
32
|
-
it 'includes loader information' do
|
33
|
-
expect(environment_info).to eq('percy-capybara-loader/sprockets_loader')
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
describe '#_client_info' do
|
39
|
-
subject(:client_info) { client._client_info }
|
40
|
-
|
41
|
-
it 'includes client information' do
|
42
|
-
expect(client_info).to eq("percy-capybara/#{Percy::Capybara::VERSION}")
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
@@ -1,232 +0,0 @@
|
|
1
|
-
RSpec.describe Percy::Capybara::Client do
|
2
|
-
describe '#enabled?' do
|
3
|
-
context 'when required environment variables set' do
|
4
|
-
before(:each) { set_required_env_variables }
|
5
|
-
after(:each) { clear_percy_env_variables }
|
6
|
-
|
7
|
-
it 'is true when PERCY_ENABLE is 1' do
|
8
|
-
ENV['PERCY_ENABLE'] = '1'
|
9
|
-
expect(Percy::Capybara::Client.new.enabled?).to eq(true)
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'is true when PERCY_ENABLE is not set' do
|
13
|
-
ENV.delete 'PERCY_ENABLE'
|
14
|
-
expect(Percy::Capybara::Client.new.enabled?).to eq(true)
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'is false when PERCY_ENABLE is 0' do
|
18
|
-
ENV['PERCY_ENABLE'] = '0'
|
19
|
-
expect(Percy::Capybara::Client.new.enabled?).to eq(false)
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'is false if PERCY_TOKEN is not set' do
|
23
|
-
ENV.delete 'PERCY_TOKEN'
|
24
|
-
expect(Percy::Capybara::Client.new.enabled?).to eq(false)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
context 'when required environment variables not set' do
|
29
|
-
before(:each) { clear_percy_env_variables }
|
30
|
-
|
31
|
-
it 'is false' do
|
32
|
-
ENV.delete 'PERCY_ENABLE'
|
33
|
-
expect(Percy::Capybara::Client.new.enabled?).to eq(false)
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'is false when PERCY_ENABLE is 1' do
|
37
|
-
ENV['PERCY_ENABLE'] = '1'
|
38
|
-
expect(Percy::Capybara::Client.new.enabled?).to eq(false)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
describe '#failed?' do
|
44
|
-
it 'is false by default' do
|
45
|
-
expect(Percy::Capybara::Client.new.failed?).to eq(false)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
describe '#rescue_connection_failures' do
|
50
|
-
let(:capybara_client) { Percy::Capybara::Client.new(enabled: true) }
|
51
|
-
|
52
|
-
it 'returns block result on success' do
|
53
|
-
result = capybara_client.rescue_connection_failures { true }
|
54
|
-
|
55
|
-
expect(result).to eq(true)
|
56
|
-
expect(capybara_client.enabled?).to eq(true)
|
57
|
-
expect(capybara_client.failed?).to eq(false)
|
58
|
-
end
|
59
|
-
|
60
|
-
it 'makes block safe from server errors' do
|
61
|
-
result = capybara_client.rescue_connection_failures do
|
62
|
-
raise Percy::Client::ServerError.new(500, 'POST', '', '')
|
63
|
-
end
|
64
|
-
|
65
|
-
expect(result).to eq(nil)
|
66
|
-
expect(capybara_client.enabled?).to eq(false)
|
67
|
-
expect(capybara_client.failed?).to eq(true)
|
68
|
-
end
|
69
|
-
|
70
|
-
it 'makes block safe from quota exceeded errors' do
|
71
|
-
result = capybara_client.rescue_connection_failures do
|
72
|
-
raise Percy::Client::PaymentRequiredError.new(409, 'POST', '', '')
|
73
|
-
end
|
74
|
-
|
75
|
-
expect(result).to eq(nil)
|
76
|
-
expect(capybara_client.enabled?).to eq(false)
|
77
|
-
expect(capybara_client.failed?).to eq(true)
|
78
|
-
end
|
79
|
-
|
80
|
-
it 'makes block safe from ConnectionFailed' do
|
81
|
-
result = capybara_client.rescue_connection_failures do
|
82
|
-
raise Percy::Client::ConnectionFailed
|
83
|
-
end
|
84
|
-
|
85
|
-
expect(result).to eq(nil)
|
86
|
-
expect(capybara_client.enabled?).to eq(false)
|
87
|
-
expect(capybara_client.failed?).to eq(true)
|
88
|
-
end
|
89
|
-
|
90
|
-
it 'makes block safe from TimeoutError' do
|
91
|
-
result = capybara_client.rescue_connection_failures do
|
92
|
-
raise Percy::Client::TimeoutError
|
93
|
-
end
|
94
|
-
|
95
|
-
expect(result).to eq(nil)
|
96
|
-
expect(capybara_client.enabled?).to eq(false)
|
97
|
-
expect(capybara_client.failed?).to eq(true)
|
98
|
-
end
|
99
|
-
|
100
|
-
it 'requires a block' do
|
101
|
-
expect { capybara_client.rescue_connection_failures }.to raise_error(ArgumentError)
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
describe '#initialize' do
|
106
|
-
let(:capybara_client) { Percy::Capybara::Client.new }
|
107
|
-
|
108
|
-
it 'accepts and memoizes a client arg' do
|
109
|
-
client = Percy::Client.new
|
110
|
-
capybara_client = Percy::Capybara::Client.new(client: client)
|
111
|
-
expect(capybara_client.client).to eq(client)
|
112
|
-
end
|
113
|
-
|
114
|
-
it 'passes client info down to the lower level Percy client' do
|
115
|
-
expect(capybara_client.client.client_info).to eq("percy-capybara/#{Percy::Capybara::VERSION}")
|
116
|
-
end
|
117
|
-
|
118
|
-
context 'when Rails and Sprockets::Rails is defined' do
|
119
|
-
let(:environment) { double('environment') }
|
120
|
-
let(:options) { double('options') }
|
121
|
-
|
122
|
-
before(:each) do
|
123
|
-
rails = double(version: 5)
|
124
|
-
|
125
|
-
stub_const('Sprockets::Rails', double)
|
126
|
-
stub_const('Rails', rails)
|
127
|
-
|
128
|
-
allow(rails).to receive(:application) do
|
129
|
-
double(
|
130
|
-
assets: environment,
|
131
|
-
config: double(assets: options),
|
132
|
-
)
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
it 'assigns sprockets_environment to Rails.application.assets' do
|
137
|
-
expect(capybara_client.sprockets_environment).to eq environment
|
138
|
-
end
|
139
|
-
|
140
|
-
it 'assigns sprockets_options to Rails.application.config.assets' do
|
141
|
-
expect(capybara_client.sprockets_options).to eq options
|
142
|
-
end
|
143
|
-
|
144
|
-
context 'when sprockets_environment is passed' do
|
145
|
-
let(:passed_environment) { double('passed-environment') }
|
146
|
-
let(:capybara_client) do
|
147
|
-
Percy::Capybara::Client.new(
|
148
|
-
sprockets_environment: passed_environment,
|
149
|
-
)
|
150
|
-
end
|
151
|
-
|
152
|
-
it 'assigns sprockets_environment to the passed environment' do
|
153
|
-
expect(capybara_client.sprockets_environment).to eq passed_environment
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
context 'when sprockets_options is passed' do
|
158
|
-
let(:passed_options) { double('passed-options') }
|
159
|
-
let(:capybara_client) { Percy::Capybara::Client.new(sprockets_options: passed_options) }
|
160
|
-
|
161
|
-
it 'assigns sprockets_options to the passed options' do
|
162
|
-
expect(capybara_client.sprockets_options).to eq passed_options
|
163
|
-
end
|
164
|
-
end
|
165
|
-
end
|
166
|
-
|
167
|
-
context 'when Rails or Sprockets::Rails is not defined' do
|
168
|
-
it 'does not assign sprockets_environment or sprockets_options' do
|
169
|
-
expect(capybara_client.sprockets_environment).to_not be
|
170
|
-
expect(capybara_client.sprockets_options).to_not be
|
171
|
-
end
|
172
|
-
end
|
173
|
-
end
|
174
|
-
|
175
|
-
describe '#initialize_loader' do
|
176
|
-
let(:capybara_client) { Percy::Capybara::Client.new }
|
177
|
-
|
178
|
-
context 'when loader has been set to :native' do
|
179
|
-
it 'returns a NativeLoader' do
|
180
|
-
capybara_client.loader = :native
|
181
|
-
loader = capybara_client.initialize_loader
|
182
|
-
expect(loader.class).to eq(Percy::Capybara::Loaders::NativeLoader)
|
183
|
-
end
|
184
|
-
end
|
185
|
-
|
186
|
-
context 'when loader has been set to :filesystem' do
|
187
|
-
it 'returns a FilesystemLoader' do
|
188
|
-
capybara_client.loader = :filesystem
|
189
|
-
capybara_client.loader_options = {assets_dir: '/', base_url: '/'}
|
190
|
-
loader = capybara_client.initialize_loader
|
191
|
-
expect(loader.class).to eq(Percy::Capybara::Loaders::FilesystemLoader)
|
192
|
-
end
|
193
|
-
end
|
194
|
-
|
195
|
-
context 'when loader has been set to a class' do
|
196
|
-
it 'returns an instance of the clients custom loader' do
|
197
|
-
class DummyLoader < Percy::Capybara::Loaders::NativeLoader; end
|
198
|
-
capybara_client.loader = DummyLoader
|
199
|
-
loader = capybara_client.initialize_loader
|
200
|
-
expect(loader.class).to eq(DummyLoader)
|
201
|
-
end
|
202
|
-
end
|
203
|
-
|
204
|
-
context 'when sprockets is configured' do
|
205
|
-
it 'returns a SprocketsLoader' do
|
206
|
-
capybara_client.sprockets_environment = double('sprockets_environment')
|
207
|
-
capybara_client.sprockets_options = double('sprockets_options')
|
208
|
-
loader = capybara_client.initialize_loader
|
209
|
-
expect(loader.class).to eq(Percy::Capybara::Loaders::SprocketsLoader)
|
210
|
-
end
|
211
|
-
end
|
212
|
-
|
213
|
-
context 'when no configuration has been set' do
|
214
|
-
it 'returns a NativeLoader' do
|
215
|
-
expect(capybara_client.initialize_loader.class)
|
216
|
-
.to eq(Percy::Capybara::Loaders::NativeLoader)
|
217
|
-
end
|
218
|
-
end
|
219
|
-
|
220
|
-
context 'when loader_options are set' do
|
221
|
-
let(:loader_class) { Percy::Capybara::Loaders::FilesystemLoader }
|
222
|
-
let(:options) { {assets_dir: 'xyz'} }
|
223
|
-
|
224
|
-
it 'initializes the loader with them' do
|
225
|
-
capybara_client.loader = :filesystem
|
226
|
-
capybara_client.loader_options = options
|
227
|
-
expect(loader_class).to receive(:new).with(options).once
|
228
|
-
capybara_client.initialize_loader
|
229
|
-
end
|
230
|
-
end
|
231
|
-
end
|
232
|
-
end
|