percy-capybara 0.5.0 → 0.6.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: 4c2619a9098477489f443eed78751adf81401c66
4
- data.tar.gz: 0c41b94845f31ddd1fe133c49749cd2bd76b36af
3
+ metadata.gz: faafc67e726d7df13e2553551a48e84f1a305be3
4
+ data.tar.gz: dd4544479963729d3a813dfde0596a59c041a07d
5
5
  SHA512:
6
- metadata.gz: 0dc1613a5a0614815620e004be594d50a833e0ffc2dda8633b9c61ab41a750062fc88f4aea5e7e81b0ba408060637eff0fc28bfd1f20d0727e863a7b1190b78a
7
- data.tar.gz: 7f58f3e80ceffcb84feea0403f0f93bfe6d94e66cfbfeb15dd152ba03ebc82907783bb9c8495a6ed289bf0d8509405ae5119a05d2813155d1817314f0933cea4
6
+ metadata.gz: eeebe611d3e3314a7c51a3da0949c9093f8726aa97169b53957712d3ee8cb5e3bd2befffbd8d9ff913d130af4938e69b947e7d193411fffbe5fa2e1e177ff91d
7
+ data.tar.gz: b4f548b486353e57ceb41447e18096e16cfe26fa6698a4ba8d8a6d63b8ec519737011804d02eb3410acf3662132e56fc9a7d2bce6cca11e91b9ec5ab8b02c1bd
@@ -2,14 +2,44 @@ module Percy
2
2
  module Capybara
3
3
  class Client
4
4
  module Builds
5
- def current_build(options = {})
5
+ def initialize_build(options = {})
6
6
  return if !enabled? # Silently skip if the client is disabled.
7
- @current_build ||= client.create_build(client.config.repo, options)
7
+ return @current_build if build_initialized?
8
+
9
+ # Gather build resources to upload with build.
10
+ start = Time.now
11
+ build_resources = options[:build_resources] || initialize_loader.build_resources
12
+ options[:resources] = build_resources if !build_resources.empty?
13
+
14
+ # Extra debug info.
15
+ build_resources.each { |br| Percy.logger.debug { "Build resource: #{br.resource_url}" } }
16
+ Percy.logger.debug { "All build resources loaded (#{Time.now - start}s)" }
17
+
18
+ @current_build = client.create_build(client.config.repo, options)
19
+ _upload_missing_build_resources(build_resources) if !build_resources.empty?
8
20
  @current_build
9
21
  end
10
- alias_method :initialize_build, :current_build
11
22
 
12
- def upload_missing_build_resources(build_resources)
23
+ def current_build
24
+ return if !enabled? # Silently skip if the client is disabled.
25
+ @current_build
26
+ end
27
+
28
+ def build_initialized?
29
+ !!@current_build
30
+ end
31
+
32
+ def finalize_current_build
33
+ return if !enabled? # Silently skip if the client is disabled.
34
+ if !build_initialized?
35
+ raise Percy::Capybara::Client::BuildNotInitializedError.new(
36
+ 'Failed to finalize build because no build has been initialized.')
37
+ end
38
+ client.finalize_build(current_build['data']['id'])
39
+ end
40
+
41
+ # @private
42
+ def _upload_missing_build_resources(build_resources)
13
43
  # Upload any missing build resources.
14
44
  new_build_resources = current_build['data'] &&
15
45
  current_build['data']['relationships'] &&
@@ -28,19 +58,7 @@ module Percy
28
58
  end
29
59
  new_build_resources.length
30
60
  end
31
-
32
- def build_initialized?
33
- !!@current_build
34
- end
35
-
36
- def finalize_current_build
37
- return if !enabled? # Silently skip if the client is disabled.
38
- if !build_initialized?
39
- raise Percy::Capybara::Client::BuildNotInitializedError.new(
40
- 'Failed to finalize build because no build has been initialized.')
41
- end
42
- client.finalize_build(current_build['data']['id'])
43
- end
61
+ private :_upload_missing_build_resources
44
62
  end
45
63
  end
46
64
  end
@@ -26,7 +26,14 @@ module Percy
26
26
  Percy.logger.debug { "Snapshot started (name: #{name.inspect})" }
27
27
 
28
28
  # If this is the first snapshot, create the build and upload build resources.
29
+ # DEPRECATED: this flow is for the pre-parallel world.
29
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
+
30
37
  start = Time.now
31
38
  build_resources = loader.build_resources
32
39
  if Percy.config.debug
@@ -36,7 +43,7 @@ module Percy
36
43
  end
37
44
  Percy.logger.debug { "All build resources loaded (#{Time.now - start}s)" }
38
45
  initialize_build(resources: build_resources)
39
- upload_missing_build_resources(build_resources)
46
+ _upload_missing_build_resources(build_resources)
40
47
  end
41
48
 
42
49
  start = Time.now
@@ -63,6 +63,11 @@ module Percy
63
63
  current_url = page.current_url
64
64
  url_match = URL_REGEX.match(current_url)
65
65
  return url_match[4] if url_match
66
+
67
+ # Special case: prepend a slash to the path to force a valid URL for things like
68
+ # "about:srcdoc" iframe srcdoc pages.
69
+ current_url = "/#{current_url}" if current_url[0] != '/'
70
+
66
71
  current_url
67
72
  end
68
73
  end
@@ -1,5 +1,6 @@
1
1
  require 'rspec/core'
2
2
 
3
3
  RSpec.configure do |config|
4
+ config.before(:suite) { Percy::Capybara.initialize_build }
4
5
  config.after(:suite) { Percy::Capybara.finalize_build }
5
6
  end
@@ -1,5 +1,5 @@
1
1
  module Percy
2
2
  module Capybara
3
- VERSION = '0.5.0'
3
+ VERSION = '0.6.0'
4
4
  end
5
5
  end
@@ -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', '>= 0.8.0'
21
+ spec.add_dependency 'percy-client', '>= 0.10.0'
22
22
 
23
23
  spec.add_development_dependency 'bundler', '~> 1.7'
24
24
  spec.add_development_dependency 'rake', '~> 10.0'
@@ -1,13 +1,37 @@
1
1
  RSpec.describe Percy::Capybara::Client::Builds do
2
- let(:capybara_client) { Percy::Capybara::Client.new(enabled: true) }
2
+ let(:enabled) { true }
3
+ let(:capybara_client) { Percy::Capybara::Client.new(enabled: enabled) }
3
4
 
5
+ describe '#initialize_build' do
6
+ context 'percy is not enabled' do
7
+ let(:enabled) { false }
8
+ it 'returns nil if not enabled' do
9
+ expect(capybara_client.initialize_build).to be_nil
10
+ end
11
+ end
12
+ it 'initializes and returns a build' do
13
+ mock_response = {
14
+ 'data' => {
15
+ 'id' => '123',
16
+ 'type' => 'builds',
17
+ },
18
+ }
19
+ stub_request(:post, 'https://percy.io/api/v1/repos/percy/percy-capybara/builds/')
20
+ .to_return(status: 201, body: mock_response.to_json)
21
+ expect(capybara_client.initialize_build).to eq(mock_response)
22
+ end
23
+ end
4
24
  describe '#current_build' do
5
- it 'returns the current build or creates a new one' do
25
+ it 'returns nil if no build has been initialized' do
26
+ expect(capybara_client.current_build).to be_nil
27
+ end
28
+ it 'returns the current build' do
6
29
  mock_double = double('build')
7
30
  expect(capybara_client.client).to receive(:create_build)
8
31
  .with(capybara_client.client.config.repo, {})
9
32
  .and_return(mock_double)
10
33
  .once
34
+ capybara_client.initialize_build
11
35
 
12
36
  current_build = capybara_client.current_build
13
37
  expect(current_build).to eq(mock_double)
@@ -15,7 +39,31 @@ RSpec.describe Percy::Capybara::Client::Builds do
15
39
  expect(current_build).to eq(mock_double)
16
40
  end
17
41
  end
