percy-client 1.3.0 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 83fb35f9fc640e3977279f706cfd9f89fc0f9fa0
4
- data.tar.gz: f10670c00a19ed150df06ef41c679a62f909e7e3
3
+ metadata.gz: 91dde3564fe8e518402afa26ee2f52d5690ae688
4
+ data.tar.gz: 4653d42a6fe35bbf4f55e97a4b181ced166b63b8
5
5
  SHA512:
6
- metadata.gz: 1f69fdabc1807da61eaed7cd76b354c1acb21af65a89c68a38c41ad287862d291e0df4bbb7c5510140638243c21a058669d08a4732f9a006aa745d6ff07e740e
7
- data.tar.gz: 0252cd9c150a9fc37d5095bbe5e400a8b30f56289c502643712e794a20f69d851eb336f4dde434465499f8268e9de00e69272f14188b330276657cdfd7fc4f6d
6
+ metadata.gz: 503bad70215a73b1c78ca2aa617c29f1a84baff8b6d5adee4270ed34885a3ad31b333775062045479e7588d580a9d1db34b6856b0b39f0d59509740057a851de
7
+ data.tar.gz: 30a2bbcc431217f32c1afd707440641fe166a9d81951680e507c2dcf778a3f27820f4cd82a2213dbd97401ed04c1cb186e0213255df67d1f1d2bf13b843cbbd0
data/.travis.yml CHANGED
@@ -1,7 +1,11 @@
1
1
  language: ruby
2
+ sudo: false
3
+ cache: bundler
2
4
  rvm:
3
5
  - 1.9.3
4
6
  - 2.1.1
5
7
  - 2.2.2
6
8
  - ruby-head
9
+ before_install:
10
+ - gem update bundler
7
11
  script: bundle exec rspec
data/lib/percy.rb CHANGED
@@ -41,6 +41,7 @@ module Percy
41
41
  client.respond_to?(method_name, include_private) || super
42
42
  end if RUBY_VERSION < '1.9'
43
43
 
44
+ # @private
44
45
  def self.method_missing(method_name, *args, &block)
45
46
  return super if !client.respond_to?(method_name)
46
47
  client.send(method_name, *args, &block)
data/lib/percy/client.rb CHANGED
@@ -32,6 +32,19 @@ module Percy
32
32
  end
33
33
  end
34
34
 
35
+ class ClientError < HttpError; end # 4xx;
36
+ class BadRequestError < ClientError; end # 400.
37
+ class UnauthorizedError < ClientError; end # 401.
38
+ class PaymentRequiredError < ClientError; end # 402.
39
+ class ForbiddenError < ClientError; end # 403.
40
+ class NotFoundError < ClientError; end # 404.
41
+ class ConflictError < ClientError; end # 409.
42
+
43
+ class ServerError < HttpError; end # 5xx.
44
+ class InternalServerError < ServerError; end # 500.
45
+ class BadGatewayError < ServerError; end # 502.
46
+ class ServiceUnavailableError < ServerError; end # 503.
47
+
35
48
  attr_reader :config
36
49
 
37
50
  def initialize(options = {})
@@ -19,12 +19,32 @@ module Percy
19
19
  CLIENT_ERROR_STATUS_RANGE = 400...600
20
20
 
21
21
  def on_complete(env)
22
+ error_class = nil
22
23
  case env[:status]
23
- when CLIENT_ERROR_STATUS_RANGE
24
- raise Percy::Client::HttpError.new(
25
- env.status, env.method.upcase, env.url, env.body,
26
- "Got #{env.status} (#{env.method.upcase} #{env.url}):\n#{env.body}")
24
+ when 400
25
+ error_class = Percy::Client::BadRequestError
26
+ when 401
27
+ error_class = Percy::Client::UnauthorizedError
28
+ when 402
29
+ error_class = Percy::Client::PaymentRequiredError
30
+ when 403
31
+ error_class = Percy::Client::ForbiddenError
32
+ when 404
33
+ error_class = Percy::Client::NotFoundError
34
+ when 409
35
+ error_class = Percy::Client::ConflictError
36
+ when 500
37
+ error_class = Percy::Client::InternalServerError
38
+ when 502
39
+ error_class = Percy::Client::BadGatewayError
40
+ when 503
41
+ error_class = Percy::Client::ServiceUnavailableError
42
+ when CLIENT_ERROR_STATUS_RANGE # Catchall.
43
+ error_class = Percy::Client::HttpError
27
44
  end
