hyperclient 0.8.5 → 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,16 +38,32 @@ 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
+ end
43
+
44
+ describe 'with an empty body in response' do
45
+ it 'initializes the response' do
46
+ mock_response = mock(body: '')
47
+
48
+ resource = Resource.new(mock_response.body, entry_point, mock_response)
49
+
50
+ _(resource._response).must_equal mock_response
51
+ end
52
+ end
53
+
54
+ describe 'with an invalid representation' do
55
+ it 'raises an InvalidRepresentationError' do
56
+ _(proc { Resource.new('invalid representation data', entry_point) }).must_raise InvalidRepresentationError
57
+ end
42
58
  end
43
59
  end
44
60
 
45
61
  describe '_links' do
46
62
  it '_expand' do
47
63
  resource = Resource.new({ '_links' => { 'orders' => { 'href' => '/orders/{id}', 'templated' => true } } }, entry_point)
48
- resource._links.orders._expand(id: 1)._url.must_equal '/orders/1'
49
- resource.orders._expand(id: 1)._url.must_equal '/orders/1'
50
- 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'
51
67
  end
52
68
  end
53
69
 
@@ -58,84 +74,84 @@ module Hyperclient
58
74
 
59
75
  describe 'links' do
60
76
  it 'returns a LinkCollection' do
61
- resource._links.must_be_kind_of LinkCollection
77
+ _(resource._links).must_be_kind_of LinkCollection
62
78
  end
63
79
  end
64
80
 
65
81
  describe 'attributes' do
66
82
  it 'returns a Attributes' do
67
- resource._attributes.must_be_kind_of Attributes
83
+ _(resource._attributes).must_be_kind_of Attributes
68
84
  end
69
85
  end
70
86
 
71
87
  describe 'embedded' do
72
88
  it 'returns a ResourceCollection' do
73
- resource._embedded.must_be_kind_of ResourceCollection
89
+ _(resource._embedded).must_be_kind_of ResourceCollection
74
90
  end
75
91
  end
76
92
 
77
93
  describe 'method_missing' do
78
94
  it 'delegates to attributes' do
79
95
  resource._attributes.expects(:foo).returns('bar')
80
- resource.foo.must_equal 'bar'
96
+ _(resource.foo).must_equal 'bar'
81
97
  end
82
98
 
83
99
  it 'delegates to links' do
84
100
  resource._links.expects(:foo).returns('bar')
85
- resource.foo.must_equal 'bar'
101
+ _(resource.foo).must_equal 'bar'
86
102
  end
87
103
 
88
104
  it 'delegates to embedded' do
89
105
  resource._embedded.expects(:foo).returns('bar')
90
- resource.foo.must_equal 'bar'
106
+ _(resource.foo).must_equal 'bar'
91
107
  end
92
108
 
93
109
  it 'delegates to attributes, links, embedded' do
94
110
  resource._attributes.expects('respond_to?').with('foo').returns(false)
95
111
  resource._links.expects('respond_to?').with('foo').returns(false)
96
112
  resource._embedded.expects('respond_to?').with('foo').returns(false)
97
- lambda { resource.foo }.must_raise NoMethodError
113
+ _(-> { resource.foo }).must_raise NoMethodError
98
114
  end
99
115
 
100
116
  it 'delegates []' do
101
117
  resource._attributes.expects(:foo).returns('bar')
102
- resource['foo'].must_equal 'bar'
118
+ _(resource['foo']).must_equal 'bar'
103
119
  end
104
120
 
105
121
  describe '#fetch' do
106
122
  it 'returns the value for keys that exist' do
107
123
  resource._attributes.expects(:foo).returns('bar')
108
124
 
109
- resource.fetch('foo').must_equal 'bar'
125
+ _(resource.fetch('foo')).must_equal 'bar'
110
126
  end
111
127
 
112
128
  it 'raises an error for missing keys' do
113
- proc { resource.fetch('missing key') }.must_raise KeyError
129
+ _(proc { resource.fetch('missing key') }).must_raise KeyError
114
130
  end
115
131
 
116
132
  describe 'with a default value' do
117
133
  it 'returns the value for keys that exist' do
118
134
  resource._attributes.expects(:foo).returns('bar')
119
- resource.fetch('foo', 'default value').must_equal 'bar'
135
+ _(resource.fetch('foo', 'default value')).must_equal 'bar'
120
136
  end
121
137
 
122
138
  it 'returns the default value for missing keys' do
123
- resource.fetch('missing key', 'default value').must_equal 'default value'
139
+ _(resource.fetch('missing key', 'default value')).must_equal 'default value'
124
140
  end
125
141
  end
126
142
 
127
143
  describe 'with a block' do
128
144
  it 'returns the value for keys that exist' do
129
145
  resource._attributes.expects(:foo).returns('bar')
130
- resource.fetch('foo') { 'default value' }.must_equal 'bar'
146
+ _(resource.fetch('foo') { 'default value' }).must_equal 'bar'
131
147
  end
132
148
 
133
149
  it 'returns the value from the block' do
134
- resource.fetch('z') { 'go fish!' }.must_equal 'go fish!'
150
+ _(resource.fetch('z') { 'go fish!' }).must_equal 'go fish!'
135
151
  end
136
152
 
137
153
  it 'returns the value with args from the block' do
138
- 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'
139
155
  end
140
156
  end
141
157
  end
@@ -163,7 +179,7 @@ module Hyperclient
163
179
  end
164
180
 
165
181
  it 'proxies to the response object' do
166
- resource._success?.must_equal true
182
+ _(resource._success?).must_equal true
167
183
  end
168
184
  end
169
185
 
@@ -173,7 +189,7 @@ module Hyperclient
173
189
  end
174
190
 
175
191
  it 'returns nil' do
176
- resource._success?.must_be_nil
192
+ _(resource._success?).must_be_nil
177
193
  end
178
194
  end
179
195
  end
@@ -189,7 +205,7 @@ module Hyperclient
189
205
  end
190
206
 
191
207
  it 'proxies to the response object' do
192
- resource._status.must_equal 200
208
+ _(resource._status).must_equal 200
193
209
  end
194
210
  end
195
211
 
@@ -199,7 +215,7 @@ module Hyperclient
199
215
  end
200
216
 
201
217
  it 'returns nil' do
202
- resource._status.must_be_nil
218
+ _(resource._status).must_be_nil
203
219
  end
204
220
  end
205
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
@@ -1,18 +1,17 @@
1
1
  $LOAD_PATH << 'lib'
2
2
 
3
- require 'minitest/spec'
4
3
  require 'minitest/autorun'
5
- require 'mocha/setup'
6
- require 'turn'
4
+ require 'minitest/pride'
5
+ require 'mocha/minitest'
7
6
  require 'json'
8
7
 
9
- MiniTest::Unit::TestCase.class_eval do
8
+ MiniTest::Test.class_eval do
10
9
  def stub_request(conn, adapter_class = Faraday::Adapter::Test, &stubs_block)
11
10
  adapter_handler = conn.builder.handlers.find { |h| h.klass < Faraday::Adapter }
12
- 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
13
16
  end
14
17
  end
15
-
16
- require 'futuroscope'
17
- require 'futuroscope/pools/no_pool'
18
- Futuroscope.default_pool = Futuroscope::Pools::NoPool.new
metadata CHANGED
@@ -1,31 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hyperclient
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.5
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: 2017-07-05 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
- name: faraday
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: 0.9.0
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: 0.9.0
27
- - !ruby/object:Gem::Dependency
28
- name: futuroscope
14
+ name: addressable
29
15
  requirement: !ruby/object:Gem::Requirement
30
16
  requirements:
31
17
  - - ">="
@@ -39,19 +25,19 @@ dependencies:
39
25
  - !ruby/object:Gem::Version
40
26
  version: '0'
41
27
  - !ruby/object:Gem::Dependency
42
- name: faraday_middleware
28
+ name: faraday
43
29
  requirement: !ruby/object:Gem::Requirement
44
30
  requirements:
45
31
  - - ">="
46
32
  - !ruby/object:Gem::Version
47
- version: '0'
33
+ version: 0.9.0
48
34
  type: :runtime
49
35
  prerelease: false
50
36
  version_requirements: !ruby/object:Gem::Requirement
51
37
  requirements:
52
38
  - - ">="
53
39
  - !ruby/object:Gem::Version
54
- version: '0'
40
+ version: 0.9.0
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: faraday_hal_middleware
57
43
  requirement: !ruby/object:Gem::Requirement
@@ -67,35 +53,7 @@ dependencies:
67
53
  - !ruby/object:Gem::Version
68
54
  version: '0'
69
55
  - !ruby/object:Gem::Dependency
70
- name: uri_template
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :runtime
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- 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
- - !ruby/object:Gem::Dependency
98
- name: faraday-digestauth
56
+ name: faraday_middleware
99
57
  requirement: !ruby/object:Gem::Requirement
100
58
  requirements:
101
59
  - - ">="
@@ -108,7 +66,7 @@ dependencies:
108
66
  - - ">="
109
67
  - !ruby/object:Gem::Version
110
68
  version: '0'
111
- description: HyperClient is a Ruby Hypermedia API client.
69
+ description: Hyperclient is a Ruby Hypermedia API client.
112
70
  email:
113
71
  - oriol.gual@gmail.com
114
72
  executables: []
@@ -139,7 +97,6 @@ files:
139
97
  - features/support/env.rb
140
98
  - features/support/fixtures.rb
141
99
  - hyperclient.gemspec
142
- - lib/faraday/connection.rb
143
100
  - lib/hyperclient.rb
144
101
  - lib/hyperclient/attributes.rb
145
102
  - lib/hyperclient/collection.rb
@@ -150,7 +107,6 @@ files:
150
107
  - lib/hyperclient/resource.rb
151
108
  - lib/hyperclient/resource_collection.rb
152
109
  - lib/hyperclient/version.rb
153
- - test/faraday/connection_test.rb
154
110
  - test/fixtures/collection.json
155
111
  - test/fixtures/element.json
156
112
  - test/fixtures/root.json
@@ -167,7 +123,7 @@ files:
167
123
  homepage: https://github.com/codegram/hyperclient/
168
124
  licenses: []
169
125
  metadata: {}
170
- post_install_message:
126
+ post_install_message:
171
127
  rdoc_options: []
172
128
  require_paths:
173
129
  - lib
@@ -182,9 +138,28 @@ required_rubygems_version: !ruby/object:Gem::Requirement
182
138
  - !ruby/object:Gem::Version
183
139
  version: '0'
184
140
  requirements: []
185
- rubyforge_project:
186
- rubygems_version: 2.6.11
187
- signing_key:
141
+ rubygems_version: 3.1.3
142
+ signing_key:
188
143
  specification_version: 4
189
144
  summary: ''
190
- test_files: []
145
+ test_files:
146
+ - features/api_navigation.feature
147
+ - features/default_config.feature
148
+ - features/steps/api_navigation.rb
149
+ - features/steps/default_config.rb
150
+ - features/support/api.rb
151
+ - features/support/env.rb
152
+ - features/support/fixtures.rb
153
+ - test/fixtures/collection.json
154
+ - test/fixtures/element.json
155
+ - test/fixtures/root.json
156
+ - test/hyperclient/attributes_test.rb
157
+ - test/hyperclient/collection_test.rb
158
+ - test/hyperclient/curie_test.rb
159
+ - test/hyperclient/entry_point_test.rb
160
+ - test/hyperclient/link_collection_test.rb
161
+ - test/hyperclient/link_test.rb
162
+ - test/hyperclient/resource_collection_test.rb
163
+ - test/hyperclient/resource_test.rb
164
+ - test/hyperclient_test.rb
165
+ - test/test_helper.rb
@@ -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