percy-capybara 2.4.5 → 2.5.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: e561d868086de68aa397b3e538011fc091dda1b6
4
- data.tar.gz: 60546d75deeba4888104d845e044dda785618ffe
3
+ metadata.gz: a93e613a082603c5384a75f77067ba5f9c54d610
4
+ data.tar.gz: 78c5eaf278c3216124c5f1f0e1bd8d8bfc9face1
5
5
  SHA512:
6
- metadata.gz: 24fc1254f9ab3c787044f1a56197cb45c58e94c1444b8e256a5c00fb3262dab1d8ed9b37d05495c0266b8f2df4a0509b47499162e1c4e2bc820c2143b839424d
7
- data.tar.gz: e061a97734fceac8e4cb050cbdc492797dc02157496b871ada5d7fd60157f37005cc21eb0cc154441057ddac40cf1f6e7bde940add9c21e1c614c16f3c3daba0
6
+ metadata.gz: 206802cab6fac788341736da0cd30ff3775d88b4e87d498126fb826025924d94b2e06135bc6d895cecc49e9bd01e850b0f5f993b3b51e933fbfc2747944f0689
7
+ data.tar.gz: ab66d080a77fbd298288bafe18ca27014f66c62e5e57cc5274209f298962a1e8a202c84bf796c48565c2e6f74d831e759f83895e50fe6f15d634715483b5bff8
@@ -0,0 +1,37 @@
1
+ require 'percy/capybara'
2
+ require 'capybara/poltergeist'
3
+
4
+ module Percy
5
+ module Capybara
6
+ # Simple block runner for self-contained Capybara tests.
7
+ #
8
+ # Requires:
9
+ # - poltergeist gem (which requires phantomjs)
10
+ # Usage:
11
+ # Percy::Capybara::Anywhere.run(SERVER, ASSETS_DIR, ASSETS_BASE_URL) do |page|
12
+ # page.visit('/')
13
+ # Percy::Capybara.snapshot(page, name: 'main page')
14
+ # end
15
+ module Anywhere
16
+ def self.run(server, assets_dir, assets_base_url = nil)
17
+ unless ENV['PERCY_PROJECT'] && ENV['PERCY_TOKEN']
18
+ raise 'Whoops! You need to setup the PERCY_PROJECT and PERCY_TOKEN environment variables.'
19
+ end
20
+
21
+ ::Capybara.run_server = false
22
+ ::Capybara.app_host = server
23
+ page = ::Capybara::Session.new(:poltergeist)
24
+
25
+ Percy::Capybara.use_loader(:filesystem, assets_dir: assets_dir, base_url: assets_base_url)
26
+ build = Percy::Capybara.initialize_build
27
+
28
+ yield(page)
29
+
30
+ Percy::Capybara.finalize_build
31
+ puts
32
+ puts 'Done! Percy snapshots are now processing...'
33
+ puts "--> #{build['data']['attributes']['web-url']}"
34
+ end
35
+ end
36
+ end
37
+ end
@@ -1,3 +1,5 @@
1
+ require 'percy/capybara'
2
+
1
3
  module Percy
2
4
  module Capybara
3
5
  module Loaders
@@ -17,7 +17,7 @@ module Percy
17
17
  def initialize(options = {})
18
18
  # @assets_dir should point to a _compiled_ static assets directory, not source assets.
19
19
  @assets_dir = options[:assets_dir]
20
- @base_url = options[:base_url] || ''
20
+ @base_url = options[:base_url] || '/'
21
21
 
22
22
  raise ArgumentError, 'assets_dir is required' if @assets_dir.nil? || @assets_dir == ''
23
23
  unless Pathname.new(@assets_dir).absolute?
@@ -45,7 +45,7 @@ module Percy
45
45
  next if File.size(path) > MAX_FILESIZE_BYTES
46
46
 
47
47
  # Replace the assets_dir with the base_url to generate the resource_url
48
- resource_url = path.sub(@assets_dir, @base_url)
48
+ resource_url = @base_url.chomp('/') + path.sub(@assets_dir, '')
49
49
 
50
50
  sha = Digest::SHA256.hexdigest(File.read(path))
51
51
  resources << Percy::Client::Resource.new(resource_url, sha: sha, path: path)
@@ -1,5 +1,5 @@
1
1
  module Percy
2
2
  module Capybara
3
- VERSION = '2.4.5'.freeze
3
+ VERSION = '2.5.0'.freeze
4
4
  end
5
5
  end
@@ -10,6 +10,7 @@ RSpec.describe Percy::Capybara::Client::Builds do
10
10
 
11
11
  context 'percy is not enabled' do
12
12
  let(:enabled) { false }
13
+
13
14
  it 'returns nil if not enabled' do
14
15
  expect(capybara_client.initialize_build).to be_nil
15
16
  end
@@ -42,6 +42,7 @@ RSpec.describe Percy::Capybara::Client::Snapshots, type: :feature do
42
42
  },
43
43
  }
44
44
  end
45
+
45
46
  before do
46
47
  setup_sprockets(capybara_client)
47
48
 
@@ -47,6 +47,7 @@ RSpec.describe Percy::Capybara::Client do
47
47
  end
48
48
  describe '#rescue_connection_failures' do
49
49
  let(:capybara_client) { Percy::Capybara::Client.new(enabled: true) }
50
+
50
51
  it 'returns block result on success' do
51
52
  result = capybara_client.rescue_connection_failures do
52
53
  true
@@ -1,24 +1,27 @@
1
1
  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/testdata', __FILE__) }
4
- let(:base_url) { '/url-prefix' }
4
+ let(:base_url) { '/url-prefix/' }
5
5
  let(:loader) { described_class.new(base_url: base_url, assets_dir: assets_dir, page: fake_page) }
6
6
 
7
7
  describe 'initialize' do
8
8
  context 'assets_dir not specified' do
9
9
  let(:assets_dir) { nil }
10
+
10
11
  it 'raises an error' do
11
12
  expect { loader }.to raise_error(ArgumentError)
12
13
  end
13
14
  end
14
15
  context 'assets_dir is not an absolute path' do
15
16
  let(:assets_dir) { '../../client/testdata' }
17
+
16
18
  it 'raises an error' do
17
19
  expect { loader }.to raise_error(ArgumentError)
18
20
  end
19
21
  end
20
22
  context 'assets_dir doesn\'t exist' do
21
23
  let(:assets_dir) { File.expand_path('../../client/testdata-doesnt-exist', __FILE__) }
24
+
22
25
  it 'raises an error' do
23
26
  expect { loader }.to raise_error(ArgumentError)
24
27
  end
@@ -110,9 +113,27 @@ RSpec.describe Percy::Capybara::Loaders::FilesystemLoader do
110
113
  ]
111
114
  expect(actual_urls).to match_array(expected_urls)
112
115
  end
116
+ it 'works with different base_url configs' do
117
+ loader = described_class.new(base_url: '/url-prefix/', assets_dir: assets_dir)
118
+ expected_urls = loader.build_resources.collect(&:resource_url)
119
+ expect(expected_urls).to include('/url-prefix/css/font.css')
120
+
121
+ loader = described_class.new(base_url: '/url-prefix', assets_dir: assets_dir)
122
+ expected_urls = loader.build_resources.collect(&:resource_url)
123
+ expect(expected_urls).to include('/url-prefix/css/font.css')
124
+
125
+ loader = described_class.new(base_url: '/', assets_dir: assets_dir)
126
+ expected_urls = loader.build_resources.collect(&:resource_url)
127
+ expect(expected_urls).to include('/css/font.css')
128
+
129
+ loader = described_class.new(base_url: '', assets_dir: assets_dir)
130
+ expected_urls = loader.build_resources.collect(&:resource_url)
131
+ expect(expected_urls).to include('/css/font.css')
132
+ end
113
133
  end
114
134
  context 'assets_dir with only skippable resources' do
115
135
  let(:assets_dir) { File.expand_path('../../client/testdata/assets/images', __FILE__) }
136
+
116
137
  it 'returns an empty list' do
117
138
  expect(loader.build_resources).to eq([])
118
139
  end
@@ -64,6 +64,7 @@ RSpec.describe Percy::Capybara::Loaders::NativeLoader do
64
64
  end
65
65
  describe 'nonlocal.me', type: :feature, js: true do
66
66
  let(:orig_app_host) { Capybara.app_host }
67
+
67
68
  before do
68
69
  Capybara.app_host = Capybara.app_host.gsub('http://localhost:', 'http://localtest.me:')
69
70
  end
@@ -113,6 +114,7 @@ RSpec.describe Percy::Capybara::Loaders::NativeLoader do
113
114
 
114
115
  context 'when loader is initialised with asset hostnames' do
115
116
  let(:asset_hostnames) { ['dev.local'] }
117
+
116
118
  context 'with the same port' do
117
119
  it 'returns in accordance with asset_hostnames' do
118
120
  expect(loader._should_include_url?('http://dev.local/')).to eq(true)
@@ -136,6 +138,7 @@ RSpec.describe Percy::Capybara::Loaders::NativeLoader do
136
138
  end
137
139
  context 'for nonlocal hosts' do
138
140
  let(:fake_page) { OpenStruct.new(current_url: 'http://foo:123/') }
141
+
139
142
  it 'returns true for the same host port' do
140
143
  expect(loader._should_include_url?('http://foo:123/')).to eq(true)
141
144
  expect(loader._should_include_url?('http://foo:123/bar')).to eq(true)
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: 2.4.5
4
+ version: 2.5.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: 2017-02-22 00:00:00.000000000 Z
11
+ date: 2017-03-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: percy-client
@@ -190,6 +190,7 @@ files:
190
190
  - README.md
191
191
  - Rakefile
192
192
  - lib/percy/capybara.rb
193
+ - lib/percy/capybara/anywhere.rb
193
194
  - lib/percy/capybara/client.rb
194
195
  - lib/percy/capybara/client/builds.rb
195
196
  - lib/percy/capybara/client/snapshots.rb
@@ -262,7 +263,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
262
263
  version: '0'
263
264
  requirements: []
264
265
  rubyforge_project:
265
- rubygems_version: 2.4.8
266
+ rubygems_version: 2.6.7
266
267
  signing_key:
267
268
  specification_version: 4
268
269
  summary: Percy::Capybara