percy-capybara 2.4.0 → 2.4.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: bb10aec66c3c56197c20d065c40d832e877a6f6c
4
- data.tar.gz: c0ceaad44d882dd332bc311f9487254ebddd629e
3
+ metadata.gz: 1ffda7d1edb1b8af63b836b222198c91f5b4123b
4
+ data.tar.gz: 0a4530980562b8eee91a122ccb605c10376d8d9f
5
5
  SHA512:
6
- metadata.gz: 8c77f2d2408b130ae4ddc0da23a4dc57ab2cfb17eeb7d0f70f95856bfd4b5f0d48c55f9098c002c5ff43e233621ab7329034b089dbb8943e132f15b1698a58d8
7
- data.tar.gz: 61edd95f68244f5d7b63d169a9da0b95be1743c5ebfeaf96f9f226721467ec059f38d76722bd4b53e4dccf7ee562de2e818fd36647d6e40f0ee8d69df223a310
6
+ metadata.gz: 0b80f67fc99db1389d5c3dbc9b3e743d4ccc3ba87cde1db6e6397e056457a3d85a20233ecdff8d291108a66f0e00848f56642e899f85c2d96259e48b4e3a0442
7
+ data.tar.gz: 84c9e112198d7d43f46519d639ae9dc9ee620fac769331a5e43eccdaeb253f507bc51c2dc91bf3c826dae0f08034d0dd954b950986fc03621936a97a145c3558
data/.rubocop.yml ADDED
@@ -0,0 +1,42 @@
1
+ require: rubocop-rspec
2
+ inherit_from: .rubocop_todo.yml
3
+ AllCops:
4
+ Include:
5
+ - Rakefile
6
+ - lib/**/*.rake
7
+
8
+ Metrics/LineLength:
9
+ Max: 100
10
+
11
+ Style/Documentation:
12
+ Enabled: false
13
+
14
+ Style/DoubleNegation:
15
+ Enabled: false
16
+
17
+ Style/IndentArray:
18
+ EnforcedStyle: consistent
19
+
20
+ Style/MultilineMethodCallIndentation:
21
+ EnforcedStyle: indented
22
+
23
+ Style/MultilineOperationIndentation:
24
+ EnforcedStyle: indented
25
+
26
+ Style/RedundantBegin:
27
+ Enabled: false
28
+
29
+ Style/SpaceInsideHashLiteralBraces:
30
+ EnforcedStyle: no_space
31
+
32
+ Style/TrailingCommaInLiteral:
33
+ EnforcedStyleForMultiline: comma
34
+
35
+ RSpec/MessageSpies:
36
+ EnforcedStyle: receive
37
+
38
+
39
+
40
+ # Will be able to do this in >= v1.11
41
+ # RSpec/DescribedClass:
42
+ # EnforcedStyle: explicit
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,98 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2017-02-08 20:09:02 -0800 using RuboCop version 0.47.1.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 8
10
+ Metrics/AbcSize:
11
+ Max: 54
12
+
13
+ # Offense count: 27
14
+ # Configuration parameters: CountComments, ExcludedMethods.
15
+ Metrics/BlockLength:
16
+ Max: 227
17
+
18
+ # Offense count: 1
19
+ # Configuration parameters: CountComments.
20
+ Metrics/ClassLength:
21
+ Max: 164
22
+
23
+ # Offense count: 5
24
+ Metrics/CyclomaticComplexity:
25
+ Max: 11
26
+
27
+ # Offense count: 11
28
+ # Configuration parameters: CountComments.
29
+ Metrics/MethodLength:
30
+ Max: 57
31
+
32
+ # Offense count: 2
33
+ Metrics/PerceivedComplexity:
34
+ Max: 12
35
+
36
+ # Offense count: 43
37
+ # Configuration parameters: SkipBlocks.
38
+ RSpec/DescribedClass:
39
+ Exclude:
40
+ - 'spec/lib/percy/capybara/client_spec.rb'
41
+ - 'spec/lib/percy/capybara/http_fetcher_spec.rb'
42
+ - 'spec/lib/percy/capybara_spec.rb'
43
+
44
+ # Offense count: 29
45
+ # Configuration parameters: Max.
46
+ RSpec/ExampleLength:
47
+ Exclude:
48
+ - 'spec/lib/percy/capybara/client/builds_spec.rb'
49
+ - 'spec/lib/percy/capybara/client/snapshots_spec.rb'
50
+ - 'spec/lib/percy/capybara/client_spec.rb'
51
+ - 'spec/lib/percy/capybara/loaders/base_loader_spec.rb'
52
+ - 'spec/lib/percy/capybara/loaders/filesystem_loader_spec.rb'
53
+ - 'spec/lib/percy/capybara/loaders/native_loader_spec.rb'
54
+ - 'spec/lib/percy/capybara/loaders/sprockets_loader_spec.rb'
55
+ - 'spec/lib/percy/capybara_spec.rb'
56
+
57
+ # Offense count: 1
58
+ # Configuration parameters: AssignmentOnly.
59
+ RSpec/InstanceVariable:
60
+ Exclude:
61
+ - 'spec/lib/percy/capybara_spec.rb'
62
+
63
+ # Offense count: 42
64
+ RSpec/MultipleExpectations:
65
+ Max: 29
66
+
67
+ # Offense count: 1
68
+ # Configuration parameters: Max.
69
+ RSpec/NestedGroups:
70
+ Exclude:
71
+ - 'spec/lib/percy/capybara/loaders/sprockets_loader_spec.rb'
72
+
73
+ # Offense count: 10
74
+ # Configuration parameters: IgnoreSymbolicNames.
75
+ RSpec/VerifiedDoubles:
76
+ Exclude:
77
+ - 'spec/lib/percy/capybara/client/builds_spec.rb'
78
+ - 'spec/lib/percy/capybara/client_spec.rb'
79
+ - 'spec/lib/percy/capybara/loaders/base_loader_spec.rb'
80
+ - 'spec/lib/percy/capybara/loaders/sprockets_loader_spec.rb'
81
+ - 'spec/lib/percy/capybara_spec.rb'
82
+ - 'spec/support/test_helpers.rb'
83
+
84
+ # Offense count: 4
85
+ # Cop supports --auto-correct.
86
+ # Configuration parameters: EnforcedStyle, SupportedStyles, AllowInnerSlashes.
87
+ # SupportedStyles: slashes, percent_r, mixed
88
+ Style/RegexpLiteral:
89
+ Exclude:
90
+ - 'lib/percy/capybara/loaders/native_loader.rb'
91
+ - 'spec/lib/percy/capybara/loaders/native_loader_spec.rb'
92
+ - 'spec/lib/percy/capybara/loaders/sprockets_loader_spec.rb'
93
+ - 'spec/support/test_helpers.rb'
94
+
95
+ # Offense count: 1
96
+ Style/StructInheritance:
97
+ Exclude:
98
+ - 'lib/percy/capybara/httpfetcher.rb'
data/.travis.yml CHANGED
@@ -10,5 +10,8 @@ matrix:
10
10
  allow_failures:
11
11
  - rvm: ruby-head
12
12
  before_install:
13
+ - gem update --system
13
14
  - gem update bundler
14
- script: xvfb-run bundle exec rspec
15
+ script:
16
+ - xvfb-run bundle exec rspec
17
+ - bundle exec rubocop -D
data/Gemfile CHANGED
@@ -6,4 +6,9 @@ gemspec
6
6
  gem 'guard-rspec', require: false
7
7
 
8
8
  # (for development)
9
- # gem 'percy-client', path: '~/src/percy-client'
9
+ # gem 'percy-client', path: '~/src/percy-client'
10
+
11
+ group :test do
12
+ gem 'rubocop'
13
+ gem 'rubocop-rspec'
14
+ end
data/Rakefile CHANGED
@@ -1,2 +1 @@
1
1
  require 'bundler/gem_tasks'
2
-
@@ -36,7 +36,7 @@ module Percy
36
36
  #
37
37
  # @see Percy::Capybara::Client::Builds#finalize_current_build
38
38
  def self.finalize_build
39
- return if !capybara_client.build_initialized?
39
+ return unless capybara_client.build_initialized?
40
40
  capybara_client.finalize_current_build
41
41
  end
42
42
 
@@ -45,7 +45,7 @@ module Percy
45
45
  @capybara_client = nil
46
46
  end
47
47
  # The 'reset' method is deprecated and will be removed: use the reset! method instead.
48
- class << self; alias_method :reset, :reset!; end;
48
+ class << self; alias reset reset!; end
49
49
 
50
50
  # Manually disable Percy for the current capybara client. This can also be done with the
51
51
  # PERCY_ENABLE=0 environment variable.
@@ -10,7 +10,7 @@ module Percy
10
10
  include Percy::Capybara::Client::Builds
11
11
  include Percy::Capybara::Client::Snapshots
12
12
 
13
- class Error < Exception; end
13
+ class Error < RuntimeError; end
14
14
  class BuildNotInitializedError < Error; end
15
15
  class WebMockBlockingConnectionsError < Error; end
16
16
 
@@ -29,26 +29,24 @@ module Percy
29
29
 
30
30
  @loader_options = options[:loader_options] || {}
31
31
 
32
- if defined?(Rails)
33
- @sprockets_environment = options[:sprockets_environment] || Rails.application.assets
34
- @sprockets_options = options[:sprockets_options] || Rails.application.config.assets
35
- end
32
+ return unless defined?(Rails)
33
+
34
+ @sprockets_environment = options[:sprockets_environment] || Rails.application.assets
35
+ @sprockets_options = options[:sprockets_options] || Rails.application.config.assets
36
36
  end
37
37
 
38
38
  # Check that environment variables required for Percy::Client are set
39
39
  def required_environment_variables_set?
40
40
  if !ENV['PERCY_TOKEN'].nil? && ENV['PERCY_PROJECT'].nil?
41
- raise RuntimeError.new(
42
- '[percy] It looks like you were trying to enable Percy because PERCY_TOKEN is set, ' +
43
- 'but you are missing the PERCY_PROJECT environment variable!'
44
- )
41
+ raise '[percy] It looks like you were trying to enable Percy because PERCY_TOKEN ' \
42
+ 'is set, but you are missing the PERCY_PROJECT environment variable!'
45
43
  end
46
44
 
47
45
  !(ENV['PERCY_PROJECT'].nil? || ENV['PERCY_TOKEN'].nil?)
48
46
  end
49
47
 
50
48
  def enabled?
51
- return @enabled if !@enabled.nil?
49
+ return @enabled unless @enabled.nil?
52
50
 
53
51
  # Disable if PERCY_ENABLE is set to 0
54
52
  return @enabled = false if ENV['PERCY_ENABLE'] == '0'
@@ -57,21 +55,21 @@ module Percy
57
55
  return @enabled = true if required_environment_variables_set?
58
56
 
59
57
  # Disable otherwise
60
- return @enabled = false
58
+ @enabled = false
61
59
  end
62
60
 
63
61
  def disable!
64
62
  @enabled = false
65
63
  end
66
64
 
67
- def rescue_connection_failures(&block)
68
- raise ArgumentError.new('block is required') if !block_given?
65
+ def rescue_connection_failures
66
+ raise ArgumentError, 'block is required' unless block_given?
69
67
  begin
70
- block.call
71
- rescue Percy::Client::ServerError, # Rescue server errors.
72
- Percy::Client::PaymentRequiredError, # Rescue quota exceeded errors.
73
- Percy::Client::ConnectionFailed, # Rescue some networking errors.
74
- Percy::Client::TimeoutError => e
68
+ yield
69
+ rescue Percy::Client::ServerError, # Rescue server errors.
70
+ Percy::Client::PaymentRequiredError, # Rescue quota exceeded errors.
71
+ Percy::Client::ConnectionFailed, # Rescue some networking errors.
72
+ Percy::Client::TimeoutError => e
75
73
  Percy.logger.error(e)
76
74
  @enabled = false
77
75
  @failed = true
@@ -80,7 +78,7 @@ module Percy
80
78
  end
81
79
 
82
80
  def failed?
83
- return !!@failed
81
+ !!@failed
84
82
  end
85
83
 
86
84
  def initialize_loader(options = {})
@@ -105,9 +103,9 @@ module Percy
105
103
  else
106
104
  unless @warned_about_native_loader
107
105
  Percy.logger.warn \
108
- '[DEPRECATED] The native_loader is deprecated and will be opt-in in a future release. ' +
109
- 'You should move to the faster, more reliable filesystem_loader. See the docs for ' +
110
- 'Non-Rails frameworks: https://percy.io/docs/clients/ruby/capybara '
106
+ '[DEPRECATED] The native_loader is deprecated and will be opt-in in a future ' \
107
+ 'release. You should move to the faster, more reliable filesystem_loader. See the ' \
108
+ 'docs for Non-Rails frameworks: https://percy.io/docs/clients/ruby/capybara '
111
109
  @warned_about_native_loader = true
112
110
  end
113
111
  Percy.logger.debug { 'Using native_loader to discover assets (slower).' }
@@ -3,13 +3,13 @@ module Percy
3
3
  class Client
4
4
  module Builds
5
5
  def initialize_build(options = {})
6
- return if !enabled? # Silently skip if the client is disabled.
6
+ return unless enabled? # Silently skip if the client is disabled.
7
7
  return @current_build if build_initialized?
8
8
 
9
9
  # Gather build resources to upload with build.
10
10
  start = Time.now
11
11
  build_resources = options[:build_resources] || initialize_loader.build_resources
12
- options[:resources] = build_resources if !build_resources.empty?
12
+ options[:resources] = build_resources unless build_resources.empty?
13
13
 
14
14
  # Extra debug info.
15
15
  build_resources.each { |br| Percy.logger.debug { "Build resource: #{br.resource_url}" } }
@@ -17,17 +17,17 @@ module Percy
17
17
 
18
18
  rescue_connection_failures do
19
19
  @current_build = client.create_build(client.config.repo, options)
20
- _upload_missing_build_resources(build_resources) if !build_resources.empty?
20
+ _upload_missing_build_resources(build_resources) unless build_resources.empty?
21
21
  end
22
22
  if failed?
23
- Percy.logger.error { "Percy build failed! Check log above for errors." }
23
+ Percy.logger.error { 'Percy build failed! Check log above for errors.' }
24
24
  return
25
25
  end
26
26
  @current_build
27
27
  end
28
28
 
29
29
  def current_build
30
- return if !enabled? # Silently skip if the client is disabled.
30
+ return unless enabled? # Silently skip if the client is disabled.
31
31
  @current_build
32
32
  end
33
33
 
@@ -37,16 +37,16 @@ module Percy
37
37
  end
38
38
 
39
39
  def finalize_current_build
40
- return if !enabled? # Silently skip if the client is disabled.
41
- if !build_initialized?
42
- raise Percy::Capybara::Client::BuildNotInitializedError.new(
43
- 'Failed to finalize build because no build has been initialized.')
40
+ return unless enabled? # Silently skip if the client is disabled.
41
+ unless build_initialized?
42
+ raise Percy::Capybara::Client::BuildNotInitializedError,
43
+ 'Failed to finalize build because no build has been initialized.'
44
44
  end
45
45
  result = rescue_connection_failures do
46
46
  client.finalize_build(current_build['data']['id'])
47
47
  end
48
48
  if failed?
49
- Percy.logger.error { "Percy build failed! Check log above for errors." }
49
+ Percy.logger.error { 'Percy build failed! Check log above for errors.' }
50
50
  return
51
51
  end
52
52
  result
@@ -59,15 +59,15 @@ module Percy
59
59
  current_build['data']['relationships'] &&
60
60
  current_build['data']['relationships']['missing-resources'] &&
61
61
  current_build['data']['relationships']['missing-resources']['data']
62
- return 0 if !new_build_resources
62
+ return 0 unless new_build_resources
63
63
 
64
64
  new_build_resources.each_with_index do |missing_resource, i|
65
65
  sha = missing_resource['id']
66
66
  resource = build_resources.find { |r| r.sha == sha }
67
67
  content = resource.content || File.read(resource.path)
68
68
  client.upload_resource(current_build['data']['id'], content)
69
- if i % 10 == 0
70
- puts "[percy] Uploading #{i+1} of #{new_build_resources.length} new resources..."
69
+ if (i % 10).zero?
70
+ puts "[percy] Uploading #{i + 1} of #{new_build_resources.length} new resources..."
71
71
  end
72
72
  end
73
73
  new_build_resources.length
@@ -8,18 +8,16 @@ module Percy
8
8
  #
9
9
  # @param [Capybara::Session] page The Capybara page to snapshot.
10
10
  # @param [Hash] options
11
- # @option options [String] :name A unique name for the current page that identifies it across
12
- # builds. By default this is the URL of the page, but can be customized if the URL does not
13
- # entirely identify the current state.
11
+ # @option options [String] :name A unique name for the current page that identifies
12
+ # it across builds. By default this is the URL of the page, but can be customized if the
13
+ # URL does not entirely identify the current state.
14
14
  def snapshot(page, options = {})
15
- return if !enabled? # Silently skip if the client is disabled.
15
+ return unless enabled? # Silently skip if the client is disabled.
16
16
 
17
17
  if current_build.nil?
18
- raise RuntimeError.new(
19
- 'Whoops! Percy is enabled, but Percy::Capybara.initialize_build was never called. ' +
20
- 'Did you forget to setup Percy in your spec_helper.rb? ' +
18
+ raise 'Whoops! Percy is enabled, but Percy::Capybara.initialize_build was never ' \
19
+ 'called. Did you forget to setup Percy in your spec_helper.rb? ' \
21
20
  'See: https://percy.io/docs/clients/ruby/capybara'
22
- )
23
21
  end
