percy-capybara 0.1.2 → 0.1.3
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 +4 -4
- data/lib/percy/capybara/client/builds.rb +2 -0
- data/lib/percy/capybara/client/snapshots.rb +1 -0
- data/lib/percy/capybara/client.rb +6 -0
- data/lib/percy/capybara/version.rb +1 -1
- data/spec/lib/percy/capybara/client/builds_spec.rb +1 -1
- data/spec/lib/percy/capybara/client/snapshots_spec.rb +1 -1
- data/spec/lib/percy/capybara/client_spec.rb +32 -0
- data/spec/lib/percy/capybara_spec.rb +25 -2
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e3dce95f1470e064a58efea7de8c8e324ce26cd2
|
4
|
+
data.tar.gz: 25cc759cc54c27a9519b42bf4e582e86d1879f85
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fcc5c0a05c238b73155485b9bd3917755f647bdfc0945f502e156b65f4495c18d35678ba7eb158bc122a764173e924bd77eb371930cb594a70e3cd39bc32ba13
|
7
|
+
data.tar.gz: 6ea4f3b98cade21c21b6fa20500db0d974679b484fdf881171787660efd07122dee0ba0168f56240802a6dbcf3db67821fa2a9d4fd35c0751e3aad13f61541b8
|
@@ -3,6 +3,7 @@ module Percy
|
|
3
3
|
class Client
|
4
4
|
module Builds
|
5
5
|
def current_build
|
6
|
+
return if !enabled? # Silently skip if the client is disabled.
|
6
7
|
@current_build ||= client.create_build(client.config.repo)
|
7
8
|
end
|
8
9
|
alias_method :initialize_build, :current_build
|
@@ -12,6 +13,7 @@ module Percy
|
|
12
13
|
end
|
13
14
|
|
14
15
|
def finalize_current_build
|
16
|
+
return if !enabled? # Silently skip if the client is disabled.
|
15
17
|
if !build_initialized?
|
16
18
|
raise Percy::Capybara::Client::BuildNotInitializedError.new(
|
17
19
|
'Failed to finalize build because no build has been initialized.')
|
@@ -15,6 +15,7 @@ module Percy
|
|
15
15
|
# builds. By default this is the URL of the page, but can be customized if the URL does not
|
16
16
|
# entirely identify the current state.
|
17
17
|
def snapshot(page, options = {})
|
18
|
+
return if !enabled? # Silently skip if the client is disabled.
|
18
19
|
name = options[:name]
|
19
20
|
current_build_id = current_build['data']['id']
|
20
21
|
resource_map = _find_resources(page)
|
@@ -15,6 +15,12 @@ module Percy
|
|
15
15
|
|
16
16
|
def initialize(options = {})
|
17
17
|
@client = options[:client] || Percy.client
|
18
|
+
@enabled = options[:enabled]
|
19
|
+
end
|
20
|
+
|
21
|
+
def enabled?
|
22
|
+
# Only enable if in supported CI environment or local dev with PERCY_ENABLE=1.
|
23
|
+
@enabled ||= !Percy::Client::Environment.current_ci.nil? || ENV['PERCY_ENABLE'] == '1'
|
18
24
|
end
|
19
25
|
end
|
20
26
|
end
|
@@ -2,7 +2,7 @@ require 'json'
|
|
2
2
|
require 'digest'
|
3
3
|
|
4
4
|
RSpec.describe Percy::Capybara::Client::Snapshots, type: :feature do
|
5
|
-
let(:capybara_client) { Percy::Capybara::Client.new }
|
5
|
+
let(:capybara_client) { Percy::Capybara::Client.new(enabled: true) }
|
6
6
|
|
7
7
|
# Start a temp webserver that serves the testdata directory.
|
8
8
|
# You can test this server manually by running:
|
@@ -0,0 +1,32 @@
|
|
1
|
+
RSpec.describe Percy::Capybara::Client do
|
2
|
+
it 'accepts and memoizes a client arg' do
|
3
|
+
client = Percy::Client.new
|
4
|
+
capybara_client = Percy::Capybara::Client.new(client: client)
|
5
|
+
expect(capybara_client.client).to eq(client)
|
6
|
+
end
|
7
|
+
describe '#enabled?' do
|
8
|
+
before(:each) do
|
9
|
+
@original_env = ENV['TRAVIS_BUILD_ID']
|
10
|
+
ENV['TRAVIS_BUILD_ID'] = nil
|
11
|
+
end
|
12
|
+
after(:each) do
|
13
|
+
ENV['TRAVIS_BUILD_ID'] = @original_env
|
14
|
+
ENV['PERCY_ENABLE'] = nil
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'in supported CI environment' do
|
18
|
+
it 'is true' do
|
19
|
+
ENV['TRAVIS_BUILD_ID'] = '123'
|
20
|
+
expect(Percy::Capybara::Client.new.enabled?).to be_truthy
|
21
|
+
end
|
22
|
+
end
|
23
|
+
it 'is false by default for local dev environments or unknown CI environments' do
|
24
|
+
expect(Percy::Capybara::Client.new.enabled?).to be_falsey
|
25
|
+
end
|
26
|
+
it 'is true if PERCY_ENABLE=1 is set' do
|
27
|
+
ENV['PERCY_ENABLE'] = '1'
|
28
|
+
expect(Percy::Capybara::Client.new.enabled?).to be_truthy
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
@@ -1,5 +1,15 @@
|
|
1
1
|
RSpec.describe Percy::Capybara do
|
2
|
-
before(:each)
|
2
|
+
before(:each) do
|
3
|
+
Percy::Capybara.reset
|
4
|
+
@original_env = ENV['TRAVIS_BUILD_ID']
|
5
|
+
ENV['PERCY_ENABLE'] = '1'
|
6
|
+
ENV['TRAVIS_BUILD_ID'] = nil
|
7
|
+
end
|
8
|
+
after(:each) do
|
9
|
+
ENV['TRAVIS_BUILD_ID'] = @original_env
|
10
|
+
ENV['PERCY_ENABLE'] = nil
|
11
|
+
end
|
12
|
+
|
3
13
|
|
4
14
|
describe '#capybara_client' do
|
5
15
|
it 'returns the current client or creates a new one' do
|
@@ -18,8 +28,13 @@ RSpec.describe Percy::Capybara do
|
|
18
28
|
expect(capybara_client).to receive(:snapshot).with(mock_page, name: '/foo.html (modal)').once
|
19
29
|
Percy::Capybara.snapshot(mock_page, name: '/foo.html (modal)')
|
20
30
|
end
|
31
|
+
it 'silently skips if not enabled' do
|
32
|
+
ENV['PERCY_ENABLE'] = nil
|
33
|
+
mock_page = double('page')
|
34
|
+
Percy::Capybara.snapshot(mock_page)
|
35
|
+
end
|
21
36
|
end
|
22
|
-
describe '#
|
37
|
+
describe '#initialize_build' do
|
23
38
|
it 'delegates to Percy::Capybara::Client' do
|
24
39
|
capybara_client = Percy::Capybara.capybara_client
|
25
40
|
expect(capybara_client).to receive(:initialize_build).once
|
@@ -38,6 +53,14 @@ RSpec.describe Percy::Capybara do
|
|
38
53
|
expect(capybara_client).to receive(:finalize_current_build).once
|
39
54
|
Percy::Capybara.finalize_build
|
40
55
|
end
|
56
|
+
it 'silently skips if not enabled' do
|
57
|
+
ENV['PERCY_ENABLE'] = nil
|
58
|
+
capybara_client = Percy::Capybara.capybara_client
|
59
|
+
expect(capybara_client.client).to_not receive(:create_build)
|
60
|
+
Percy::Capybara.initialize_build
|
61
|
+
expect(capybara_client).to_not receive(:finalize_current_build)
|
62
|
+
Percy::Capybara.finalize_build
|
63
|
+
end
|
41
64
|
end
|
42
65
|
describe '#reset' do
|
43
66
|
it 'clears the current capybara_client' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: percy-capybara
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Perceptual Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05-
|
11
|
+
date: 2015-05-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: percy-client
|
@@ -179,6 +179,7 @@ files:
|
|
179
179
|
- spec/lib/percy/capybara/client/testdata/index.html
|
180
180
|
- spec/lib/percy/capybara/client/testdata/test-css.html
|
181
181
|
- spec/lib/percy/capybara/client/testdata/test-images.html
|
182
|
+
- spec/lib/percy/capybara/client_spec.rb
|
182
183
|
- spec/lib/percy/capybara/httpfetcher_spec.rb
|
183
184
|
- spec/lib/percy/capybara_spec.rb
|
184
185
|
- spec/spec_helper.rb
|
@@ -228,8 +229,8 @@ test_files:
|
|
228
229
|
- spec/lib/percy/capybara/client/testdata/index.html
|
229
230
|
- spec/lib/percy/capybara/client/testdata/test-css.html
|
230
231
|
- spec/lib/percy/capybara/client/testdata/test-images.html
|
232
|
+
- spec/lib/percy/capybara/client_spec.rb
|
231
233
|
- spec/lib/percy/capybara/httpfetcher_spec.rb
|
232
234
|
- spec/lib/percy/capybara_spec.rb
|
233
235
|
- spec/spec_helper.rb
|
234
236
|
- spec/support/test_helpers.rb
|
235
|
-
has_rdoc:
|