percy-capybara 3.1.0 → 3.1.1

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: 53f2668e01507cd49c909945a6435742c47a808c
4
- data.tar.gz: 4fb5f9a5c161cc8a0a6f86147d488a30a76d93c1
3
+ metadata.gz: 6c4cebeea7c67b0a6fbd86628017792847e7ba8a
4
+ data.tar.gz: bcdefb57b54838500ab9c849b3b4a25910114d8e
5
5
  SHA512:
6
- metadata.gz: 60e77918f3676584e6b9e55945e5faff86d42ec0d440c58f4bb8e0bf555bcb898394ea0974e6392935d23dcb58927f2998e1efea39bc1c852db76072d895b187
7
- data.tar.gz: 8ff66916392f263cb3df3ed72b1ac88c6c1da9368daf11f72cd5a909d8f1f65877c1bc77e0aa45ede761a95ff3a0e44e5d05c5b17bd6f36ab7d7eb4df4e3ca74
6
+ metadata.gz: 72d5dc24fa6e916e0eb2f7986841a7575661707929f2a31abe15cf8451e6848b604c8a3aee09a942d92e1d9dac06ddf8208af501ff7c447d8f4f470954f76dbc
7
+ data.tar.gz: fb152dd45ec55df52ee62c28610e0d5fd5cb8e9a708f06ecc1fbc5483b38a7472af85341d0cc391a0388905615d383b1d140922c243d962006d4152e791cc5e4
data/Gemfile CHANGED
@@ -12,3 +12,7 @@ group :test do
12
12
  gem 'rubocop', '~> 0.48.0'
13
13
  gem 'rubocop-rspec'
14
14
  end
15
+
16
+ group :test, :development do
17
+ gem 'pry'
18
+ end
data/RELEASING.md ADDED
@@ -0,0 +1,17 @@
1
+ # Releasing
2
+
3
+ 1. Update version.rb file accordingly.
4
+ 1. Tag the release: `git tag vVERSION`
5
+ 1. Push changes: `git push --tags`
6
+ 1. Ensure tests have passed on that tag
7
+ 1. [Update the release notes](https://github.com/percy/percy-capybara/releases) on GitHub
8
+ 1. Build and publish:
9
+
10
+ ```bash
11
+ bundle exec rake build
12
+ gem push pkg/percy-capybara-X.XX.XX.gem
13
+ ```
14
+
15
+ * Announce the new release,
16
+ making sure to say "thank you" to the contributors
17
+ who helped shape this version!
@@ -6,8 +6,8 @@ require 'percy/capybara/client'
6
6
  module Percy
7
7
  module Capybara
8
8
  # @see Percy::Capybara::Client
9
- def self.capybara_client
10
- @capybara_client ||= Percy::Capybara::Client.new
9
+ def self.capybara_client(options = {})
10
+ @capybara_client ||= Percy::Capybara::Client.new(options)
11
11
  end
12
12
 
13
13
  # {include:Percy::Capybara::Client::Snapshots#snapshot}
@@ -54,8 +54,7 @@ module Percy
54
54
  end
55
55
 
56
56
  def self.use_loader(loader, options = {})
57
- capybara_client.loader = loader
58
- capybara_client.loader_options = options
57
+ capybara_client(loader: loader, loader_options: options)
59
58
  end
60
59
  end
61
60
  end
@@ -1,5 +1,6 @@
1
1
  require 'percy/capybara/client/builds'
2
2
  require 'percy/capybara/client/snapshots'
3
+ require 'percy/capybara/client/user_agent'
3
4
  require 'percy/capybara/loaders/filesystem_loader'
4
5
  require 'percy/capybara/loaders/native_loader'
5
6
  require 'percy/capybara/loaders/sprockets_loader'
@@ -10,6 +11,7 @@ module Percy
10
11
  class Client
11
12
  include Percy::Capybara::Client::Builds
12
13
  include Percy::Capybara::Client::Snapshots
14
+ include Percy::Capybara::Client::UserAgent
13
15
 
14
16
  class Error < RuntimeError; end
15
17
  class BuildNotInitializedError < Error; end
@@ -25,10 +27,12 @@ module Percy
25
27
  def initialize(options = {})
26
28
  @failed = false
27
29
 
28
- @client = options[:client] || Percy.client
29
30
  @enabled = options[:enabled]
30
-
31
31
  @loader_options = options[:loader_options] || {}
32
+ @loader = options[:loader]
33
+
34
+ @client = options[:client] || \
35
+ Percy.client(client_info: _client_info, environment_info: _environment_info)
32
36
 
33
37
  return unless defined?(Rails)
34
38
 
@@ -0,0 +1,37 @@
1
+ module Percy
2
+ module Capybara
3
+ class Client
4
+ module UserAgent
5
+ def _client_info
6
+ "percy-capybara/#{VERSION}"
7
+ end
8
+
9
+ def _environment_info
10
+ [
11
+ "percy-capybara-loader/#{loader}",
12
+ "rails/#{_rails_version}",
13
+ "sinatra/#{_sinatra_version}",
14
+ "ember-cli-rails/#{_ember_cli_rails_version}",
15
+ ].reject do |info|
16
+ info =~ %r{\/$} # reject if version is empty
17
+ end.join('; ')
18
+ end
19
+
20
+ def _ember_cli_rails_version
21
+ return unless defined? EmberCli
22
+
23
+ require 'ember_cli/version'
24
+ EmberCli::VERSION
25
+ end
26
+
27
+ def _rails_version
28
+ Rails.version if defined? Rails
29
+ end
30
+
31
+ def _sinatra_version
32
+ Sinatra::VERSION if defined? Sinatra
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -1,5 +1,5 @@
1
1
  module Percy
2
2
  module Capybara
3
- VERSION = '3.1.0'.freeze
3
+ VERSION = '3.1.1'.freeze
4
4
  end
5
5
  end
@@ -18,11 +18,11 @@ 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', '~> 1.12'
21
+ spec.add_dependency 'percy-client', '~> 1.13'
22
22
 
23
23
  spec.add_development_dependency 'bundler', '~> 1.7'
24
24
  spec.add_development_dependency 'rake', '~> 10.0'
25
- spec.add_development_dependency 'rspec', '~> 3.2'
25
+ spec.add_development_dependency 'rspec', '~> 3.5'
26
26
  spec.add_development_dependency 'capybara', '~> 2.4'
27
27
  spec.add_development_dependency 'poltergeist'
28
28
  spec.add_development_dependency 'selenium-webdriver'
@@ -0,0 +1,45 @@
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 { 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,9 +1,4 @@
1
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
2
  describe '#enabled?' do
8
3
  context 'when required environment variables set' do
9
4
  before { set_required_env_variables }
@@ -13,14 +8,17 @@ RSpec.describe Percy::Capybara::Client do
13
8
  ENV['PERCY_ENABLE'] = '1'
14
9
  expect(Percy::Capybara::Client.new.enabled?).to eq(true)
15
10
  end
11
+
16
12
  it 'is true when PERCY_ENABLE is not set' do
17
13
  ENV.delete 'PERCY_ENABLE'
18
14
  expect(Percy::Capybara::Client.new.enabled?).to eq(true)
19
15
  end
16
+
20
17
  it 'is false when PERCY_ENABLE is 0' do
21
18
  ENV['PERCY_ENABLE'] = '0'
22
19
  expect(Percy::Capybara::Client.new.enabled?).to eq(false)
23
20
  end
21
+
24
22
  it 'raises error if PERCY_TOKEN is set but PERCY_PROJECT is not' do
25
23
  ENV.delete 'PERCY_PROJECT'
26
24
  expect { Percy::Capybara::Client.new.enabled? }.to raise_error(RuntimeError)
@@ -34,64 +32,90 @@ RSpec.describe Percy::Capybara::Client do
34
32
  ENV.delete 'PERCY_ENABLE'
35
33
  expect(Percy::Capybara::Client.new.enabled?).to eq(false)
36
34
  end
35
+
37
36
  it 'is false when PERCY_ENABLE is 1' do
38
37
  ENV['PERCY_ENABLE'] = '1'
39
38
  expect(Percy::Capybara::Client.new.enabled?).to eq(false)
40
39
  end
41
40
  end
42
41
  end
42
+
43
43
  describe '#failed?' do
44
44
  it 'is false by default' do
45
45
  expect(Percy::Capybara::Client.new.failed?).to eq(false)
46
46
  end
47
47
  end
48
+
48
49
  describe '#rescue_connection_failures' do
49
50
  let(:capybara_client) { Percy::Capybara::Client.new(enabled: true) }
50
51
 
51
52
  it 'returns block result on success' do
52
- result = capybara_client.rescue_connection_failures do
53
- true
54
- end
53
+ result = capybara_client.rescue_connection_failures { true }
54
+
55
55
  expect(result).to eq(true)
56
56
  expect(capybara_client.enabled?).to eq(true)
57
57
  expect(capybara_client.failed?).to eq(false)
58
58
  end
59
+
59
60
  it 'makes block safe from server errors' do
60
61
  result = capybara_client.rescue_connection_failures do
61
62
  raise Percy::Client::ServerError.new(500, 'POST', '', '')
62
63
  end
64
+
63
65
  expect(result).to eq(nil)
64
66
  expect(capybara_client.enabled?).to eq(false)
65
67
  expect(capybara_client.failed?).to eq(true)
66
68
  end
69
+
67
70
  it 'makes block safe from quota exceeded errors' do
68
71
  result = capybara_client.rescue_connection_failures do
69
72
  raise Percy::Client::PaymentRequiredError.new(409, 'POST', '', '')
70
73
  end
74
+
71
75
  expect(result).to eq(nil)
72
76
  expect(capybara_client.enabled?).to eq(false)
73
77
  expect(capybara_client.failed?).to eq(true)
74
78
  end
79
+
75
80
  it 'makes block safe from ConnectionFailed' do
76
81
  result = capybara_client.rescue_connection_failures do
77
82
  raise Percy::Client::ConnectionFailed
78
83
  end
84
+
79
85
  expect(result).to eq(nil)
80
86
  expect(capybara_client.enabled?).to eq(false)
81
87
  expect(capybara_client.failed?).to eq(true)
82
88
  end
89
+
83
90
  it 'makes block safe from TimeoutError' do
84
91
  result = capybara_client.rescue_connection_failures do
85
92
  raise Percy::Client::TimeoutError
86
93
  end
94
+
87
95
  expect(result).to eq(nil)
88
96
  expect(capybara_client.enabled?).to eq(false)
89
97
  expect(capybara_client.failed?).to eq(true)
90
98
  end
99
+
91
100
  it 'requires a block' do
92
101
  expect { capybara_client.rescue_connection_failures }.to raise_error(ArgumentError)
93
102
  end
94
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
+ end
118
+
95
119
  describe '#initialize_loader' do
96
120
  let(:capybara_client) { Percy::Capybara::Client.new }
97
121
 
@@ -83,12 +83,16 @@ RSpec.describe Percy::Capybara do
83
83
 
84
84
  it 'sets the current capybara client\'s loader' do
85
85
  expect(Percy::Capybara.capybara_client.loader).not_to be
86
+ Percy::Capybara.reset!
87
+
86
88
  Percy::Capybara.use_loader(DummyLoader)
87
89
  expect(Percy::Capybara.capybara_client.loader).to be
88
90
  end
89
91
 
90
92
  it 'sets the current capybara client\'s loader options' do
91
93
  expect(Percy::Capybara.capybara_client.loader_options).to eq({})
94
+ Percy::Capybara.reset!
95
+
92
96
  Percy::Capybara.use_loader(DummyLoader, test_option: 3)
93
97
  expect(Percy::Capybara.capybara_client.loader_options).to be
94
98
  expect(Percy::Capybara.capybara_client.loader_options[:test_option]).to eq(3)
data/spec/spec_helper.rb CHANGED
@@ -38,7 +38,7 @@ RSpec.configure do |config|
38
38
  Capybara::Poltergeist::Driver.new(app, timeout: 1, url_blacklist: ['i.imgur.com'])
39
39
  end
40
40
 
41
- config.before(:each) do
41
+ config.before do
42
42
  WebMock.disable_net_connect!(allow_localhost: true)
43
43
  end
44
44
  config.before(:each, type: :feature) 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: 3.1.0
4
+ version: 3.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Perceptual Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-17 00:00:00.000000000 Z
11
+ date: 2017-06-23 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: '1.12'
19
+ version: '1.13'
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.12'
26
+ version: '1.13'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '3.2'
61
+ version: '3.5'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '3.2'
68
+ version: '3.5'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: capybara
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -182,12 +182,14 @@ files:
182
182
  - Guardfile
183
183
  - LICENSE
184
184
  - README.md
185
+ - RELEASING.md
185
186
  - Rakefile
186
187
  - lib/percy/capybara.rb
187
188
  - lib/percy/capybara/anywhere.rb
188
189
  - lib/percy/capybara/client.rb
189
190
  - lib/percy/capybara/client/builds.rb
190
191
  - lib/percy/capybara/client/snapshots.rb
192
+ - lib/percy/capybara/client/user_agent.rb
191
193
  - lib/percy/capybara/httpfetcher.rb
192
194
  - lib/percy/capybara/loaders/base_loader.rb
193
195
  - lib/percy/capybara/loaders/ember_cli_rails_loader.rb
@@ -206,7 +208,6 @@ files:
206
208
  - spec/lib/percy/capybara/client/ember_test_data/ember-cli/frontend/percy-frontend-public.svg
207
209
  - spec/lib/percy/capybara/client/rails_public_test_data/large-file-skipped.png
208
210
  - spec/lib/percy/capybara/client/rails_public_test_data/percy-from-public.svg
209
- - spec/lib/percy/capybara/client/rails_public_test_data/symlink_to_images
210
211
  - spec/lib/percy/capybara/client/snapshots_spec.rb
211
212
  - spec/lib/percy/capybara/client/symlink_test_data/test.png
212
213
  - spec/lib/percy/capybara/client/test_data/assets/css/digested-f3420c6aee71c137a3ca39727052811bae84b2f37d898f4db242e20656a1579e.css
@@ -237,6 +238,7 @@ files:
237
238
  - spec/lib/percy/capybara/client/test_data/test-iframe.html
238
239
  - spec/lib/percy/capybara/client/test_data/test-images.html
239
240
  - spec/lib/percy/capybara/client/test_data/test-localtest-me-images.html
241
+ - spec/lib/percy/capybara/client/user_agent_spec.rb
240
242
  - spec/lib/percy/capybara/client_spec.rb
241
243
  - spec/lib/percy/capybara/http_fetcher_spec.rb
242
244
  - spec/lib/percy/capybara/loaders/base_loader_spec.rb
@@ -267,7 +269,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
267
269
  version: '0'
268
270
  requirements: []
269
271
  rubyforge_project:
270
- rubygems_version: 2.6.12
272
+ rubygems_version: 2.4.5.2
271
273
  signing_key:
272
274
  specification_version: 4
273
275
  summary: Percy::Capybara
@@ -281,7 +283,6 @@ test_files:
281
283
  - spec/lib/percy/capybara/client/ember_test_data/ember-cli/frontend/percy-frontend-public.svg
282
284
  - spec/lib/percy/capybara/client/rails_public_test_data/large-file-skipped.png
283
285
  - spec/lib/percy/capybara/client/rails_public_test_data/percy-from-public.svg
284
- - spec/lib/percy/capybara/client/rails_public_test_data/symlink_to_images
285
286
  - spec/lib/percy/capybara/client/snapshots_spec.rb
286
287
  - spec/lib/percy/capybara/client/symlink_test_data/test.png
287
288
  - spec/lib/percy/capybara/client/test_data/assets/css/digested-f3420c6aee71c137a3ca39727052811bae84b2f37d898f4db242e20656a1579e.css
@@ -312,6 +313,7 @@ test_files:
312
313
  - spec/lib/percy/capybara/client/test_data/test-iframe.html
313
314
  - spec/lib/percy/capybara/client/test_data/test-images.html
314
315
  - spec/lib/percy/capybara/client/test_data/test-localtest-me-images.html
316
+ - spec/lib/percy/capybara/client/user_agent_spec.rb
315
317
  - spec/lib/percy/capybara/client_spec.rb
316
318
  - spec/lib/percy/capybara/http_fetcher_spec.rb
317
319
  - spec/lib/percy/capybara/loaders/base_loader_spec.rb
@@ -1 +0,0 @@
1
- spec/lib/percy/capybara/client/rails_public_test_data/../symlink_test_data