24
22
 
25
23
  loader = initialize_loader(page: page)
@@ -46,7 +44,8 @@ module Percy
46
44
  return
47
45
  end
48
46
 
49
- snapshot['data']['relationships']['missing-resources']['data'].each do |missing_resource|
47
+ missing_resource_data = snapshot['data']['relationships']['missing-resources']['data']
48
+ missing_resource_data.each do |missing_resource|
50
49
  sha = missing_resource['id']
51
50
  client.upload_resource(current_build_id, resource_map[sha].content)
52
51
  end
@@ -56,7 +55,7 @@ module Percy
56
55
  client.finalize_snapshot(snapshot['data']['id'])
57
56
  end
58
57
  if failed?
59
- Percy.logger.error { "Percy build failed! Check log above for errors." }
58
+ Percy.logger.error { 'Percy build failed! Check log above for errors.' }
60
59
  return
61
60
  end
62
61
  true
@@ -23,13 +23,13 @@ module Percy
23
23
  content_type = output.match(/< Content-Type:(.*)/i)
24
24
  content_type = content_type[1].strip if content_type
25
25
 
26
- if File.exist?(temppath)
27
- response = Percy::Capybara::HttpFetcher::Response.new(File.read(temppath), content_type)
28
- # We've broken the tempfile so it won't get deleted when garbage collected. Delete!
29
- File.delete(temppath)
30
- return if response.body == ''
31
- response
32
- end
26
+ return unless File.exist?(temppath)
27
+
28
+ response = Percy::Capybara::HttpFetcher::Response.new(File.read(temppath), content_type)
29
+ # We've broken the tempfile so it won't get deleted when garbage collected. Delete!
30
+ File.delete(temppath)
31
+ return if response.body == ''
32
+ response
33
33
  end
34
34
  end
35
35
  end
@@ -5,29 +5,29 @@ module Percy
5
5
  # Modified version of Diego Perini's URL regex. https://gist.github.com/dperini/729294
6
6
  URL_REGEX = Regexp.new(
7
7
  # protocol identifier
8
- "((?:https?:)?//)" +
9
- "(" +
8
+ '((?:https?:)?//)' \
9
+ '(' +
10
10
  # IP address exclusion
11
11
  # private & local networks
12
- "(?!(?:10|127)(?:\\.\\d{1,3}){3})" +
13
- "(?!(?:169\\.254|192\\.168)(?:\\.\\d{1,3}){2})" +
14
- "(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})" +
12
+ '(?!(?:10|127)(?:\\.\\d{1,3}){3})' \
13
+ '(?!(?:169\\.254|192\\.168)(?:\\.\\d{1,3}){2})' \
14
+ '(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})' +
15
15
  # IP address dotted notation octets
16
16
  # excludes loopback network 0.0.0.0
17
17
  # excludes reserved space >= 224.0.0.0
18
18
  # excludes network & broacast addresses
19
19
  # (first & last IP address of each class)
20
- "(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])" +
21
- "(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}" +
22
- "(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))" +
23
- "|" +
20
+ '(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])' \
21
+ '(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}' \
22
+ '(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))' \
23
+ '|' +
24
24
  # host name
25
- "(?:(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)" +
25
+ '(?:(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)' +
26
26
  # domain name
27
- "(?:\\.(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)*" +
28
- ")" +
27
+ '(?:\\.(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)*' \
28
+ ')' +
29
29
  # port number
30
- "(:\\d{2,5})?" +
30
+ '(:\\d{2,5})?' +
31
31
  # resource path
32
32
  "(/[^\\s\"']*)?"
33
33
  )
@@ -40,17 +40,18 @@ module Percy
40
40
  end
41
41
 
42
42
  def build_resources
43
- raise NotImplementedError.new('subclass must implement abstract method')
43
+ raise NotImplementedError, 'subclass must implement abstract method'
44
44
  end
45
45
 
46
46
  def snapshot_resources
47
- raise NotImplementedError.new('subclass must implement abstract method')
47
+ raise NotImplementedError, 'subclass must implement abstract method'
48
48
  end
49
49
 
50
50
  # @private
51
51
  def root_html_resource
52
52
  Percy::Client::Resource.new(
53
- current_path, is_root: true, mimetype: 'text/html', content: page.html)
53
+ current_path, is_root: true, mimetype: 'text/html', content: page.html
54
+ )
54
55
  end
55
56
 
56
57
  # Transformed version of the current URL to be a relative path.