45
+ raise error_class.new(
46
+ env.status, env.method.upcase, env.url, env.body,
47
+ "Got #{env.status} (#{env.method.upcase} #{env.url}):\n#{env.body}") if error_class
28
48
  end
29
49
  end
30
50
 
@@ -41,8 +61,8 @@ module Percy
41
61
  @connection
42
62
  end
43
63
 
44
- def get(path)
45
- retries = 3
64
+ def get(path, options = {})
65
+ retries = options[:retries] || 3
46
66
  begin
47
67
  response = connection.get do |request|
48
68
  request.url(path)
@@ -63,8 +83,8 @@ module Percy
63
83
  JSON.parse(response.body)
64
84
  end
65
85
 
66
- def post(path, data)
67
- retries = 3
86
+ def post(path, data, options = {})
87
+ retries = options[:retries] || 3
68
88
  begin
69
89
  response = connection.post do |request|
70
90
  request.url(path)
@@ -75,9 +95,8 @@ module Percy
75
95
  raise Percy::Client::TimeoutError
76
96
  rescue Faraday::ConnectionFailed
77
97
  raise Percy::Client::ConnectionFailed
78
- rescue Percy::Client::HttpError => e
79
- # Retry on 502 errors.
80
- if e.status == 502 && (retries -= 1) >= 0
98
+ rescue Percy::Client::ServerError => e
99
+ if (retries -= 1) >= 0
81
100
  sleep(rand(1..3))
82
101
  retry
83
102
  end
@@ -65,7 +65,7 @@ module Percy
65
65
  }
66
66
  begin
67
67
  post("#{config.api_url}/builds/#{build_id}/resources/", data)
68
- rescue Percy::Client::HttpError => e
68
+ rescue Percy::Client::ConflictError => e
69
69
  raise e if e.status != 409
70
70
  STDERR.puts "[percy] Warning: unnecessary resource reuploaded with SHA-256: #{sha}"
71
71
  end
@@ -6,14 +6,15 @@ module Percy
6
6
  raise ArgumentError.new(
7
7
  'resources argument must be an iterable of Percy::Client::Resource objects')
8
8
  end
9
- name = options[:name]
10
- enable_javascript = options[:enable_javascript]
9
+
10
+ widths = options[:widths] || config.default_widths
11
11
  data = {
12
12
  'data' => {
13
13
  'type' => 'snapshots',
14
14
  'attributes' => {
15
- 'name' => name,
16
- 'enable-javascript' => enable_javascript,
15
+ 'name' => options[:name],
16
+ 'enable-javascript' => options[:enable_javascript],
17
+ 'widths' => widths,
17
18
  },
18
19
  'relationships' => {
19
20
  'resources' => {
@@ -1,5 +1,5 @@
1
1
  module Percy
2
2
  class Client
3
- VERSION = '1.3.0'
3
+ VERSION = '1.4.0'
4
4
  end
5
5
  end
data/lib/percy/config.rb CHANGED
@@ -4,11 +4,18 @@ module Percy
4
4
  # @return [String] Percy repo access token.
5
5
  # @!attribute api_url
6
6
  # @return [String] Base URL for API requests. Default: https://percy.io/api/v1/
7
+ # @!attribute debug
8
+ # @return [Boolean] Whether or not to enable debug logging.
9
+ # @!attribute repo
10
+ # @return [String] Git repo name.
11
+ # @!attribute default_widths
12
+ # @return [Array] List of default widths for snapshot rendering unless overridden.
7
13
 
8
14
  attr_accessor :access_token
9
15
  attr_accessor :api_url
10
16
  attr_accessor :debug
11
17
  attr_accessor :repo
18
+ attr_accessor :default_widths
12
19
 
13
20
  # List of configurable keys for {Percy::Client}
14
21
  # @return [Array] Option keys.
@@ -18,6 +25,7 @@ module Percy
18
25
  :api_url,
19
26
  :debug,
20
27
  :repo,
28
+ :default_widths,
21
29
  ]
22
30
  end
23
31
 
@@ -36,5 +44,10 @@ module Percy
36
44
  def repo
37
45
  @repo ||= Percy::Client::Environment.repo
38
46
  end
47
+
48
+ # List of default widths sent for every snapshot, unless overridden on a per-snapshot basis.
49
+ def default_widths
50
+ @default_widths ||= []
51
+ end
39
52
  end
40
53
  end
@@ -0,0 +1,120 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://localhost:3000/api/v1/repos/fotinakis/percy-examples/builds/
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"data":{"type":"builds","attributes":{"commit-sha":"fc4d2c2e6b55d995a005dba2d071e2f2fca5e04b","commit-branch":"master","commit-committed-at":"2015-06-09
9
+ 23:22:31 -0700","commit-author-name":"<COMMIT_AUTHOR_NAME>","commit-author-email":"<COMMIT_AUTHOR_EMAIL>","commit-committer-name":"<COMMIT_AUTHOR_NAME>","commit-committer-email":"<COMMIT_AUTHOR_EMAIL>","commit-message":"Fix
10
+ test environment issue.","pull-request-number":null}}}'
11
+ headers:
12
+ User-Agent:
13
+ - Faraday v0.9.1
14
+ Accept:
15
+ - "*/*"
16
+ Date:
17
+ - Thu, 11 Jun 2015 00:20:37 GMT
18
+ Content-Type:
19
+ - application/vnd.api+json
20
+ Authorization:
21
+ - Token token="<FILTERED_PERCY_TOKEN>"
22
+ response:
23
+ status:
24
+ code: 201
25
+ message: Created
26
+ headers:
27
+ Date:
28
+ - Thu, 11 Jun 2015 00:20:37 GMT
29
+ Status:
30
+ - 201 Created
31
+ Connection:
32
+ - close
33
+ X-Frame-Options:
34
+ - SAMEORIGIN
35
+ X-Xss-Protection:
36
+ - 1; mode=block
37
+ X-Content-Type-Options:
38
+ - nosniff
39
+ Access-Control-Allow-Origin:
40
+ - "*"
41
+ Access-Control-Allow-Methods:
42
+ - GET, POST, PUT, PATCH, DELETE, OPTIONS
43
+ Access-Control-Allow-Headers:
44
+ - Authorization, Content-Type
45
+ Cache-Control:
46
+ - no-cache, no-store, max-age=0, must-revalidate
47
+ Expires:
48
+ - Thu, 01 Jan 1970 00:00:00 GMT
49
+ Content-Type:
50
+ - application/json; charset=utf-8
51
+ X-Request-Id:
52
+ - 998e5483-89b7-4118-aa43-63883455d31b
53
+ X-Runtime:
54
+ - '0.042738'
55
+ Transfer-Encoding:
56
+ - chunked
57
+ body:
58
+ encoding: UTF-8
59
+ string: '{"data":{"id":"28","type":"builds","attributes":{"build-number":28,"state":"pending","is-pull-request":false,"pull-request-number":0,"pull-request-title":null,"approved-at":null,"created-at":"2015-06-11T00:20:37.863Z","updated-at":"2015-06-11T00:20:37.863Z"},"links":{"self":"/api/v1/builds/28"},"relationships":{"commit":{"links":{"self":"/api/v1/builds/28/relationships/commit","related":"/api/v1/builds/28/commit"},"data":{"type":"commits","id":"2"}},"repo":{"links":{"self":"/api/v1/builds/28/relationships/repo","related":"/api/v1/builds/28/repo"}},"base-build":{"links":{"self":"/api/v1/builds/28/relationships/base-build","related":"/api/v1/builds/28/base-build"},"data":{"type":"builds","id":"22"}},"approved-by":{"links":{"self":"/api/v1/builds/28/relationships/approved-by","related":"/api/v1/builds/28/approved-by"}},"snapshots":{"links":{"self":"/api/v1/builds/28/relationships/snapshots","related":"/api/v1/builds/28/snapshots"}},"comparisons":{"links":{"self":"/api/v1/builds/28/relationships/comparisons","related":"/api/v1/builds/28/comparisons"}},"missing-resources":{"links":{"self":"/api/v1/builds/28/relationships/missing-resources","related":"/api/v1/builds/28/missing-resources"}}},"meta":{"finalize-link":"/api/v1/builds/28/finalize","approve-link":"/api/v1/builds/28/approve"}},"included":[{"id":"2","type":"commits","attributes":{"sha":"fc4d2c2e6b55d995a005dba2d071e2f2fca5e04b","branch":"master","message":"Fix
60
+ test environment issue.","committed-at":"2015-06-09 23:22:31 -0700","author-name":"<COMMIT_AUTHOR_NAME>","committer-name":"<COMMIT_AUTHOR_NAME>","created-at":"2015-06-11T00:15:24.000Z","updated-at":"2015-06-11T00:15:24.000Z"},"links":{"self":"/api/v1/commits/2"}},{"id":"22","type":"builds","attributes":{"build-number":22,"state":"finished","is-pull-request":false,"pull-request-number":0,"pull-request-title":null,"approved-at":null,"created-at":"2015-06-11T00:17:46.000Z","updated-at":"2015-06-11T00:17:46.000Z"},"links":{"self":"/api/v1/builds/22"},"relationships":{"commit":{"links":{"self":"/api/v1/builds/22/relationships/commit","related":"/api/v1/builds/22/commit"},"data":{"type":"commits","id":"2"}},"repo":{"links":{"self":"/api/v1/builds/22/relationships/repo","related":"/api/v1/builds/22/repo"}},"base-build":{"links":{"self":"/api/v1/builds/22/relationships/base-build","related":"/api/v1/builds/22/base-build"}},"approved-by":{"links":{"self":"/api/v1/builds/22/relationships/approved-by","related":"/api/v1/builds/22/approved-by"}},"snapshots":{"links":{"self":"/api/v1/builds/22/relationships/snapshots","related":"/api/v1/builds/22/snapshots"}},"comparisons":{"links":{"self":"/api/v1/builds/22/relationships/comparisons","related":"/api/v1/builds/22/comparisons"}},"missing-resources":{"links":{"self":"/api/v1/builds/22/relationships/missing-resources","related":"/api/v1/builds/22/missing-resources"}}},"meta":{"finalize-link":"/api/v1/builds/22/finalize","approve-link":"/api/v1/builds/22/approve"}}]}'
61
+ http_version:
62
+ recorded_at: Thu, 11 Jun 2015 00:20:37 GMT
63
+ - request:
64
+ method: post
65
+ uri: http://localhost:3000/api/v1/builds/28/snapshots/
66
+ body:
67
+ encoding: UTF-8
68
+ string: '{"data":{"type":"snapshots","attributes":{"name":"homepage"},"relationships":{"resources":{"data":[{"type":"resources","id":"8d68af40ce7ee4591a7df49d1a40db8bf0b6535a37c896eda504f963c622535a","attributes":{"resource-url":"/foo/test.html","mimetype":null,"is-root":true}},{"type":"resources","id":"8d68af40ce7ee4591a7df49d1a40db8bf0b6535a37c896eda504f963c622535a","attributes":{"resource-url":"/css/test.css","mimetype":null,"is-root":null}}]}}}}'
69
+ headers:
70
+ User-Agent:
71
+ - Faraday v0.9.1
72
+ Accept:
73
+ - "*/*"
74
+ Date:
75
+ - Thu, 11 Jun 2015 00:20:37 GMT
76
+ Content-Type:
77
+ - application/vnd.api+json
78
+ Authorization:
79
+ - Token token="<FILTERED_PERCY_TOKEN>"
80
+ response:
81
+ status:
82
+ code: 201
83
+ message: Created
84
+ headers:
85
+ Date:
86
+ - Thu, 11 Jun 2015 00:20:38 GMT
87
+ Status:
88
+ - 201 Created
89
+ Connection:
90
+ - close
91
+ X-Frame-Options:
92
+ - SAMEORIGIN
93
+ X-Xss-Protection:
94
+ - 1; mode=block
95
+ X-Content-Type-Options:
96
+ - nosniff
97
+ Access-Control-Allow-Origin:
98
+ - "*"
99
+ Access-Control-Allow-Methods:
100
+ - GET, POST, PUT, PATCH, DELETE, OPTIONS
101
+ Access-Control-Allow-Headers:
102
+ - Authorization, Content-Type
103
+ Cache-Control:
104
+ - no-cache, no-store, max-age=0, must-revalidate
105
+ Expires:
106
+ - Thu, 01 Jan 1970 00:00:00 GMT
107
+ Content-Type:
108
+ - application/json; charset=utf-8
109
+ X-Request-Id:
110
+ - 54eed09b-c2ca-4378-a52b-5d5003f6f7ec
111
+ X-Runtime:
112
+ - '0.212265'
113
+ Transfer-Encoding:
114
+ - chunked
115
+ body:
116
+ encoding: UTF-8
117
+ string: '{"data":{"id":"1110","type":"snapshots","attributes":{"name":"homepage","created-at":"2015-06-11T00:20:38.085Z","updated-at":"2015-06-11T00:20:38.085Z","finished-processing-at":null},"links":{"self":"/api/v1/snapshots/1110"},"relationships":{"build":{"links":{"self":"/api/v1/snapshots/1110/relationships/build","related":"/api/v1/snapshots/1110/build"}},"screenshots":{"links":{"self":"/api/v1/snapshots/1110/relationships/screenshots","related":"/api/v1/snapshots/1110/screenshots"}},"missing-resources":{"links":{"self":"/api/v1/snapshots/1110/relationships/missing-resources","related":"/api/v1/snapshots/1110/missing-resources"},"data":[{"type":"resources","id":"8d68af40ce7ee4591a7df49d1a40db8bf0b6535a37c896eda504f963c622535a"}]}}},"included":[{"id":"8d68af40ce7ee4591a7df49d1a40db8bf0b6535a37c896eda504f963c622535a","type":"resources","attributes":{},"links":{"self":"/api/v1/resources/8d68af40ce7ee4591a7df49d1a40db8bf0b6535a37c896eda504f963c622535a"}}]}'
118
+ http_version:
119
+ recorded_at: Thu, 11 Jun 2015 00:20:38 GMT
120
+ recorded_with: VCR 2.9.3
@@ -35,7 +35,7 @@ RSpec.describe Percy::Client::Connection do
35
35
  .to_return(body: {foo: true}.to_json, status: 502).times(3)
36
36
  expect do
37
37
  Percy.client.get("#{Percy.config.api_url}/test")
38
- end.to raise_error(Percy::Client::HttpError)
38
+ end.to raise_error(Percy::Client::BadGatewayError)
39
39
  end
40
40
  end
41
41
  describe '#post' do
@@ -56,9 +56,48 @@ RSpec.describe Percy::Client::Connection do
56
56
  Percy.client.post("#{Percy.config.api_url}/test", {})
57
57
  end.to raise_error(Percy::Client::ConnectionFailed)
58
58
  end
59
- it 'retries on 502 errors' do
59
+ it 'raises custom error classes for some HTTP errors' do
60
60
  stub_request(:post, "#{Percy.config.api_url}/test")
61
- .to_return(body: {foo: true}.to_json, status: 502)
61
+ .to_return(body: {foo: true}.to_json, status: 400)
62
+ .then.to_return(body: {foo: true}.to_json, status: 401)
63
+ .then.to_return(body: {foo: true}.to_json, status: 402)
64
+ .then.to_return(body: {foo: true}.to_json, status: 403)
65
+ .then.to_return(body: {foo: true}.to_json, status: 404)
66
+ .then.to_return(body: {foo: true}.to_json, status: 409)
67
+ .then.to_return(body: {foo: true}.to_json, status: 500)
68
+ .then.to_return(body: {foo: true}.to_json, status: 502)
69
+ .then.to_return(body: {foo: true}.to_json, status: 503)
70
+ expect do
71
+ Percy.client.post("#{Percy.config.api_url}/test", {}, retries: 0)
72
+ end.to raise_error(Percy::Client::BadRequestError)
73
+ expect do
74
+ Percy.client.post("#{Percy.config.api_url}/test", {}, retries: 0)
75
+ end.to raise_error(Percy::Client::UnauthorizedError)
76
+ expect do
77
+ Percy.client.post("#{Percy.config.api_url}/test", {}, retries: 0)
78
+ end.to raise_error(Percy::Client::PaymentRequiredError)
79
+ expect do
80
+ Percy.client.post("#{Percy.config.api_url}/test", {}, retries: 0)
81
+ end.to raise_error(Percy::Client::ForbiddenError)
82
+ expect do
83
+ Percy.client.post("#{Percy.config.api_url}/test", {}, retries: 0)
84
+ end.to raise_error(Percy::Client::NotFoundError)
85
+ expect do
86
+ Percy.client.post("#{Percy.config.api_url}/test", {}, retries: 0)
87
+ end.to raise_error(Percy::Client::ConflictError)
88
+ expect do
89
+ Percy.client.post("#{Percy.config.api_url}/test", {}, retries: 0)
90
+ end.to raise_error(Percy::Client::InternalServerError)
91
+ expect do
92
+ Percy.client.post("#{Percy.config.api_url}/test", {}, retries: 0)
93
+ end.to raise_error(Percy::Client::BadGatewayError)
94
+ expect do
95
+ Percy.client.post("#{Percy.config.api_url}/test", {}, retries: 0)
96
+ end.to raise_error(Percy::Client::ServiceUnavailableError)
97
+ end
98
+ it 'retries on server errors' do
99
+ stub_request(:post, "#{Percy.config.api_url}/test")
100
+ .to_return(body: {foo: true}.to_json, status: 500)
62
101
  .then.to_return(body: {foo: true}.to_json, status: 200)
63
102
 
64
103
  data = Percy.client.post("#{Percy.config.api_url}/test", {})
@@ -69,7 +108,7 @@ RSpec.describe Percy::Client::Connection do
69
108
  .to_return(body: {foo: true}.to_json, status: 502).times(3)
70
109
  expect do
71
110
  Percy.client.post("#{Percy.config.api_url}/test", {})
72
- end.to raise_error(Percy::Client::HttpError)
111
+ end.to raise_error(Percy::Client::BadGatewayError)
73
112
  end
74
113
  end
75
114
  end
@@ -8,6 +8,46 @@ RSpec.describe Percy::Client::Snapshots, :vcr do
8
8
  resources = []
9
9
  resources << Percy::Client::Resource.new('/foo/test.html', sha: sha, is_root: true)
10
10
  resources << Percy::Client::Resource.new('/css/test.css', sha: sha)
11
+
12
+ # Whitebox test to catch POST data that is sent but is not returned in the API response.
13
+ expect_any_instance_of(Percy::Client).to \
14
+ receive(:post)
15
+ .with(/snapshots\/$/, {
16
+ 'data' => {
17
+ 'type' => 'snapshots',
18
+ 'attributes' => {
19
+ 'name' => 'homepage',
20
+ 'enable-javascript' => true,
21
+ 'widths' => Percy.config.default_widths,
22
+ },
23
+ 'relationships' => {
24
+ 'resources' => {
25
+ 'data' => [
26
+ {
27
+ 'type' => 'resources',
28
+ 'id' => kind_of(String),
29
+ 'attributes' => {
30
+ 'resource-url' => '/foo/test.html',
31
+ 'mimetype' => nil,
32
+ 'is-root' => true,
33
+ },
34
+ },
35
+ {
36
+ 'type' => 'resources',
37
+ 'id' => kind_of(String),
38
+ 'attributes' => {
39
+ 'resource-url' => '/css/test.css',
40
+ 'mimetype' => nil,
41
+ 'is-root' => nil,
42
+ },
43
+ },
44
+ ],
45
+ },
46
+ },
47
+ },
48
+ })
49
+ .and_call_original
50
+
11
51
  snapshot = Percy.create_snapshot(
12
52
  build['data']['id'],
13
53
  resources,
@@ -21,6 +61,64 @@ RSpec.describe Percy::Client::Snapshots, :vcr do
21
61
  expect(snapshot['data']['attributes']['name']).to eq('homepage')
22
62
  expect(snapshot['data']['relationships']['missing-resources']).to be
23
63
  end
64
+ it 'overrides default_widths if given' do
65
+ build = Percy.create_build('fotinakis/percy-examples')
66
+ resources = []
67
+ resources << Percy::Client::Resource.new('/foo/test.html', sha: sha, is_root: true)
68
+ resources << Percy::Client::Resource.new('/css/test.css', sha: sha)
69
+
70
+ # Whitebox test to catch POST data that is sent but is not returned in the API response.
71
+ expect_any_instance_of(Percy::Client).to \
72
+ receive(:post)
73
+ .with(/snapshots\/$/, {
74
+ 'data' => {
75
+ 'type' => 'snapshots',
76
+ 'attributes' => {
77
+ 'name' => 'homepage',
78
+ 'enable-javascript' => nil,
79
+ 'widths' => [320, 1280],
80
+ },
81
+ 'relationships' => {
82
+ 'resources' => {
83
+ 'data' => [
84
+ {
85
+ 'type' => 'resources',
86
+ 'id' => kind_of(String),
87
+ 'attributes' => {
88
+ 'resource-url' => '/foo/test.html',
89
+ 'mimetype' => nil,
90
+ 'is-root' => true,
91
+ },
92
+ },
93
+ {
94
+ 'type' => 'resources',
95
+ 'id' => kind_of(String),
96
+ 'attributes' => {
97
+ 'resource-url' => '/css/test.css',
98
+ 'mimetype' => nil,
99
+ 'is-root' => nil,
100
+ },
101
+ },
102
+ ],
103
+ },
104
+ },
105
+ },
106
+ })
107
+ .and_call_original
108
+
109
+ snapshot = Percy.create_snapshot(
110
+ build['data']['id'],
111
+ resources,
112
+ name: 'homepage',
113
+ widths: [320, 1280],
114
+ )
115
+
116
+ expect(snapshot['data']).to be
117
+ expect(snapshot['data']['id']).to be
118
+ expect(snapshot['data']['type']).to eq('snapshots')
119
+ expect(snapshot['data']['attributes']['name']).to eq('homepage')
120
+ expect(snapshot['data']['relationships']['missing-resources']).to be
121
+ end
24
122
  it 'fails if no resources are given' do
25
123
  build = Percy.create_build('fotinakis/percy-examples')
26
124
  expect do
@@ -1,19 +1,9 @@
1
1
  RSpec.describe Percy::Client do
2
- describe '#config' do
2
+ describe 'config' do
3
3
  it 'returns the config object given when initialized' do
4
4
  config = Percy::Config.new
5
5
  client = Percy::Client.new(config: config)
6
6
  expect(client.config).to eq(config)
7
- expect(client.config.keys).to eq([
8
- :access_token,
9
- :api_url,
10
- :debug,
11
- :repo,
12
- ])
13
- expect(client.config.access_token).to be_nil
14
- expect(client.config.api_url).to eq(ENV['PERCY_API'])
15
- expect(client.config.debug).to eq(false)
16
- expect(client.config.repo).to eq('percy/percy-client')
17
7
  end
18
8
  end
19
9
  end
@@ -0,0 +1,18 @@
1
+ RSpec.describe Percy::Config do
2
+ let(:config) { described_class.new }
3
+
4
+ it 'returns the correct defaults' do
5
+ expect(config.keys).to eq([
6
+ :access_token,
7
+ :api_url,
8
+ :debug,
9
+ :repo,
10
+ :default_widths,
11
+ ])
12
+ expect(config.access_token).to be_nil
13
+ expect(config.api_url).to eq(ENV['PERCY_API'])
14
+ expect(config.debug).to eq(false)
15
+ expect(config.repo).to eq('percy/percy-client')
16
+ expect(config.default_widths).to eq([])
17
+ end
18
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: percy-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.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-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -140,6 +140,7 @@ files:
140
140
  - spec/cassettes/Percy_Client_Resources/_upload_resource/returns_true_with_success.yml
141
141
  - spec/cassettes/Percy_Client_Snapshots/_create_snapshot/creates_a_snapshot.yml
142
142
  - spec/cassettes/Percy_Client_Snapshots/_create_snapshot/fails_if_no_resources_are_given.yml
143
+ - spec/cassettes/Percy_Client_Snapshots/_create_snapshot/overrides_default_widths_if_given.yml
143
144
  - spec/cassettes/Percy_Client_Snapshots/_finalize_snapshot/finalizes_a_snapshot.yml
144
145
  - spec/lib/percy/client/builds_spec.rb
145
146
  - spec/lib/percy/client/connection_spec.rb
@@ -147,6 +148,7 @@ files:
147
148
  - spec/lib/percy/client/resources_spec.rb
148
149
  - spec/lib/percy/client/snapshots_spec.rb
149
150
  - spec/lib/percy/client_spec.rb
151
+ - spec/lib/percy/config_spec.rb
150
152
  - spec/lib/percy_spec.rb
151
153
  - spec/spec_helper.rb
152
154
  - spec/support/vcr_setup.rb
@@ -182,6 +184,7 @@ test_files:
182
184
  - spec/cassettes/Percy_Client_Resources/_upload_resource/returns_true_with_success.yml
183
185
  - spec/cassettes/Percy_Client_Snapshots/_create_snapshot/creates_a_snapshot.yml
184
186
  - spec/cassettes/Percy_Client_Snapshots/_create_snapshot/fails_if_no_resources_are_given.yml
187
+ - spec/cassettes/Percy_Client_Snapshots/_create_snapshot/overrides_default_widths_if_given.yml
185
188
  - spec/cassettes/Percy_Client_Snapshots/_finalize_snapshot/finalizes_a_snapshot.yml
186
189
  - spec/lib/percy/client/builds_spec.rb
187
190
  - spec/lib/percy/client/connection_spec.rb
@@ -189,6 +192,7 @@ test_files:
189
192
  - spec/lib/percy/client/resources_spec.rb
190
193
  - spec/lib/percy/client/snapshots_spec.rb
191
194
  - spec/lib/percy/client_spec.rb
195
+ - spec/lib/percy/config_spec.rb
192
196
  - spec/lib/percy_spec.rb
193
197
  - spec/spec_helper.rb
194
198
  - spec/support/vcr_setup.rb