18
- describe '#upload_missing_build_resources', type: :feature, js: true do
42
+ describe '#build_initialized?' do
43
+ it 'is false before a build is initialized and true afterward' do
44
+ expect(capybara_client.client).to receive(:create_build).and_return(double('build'))
45
+ expect(capybara_client.build_initialized?).to be_falsey
46
+
47
+ capybara_client.initialize_build
48
+ expect(capybara_client.build_initialized?).to be_truthy
49
+ end
50
+ end
51
+ describe '#finalize_current_build' do
52
+ it 'finalizes the current build' do
53
+ build_data = {'data' => {'id' => 123}}
54
+ expect(capybara_client.client).to receive(:create_build).and_return(build_data)
55
+ capybara_client.initialize_build
56
+
57
+ expect(capybara_client.client).to receive(:finalize_build).with(123)
58
+ capybara_client.finalize_current_build
59
+ end
60
+ it 'raises an error if no current build exists' do
61
+ expect do
62
+ capybara_client.finalize_current_build
63
+ end.to raise_error(Percy::Capybara::Client::BuildNotInitializedError)
64
+ end
65
+ end
66
+ describe '#_upload_missing_build_resources', type: :feature, js: true do
19
67
  before(:each) { setup_sprockets(capybara_client) }
20
68
 
21
69
  it 'returns 0 if there are no missing build resources to upload' do
@@ -27,9 +75,10 @@ RSpec.describe Percy::Capybara::Client::Builds do
27
75
  }
28
76
  stub_request(:post, 'https://percy.io/api/v1/repos/percy/percy-capybara/builds/')
29
77
  .to_return(status: 201, body: mock_response.to_json)
78
+ capybara_client.initialize_build
30
79
 
31
80
  loader = capybara_client.initialize_loader
32
- expect(capybara_client.upload_missing_build_resources(loader.build_resources)).to eq(0)
81
+ expect(capybara_client.send(:_upload_missing_build_resources, loader.build_resources)).to eq(0)
33
82
  end
34
83
  it 'uploads missing resources and returns the number uploaded' do
35
84
  visit '/'
@@ -55,37 +104,14 @@ RSpec.describe Percy::Capybara::Client::Builds do
55
104
  # Stub create build.
56
105
  stub_request(:post, 'https://percy.io/api/v1/repos/percy/percy-capybara/builds/')
57
106
  .to_return(status: 201, body: mock_response.to_json)
58
- capybara_client.initialize_build
59
107
 
60
108
  # Stub resource upload.
61
109
  stub_request(:post, "https://percy.io/api/v1/builds/123/resources/")
62
110
  .to_return(status: 201, body: {success: true}.to_json)
63
- result = capybara_client.upload_missing_build_resources(loader.build_resources)
64
- expect(result).to eq(1)
65
- end
66
- end
67
- describe '#build_initialized?' do
68
- it 'is false before a build is initialized and true afterward' do
69
- expect(capybara_client.client).to receive(:create_build).and_return(double('build'))
70
- expect(capybara_client.build_initialized?).to be_falsey
71
-
72
111
  capybara_client.initialize_build
73
- expect(capybara_client.build_initialized?).to be_truthy
112
+ result = capybara_client.send(:_upload_missing_build_resources, loader.build_resources)
113
+ expect(result).to eq(1)
74
114
  end
75
115
  end
76
- describe '#finalize_current_build' do
77
- it 'finalizes the current build' do
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
116
 
82
- expect(capybara_client.client).to receive(:finalize_build).with(123)
83
- capybara_client.finalize_current_build
84
- end
85
- it 'raises an error if no current build exists' do
86
- expect do
87
- capybara_client.finalize_current_build
88
- end.to raise_error(Percy::Capybara::Client::BuildNotInitializedError)
89
- end
90
- end
91
117
  end
@@ -45,6 +45,10 @@ RSpec.describe Percy::Capybara::Loaders::BaseLoader do
45
45
  expect(page_double).to receive(:current_url).and_return('http://www.example.com/')
46
46
  loader = described_class.new(page: page_double)
47
47
  expect(loader.current_path).to eq('/')
48
+
49
+ expect(page_double).to receive(:current_url).and_return('about:srcdoc')
50
+ loader = described_class.new(page: page_double)
51
+ expect(loader.current_path).to eq('/about:srcdoc')
48
52
  end
49
53
  end
50
54
  end
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.5.0
4
+ version: 0.6.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: 2015-10-01 00:00:00.000000000 Z
11
+ date: 2015-10-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: percy-client
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.8.0
19
+ version: 0.10.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
- version: 0.8.0
26
+ version: 0.10.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement