percy-capybara 3.1.1 → 3.1.2

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: 6c4cebeea7c67b0a6fbd86628017792847e7ba8a
4
- data.tar.gz: bcdefb57b54838500ab9c849b3b4a25910114d8e
3
+ metadata.gz: 58f05b4af92c2331c4f96ea61734cb56240a847f
4
+ data.tar.gz: ecb08a90a16eb404f2815c849162ff467935560e
5
5
  SHA512:
6
- metadata.gz: 72d5dc24fa6e916e0eb2f7986841a7575661707929f2a31abe15cf8451e6848b604c8a3aee09a942d92e1d9dac06ddf8208af501ff7c447d8f4f470954f76dbc
7
- data.tar.gz: fb152dd45ec55df52ee62c28610e0d5fd5cb8e9a708f06ecc1fbc5483b38a7472af85341d0cc391a0388905615d383b1d140922c243d962006d4152e791cc5e4
6
+ metadata.gz: db7827c87c482dab2e0a1e8852ba3c7d67f60d87954e799ceb1eb3001d7bbb09a54da74a7f18cd6e46686f0f9fefbec47820470c581cbc96d8c91d5634896c5a
7
+ data.tar.gz: 27ad4037efaae00d19654a9409992e08297864eac2bdd3482502f676e48480744a644c1b8f169e7fc274e958a004d3a25249556ca31e69eabc1498d66c1330f8
@@ -1,92 +1,14 @@
1
- require: rubocop-rspec
2
- inherit_from: .rubocop_todo.yml
3
- AllCops:
4
- Include:
5
- - Rakefile
6
- - lib/**/*.rake
7
-
8
- Lint/EndAlignment:
9
- EnforcedStyleAlignWith: variable
10
-
11
- Metrics/LineLength:
12
- Max: 100
13
-
14
- Style/CaseIndentation:
15
- EnforcedStyle: end
16
-
17
- Style/AlignParameters:
18
- EnforcedStyle: with_fixed_indentation
19
-
20
- Style/Documentation:
21
- Enabled: false
22
-
23
- Style/DoubleNegation:
24
- Enabled: false
25
-
26
- Style/IndentArray:
27
- EnforcedStyle: consistent
28
-
29
- Style/MultilineMethodCallIndentation:
30
- EnforcedStyle: indented
31
-
32
- Style/MultilineOperationIndentation:
33
- EnforcedStyle: indented
34
-
35
- # Disable Style/NumericLiterals so numbers don't need underscores
36
- Style/NumericLiterals:
37
- Enabled: false
38
-
39
- Style/NumericPredicate:
40
- EnforcedStyle: comparison
41
-
42
- Style/RedundantBegin:
43
- Enabled: false
1
+ inherit_gem:
2
+ percy-style:
3
+ - default.yml
44
4
 
45
- Style/RegexpLiteral:
46
- EnforcedStyle: slashes
47
- AllowInnerSlashes: true
48
5
 
49
- Style/SpaceInsideHashLiteralBraces:
50
- EnforcedStyle: no_space
51
-
52
- Style/TrailingCommaInArguments:
53
- EnforcedStyleForMultiline: consistent_comma
54
-
55
- Style/TrailingCommaInLiteral:
56
- EnforcedStyleForMultiline: consistent_comma
57
-
58
- RSpec/MessageSpies:
59
- EnforcedStyle: receive
60
-
61
- RSpec/ExampleLength:
62
- Enabled: false
63
-
64
- Style/FileName:
65
- Exclude:
66
- - 'Gemfile'
67
- - 'Guardfile'
68
- - 'percy-capybara.gemspec'
69
-
70
- Style/EmptyLineAfterMagicComment:
6
+ RSpec/InstanceVariable:
71
7
  Exclude:
72
- - 'percy-capybara.gemspec'
8
+ - spec/lib/percy/capybara_spec.rb
73
9
 
74
- Style/PercentLiteralDelimiters:
75
- Exclude:
76
- - 'percy-capybara.gemspec'
77
-
78
- Style/UnneededPercentQ:
79
- Exclude:
80
- - 'percy-capybara.gemspec'
81
-
82
- Style/RegexpLiteral:
83
- Exclude:
84
- - 'percy-capybara.gemspec'
85
-
86
- Style/SymbolArray:
87
- Exclude:
88
- - 'spec/spec_helper.rb'
10
+ RSpec/ContextWording:
11
+ Enabled: false
89
12
 
90
- # Will be able to do this in >= v1.11
91
- # RSpec/DescribedClass:
92
- # EnforcedStyle: explicit
13
+ AllCops:
14
+ TargetRubyVersion: 2.1
data/Gemfile CHANGED
@@ -8,11 +8,6 @@ gem 'guard-rspec', require: false
8
8
  # (for development)
9
9
  # gem 'percy-client', path: '~/src/percy-client'
10
10
 
11
- group :test do
12
- gem 'rubocop', '~> 0.48.0'
13
- gem 'rubocop-rspec'
14
- end
15
-
16
11
  group :test, :development do
17
12
  gem 'pry'
18
13
  end
@@ -34,7 +34,7 @@ module Percy
34
34
  @client = options[:client] || \
35
35
  Percy.client(client_info: _client_info, environment_info: _environment_info)
36
36
 
37
- return unless defined?(Rails)
37
+ return unless defined?(Rails) && defined?(Sprockets::Rails)
38
38
 
39
39
  @sprockets_environment = options[:sprockets_environment] || Rails.application.assets
40
40
  @sprockets_options = options[:sprockets_options] || Rails.application.config.assets
@@ -13,7 +13,7 @@ module Percy
13
13
  "sinatra/#{_sinatra_version}",
14
14
  "ember-cli-rails/#{_ember_cli_rails_version}",
15
15
  ].reject do |info|
16
- info =~ %r{\/$} # reject if version is empty
16
+ info =~ /\/$/ # reject if version is empty
17
17
  end.join('; ')
18
18
  end
19
19
 
@@ -4,7 +4,7 @@ require 'shellwords'
4
4
  module Percy
5
5
  module Capybara
6
6
  module HttpFetcher
7
- class Response < Struct.new(:body, :content_type); end
7
+ Response = Struct.new(:body, :content_type)
8
8
 
9
9
  def self.fetch(url)
10
10
  tempfile = Tempfile.new('percy-capybara-fetch')
@@ -8,8 +8,8 @@ module Percy
8
8
  # Resource loader that uses the native Capybara browser interface to discover resources.
9
9
  # This loader uses JavaScript to discover page resources, so specs must be tagged with
10
10
  # "js: true" because the default Rack::Test driver does not support executing JavaScript.
11
- class NativeLoader < BaseLoader # rubocop:disable ClassLength
12
- PATH_REGEX = %r{\A/[^\\s\"']*}
11
+ class NativeLoader < BaseLoader
12
+ PATH_REGEX = /\A\/[^\\s\"']*/
13
13
  DATA_URL_REGEX = /\Adata:/
14
14
  LOCAL_HOSTNAMES = [
15
15
  'localhost',
@@ -2,7 +2,7 @@ require 'percy/capybara/loaders/base_loader'
2
2
  require 'digest'
3
3
  require 'find'
4
4
  require 'set'
5
- require 'uri'
5
+ require 'addressable/uri'
6
6
 
7
7
  module Percy
8
8
  module Capybara
@@ -52,7 +52,7 @@ module Percy
52
52
  # TODO: more robust support for Sprockets usage outside Rails, ie Sinatra.
53
53
  # How do we find the correct path in that case?
54
54
  path = sprockets_options.digest ? asset.digest_path : logical_path
55
- resource_url = URI.escape("/assets/#{path}")
55
+ resource_url = Addressable::URI.escape("/assets/#{path}")
56
56
  end
57
57
 
58
58
  next if SKIP_RESOURCE_EXTENSIONS.include?(File.extname(resource_url))
@@ -1,5 +1,5 @@
1
1
  module Percy
2
2
  module Capybara
3
- VERSION = '3.1.1'.freeze
3
+ VERSION = '3.1.2'.freeze
4
4
  end
5
5
  end
@@ -19,6 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ['lib']
20
20
 
21
21
  spec.add_dependency 'percy-client', '~> 1.13'
22
+ spec.add_dependency 'addressable', '~> 2'
22
23
 
23
24
  spec.add_development_dependency 'bundler', '~> 1.7'
24
25
  spec.add_development_dependency 'rake', '~> 10.0'
@@ -29,5 +30,7 @@ Gem::Specification.new do |spec|
29
30
  spec.add_development_dependency 'webmock', '~> 1'
30
31
  spec.add_development_dependency 'mime-types', '< 3' # For Ruby 1.9 testing support.
31
32
  spec.add_development_dependency 'faraday', '>= 0.8'
33
+ spec.add_development_dependency 'httpclient', '~> 2.8'
32
34
  spec.add_development_dependency 'sprockets', '>= 3.2.0'
35
+ spec.add_development_dependency 'percy-style'
33
36
  end
@@ -6,7 +6,7 @@ RSpec.describe Percy::Capybara::Client::Builds do
6
6
  end
7
7
 
8
8
  describe '#initialize_build', type: :feature, js: true do
9
- before { setup_sprockets(capybara_client) }
9
+ before(:each) { setup_sprockets(capybara_client) }
10
10
 
11
11
  context 'percy is not enabled' do
12
12
  let(:enabled) { false }
@@ -152,7 +152,7 @@ RSpec.describe Percy::Capybara::Client::Builds do
152
152
  end
153
153
  end
154
154
  describe '#_upload_missing_build_resources', type: :feature, js: true do
155
- before { setup_sprockets(capybara_client) }
155
+ before(:each) { setup_sprockets(capybara_client) }
156
156
 
157
157
  it 'returns 0 if there are no missing build resources to upload' do
158
158
  mock_response = {
@@ -0,0 +1 @@
1
+ spec/lib/percy/capybara/client/rails_public_test_data/../symlink_test_data
@@ -42,7 +42,7 @@ RSpec.describe Percy::Capybara::Client::Snapshots, type: :feature do
42
42
  }
43
43
  end
44
44
 
45
- before do
45
+ before(:each) do
46
46
  setup_sprockets(capybara_client)
47
47
 
48
48
  visit '/'
@@ -27,7 +27,7 @@ RSpec.describe Percy::Capybara::Client::UserAgent do
27
27
  end
28
28
 
29
29
  context 'a loader is configured' do
30
- before { client.loader = :sprockets_loader }
30
+ before(:each) { client.loader = :sprockets_loader }
31
31
 
32
32
  it 'includes loader information' do
33
33
  expect(environment_info).to eq('percy-capybara-loader/sprockets_loader')
@@ -1,8 +1,8 @@
1
1
  RSpec.describe Percy::Capybara::Client do
2
2
  describe '#enabled?' do
3
3
  context 'when required environment variables set' do
4
- before { set_required_env_variables }
5
- after { clear_percy_env_variables }
4
+ before(:each) { set_required_env_variables }
5
+ after(:each) { clear_percy_env_variables }
6
6
 
7
7
  it 'is true when PERCY_ENABLE is 1' do
8
8
  ENV['PERCY_ENABLE'] = '1'
@@ -26,7 +26,7 @@ RSpec.describe Percy::Capybara::Client do
26
26
  end
27
27
 
28
28
  context 'when required environment variables not set' do
29
- before { clear_percy_env_variables }
29
+ before(:each) { clear_percy_env_variables }
30
30
 
31
31
  it 'is false' do
32
32
  ENV.delete 'PERCY_ENABLE'
@@ -114,6 +114,62 @@ RSpec.describe Percy::Capybara::Client do
114
114
  it 'passes client info down to the lower level Percy client' do
115
115
  expect(capybara_client.client.client_info).to eq("percy-capybara/#{Percy::Capybara::VERSION}")
116
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
117
173
  end
118
174
 
119
175
  describe '#initialize_loader' do
@@ -7,13 +7,13 @@ class RackAppWithIframe
7
7
  end
8
8
 
9
9
  RSpec.describe Percy::Capybara::Loaders::BaseLoader do
10
- let(:loader) { described_class.new }
10
+ let(:loader) { Percy::Capybara::Loaders::BaseLoader.new }
11
11
 
12
12
  describe '#root_html_resource', type: :feature, js: true do
13
13
  it 'includes the root DOM HTML' do
14
14
  visit '/'
15
15
 
16
- loader = described_class.new(page: page)
16
+ loader = Percy::Capybara::Loaders::BaseLoader.new(page: page)
17
17
  resource = loader.root_html_resource
18
18
 
19
19
  expect(resource.is_root).to be_truthy
@@ -27,7 +27,7 @@ RSpec.describe Percy::Capybara::Loaders::BaseLoader do
27
27
  it 'excludes the iframe by default' do
28
28
  visit '/test-iframe.html'
29
29
 
30
- loader = described_class.new(page: page)
30
+ loader = Percy::Capybara::Loaders::BaseLoader.new(page: page)
31
31
  resources = loader.iframes_resources
32
32
  expect(resources).to eq([])
33
33
  end
@@ -35,7 +35,7 @@ RSpec.describe Percy::Capybara::Loaders::BaseLoader do
35
35
  it 'includes the iframe with DOM HTML when include_iframes true' do
36
36
  visit '/test-iframe.html'
37
37
 
38
- loader = described_class.new(page: page, include_iframes: true)
38
+ loader = Percy::Capybara::Loaders::BaseLoader.new(page: page, include_iframes: true)
39
39
  resources = loader.iframes_resources
40
40
 
41
41
  expect(resources.size).to eq(1) # doesn't include iframe to remote host
@@ -49,7 +49,7 @@ RSpec.describe Percy::Capybara::Loaders::BaseLoader do
49
49
 
50
50
  expect(page).to receive(:within_frame).twice
51
51
  .and_raise(Capybara::Poltergeist::FrameNotFound, 'Hi')
52
- loader = described_class.new(page: page, include_iframes: true)
52
+ loader = Percy::Capybara::Loaders::BaseLoader.new(page: page, include_iframes: true)
53
53
  resources = loader.iframes_resources
54
54
  expect(resources.size).to eq(0)
55
55
  end
@@ -58,7 +58,7 @@ RSpec.describe Percy::Capybara::Loaders::BaseLoader do
58
58
 
59
59
  expect(page).to receive(:within_frame).twice
60
60
  .and_raise(Capybara::Poltergeist::TimeoutError, 'Hi')
61
- loader = described_class.new(page: page, include_iframes: true)
61
+ loader = Percy::Capybara::Loaders::BaseLoader.new(page: page, include_iframes: true)
62
62
  resources = loader.iframes_resources
63
63
  expect(resources.size).to eq(0)
64
64
  end
@@ -78,36 +78,36 @@ RSpec.describe Percy::Capybara::Loaders::BaseLoader do
78
78
  page_double = double('page')
79
79
 
80
80
  expect(page_double).to receive(:current_url).and_return('/')
81
- loader = described_class.new(page: page_double)
81
+ loader = Percy::Capybara::Loaders::BaseLoader.new(page: page_double)
82
82
  expect(loader.current_path).to eq('/')
83
83
 
84
84
  expect(page_double).to receive(:current_url).and_return('/test')
85
- loader = described_class.new(page: page_double)
85
+ loader = Percy::Capybara::Loaders::BaseLoader.new(page: page_double)
86
86
  expect(loader.current_path).to eq('/test')
87
87
 
88
88
  expect(page_double).to receive(:current_url).and_return('/test/a')
89
- loader = described_class.new(page: page_double)
89
+ loader = Percy::Capybara::Loaders::BaseLoader.new(page: page_double)
90
90
  expect(loader.current_path).to eq('/test/a')
91
91
 
92
92
  # Rack::Test returns a full example.com URL, so we want to make sure it is stripped:
93
93
  expect(page_double).to receive(:current_url).and_return('http://www.example.com/')
94
- loader = described_class.new(page: page_double)
94
+ loader = Percy::Capybara::Loaders::BaseLoader.new(page: page_double)
95
95
  expect(loader.current_path).to eq('/')
96
96
 
97
97
  expect(page_double).to receive(:current_url).and_return('about:srcdoc')
98
- loader = described_class.new(page: page_double)
98
+ loader = Percy::Capybara::Loaders::BaseLoader.new(page: page_double)
99
99
  expect(loader.current_path).to eq('/about:srcdoc')
100
100
  end
101
101
  end
102
102
 
103
103
  context 'Rack::Test', type: :feature do
104
- before { Capybara.app = RackAppWithIframe }
105
- after { Capybara.app = nil }
104
+ before(:each) { Capybara.app = RackAppWithIframe }
105
+ after(:each) { Capybara.app = nil }
106
106
 
107
107
  describe '#iframes_resources' do
108
108
  it 'is silently ignored' do
109
109
  visit '/test-iframe.html'
110
- loader = described_class.new(page: page)
110
+ loader = Percy::Capybara::Loaders::BaseLoader.new(page: page)
111
111
  expect(loader.iframes_resources).to eq([])
112
112
  end
113
113
  end
@@ -115,7 +115,8 @@ RSpec.describe Percy::Capybara::Loaders::BaseLoader do
115
115
 
116
116
  describe '#_uri_join' do
117
117
  it 'joins files into a uri' do
118
- expect(described_class.new.send(:_uri_join, 'foo/', '/bar', 'baz')).to eq('foo/bar/baz')
118
+ expect(Percy::Capybara::Loaders::BaseLoader.new.send(:_uri_join, 'foo/', '/bar', 'baz'))
119
+ .to eq('foo/bar/baz')
119
120
  end
120
121
  end
121
122
  end
@@ -12,7 +12,7 @@ RSpec.describe Percy::Capybara::Loaders::EmberCliRailsLoader do
12
12
  end
13
13
 
14
14
  let(:loader) do
15
- described_class.new(
15
+ Percy::Capybara::Loaders::EmberCliRailsLoader.new(
16
16
  mounted_apps,
17
17
  sprockets_environment: environment,
18
18
  sprockets_options: sprockets_options,
@@ -23,7 +23,7 @@ RSpec.describe Percy::Capybara::Loaders::EmberCliRailsLoader do
23
23
  options = instance_double('options')
24
24
  # Set specific files we want to compile. In normal use, this would be all asset files.
25
25
  # For this test we just use .svg files
26
- precompile_list = [%r{(?:/|\\|\A)\.svg}]
26
+ precompile_list = [/(?:\/|\\|\A)\.svg/]
27
27
  allow(options).to receive(:precompile).and_return(precompile_list)
28
28
  allow(options).to receive(:digest).and_return(digest_enabled)
29
29
  options
@@ -32,7 +32,7 @@ RSpec.describe Percy::Capybara::Loaders::EmberCliRailsLoader do
32
32
  describe 'initialize' do
33
33
  context 'all args supplied' do
34
34
  it 'successfully initializes' do
35
- expect { loader }.not_to raise_error
35
+ expect { loader }.to_not raise_error
36
36
  end
37
37
  end
38
38
 
@@ -54,12 +54,15 @@ RSpec.describe Percy::Capybara::Loaders::EmberCliRailsLoader do
54
54
  let(:mount_path) { mounted_apps.values.first }
55
55
  let(:dist_dir) { File.join(assets_dir, 'ember-cli', ember_app.to_s) }
56
56
  let(:loader) do
57
- described_class.new(mounted_apps, sprockets_environment: environment,
58
- sprockets_options: sprockets_options,)
57
+ Percy::Capybara::Loaders::EmberCliRailsLoader.new(
58
+ mounted_apps,
59
+ sprockets_environment: environment,
60
+ sprockets_options: sprockets_options,
61
+ )
59
62
  end
60
63
 
61
64
  context "called '#{ember_app}' and mounted at '#{mount_path}'" do
62
- before do
65
+ before(:each) do
63
66
  allow(loader).to receive(:_dist_path_for_app).and_return(dist_dir)
64
67
  end
65
68
 
@@ -2,7 +2,13 @@ RSpec.describe Percy::Capybara::Loaders::FilesystemLoader do
2
2
  let(:fake_page) { OpenStruct.new(current_url: 'http://localhost/foo') }
3
3
  let(:assets_dir) { File.expand_path('../../client/test_data', __FILE__) }
4
4
  let(:base_url) { '/url-prefix/' }
5
- let(:loader) { described_class.new(base_url: base_url, assets_dir: assets_dir, page: fake_page) }
5
+ let(:loader) do
6
+ Percy::Capybara::Loaders::FilesystemLoader.new(
7
+ base_url: base_url,
8
+ assets_dir: assets_dir,
9
+ page: fake_page,
10
+ )
11
+ end
6
12
 
7
13
  describe 'initialize' do
8
14
  context 'assets_dir not specified' do
@@ -31,12 +37,20 @@ RSpec.describe Percy::Capybara::Loaders::FilesystemLoader do
31
37
  describe '#snapshot_resources', type: :feature, js: true do
32
38
  it 'returns the root HTML' do
33
39
  visit '/'
34
- loader = described_class.new(base_url: base_url, assets_dir: assets_dir, page: page)
40
+ loader = Percy::Capybara::Loaders::FilesystemLoader.new(
41
+ base_url: base_url,
42
+ assets_dir: assets_dir,
43
+ page: page,
44
+ )
35
45
  expect(loader.snapshot_resources.collect(&:resource_url)).to match_array(['/'])
36
46
  end
37
47
  it 'returns the visited html resource' do
38
48
  visit '/test-css.html'
39
- loader = described_class.new(base_url: base_url, assets_dir: assets_dir, page: page)
49
+ loader = Percy::Capybara::Loaders::FilesystemLoader.new(
50
+ base_url: base_url,
51
+ assets_dir: assets_dir,
52
+ page: page,
53
+ )
40
54
  resource_urls = loader.snapshot_resources.collect(&:resource_url)
41
55
  expect(resource_urls).to match_array(['/test-css.html'])
42
56
  end
@@ -112,19 +126,31 @@ RSpec.describe Percy::Capybara::Loaders::FilesystemLoader do
112
126
  expect(actual_urls).to match_array(expected_urls)
113
127
  end
114
128
  it 'works with different base_url configs' do
115
- loader = described_class.new(base_url: '/url-prefix/', assets_dir: assets_dir)
129
+ loader = Percy::Capybara::Loaders::FilesystemLoader.new(
130
+ base_url: '/url-prefix/',
131
+ assets_dir: assets_dir,
132
+ )
116
133
  expected_urls = loader.build_resources.collect(&:resource_url)
117
134
  expect(expected_urls).to include('/url-prefix/css/font.css')
118
135
 
119
- loader = described_class.new(base_url: '/url-prefix', assets_dir: assets_dir)
136
+ loader = Percy::Capybara::Loaders::FilesystemLoader.new(
137
+ base_url: '/url-prefix',
138
+ assets_dir: assets_dir,
139
+ )
120
140
  expected_urls = loader.build_resources.collect(&:resource_url)
121
141
  expect(expected_urls).to include('/url-prefix/css/font.css')
122
142
 
123
- loader = described_class.new(base_url: '/', assets_dir: assets_dir)
143
+ loader = Percy::Capybara::Loaders::FilesystemLoader.new(
144
+ base_url: '/',
145
+ assets_dir: assets_dir,
146
+ )
124
147
  expected_urls = loader.build_resources.collect(&:resource_url)
125
148
  expect(expected_urls).to include('/css/font.css')
126
149
 
127
- loader = described_class.new(base_url: '', assets_dir: assets_dir)
150
+ loader = Percy::Capybara::Loaders::FilesystemLoader.new(
151
+ base_url: '',
152
+ assets_dir: assets_dir,
153
+ )
128
154
  expected_urls = loader.build_resources.collect(&:resource_url)
129
155
  expect(expected_urls).to include('/css/font.css')
130
156
  end
@@ -1,7 +1,9 @@
1
1
  RSpec.describe Percy::Capybara::Loaders::NativeLoader do
2
2
  let(:fake_page) { OpenStruct.new(current_url: 'http://localhost/foo') }
3
3
  let(:asset_hostnames) { nil }
4
- let(:loader) { described_class.new(page: fake_page, asset_hostnames: asset_hostnames) }
4
+ let(:loader) do
5
+ Percy::Capybara::Loaders::NativeLoader.new(page: fake_page, asset_hostnames: asset_hostnames)
6
+ end
5
7
 
6
8
  describe '#build_resources' do
7
9
  it 'returns an empty list' do
@@ -11,12 +13,12 @@ RSpec.describe Percy::Capybara::Loaders::NativeLoader do
11
13
  describe '#snapshot_resources', type: :feature, js: true do
12
14
  it 'returns the root HTML' do
13
15
  visit '/'
14
- loader = described_class.new(page: page)
16
+ loader = Percy::Capybara::Loaders::NativeLoader.new(page: page)
15
17
  expect(loader.snapshot_resources.collect(&:resource_url)).to match_array(['/'])
16
18
  end
17
19
  it 'returns the root HTML and CSS resources' do
18
20
  visit '/test-css.html'
19
- loader = described_class.new(page: page)
21
+ loader = Percy::Capybara::Loaders::NativeLoader.new(page: page)
20
22
  resource_urls = loader.snapshot_resources.collect(&:resource_url)
21
23
  expect(resource_urls).to match_array(
22
24
  [
@@ -32,7 +34,7 @@ RSpec.describe Percy::Capybara::Loaders::NativeLoader do
32
34
  end
33
35
  it 'returns the font resources' do
34
36
  visit '/test-font.html'
35
- loader = described_class.new(page: page)
37
+ loader = Percy::Capybara::Loaders::NativeLoader.new(page: page)
36
38
  resource_urls = loader.snapshot_resources.collect(&:resource_url)
37
39
  expect(resource_urls).to match_array(
38
40
  [
@@ -44,7 +46,7 @@ RSpec.describe Percy::Capybara::Loaders::NativeLoader do
44
46
  end
45
47
  it 'returns the root HTML and image resources' do
46
48
  visit '/test-images.html'
47
- loader = described_class.new(page: page)
49
+ loader = Percy::Capybara::Loaders::NativeLoader.new(page: page)
48
50
  resource_urls = loader.snapshot_resources.collect(&:resource_url)
49
51
  expect(resource_urls).to match_array(
50
52
  [
@@ -65,15 +67,15 @@ RSpec.describe Percy::Capybara::Loaders::NativeLoader do
65
67
  describe 'nonlocal.me', type: :feature, js: true do
66
68
  let(:orig_app_host) { Capybara.app_host }
67
69
 
68
- before do
70
+ before(:each) do
69
71
  Capybara.app_host = Capybara.app_host.gsub('http://localhost:', 'http://localtest.me:')
70
72
  end
71
- after do
73
+ after(:each) do
72
74
  Capybara.app_host = orig_app_host
73
75
  end
74
76
  it 'returns the root HTML and image resources' do
75
77
  visit '/test-localtest-me-images.html'
76
- loader = described_class.new(page: page)
78
+ loader = Percy::Capybara::Loaders::NativeLoader.new(page: page)
77
79
  resource_urls = loader.snapshot_resources.collect(&:resource_url)
78
80
  expect(resource_urls).to eq(
79
81
  [
@@ -159,7 +161,7 @@ RSpec.describe Percy::Capybara::Loaders::NativeLoader do
159
161
  it 'includes all linked and imported stylesheets' do
160
162
  visit '/test-css.html'
161
163
 
162
- loader = described_class.new(page: page)
164
+ loader = Percy::Capybara::Loaders::NativeLoader.new(page: page)
163
165
  resources = loader.send(:_get_css_resources)
164
166
 
165
167
  resource = find_resource(resources, '/css/base.css')
@@ -198,7 +200,7 @@ RSpec.describe Percy::Capybara::Loaders::NativeLoader do
198
200
  it 'includes all images' do
199
201
  visit '/test-images.html'
200
202
 
201
- loader = described_class.new(page: page)
203
+ loader = Percy::Capybara::Loaders::NativeLoader.new(page: page)
202
204
  loader.instance_variable_set(:@urls_referred_by_css, [])
203
205
  resources = loader.send(:_get_image_resources)
204
206
 
@@ -225,7 +227,7 @@ RSpec.describe Percy::Capybara::Loaders::NativeLoader do
225
227
  content = File.read(path)
226
228
  # In Ruby 1.9.3 the SVG mimetype is not registered so our mini ruby webserver doesn't serve
227
229
  # the correct content type. Allow either to work here so we can test older Rubies fully.
228
- expect(resource.mimetype).to match(%r{image/svg\+xml|application/octet-stream})
230
+ expect(resource.mimetype).to match(/image\/svg\+xml|application\/octet-stream/)
229
231
  expected_sha = Digest::SHA256.hexdigest(content)
230
232
  expect(Digest::SHA256.hexdigest(resource.content)).to eq(expected_sha)
231
233
  expect(resource.sha).to eq(expected_sha)
@@ -14,7 +14,7 @@ RSpec.describe Percy::Capybara::Loaders::SprocketsLoader do
14
14
  File.expand_path('../../client/rails_public_test_data', __FILE__)
15
15
  end
16
16
  let(:loader) do
17
- described_class.new(
17
+ Percy::Capybara::Loaders::SprocketsLoader.new(
18
18
  page: page,
19
19
  sprockets_environment: environment,
20
20
  sprockets_options: sprockets_options,
@@ -29,7 +29,7 @@ RSpec.describe Percy::Capybara::Loaders::SprocketsLoader do
29
29
  let(:sprockets_options) do
30
30
  options = double('options')
31
31
  # Set specific files we want to compile. In normal use, this would be all asset files.
32
- precompile_list = [%r{(?:/|\\|\A)(base|digested)\.(css|js)$|\.map|\.png}]
32
+ precompile_list = [/(?:\/|\\|\A)(base|digested)\.(css|js)$|\.map|\.png/]
33
33
  allow(options).to receive(:precompile).and_return(precompile_list)
34
34
  allow(options).to receive(:digest).and_return(digest_enabled)
35
35
  options
@@ -37,7 +37,7 @@ RSpec.describe Percy::Capybara::Loaders::SprocketsLoader do
37
37
 
38
38
  describe '#snapshot_resources' do
39
39
  context 'Rack::Test', type: :feature do
40
- before { Capybara.app = SimpleRackApp }
40
+ before(:each) { Capybara.app = SimpleRackApp }
41
41
 
42
42
  it 'returns the root HTML resource' do
43
43
  visit '/'
@@ -78,7 +78,7 @@ RSpec.describe Percy::Capybara::Loaders::SprocketsLoader do
78
78
  expect(resources.first.content).to include('.colored-by-base')
79
79
  end
80
80
  context 'Rails app' do
81
- before do
81
+ def setup_rails_double
82
82
  # Pretend like we're in a Rails app right now, all we care about is Rails.public_path.
83
83
  rails_double = double('Rails')
84
84
  # Pretend like the entire test_data directory is the public/ folder.
@@ -87,6 +87,7 @@ RSpec.describe Percy::Capybara::Loaders::SprocketsLoader do
87
87
  expect(loader).to receive(:_rails).at_least(:once).and_return(rails_double)
88
88
  end
89
89
  it 'includes files from the public folder (non-asset-pipeline)' do
90
+ setup_rails_double
90
91
  resources = loader.build_resources
91
92
  # Weak test that more things are in this list, because it merges asset pipeline with public.
92
93
  expect(resources.length).to be > 5
@@ -95,7 +96,7 @@ RSpec.describe Percy::Capybara::Loaders::SprocketsLoader do
95
96
  expect(resource_urls).to include('/assets/images/bg-relative.png') # From asset pipeline.
96
97
  expect(resource_urls).to include('/percy-from-public.svg') # Public merged into root.
97
98
  expect(resource_urls).to include('/symlink_to_images/test.png') # Symlink in public dir.
98
- expect(resource_urls).not_to include('/large-file-skipped.png') # Public merged into root.
99
+ expect(resource_urls).to_not include('/large-file-skipped.png') # Public merged into root.
99
100
  end
100
101
  context 'digest enabled' do
101
102
  let(:digest_enabled) { true }
@@ -104,6 +105,7 @@ RSpec.describe Percy::Capybara::Loaders::SprocketsLoader do
104
105
  # This makes sure that we correctly merge already-compiled files in the assets directory
105
106
  # with ones from the asset pipeline. This means that Rails users who have
106
107
  # `config.assets.digest = true` set can safely run "rake assets:precompile" before tests.
108
+ setup_rails_double
107
109
  resources = loader.build_resources
108
110
  expected_digest_url = \
109
111
  '/assets/css/digested-f3420c6aee71c137a3ca39727052811bae84b2f37' \
@@ -1,10 +1,10 @@
1
1
  RSpec.describe Percy::Capybara do
2
- before do
2
+ before(:each) do
3
3
  Percy::Capybara.reset!
4
4
  @original_env = ENV['TRAVIS_BUILD_ID']
5
5
  ENV['TRAVIS_BUILD_ID'] = nil
6
6
  end
7
- after do
7
+ after(:each) do
8
8
  ENV['TRAVIS_BUILD_ID'] = @original_env
9
9
  ENV.delete('PERCY_ENABLE')
10
10
  end
@@ -41,11 +41,11 @@ RSpec.describe Percy::Capybara do
41
41
  end
42
42
  describe '#finalize_build' do
43
43
  it 'returns silently if no build is initialized' do
44
- expect { Percy::Capybara.finalize_build }.not_to raise_error
44
+ expect { Percy::Capybara.finalize_build }.to_not raise_error
45
45
  end
46
46
  it 'delegates to Percy::Capybara::Client' do
47
47
  capybara_client = Percy::Capybara.capybara_client
48
- expect(capybara_client).to receive(:enabled?).and_return(:true)
48
+ expect(capybara_client).to receive(:enabled?).and_return(true)
49
49
  build_data = {'data' => {'id' => 123}}
50
50
  expect(capybara_client.client).to receive(:create_build).and_return(build_data).once
51
51
  Percy::Capybara.initialize_build
@@ -55,9 +55,9 @@ RSpec.describe Percy::Capybara do
55
55
  it 'silently skips if disabled' do
56
56
  ENV['PERCY_ENABLE'] = '0'
57
57
  capybara_client = Percy::Capybara.capybara_client
58
- expect(capybara_client.client).not_to receive(:create_build)
58
+ expect(capybara_client.client).to_not receive(:create_build)
59
59
  Percy::Capybara.initialize_build
60
- expect(capybara_client).not_to receive(:finalize_current_build)
60
+ expect(capybara_client).to_not receive(:finalize_current_build)
61
61
  Percy::Capybara.finalize_build
62
62
  end
63
63
  end
@@ -65,7 +65,7 @@ RSpec.describe Percy::Capybara do
65
65
  it 'clears the current capybara_client' do
66
66
  capybara_client = Percy::Capybara.capybara_client
67
67
  Percy::Capybara.reset!
68
- expect(Percy::Capybara.capybara_client).not_to eq(capybara_client)
68
+ expect(Percy::Capybara.capybara_client).to_not eq(capybara_client)
69
69
  end
70
70
  end
71
71
  describe '#disable!' do
@@ -82,7 +82,7 @@ RSpec.describe Percy::Capybara do
82
82
  class DummyLoader < Percy::Capybara::Loaders::NativeLoader; end
83
83
 
84
84
  it 'sets the current capybara client\'s loader' do
85
- expect(Percy::Capybara.capybara_client.loader).not_to be
85
+ expect(Percy::Capybara.capybara_client.loader).to_not be
86
86
  Percy::Capybara.reset!
87
87
 
88
88
  Percy::Capybara.use_loader(DummyLoader)
@@ -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 do
41
+ config.before(:each) do
42
42
  WebMock.disable_net_connect!(allow_localhost: true)
43
43
  end
44
44
  config.before(:each, type: :feature) do
@@ -40,7 +40,7 @@ module TestHelpers
40
40
  environment.append_path '.'
41
41
 
42
42
  sprockets_options = double('sprockets_options')
43
- allow(sprockets_options).to receive(:precompile).and_return([%r{(?:/|\\|\A)base\.(css|js)$}])
43
+ allow(sprockets_options).to receive(:precompile).and_return([/(?:\/|\\|\A)base\.(css|js)$/])
44
44
  allow(sprockets_options).to receive(:digest).and_return(false)
45
45
 
46
46
  capybara_client.sprockets_environment = environment
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.1
4
+ version: 3.1.2
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-23 00:00:00.000000000 Z
11
+ date: 2018-01-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: percy-client
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.13'
27
+ - !ruby/object:Gem::Dependency
28
+ name: addressable
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -150,6 +164,20 @@ dependencies:
150
164
  - - ">="
151
165
  - !ruby/object:Gem::Version
152
166
  version: '0.8'
167
+ - !ruby/object:Gem::Dependency
168
+ name: httpclient
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - "~>"
172
+ - !ruby/object:Gem::Version
173
+ version: '2.8'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - "~>"
179
+ - !ruby/object:Gem::Version
180
+ version: '2.8'
153
181
  - !ruby/object:Gem::Dependency
154
182
  name: sprockets
155
183
  requirement: !ruby/object:Gem::Requirement
@@ -164,6 +192,20 @@ dependencies:
164
192
  - - ">="
165
193
  - !ruby/object:Gem::Version
166
194
  version: 3.2.0
195
+ - !ruby/object:Gem::Dependency
196
+ name: percy-style
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - ">="
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ type: :development
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - ">="
207
+ - !ruby/object:Gem::Version
208
+ version: '0'
167
209
  description: ''
168
210
  email:
169
211
  - team@percy.io
@@ -174,7 +216,6 @@ files:
174
216
  - ".gitignore"
175
217
  - ".rspec"
176
218
  - ".rubocop.yml"
177
- - ".rubocop_todo.yml"
178
219
  - ".travis.yml"
179
220
  - ".yardopts"
180
221
  - CHANGELOG.md
@@ -208,6 +249,7 @@ files:
208
249
  - spec/lib/percy/capybara/client/ember_test_data/ember-cli/frontend/percy-frontend-public.svg
209
250
  - spec/lib/percy/capybara/client/rails_public_test_data/large-file-skipped.png
210
251
  - spec/lib/percy/capybara/client/rails_public_test_data/percy-from-public.svg
252
+ - spec/lib/percy/capybara/client/rails_public_test_data/symlink_to_images
211
253
  - spec/lib/percy/capybara/client/snapshots_spec.rb
212
254
  - spec/lib/percy/capybara/client/symlink_test_data/test.png
213
255
  - spec/lib/percy/capybara/client/test_data/assets/css/digested-f3420c6aee71c137a3ca39727052811bae84b2f37d898f4db242e20656a1579e.css
@@ -269,7 +311,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
269
311
  version: '0'
270
312
  requirements: []
271
313
  rubyforge_project:
272
- rubygems_version: 2.4.5.2
314
+ rubygems_version: 2.6.13
273
315
  signing_key:
274
316
  specification_version: 4
275
317
  summary: Percy::Capybara
@@ -283,6 +325,7 @@ test_files:
283
325
  - spec/lib/percy/capybara/client/ember_test_data/ember-cli/frontend/percy-frontend-public.svg
284
326
  - spec/lib/percy/capybara/client/rails_public_test_data/large-file-skipped.png
285
327
  - spec/lib/percy/capybara/client/rails_public_test_data/percy-from-public.svg
328
+ - spec/lib/percy/capybara/client/rails_public_test_data/symlink_to_images
286
329
  - spec/lib/percy/capybara/client/snapshots_spec.rb
287
330
  - spec/lib/percy/capybara/client/symlink_test_data/test.png
288
331
  - spec/lib/percy/capybara/client/test_data/assets/css/digested-f3420c6aee71c137a3ca39727052811bae84b2f37d898f4db242e20656a1579e.css
@@ -1,86 +0,0 @@
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: 300
17
-
18
- # Offense count: 1
19
- # Configuration parameters: CountComments.
20
- Metrics/ClassLength:
21
- Max: 200
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
- Enabled: false
71
-
72
- # Offense count: 10
73
- # Configuration parameters: IgnoreSymbolicNames.
74
- RSpec/VerifiedDoubles:
75
- Exclude:
76
- - 'spec/lib/percy/capybara/client/builds_spec.rb'
77
- - 'spec/lib/percy/capybara/client_spec.rb'
78
- - 'spec/lib/percy/capybara/loaders/base_loader_spec.rb'
79
- - 'spec/lib/percy/capybara/loaders/sprockets_loader_spec.rb'
80
- - 'spec/lib/percy/capybara_spec.rb'
81
- - 'spec/support/test_helpers.rb'
82
-
83
- # Offense count: 1
84
- Style/StructInheritance:
85
- Exclude:
86
- - 'lib/percy/capybara/httpfetcher.rb'