percy-client 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +9 -30
  3. data/.rspec +3 -0
  4. data/.travis.yml +7 -0
  5. data/Gemfile +3 -1
  6. data/Guardfile +14 -0
  7. data/LICENSE +2 -2
  8. data/README.md +34 -2
  9. data/Rakefile +1 -1
  10. data/lib/percy.rb +37 -0
  11. data/lib/percy/client.rb +47 -0
  12. data/lib/percy/client/builds.rb +32 -0
  13. data/lib/percy/client/connection.rb +50 -0
  14. data/lib/percy/client/local_git.rb +50 -0
  15. data/lib/percy/client/resources.rb +54 -0
  16. data/lib/percy/client/snapshots.rb +22 -0
  17. data/lib/percy/client/version.rb +5 -0
  18. data/percy-client.gemspec +29 -0
  19. data/spec/cassettes/Percy_Client_Builds/_create_build/creates_a_build.yml +64 -0
  20. data/spec/cassettes/Percy_Client_Builds/_finalize_build/finalizes_a_build.yml +121 -0
  21. data/spec/cassettes/Percy_Client_Resources/_upload_resource/returns_true_with_success.yml +237 -0
  22. data/spec/cassettes/Percy_Client_Snapshots/_create_snapshot/creates_a_build.yml +121 -0
  23. data/spec/cassettes/Percy_Client_Snapshots/_create_snapshot/fails_if_no_resources_are_given.yml +122 -0
  24. data/spec/lib/percy/client/builds_spec.rb +19 -0
  25. data/spec/lib/percy/client/connection_spec.rb +16 -0
  26. data/spec/lib/percy/client/local_git_spec.rb +21 -0
  27. data/spec/lib/percy/client/resources_spec.rb +40 -0
  28. data/spec/lib/percy/client/snapshots_spec.rb +26 -0
  29. data/spec/lib/percy/client_spec.rb +17 -0
  30. data/spec/spec_helper.rb +34 -0
  31. data/spec/support/test_helpers.rb +7 -0
  32. data/spec/support/vcr_setup.rb +27 -0
  33. metadata +116 -9
  34. data/lib/perceptual.rb +0 -5
  35. data/lib/perceptual/version.rb +0 -3
  36. data/perceptual.gemspec +0 -23
