percy-capybara 1.1.0 → 1.2.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: b1916f2f89e65fa1b84d3ed78419dbb3f50d2dc9
4
- data.tar.gz: 89c56cf4008d5c68f4ec32cc24fde00f7372bc20
3
+ metadata.gz: 700625bc07e0be50c30a6e9838280e5b642395dc
4
+ data.tar.gz: f56557aaa8909e676cfbd638655ea506bcd99867
5
5
  SHA512:
6
- metadata.gz: eccf59f4d2d8938770ed17df991f3bbe707c7a6bb3ae4b60d616ba7c89911d11d176909ec6e1e9840a81327a74959b5d8cb6522bf2863ac98f996eff0e2e8ea4
7
- data.tar.gz: 9c45e1da8389ad5f3eee15479bb73087b5c7ba37580d83fc8a1b163f4af63ac4b1f2d44f8a72071e8fe836356e261fee81d644871817eda338b041989b742a54
6
+ metadata.gz: ee826f8bab3a6f19233b7a85acade3509e62cf65fccfb82c21332eca520908b0579a3c03e099202cfeea0a700e7d21e001a2b0cdc70aef8efce8c10292dcf331
7
+ data.tar.gz: 340ddc44575e7bc6ceaed558494b94cef8e8cf2a4c7bf3e5e0499fe6d77047821d4cc25b91b8c7a0c433ebf0a729e19f57baef951fd2ad28d13fdd433209646b
@@ -1,5 +1,6 @@
1
1
  require 'percy/capybara/loaders/base_loader'
2
2
  require 'digest'
3
+ require 'find'
3
4
  require 'uri'
4
5
 
5
6
  module Percy
@@ -30,6 +31,8 @@ module Percy
30
31
 
31
32
  def build_resources
32
33
  resources = []
34
+
35
+ # Load resources from the asset pipeline.
33
36
  _asset_logical_paths.each do |logical_path|
34
37
  next if SKIP_RESOURCE_EXTENSIONS.include?(File.extname(logical_path))
35
38
 
@@ -48,12 +51,37 @@ module Percy
48
51
  end
49
52
 
50
53
  next if SKIP_RESOURCE_EXTENSIONS.include?(File.extname(resource_url))
51
-
52
54
  resources << Percy::Client::Resource.new(resource_url, sha: sha, content: content)
53
55
  end
56
+
57
+ # Load resources from the public/ directory, if a Rails app.
58
+ if _rails
59
+ public_path = _rails.public_path.to_s
60
+ Find.find(public_path).each do |path|
61
+ # Skip directories.
62
+ next if !FileTest.file?(path)
63
+ # Skip certain extensions.
64
+ next if SKIP_RESOURCE_EXTENSIONS.include?(File.extname(path))
65
+
66
+ # Strip the public_path from the beginning of the resource_url.
67
+ # This assumes that everything in the Rails public/ directory is served at the root
68
+ # of the app.
69
+ resource_url = path.sub(public_path, '')
70
+
71
+ sha = Digest::SHA256.hexdigest(File.read(path))
72
+
73
+ resources << Percy::Client::Resource.new(resource_url, sha: sha, path: path)
74
+ end
75
+
76
+ end
77
+
54
78
  resources
55
79
  end
56
80
 
81
+ def _rails
82
+ return Rails if defined?(Rails)
83
+ end
84
+
57
85
  def _asset_logical_paths
58
86
  # Re-implement the same technique that "rake assets:precompile" uses to generate the
59
87
  # list of asset paths to include in compiled assets. https://goo.gl/sy2R4z
@@ -1,5 +1,5 @@
1
1
  module Percy
2
2
  module Capybara
3
- VERSION = '1.1.0'
3
+ VERSION = '1.2.0'
4
4
  end
5
5
  end
@@ -55,5 +55,19 @@ RSpec.describe Percy::Capybara::Loaders::SprocketsLoader do
55
55
  expect(resources.map { |r| r.resource_url }).to eq(["/assets/css/base.css"])
56
56
  expect(resources.first.content).to include('.colored-by-base')
57
57
  end
58
+ context 'Rails app' do
59
+ it 'includes files from the public folder (non-asset-pipeline)' do
60
+
61
+ # Pretend like we're in a Rails app right now, all we care about is Rails.public_path.
62
+ rails_double = double('Rails')
63
+ # Pretend like the entire testdata directory is the public/ folder.
64
+ expect(rails_double).to receive(:public_path).and_return(environment.root)
65
+ expect(loader).to receive(:_rails).at_least(:once).and_return(rails_double)
66
+
67
+ resources = loader.build_resources
68
+ expect(resources.length).to be > 5 # Weak test that more things are in this list.
69
+ expect(resources.map { |r| r.resource_url }).to include('/images/percy.svg')
70
+ end
71
+ end
58
72
  end
59
73
  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: 1.1.0
4
+ version: 1.2.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-11-17 00:00:00.000000000 Z
11
+ date: 2016-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: percy-client
@@ -227,7 +227,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
227
227
  version: '0'
228
228
  requirements: []
229
229
  rubyforge_project:
230
- rubygems_version: 2.2.2
230
+ rubygems_version: 2.4.5
231
231
  signing_key:
232
232
  specification_version: 4
233
233
  summary: Percy::Capybara
@@ -262,3 +262,4 @@ test_files:
262
262
  - spec/lib/percy/capybara_spec.rb
263
263
  - spec/spec_helper.rb
264
264
  - spec/support/test_helpers.rb
265
+ has_rdoc: