hyperclient 0.9.3 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -14,21 +14,21 @@ module Hyperclient
14
14
  end
15
15
 
16
16
  it 'is a collection' do
17
- ResourceCollection.ancestors.must_include Collection
17
+ _(ResourceCollection.ancestors).must_include Collection
18
18
  end
19
19
 
20
20
  it 'initializes the collection with resources' do
21
- resources.must_respond_to :author
22
- resources.must_respond_to :episodes
21
+ _(resources).must_respond_to :author
22
+ _(resources).must_respond_to :episodes
23
23
  end
24
24
 
25
25
  it 'returns resource objects for each resource' do
26
- resources.author.must_be_kind_of Resource
26
+ _(resources.author).must_be_kind_of Resource
27
27
  end
28
28
 
29
29
  it 'also builds arras of resource' do
30
- resources.episodes.must_be_kind_of Array
31
- resources.episodes.first.must_be_kind_of Resource
30
+ _(resources.episodes).must_be_kind_of Array
31
+ _(resources.episodes.first).must_be_kind_of Resource
32
32
  end
33
33
  end
34
34
  end
@@ -29,7 +29,7 @@ module Hyperclient
29
29
 
30
30
  resource = Resource.new(mock_response.body, entry_point, mock_response)
31
31
 
32
- resource._response.must_equal mock_response
32
+ _(resource._response).must_equal mock_response
33
33
  end
34
34
 
35
35
  it 'does not mutate the response.body' do
@@ -38,7 +38,7 @@ module Hyperclient
38
38
 
39
39
  resource = Resource.new(mock_response.body, entry_point, mock_response)
40
40
 
41
- resource._response.body.must_equal body
41
+ _(resource._response.body).must_equal body
42
42
  end
43
43
 
44
44
  describe 'with an empty body in response' do
@@ -47,13 +47,13 @@ module Hyperclient
47
47
 
48
48
  resource = Resource.new(mock_response.body, entry_point, mock_response)
49
49
 
50
- resource._response.must_equal mock_response
50
+ _(resource._response).must_equal mock_response
51
51
  end
52
52
  end
53
53
 
54
54
  describe 'with an invalid representation' do
55
55
  it 'raises an InvalidRepresentationError' do
56
- proc { Resource.new('invalid representation data', entry_point) }.must_raise InvalidRepresentationError
56
+ _(proc { Resource.new('invalid representation data', entry_point) }).must_raise InvalidRepresentationError
57
57
  end
58
58
  end
59
59
  end
@@ -61,9 +61,9 @@ module Hyperclient
61
61
  describe '_links' do
62
62
  it '_expand' do
63
63
  resource = Resource.new({ '_links' => { 'orders' => { 'href' => '/orders/{id}', 'templated' => true } } }, entry_point)
64
- resource._links.orders._expand(id: 1)._url.must_equal '/orders/1'
65
- resource.orders._expand(id: 1)._url.must_equal '/orders/1'
66
- resource.orders(id: 1)._url.must_equal '/orders/1'
64
+ _(resource._links.orders._expand(id: 1)._url).must_equal '/orders/1'
65
+ _(resource.orders._expand(id: 1)._url).must_equal '/orders/1'
66
+ _(resource.orders(id: 1)._url).must_equal '/orders/1'
67
67
  end
68
68
  end
69
69
 
@@ -74,84 +74,84 @@ module Hyperclient
74
74
 
75
75
  describe 'links' do
76
76
  it 'returns a LinkCollection' do
77
- resource._links.must_be_kind_of LinkCollection
77
+ _(resource._links).must_be_kind_of LinkCollection
78
78
  end
79
79
  end
80
80
 
81
81
  describe 'attributes' do
82
82
  it 'returns a Attributes' do
83
- resource._attributes.must_be_kind_of Attributes
83
+ _(resource._attributes).must_be_kind_of Attributes
84
84
  end
85
85
  end
86
86
 
87
87
  describe 'embedded' do
88
88
  it 'returns a ResourceCollection' do
89
- resource._embedded.must_be_kind_of ResourceCollection
89
+ _(resource._embedded).must_be_kind_of ResourceCollection
90
90
  end
91
91
  end
92
92
 
93
93
  describe 'method_missing' do
94
94
  it 'delegates to attributes' do
95
95
  resource._attributes.expects(:foo).returns('bar')
96
- resource.foo.must_equal 'bar'
96
+ _(resource.foo).must_equal 'bar'
97
97
  end
98
98
 
99
99
  it 'delegates to links' do
100
100
  resource._links.expects(:foo).returns('bar')
101
- resource.foo.must_equal 'bar'
101
+ _(resource.foo).must_equal 'bar'
102
102
  end
103
103
 
104
104
  it 'delegates to embedded' do
105
105
  resource._embedded.expects(:foo).returns('bar')
106
- resource.foo.must_equal 'bar'
106
+ _(resource.foo).must_equal 'bar'
107
107
  end
108
108
 
109
109
  it 'delegates to attributes, links, embedded' do
110
110
  resource._attributes.expects('respond_to?').with('foo').returns(false)
111
111
  resource._links.expects('respond_to?').with('foo').returns(false)
112
112
  resource._embedded.expects('respond_to?').with('foo').returns(false)
113
- -> { resource.foo }.must_raise NoMethodError
113
+ _(-> { resource.foo }).must_raise NoMethodError
114
114
  end
115
115
 
116
116
  it 'delegates []' do
117
117
  resource._attributes.expects(:foo).returns('bar')
118
- resource['foo'].must_equal 'bar'
118
+ _(resource['foo']).must_equal 'bar'
119
119
  end
120
120
 
121
121
  describe '#fetch' do
122
122
  it 'returns the value for keys that exist' do
123
123
  resource._attributes.expects(:foo).returns('bar')
124
124
 
125
- resource.fetch('foo').must_equal 'bar'
125
+ _(resource.fetch('foo')).must_equal 'bar'
126
126
  end
127
127
 
128
128
  it 'raises an error for missing keys' do
129
- proc { resource.fetch('missing key') }.must_raise KeyError
129
+ _(proc { resource.fetch('missing key') }).must_raise KeyError
130
130
  end
131
131
 
132
132
  describe 'with a default value' do
133
133
  it 'returns the value for keys that exist' do
134
134
  resource._attributes.expects(:foo).returns('bar')
135
- resource.fetch('foo', 'default value').must_equal 'bar'
135
+ _(resource.fetch('foo', 'default value')).must_equal 'bar'
136
136
  end
137
137
 
138
138
  it 'returns the default value for missing keys' do
139
- resource.fetch('missing key', 'default value').must_equal 'default value'
139
+ _(resource.fetch('missing key', 'default value')).must_equal 'default value'
140
140
  end
141
141
  end
142
142
 
143
143
  describe 'with a block' do
144
144
  it 'returns the value for keys that exist' do
145
145
  resource._attributes.expects(:foo).returns('bar')
146
- resource.fetch('foo') { 'default value' }.must_equal 'bar'
146
+ _(resource.fetch('foo') { 'default value' }).must_equal 'bar'
147
147
  end
148
148
 
149
149
  it 'returns the value from the block' do
150
- resource.fetch('z') { 'go fish!' }.must_equal 'go fish!'
150
+ _(resource.fetch('z') { 'go fish!' }).must_equal 'go fish!'
151
151
  end
152
152
 
153
153
  it 'returns the value with args from the block' do
154
- resource.fetch('z') { |el| "go fish, #{el}" }.must_equal 'go fish, z'
154
+ _(resource.fetch('z') { |el| "go fish, #{el}" }).must_equal 'go fish, z'
155
155
  end
156
156
  end
157
157
  end
@@ -179,7 +179,7 @@ module Hyperclient
179
179
  end
180
180
 
181
181
  it 'proxies to the response object' do
182
- resource._success?.must_equal true
182
+ _(resource._success?).must_equal true
183
183
  end
184
184
  end
185
185
 
@@ -189,7 +189,7 @@ module Hyperclient
189
189
  end
190
190
 
191
191
  it 'returns nil' do
192
- resource._success?.must_be_nil
192
+ _(resource._success?).must_be_nil
193
193
  end
194
194
  end
195
195
  end
@@ -205,7 +205,7 @@ module Hyperclient
205
205
  end
206
206
 
207
207
  it 'proxies to the response object' do
208
- resource._status.must_equal 200
208
+ _(resource._status).must_equal 200
209
209
  end
210
210
  end
211
211
 
@@ -215,7 +215,7 @@ module Hyperclient
215
215
  end
216
216
 
217
217
  it 'returns nil' do
218
- resource._status.must_be_nil
218
+ _(resource._status).must_be_nil
219
219
  end
220
220
  end
221
221
  end
@@ -20,23 +20,22 @@ describe Hyperclient do
20
20
  end
21
21
 
22
22
  it 'creates a Faraday connection with the default and additional headers' do
23
- client.headers['Content-Type'].must_equal 'application/hal+json'
24
- client.headers['Accept'].must_equal 'application/hal+json,application/json'
25
- client.headers['Access-Token'].must_equal 'token'
23
+ _(client.headers['Content-Type']).must_equal 'application/hal+json'
24
+ _(client.headers['Accept']).must_equal 'application/hal+json,application/json'
25
+ _(client.headers['Access-Token']).must_equal 'token'
26
26
  end
27
27
 
28
28
  it 'creates a Faraday connection with the entry point url' do
29
- client.connection.url_prefix.to_s.must_equal 'http://api.example.org/'
29
+ _(client.connection.url_prefix.to_s).must_equal 'http://api.example.org/'
30
30
  end
31
31
 
32
32
  it 'creates a Faraday connection with the default block plus any additional handlers' do
33
33
  handlers = client.connection.builder.handlers
34
- handlers.must_include Faraday::Request::OAuth
35
- handlers.must_include Faraday::Response::RaiseError
36
- handlers.must_include FaradayMiddleware::FollowRedirects
37
- handlers.must_include FaradayMiddleware::EncodeHalJson
38
- handlers.must_include FaradayMiddleware::ParseHalJson
39
- handlers.must_include Faraday::Adapter::NetHttp
34
+ _(handlers).must_include Faraday::Request::OAuth
35
+ _(handlers).must_include Faraday::Response::RaiseError
36
+ _(handlers).must_include FaradayMiddleware::FollowRedirects
37
+ _(handlers).must_include FaradayMiddleware::EncodeHalJson
38
+ _(handlers).must_include FaradayMiddleware::ParseHalJson
40
39
  end
41
40
  end
42
41
  end
@@ -2,12 +2,16 @@ $LOAD_PATH << 'lib'
2
2
 
3
3
  require 'minitest/autorun'
4
4
  require 'minitest/pride'
5
- require 'mocha/setup'
5
+ require 'mocha/minitest'
6
6
  require 'json'
7
7
 
8
8
  MiniTest::Test.class_eval do
9
9
  def stub_request(conn, adapter_class = Faraday::Adapter::Test, &stubs_block)
10
10
  adapter_handler = conn.builder.handlers.find { |h| h.klass < Faraday::Adapter }
11
- conn.builder.swap(adapter_handler, adapter_class, &stubs_block)
11
+ if adapter_handler
12
+ conn.builder.swap(adapter_handler, adapter_class, &stubs_block)
13
+ else
14
+ conn.builder.adapter adapter_class, &stubs_block
15
+ end
12
16
  end
13
17
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hyperclient
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.3
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oriol Gual
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-14 00:00:00.000000000 Z
11
+ date: 2021-01-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -38,20 +38,6 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: 0.9.0
41
- - !ruby/object:Gem::Dependency
42
- name: faraday-digestauth
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: 0.3.0
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: 0.3.0
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: faraday_hal_middleware
57
43
  requirement: !ruby/object:Gem::Requirement
@@ -80,20 +66,6 @@ dependencies:
80
66
  - - ">="
81
67
  - !ruby/object:Gem::Version
82
68
  version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: net-http-digest_auth
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
- type: :runtime
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: '0'
97
69
  description: Hyperclient is a Ruby Hypermedia API client.
98
70
  email:
99
71
  - oriol.gual@gmail.com
@@ -125,7 +97,6 @@ files:
125
97
  - features/support/env.rb
126
98
  - features/support/fixtures.rb
127
99
  - hyperclient.gemspec
128
- - lib/faraday/connection.rb
129
100
  - lib/hyperclient.rb
130
101
  - lib/hyperclient/attributes.rb
131
102
  - lib/hyperclient/collection.rb
@@ -136,7 +107,6 @@ files:
136
107
  - lib/hyperclient/resource.rb
137
108
  - lib/hyperclient/resource_collection.rb
138
109
  - lib/hyperclient/version.rb
139
- - test/faraday/connection_test.rb
140
110
  - test/fixtures/collection.json
141
111
  - test/fixtures/element.json
142
112
  - test/fixtures/root.json
@@ -153,7 +123,7 @@ files:
153
123
  homepage: https://github.com/codegram/hyperclient/
154
124
  licenses: []
155
125
  metadata: {}
156
- post_install_message:
126
+ post_install_message:
157
127
  rdoc_options: []
158
128
  require_paths:
159
129
  - lib
@@ -169,7 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
169
139
  version: '0'
170
140
  requirements: []
171
141
  rubygems_version: 3.1.3
172
- signing_key:
142
+ signing_key:
173
143
  specification_version: 4
174
144
  summary: ''
175
145
  test_files:
@@ -180,7 +150,6 @@ test_files:
180
150
  - features/support/api.rb
181
151
  - features/support/env.rb
182
152
  - features/support/fixtures.rb
183
- - test/faraday/connection_test.rb
184
153
  - test/fixtures/collection.json
185
154
  - test/fixtures/element.json
186
155
  - test/fixtures/root.json
@@ -1,17 +0,0 @@
1
- require 'faraday'
2
- require 'faraday/digestauth'
3
-
4
- module Faraday
5
- # Reopen Faraday::Connection to add a helper to set the digest auth data.
6
- class Connection
7
- # Public: Adds the digest auth middleware at the top and sets the user and
8
- # password.
9
- #
10
- # user - A String with the user.
11
- # password - A String with the password.
12
- #
13
- def digest_auth(user, password)
14
- builder.insert(0, Faraday::Request::DigestAuth, user, password)
15
- end
16
- end
17
- end
@@ -1,29 +0,0 @@
1
- require_relative '../test_helper'
2
- require_relative '../../lib/faraday/connection'
3
-
4
- module Faraday
5
- describe Connection do
6
- describe 'digest_auth' do
7
- let(:connection) do
8
- Faraday.new('http://api.example.org/') do |builder|
9
- builder.request :url_encoded
10
- builder.adapter :net_http
11
- end
12
- end
13
-
14
- it 'inserts the DigestAuth middleware at the top' do
15
- connection.digest_auth('user', 'password')
16
-
17
- connection.builder.handlers.first.klass.must_equal Faraday::Request::DigestAuth
18
- end
19
-
20
- it 'passes the user and password to the middleware' do
21
- connection.digest_auth('user', 'password')
22
-
23
- Faraday::Request::DigestAuth.expects(:new).with(anything, 'user', 'password').returns(stub_everything)
24
-
25
- connection.get('/')
26
- end
27
- end
28
- end
29
- end