@@ -0,0 +1,121 @@
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":"85e1b2fc5e80c462bb281d4a9b72b3d86e9f5e8f","commit-branch":"master","commit-committed-at":"2015-05-16
9
+ 19:39:41 -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":"Checkpoint
10
+ some initial resources and snapshots work.","pull-request-number":null}}}'
11
+ headers:
12
+ User-Agent:
13
+ - Faraday v0.9.1
14
+ Accept:
15
+ - "*/*"
16
+ Date:
17
+ - Sun, 17 May 2015 04:14:20 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
+ X-Frame-Options:
28
+ - SAMEORIGIN
29
+ X-Xss-Protection:
30
+ - 1; mode=block
31
+ X-Content-Type-Options:
32
+ - nosniff
33
+ Access-Control-Allow-Origin:
34
+ - "*"
35
+ Access-Control-Allow-Methods:
36
+ - GET, POST, PUT, PATCH, DELETE, OPTIONS
37
+ Access-Control-Allow-Headers:
38
+ - Authorization, Content-Type
39
+ Cache-Control:
40
+ - no-cache, no-store, max-age=0, must-revalidate
41
+ Expires:
42
+ - Thu, 01 Jan 1970 00:00:00 GMT
43
+ Content-Type:
44
+ - application/json; charset=utf-8
45
+ X-Request-Id:
46
+ - 3507dc48-4680-4e97-b856-2ac59c8253df
47
+ X-Runtime:
48
+ - '0.022251'
49
+ Server:
50
+ - WEBrick/1.3.1 (Ruby/2.1.5/2014-11-13)
51
+ Date:
52
+ - Sun, 17 May 2015 04:14:20 GMT
53
+ Content-Length:
54
+ - '2402'
55
+ Connection:
56
+ - Keep-Alive
57
+ body:
58
+ encoding: UTF-8
59
+ string: '{"data":{"id":"12","type":"builds","attributes":{"state":"pending","is-pull-request":false,"pull-request-number":0,"pull-request-title":null,"approved-at":null,"created-at":"2015-05-17T04:14:20.079Z","updated-at":"2015-05-17T04:14:20.079Z"},"links":{"self":"/api/v1/builds/12","commit":{"self":"/api/v1/builds/12/links/commit","related":"/api/v1/builds/12/commit","linkage":{"type":"commits","id":"1"}},"repo":{"self":"/api/v1/builds/12/links/repo","related":"/api/v1/builds/12/repo"},"base-build":{"self":"/api/v1/builds/12/links/base-build","related":"/api/v1/builds/12/base-build","linkage":{"type":"builds","id":"8"}},"approved-by":{"self":"/api/v1/builds/12/links/approved-by","related":"/api/v1/builds/12/approved-by"},"snapshots":{"self":"/api/v1/builds/12/links/snapshots","related":"/api/v1/builds/12/snapshots"},"comparisons":{"self":"/api/v1/builds/12/links/comparisons","related":"/api/v1/builds/12/comparisons"}},"meta":{"finalize-link":"/api/v1/builds/12/finalize","approve-link":"/api/v1/builds/12/approve"}},"included":[{"id":"1","type":"commits","attributes":{"sha":"85e1b2fc5e80c462bb281d4a9b72b3d86e9f5e8f","branch":"master","message":"Checkpoint
60
+ some initial resources and snapshots work.","committed-at":"2015-05-16 19:39:41
61
+ -0700","author-name":"<COMMIT_AUTHOR_NAME>","committer-name":"<COMMIT_AUTHOR_NAME>","created-at":"2015-05-17T04:02:54.000Z","updated-at":"2015-05-17T04:02:54.000Z"},"links":{"self":"/api/v1/commits/1"}},{"id":"8","type":"builds","attributes":{"state":"finished","is-pull-request":false,"pull-request-number":0,"pull-request-title":null,"approved-at":null,"created-at":"2015-05-17T04:12:48.000Z","updated-at":"2015-05-17T04:12:48.000Z"},"links":{"self":"/api/v1/builds/8","commit":{"self":"/api/v1/builds/8/links/commit","related":"/api/v1/builds/8/commit","linkage":{"type":"commits","id":"1"}},"repo":{"self":"/api/v1/builds/8/links/repo","related":"/api/v1/builds/8/repo"},"base-build":{"self":"/api/v1/builds/8/links/base-build","related":"/api/v1/builds/8/base-build"},"approved-by":{"self":"/api/v1/builds/8/links/approved-by","related":"/api/v1/builds/8/approved-by"},"snapshots":{"self":"/api/v1/builds/8/links/snapshots","related":"/api/v1/builds/8/snapshots"},"comparisons":{"self":"/api/v1/builds/8/links/comparisons","related":"/api/v1/builds/8/comparisons"}},"meta":{"finalize-link":"/api/v1/builds/8/finalize","approve-link":"/api/v1/builds/8/approve"}}]}'
62
+ http_version:
63
+ recorded_at: Sun, 17 May 2015 04:14:20 GMT
64
+ - request:
65
+ method: post
66
+ uri: http://localhost:3000/api/v1/builds/12/snapshots/
67
+ body:
68
+ encoding: UTF-8
69
+ string: '{"data":{"type":"snapshots","attributes":{"name":"homepage"},"links":{"resources":[{"type":"resources","id":"7509e5bda0c762d2bac7f90d758b5b2263fa01ccbc542ab5e3df163be08e6ca9","resource-url":"/foo/test.html","mimetype":null,"is-root":true},{"type":"resources","id":"7509e5bda0c762d2bac7f90d758b5b2263fa01ccbc542ab5e3df163be08e6ca9","resource-url":"/css/test.css","mimetype":null,"is-root":null}]}}}'
70
+ headers:
71
+ User-Agent:
72
+ - Faraday v0.9.1
73
+ Accept:
74
+ - "*/*"
75
+ Date:
76
+ - Sun, 17 May 2015 04:14:20 GMT
77
+ Content-Type:
78
+ - application/vnd.api+json
79
+ Authorization:
80
+ - Token token="<FILTERED_PERCY_TOKEN>"
81
+ response:
82
+ status:
83
+ code: 201
84
+ message: 'Created '
85
+ headers:
86
+ X-Frame-Options:
87
+ - SAMEORIGIN
88
+ X-Xss-Protection:
89
+ - 1; mode=block
90
+ X-Content-Type-Options:
91
+ - nosniff
92
+ Access-Control-Allow-Origin:
93
+ - "*"
94
+ Access-Control-Allow-Methods:
95
+ - GET, POST, PUT, PATCH, DELETE, OPTIONS
96
+ Access-Control-Allow-Headers:
97
+ - Authorization, Content-Type
98
+ Cache-Control:
99
+ - no-cache, no-store, max-age=0, must-revalidate
100
+ Expires:
101
+ - Thu, 01 Jan 1970 00:00:00 GMT
102
+ Content-Type:
103
+ - application/json; charset=utf-8
104
+ X-Request-Id:
105
+ - 24f42185-48ad-4285-8bad-7dc43f2d4bea
106
+ X-Runtime:
107
+ - '0.040410'
108
+ Server:
109
+ - WEBrick/1.3.1 (Ruby/2.1.5/2014-11-13)
110
+ Date:
111
+ - Sun, 17 May 2015 04:14:20 GMT
112
+ Content-Length:
113
+ - '1477'
114
+ Connection:
115
+ - Keep-Alive
116
+ body:
117
+ encoding: UTF-8
118
+ string: '{"data":{"id":"7","type":"snapshots","attributes":{"name":"homepage","created-at":"2015-05-17T04:14:20.107Z","updated-at":"2015-05-17T04:14:20.107Z"},"links":{"self":"/api/v1/snapshots/7","build":{"self":"/api/v1/snapshots/7/links/build","related":"/api/v1/snapshots/7/build"},"screenshots":{"self":"/api/v1/snapshots/7/links/screenshots","related":"/api/v1/snapshots/7/screenshots"},"resources":{"self":"/api/v1/snapshots/7/links/resources","related":"/api/v1/snapshots/7/resources","linkage":[{"type":"resources","id":"7509e5bda0c762d2bac7f90d758b5b2263fa01ccbc542ab5e3df163be08e6ca9"},{"type":"resources","id":"7509e5bda0c762d2bac7f90d758b5b2263fa01ccbc542ab5e3df163be08e6ca9"}]},"missing-resources":{"self":"/api/v1/snapshots/7/links/missing-resources","related":"/api/v1/snapshots/7/missing-resources","linkage":[]}}},"included":[{"id":"7509e5bda0c762d2bac7f90d758b5b2263fa01ccbc542ab5e3df163be08e6ca9","type":"resources","attributes":{"is-root":true,"resource-url":"http://localhost/foo/test.html","mimetype":"text/html","uploaded-at":"2015-05-17T04:14:19.000Z","created-at":"2015-05-17T04:14:20.000Z","updated-at":"2015-05-17T04:14:20.000Z"},"links":{"self":"/api/v1/resources/7509e5bda0c762d2bac7f90d758b5b2263fa01ccbc542ab5e3df163be08e6ca9","snapshot":{"self":"/api/v1/resources/7509e5bda0c762d2bac7f90d758b5b2263fa01ccbc542ab5e3df163be08e6ca9/links/snapshot","related":"/api/v1/resources/7509e5bda0c762d2bac7f90d758b5b2263fa01ccbc542ab5e3df163be08e6ca9/snapshot"}}}]}'
119
+ http_version:
120
+ recorded_at: Sun, 17 May 2015 04:14:20 GMT
121
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,122 @@
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":"85e1b2fc5e80c462bb281d4a9b72b3d86e9f5e8f","commit-branch":"master","commit-committed-at":"2015-05-16
9
+ 19:39:41 -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":"Checkpoint
10
+ some initial resources and snapshots work.","pull-request-number":null}}}'
11
+ headers:
12
+ User-Agent:
13
+ - Faraday v0.9.1
14
+ Accept:
15
+ - "*/*"
16
+ Date:
17
+ - Sun, 17 May 2015 04:14:19 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
+ X-Frame-Options:
28
+ - SAMEORIGIN
29
+ X-Xss-Protection:
30
+ - 1; mode=block
31
+ X-Content-Type-Options:
32
+ - nosniff
33
+ Access-Control-Allow-Origin:
34
+ - "*"
35
+ Access-Control-Allow-Methods:
36
+ - GET, POST, PUT, PATCH, DELETE, OPTIONS
37
+ Access-Control-Allow-Headers:
38
+ - Authorization, Content-Type
39
+ Cache-Control:
40
+ - no-cache, no-store, max-age=0, must-revalidate
41
+ Expires:
42
+ - Thu, 01 Jan 1970 00:00:00 GMT
43
+ Content-Type:
44
+ - application/json; charset=utf-8
45
+ X-Request-Id:
46
+ - 56e5ca60-cdfc-4882-9407-aac6c0f332e5
47
+ X-Runtime:
48
+ - '0.019241'
49
+ Server:
50
+ - WEBrick/1.3.1 (Ruby/2.1.5/2014-11-13)
51
+ Date:
52
+ - Sun, 17 May 2015 04:14:19 GMT
53
+ Content-Length:
54
+ - '2402'
55
+ Connection:
56
+ - Keep-Alive
57
+ body:
58
+ encoding: UTF-8
59
+ string: '{"data":{"id":"11","type":"builds","attributes":{"state":"pending","is-pull-request":false,"pull-request-number":0,"pull-request-title":null,"approved-at":null,"created-at":"2015-05-17T04:14:19.984Z","updated-at":"2015-05-17T04:14:19.984Z"},"links":{"self":"/api/v1/builds/11","commit":{"self":"/api/v1/builds/11/links/commit","related":"/api/v1/builds/11/commit","linkage":{"type":"commits","id":"1"}},"repo":{"self":"/api/v1/builds/11/links/repo","related":"/api/v1/builds/11/repo"},"base-build":{"self":"/api/v1/builds/11/links/base-build","related":"/api/v1/builds/11/base-build","linkage":{"type":"builds","id":"8"}},"approved-by":{"self":"/api/v1/builds/11/links/approved-by","related":"/api/v1/builds/11/approved-by"},"snapshots":{"self":"/api/v1/builds/11/links/snapshots","related":"/api/v1/builds/11/snapshots"},"comparisons":{"self":"/api/v1/builds/11/links/comparisons","related":"/api/v1/builds/11/comparisons"}},"meta":{"finalize-link":"/api/v1/builds/11/finalize","approve-link":"/api/v1/builds/11/approve"}},"included":[{"id":"1","type":"commits","attributes":{"sha":"85e1b2fc5e80c462bb281d4a9b72b3d86e9f5e8f","branch":"master","message":"Checkpoint
60
+ some initial resources and snapshots work.","committed-at":"2015-05-16 19:39:41
61
+ -0700","author-name":"<COMMIT_AUTHOR_NAME>","committer-name":"<COMMIT_AUTHOR_NAME>","created-at":"2015-05-17T04:02:54.000Z","updated-at":"2015-05-17T04:02:54.000Z"},"links":{"self":"/api/v1/commits/1"}},{"id":"8","type":"builds","attributes":{"state":"finished","is-pull-request":false,"pull-request-number":0,"pull-request-title":null,"approved-at":null,"created-at":"2015-05-17T04:12:48.000Z","updated-at":"2015-05-17T04:12:48.000Z"},"links":{"self":"/api/v1/builds/8","commit":{"self":"/api/v1/builds/8/links/commit","related":"/api/v1/builds/8/commit","linkage":{"type":"commits","id":"1"}},"repo":{"self":"/api/v1/builds/8/links/repo","related":"/api/v1/builds/8/repo"},"base-build":{"self":"/api/v1/builds/8/links/base-build","related":"/api/v1/builds/8/base-build"},"approved-by":{"self":"/api/v1/builds/8/links/approved-by","related":"/api/v1/builds/8/approved-by"},"snapshots":{"self":"/api/v1/builds/8/links/snapshots","related":"/api/v1/builds/8/snapshots"},"comparisons":{"self":"/api/v1/builds/8/links/comparisons","related":"/api/v1/builds/8/comparisons"}},"meta":{"finalize-link":"/api/v1/builds/8/finalize","approve-link":"/api/v1/builds/8/approve"}}]}'
62
+ http_version:
63
+ recorded_at: Sun, 17 May 2015 04:14:19 GMT
64
+ - request:
65
+ method: post
66
+ uri: http://localhost:3000/api/v1/builds/11/snapshots/
67
+ body:
68
+ encoding: UTF-8
69
+ string: '{"data":{"type":"snapshots","attributes":{"name":null},"links":{"resources":[]}}}'
70
+ headers:
71
+ User-Agent:
72
+ - Faraday v0.9.1
73
+ Accept:
74
+ - "*/*"
75
+ Date:
76
+ - Sun, 17 May 2015 04:14:19 GMT
77
+ Content-Type:
78
+ - application/vnd.api+json
79
+ Authorization:
80
+ - Token token="<FILTERED_PERCY_TOKEN>"
81
+ response:
82
+ status:
83
+ code: 400
84
+ message: 'Bad Request '
85
+ headers:
86
+ X-Frame-Options:
87
+ - SAMEORIGIN
88
+ X-Xss-Protection:
89
+ - 1; mode=block
90
+ X-Content-Type-Options:
91
+ - nosniff
92
+ Access-Control-Allow-Origin:
93
+ - "*"
94
+ Access-Control-Allow-Methods:
95
+ - GET, POST, PUT, PATCH, DELETE, OPTIONS
96
+ Access-Control-Allow-Headers:
97
+ - Authorization, Content-Type
98
+ Cache-Control:
99
+ - no-cache, no-store, max-age=0, must-revalidate
100
+ Expires:
101
+ - Thu, 01 Jan 1970 00:00:00 GMT
102
+ Content-Type:
103
+ - application/json; charset=utf-8
104
+ X-Request-Id:
105
+ - f0bfa805-88ee-4677-a6cc-81cd288fa6da
106
+ X-Runtime:
107
+ - '0.007550'
108
+ Server:
109
+ - WEBrick/1.3.1 (Ruby/2.1.5/2014-11-13)
110
+ Date:
111
+ - Sun, 17 May 2015 04:14:20 GMT
112
+ Content-Length:
113
+ - '98'
114
+ Connection:
115
+ - Keep-Alive
116
+ body:
117
+ encoding: UTF-8
118
+ string: '{"errors":[{"status":"bad_request","detail":"param is missing or the
119
+ value is empty: resources"}]}'
120
+ http_version:
121
+ recorded_at: Sun, 17 May 2015 04:14:20 GMT
122
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,19 @@
1
+ RSpec.describe Percy::Client::Builds, :vcr do
2
+ describe '#create_build' do
3
+ it 'creates a build' do
4
+ build = Percy.create_build('fotinakis/percy-examples')
5
+ expect(build).to be
6
+ expect(build['data']).to be
7
+ expect(build['data']['id']).to be
8
+ expect(build['data']['type']).to eq('builds')
9
+ expect(build['data']['attributes']['state']).to eq('pending')
10
+ end
11
+ end
12
+ describe '#finalize_build' do
13
+ it 'finalizes a build' do
14
+ build = Percy.create_build('fotinakis/percy-examples')
15
+ result = Percy.finalize_build(build['data']['id'])
16
+ expect(result).to eq({'success' => true})
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,16 @@
1
+ RSpec.describe Percy::Client::Connection do
2
+ describe '#get' do
3
+ it 'performs a GET request to the base_url and parses response' do
4
+ stub_request(:get, build_url('/test')).to_return(body: {foo: true}.to_json)
5
+ data = Percy.client.get('/test')
6
+ expect(data).to eq({'foo' => true})
7
+ end
8
+ end
9
+ describe '#post' do
10
+ it 'performs a POST request to the base_url and parses response' do
11
+ stub_request(:post, build_url('/test')).to_return(body: {foo: true}.to_json)
12
+ data = Percy.client.post('/test', {})
13
+ expect(data).to eq({'foo' => true})
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,21 @@
1
+ RSpec.describe Percy::Client::LocalGit do
2
+ describe '#current_local_repo' do
3
+ it 'returns the current local repo name' do
4
+ expect(Percy.current_local_repo).to eq('percy/percy-client')
5
+ end
6
+ end
7
+ describe '#current_local_commit' do
8
+ it 'returns current local commit data' do
9
+ commit = Percy.current_local_commit
10
+ expect(commit[:author_email]).to match(/.+@.+\..+/)
11
+ expect(commit[:author_name]).to_not be_empty
12
+ expect(commit[:branch]).to_not be_empty
13
+ expect(commit[:committed_at]).to_not be_empty
14
+ expect(commit[:committer_email]).to_not be_empty
15
+ expect(commit[:committer_name]).to_not be_empty
16
+ expect(commit[:message]).to_not be_empty
17
+ expect(commit[:sha]).to_not be_empty
18
+ expect(commit[:sha].length).to eq(40)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,40 @@
1
+ require 'digest'
2
+
3
+ RSpec.describe Percy::Client::Resources, :vcr do
4
+ let(:content) { 'hello world!' }
5
+ let(:sha) { Digest::SHA256.hexdigest(content) }
6
+
7
+ describe 'Percy::Client::Resource' do
8
+ it 'can be initialized with minimal data' do
9
+ resource = Percy::Client::Resource.new(sha, '/foo.html')
10
+ expect(resource.serialize).to eq({
11
+ 'type' => 'resources',
12
+ 'id' => sha,
13
+ 'resource-url' => '/foo.html',
14
+ 'mimetype' => nil,
15
+ 'is-root' => nil,
16
+ })
17
+ end
18
+ it 'can be initialized with all data' do
19
+ resource = Percy::Client::Resource.new(sha, '/foo.html', is_root: true, mimetype: 'text/html')
20
+ expect(resource.serialize).to eq({
21
+ 'type' => 'resources',
22
+ 'id' => sha,
23
+ 'resource-url' => '/foo.html',
24
+ 'mimetype' => 'text/html',
25
+ 'is-root' => true,
26
+ })
27
+ end
28
+ end
29
+ describe '#upload_resource' do
30
+ it 'returns true with success' do
31
+ build = Percy.create_build('fotinakis/percy-examples')
32
+ resources = [Percy::Client::Resource.new(sha, '/foo/test.html', is_root: true)]
33
+ Percy.create_snapshot(build['data']['id'], resources, name: 'homepage')
34
+
35
+ # Verify that upload_resource hides conflict errors, though they are output to stderr.
36
+ expect(Percy.upload_resource(build['data']['id'], content)).to be_truthy
37
+ expect(Percy.upload_resource(build['data']['id'], content)).to be_truthy
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,26 @@
1
+ RSpec.describe Percy::Client::Snapshots, :vcr do
2
+ let(:content) { 'hello world!' }
3
+ let(:sha) { Digest::SHA256.hexdigest(content) }
4
+
5
+ describe '#create_snapshot' do
6
+ it 'creates a build' do
7
+ build = Percy.create_build('fotinakis/percy-examples')
8
+ resources = []
9
+ resources << Percy::Client::Resource.new(sha, '/foo/test.html', is_root: true)
10
+ resources << Percy::Client::Resource.new(sha, '/css/test.css')
11
+ snapshot = Percy.create_snapshot(build['data']['id'], resources, name: 'homepage')
12
+
13
+ expect(snapshot['data']).to be
14
+ expect(snapshot['data']['id']).to be
15
+ expect(snapshot['data']['type']).to eq('snapshots')
16
+ expect(snapshot['data']['attributes']['name']).to eq('homepage')
17
+ expect(snapshot['data']['links']['missing-resources']).to be
18
+ end
19
+ it 'fails if no resources are given' do
20
+ build = Percy.create_build('fotinakis/percy-examples')
21
+ expect do
22
+ Percy.create_snapshot(build['data']['id'], [])
23
+ end.to raise_error(Percy::Client::ClientError)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,17 @@
1
+ RSpec.describe Percy::Client do
2
+ describe '#base_url' do
3
+ it 'returns the base API URL' do
4
+ expect(Percy.client.base_url).to eq('http://localhost:3000')
5
+ end
6
+ end
7
+ describe '#base_path' do
8
+ it 'returns the base API URL path' do
9
+ expect(Percy.client.base_path).to eq('/api/v1')
10
+ end
11
+ end
12
+ describe '#full_base' do
13
+ it 'returns the full base API URL path' do
14
+ expect(Percy.client.full_base).to eq('http://localhost:3000/api/v1')
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,34 @@
1
+ ENV['PERCY_API'] = 'http://localhost:3000'
2
+
3
+ require 'support/test_helpers'
4
+ require 'support/vcr_setup'
5
+ require 'webmock/rspec'
6
+ require 'percy'
7
+
8
+ RSpec.configure do |config|
9
+ config.include TestHelpers
10
+
11
+ config.expect_with :rspec do |expectations|
12
+ # This option will default to `true` in RSpec 4.
13
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
14
+ end
15
+
16
+ config.mock_with :rspec do |mocks|
17
+ mocks.verify_partial_doubles = true
18
+ end
19
+
20
+ config.disable_monkey_patching!
21
+ config.warnings = true
22
+
23
+ # Run specs in random order to surface order dependencies. If you find an
24
+ # order dependency and want to debug it, you can fix the order by providing
25
+ # the seed, which is printed after each run.
26
+ # --seed 1234
27
+ config.order = :random
28
+
29
+ # Seed global randomization in this process using the `--seed` CLI option.
30
+ # Setting this allows you to use `--seed` to deterministically reproduce
31
+ # test failures related to randomization by passing the same `--seed` value
32
+ # as the one that triggered the failure.
33
+ Kernel.srand config.seed
34
+ end
@@ -0,0 +1,7 @@
1
+ require 'percy'
2
+
3
+ module TestHelpers
4
+ def build_url(path)
5
+ "#{Percy.client.base_url}#{path}"
6
+ end
7
+ end
@@ -0,0 +1,27 @@
1
+ require 'vcr'
2
+
3
+ VCR.configure do |c|
4
+ c.configure_rspec_metadata!
5
+ c.cassette_library_dir = 'spec/cassettes'
6
+ c.hook_into :webmock
7
+
8
+ c.default_cassette_options = {
9
+ record: ENV['RECORD'] ? :new_episodes : :none
10
+ }
11
+
12
+ c.filter_sensitive_data('<FILTERED_PERCY_TOKEN>') do
13
+ ENV['PERCY_TOKEN']
14
+ end
15
+ c.filter_sensitive_data('<COMMIT_AUTHOR_NAME>') do
16
+ `git show --quiet --format="%an"`.strip
17
+ end
18
+ c.filter_sensitive_data('<COMMIT_AUTHOR_EMAIL>') do
19
+ `git show --quiet --format="%ae"`.strip
20
+ end
21
+ c.filter_sensitive_data('<COMMIT_COMMITTER_NAME>') do
22
+ `git show --quiet --format="%cn"`.strip
23
+ end
24
+ c.filter_sensitive_data('<COMMIT_COMMITTER_EMAIL>') do
25
+ `git show --quiet --format="%ce"`.strip
26
+ end
27
+ end