hyperclient 0.9.3 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.DS_Store +0 -0
- data/.github/dependabot.yml +18 -0
- data/.github/workflows/coverage.yml +24 -0
- data/.github/workflows/danger.yml +22 -0
- data/.github/workflows/lint.yml +16 -0
- data/.github/workflows/test.yml +23 -0
- data/.rubocop.yml +8 -3
- data/.rubocop_todo.yml +32 -41
- data/CHANGELOG.md +18 -0
- data/CONTRIBUTING.md +1 -1
- data/Gemfile +4 -4
- data/README.md +16 -9
- data/RELEASING.md +1 -1
- data/Rakefile +0 -8
- data/features/api_navigation.feature +5 -0
- data/features/steps/api_navigation.rb +19 -6
- data/features/steps/default_config.rb +2 -2
- data/features/support/api.rb +22 -5
- data/features/support/env.rb +14 -1
- data/features/support/fixtures.rb +96 -2
- data/hyperclient.gemspec +4 -6
- data/lib/hyperclient/entry_point.rb +4 -5
- data/lib/hyperclient/link.rb +21 -0
- data/lib/hyperclient/resource.rb +1 -3
- data/lib/hyperclient/resource_collection.rb +1 -3
- data/lib/hyperclient/version.rb +1 -1
- data/test/hyperclient/attributes_test.rb +9 -9
- data/test/hyperclient/collection_test.rb +15 -15
- data/test/hyperclient/curie_test.rb +4 -4
- data/test/hyperclient/entry_point_test.rb +46 -56
- data/test/hyperclient/link_collection_test.rb +14 -14
- data/test/hyperclient/link_test.rb +43 -43
- data/test/hyperclient/resource_collection_test.rb +6 -6
- data/test/hyperclient/resource_test.rb +28 -27
- data/test/hyperclient_test.rb +10 -11
- data/test/test_helper.rb +26 -3
- metadata +21 -66
- data/.travis.yml +0 -25
- data/lib/faraday/connection.rb +0 -17
- data/test/faraday/connection_test.rb +0 -29
@@ -11,12 +11,12 @@ module Hyperclient
|
|
11
11
|
describe prop do
|
12
12
|
it 'returns the property value' do
|
13
13
|
link = Link.new('key', { prop => 'value' }, entry_point)
|
14
|
-
link.send("_#{prop}").must_equal 'value'
|
14
|
+
_(link.send("_#{prop}")).must_equal 'value'
|
15
15
|
end
|
16
16
|
|
17
17
|
it 'returns nil if the property is not present' do
|
18
18
|
link = Link.new('key', {}, entry_point)
|
19
|
-
link.send("_#{prop}").must_be_nil
|
19
|
+
_(link.send("_#{prop}")).must_be_nil
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
@@ -25,13 +25,13 @@ module Hyperclient
|
|
25
25
|
it 'returns true if the link is templated' do
|
26
26
|
link = Link.new('key', { 'templated' => true }, entry_point)
|
27
27
|
|
28
|
-
link._templated
|
28
|
+
_(link._templated?).must_equal true
|
29
29
|
end
|
30
30
|
|
31
31
|
it 'returns false if the link is not templated' do
|
32
32
|
link = Link.new('key', {}, entry_point)
|
33
33
|
|
34
|
-
link._templated
|
34
|
+
_(link._templated?).must_equal false
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
@@ -39,13 +39,13 @@ module Hyperclient
|
|
39
39
|
it 'returns a list of required variables' do
|
40
40
|
link = Link.new('key', { 'href' => '/orders{?id,owner}', 'templated' => true }, entry_point)
|
41
41
|
|
42
|
-
link._variables.must_equal %w[id owner]
|
42
|
+
_(link._variables).must_equal %w[id owner]
|
43
43
|
end
|
44
44
|
|
45
45
|
it 'returns an empty array for untemplated links' do
|
46
46
|
link = Link.new('key', { 'href' => '/orders' }, entry_point)
|
47
47
|
|
48
|
-
link._variables.must_equal []
|
48
|
+
_(link._variables).must_equal []
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
@@ -53,41 +53,41 @@ module Hyperclient
|
|
53
53
|
describe 'required argument' do
|
54
54
|
it 'builds a Link with the templated URI representation' do
|
55
55
|
link = Link.new('key', { 'href' => '/orders/{id}', 'templated' => true }, entry_point)
|
56
|
-
link._expand(id: '1')._url.must_equal '/orders/1'
|
56
|
+
_(link._expand(id: '1')._url).must_equal '/orders/1'
|
57
57
|
end
|
58
58
|
|
59
59
|
it 'expands an uri template without variables' do
|
60
60
|
link = Link.new('key', { 'href' => '/orders/{id}', 'templated' => true }, entry_point)
|
61
|
-
link._expand._url.must_equal '/orders/'
|
62
|
-
link._url.must_equal '/orders/'
|
61
|
+
_(link._expand._url).must_equal '/orders/'
|
62
|
+
_(link._url).must_equal '/orders/'
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
66
66
|
describe 'query string argument' do
|
67
67
|
it 'builds a Link with the templated URI representation' do
|
68
68
|
link = Link.new('key', { 'href' => '/orders{?id}', 'templated' => true }, entry_point)
|
69
|
-
link._expand(id: '1')._url.must_equal '/orders?id=1'
|
69
|
+
_(link._expand(id: '1')._url).must_equal '/orders?id=1'
|
70
70
|
end
|
71
71
|
|
72
72
|
it 'expands an uri template without variables' do
|
73
73
|
link = Link.new('key', { 'href' => '/orders{?id}', 'templated' => true }, entry_point)
|
74
|
-
link._expand._url.must_equal '/orders'
|
75
|
-
link._url.must_equal '/orders'
|
74
|
+
_(link._expand._url).must_equal '/orders'
|
75
|
+
_(link._url).must_equal '/orders'
|
76
76
|
end
|
77
77
|
|
78
78
|
it 'does not expand unknown variables' do
|
79
79
|
link = Link.new('key', { 'href' => '/orders{?id}', 'templated' => true }, entry_point)
|
80
|
-
link._expand(unknown: '1')._url.must_equal '/orders'
|
80
|
+
_(link._expand(unknown: '1')._url).must_equal '/orders'
|
81
81
|
end
|
82
82
|
|
83
83
|
it 'only expands known variables' do
|
84
84
|
link = Link.new('key', { 'href' => '/orders{?id}', 'templated' => true }, entry_point)
|
85
|
-
link._expand(unknown: '1', id: '2')._url.must_equal '/orders?id=2'
|
85
|
+
_(link._expand(unknown: '1', id: '2')._url).must_equal '/orders?id=2'
|
86
86
|
end
|
87
87
|
|
88
88
|
it 'only expands templated links' do
|
89
89
|
link = Link.new('key', { 'href' => '/orders{?id}', 'templated' => false }, entry_point)
|
90
|
-
link._expand(id: '1')._url.must_equal '/orders{?id}'
|
90
|
+
_(link._expand(id: '1')._url).must_equal '/orders{?id}'
|
91
91
|
end
|
92
92
|
end
|
93
93
|
end
|
@@ -96,36 +96,36 @@ module Hyperclient
|
|
96
96
|
it 'expands an uri template without variables' do
|
97
97
|
link = Link.new('key', { 'href' => '/orders{?id}', 'templated' => true }, entry_point)
|
98
98
|
|
99
|
-
link._url.must_equal '/orders'
|
99
|
+
_(link._url).must_equal '/orders'
|
100
100
|
end
|
101
101
|
|
102
102
|
it 'expands an uri template with variables' do
|
103
103
|
link = Link.new('key', { 'href' => '/orders{?id}', 'templated' => true }, entry_point, id: 1)
|
104
104
|
|
105
|
-
link._url.must_equal '/orders?id=1'
|
105
|
+
_(link._url).must_equal '/orders?id=1'
|
106
106
|
end
|
107
107
|
|
108
108
|
it 'does not expand an uri template with unknown variables' do
|
109
109
|
link = Link.new('key', { 'href' => '/orders{?id}', 'templated' => true }, entry_point, unknown: 1)
|
110
110
|
|
111
|
-
link._url.must_equal '/orders'
|
111
|
+
_(link._url).must_equal '/orders'
|
112
112
|
end
|
113
113
|
|
114
114
|
it 'only expands known variables in a uri template' do
|
115
115
|
link = Link.new('key', { 'href' => '/orders{?id}', 'templated' => true }, entry_point, unknown: 1, id: 2)
|
116
116
|
|
117
|
-
link._url.must_equal '/orders?id=2'
|
117
|
+
_(link._url).must_equal '/orders?id=2'
|
118
118
|
end
|
119
119
|
|
120
120
|
it 'returns the link when no uri template' do
|
121
121
|
link = Link.new('key', { 'href' => '/orders' }, entry_point)
|
122
|
-
link._url.must_equal '/orders'
|
122
|
+
_(link._url).must_equal '/orders'
|
123
123
|
end
|
124
124
|
|
125
125
|
it 'aliases to_s to _url' do
|
126
126
|
link = Link.new('key', { 'href' => '/orders{?id}', 'templated' => true }, entry_point, id: 1)
|
127
127
|
|
128
|
-
link.to_s.must_equal '/orders?id=1'
|
128
|
+
_(link.to_s).must_equal '/orders?id=1'
|
129
129
|
end
|
130
130
|
end
|
131
131
|
|
@@ -151,7 +151,7 @@ module Hyperclient
|
|
151
151
|
stub.get('http://api.example.org/productions/1') { [200, {}, nil] }
|
152
152
|
end
|
153
153
|
|
154
|
-
link._get.must_be_kind_of Resource
|
154
|
+
_(link._get).must_be_kind_of Resource
|
155
155
|
end
|
156
156
|
|
157
157
|
it 'raises exceptions by default' do
|
@@ -161,7 +161,7 @@ module Hyperclient
|
|
161
161
|
stub.get('http://api.example.org/productions/1') { [400, {}, nil] }
|
162
162
|
end
|
163
163
|
|
164
|
-
-> { link._get }.must_raise Faraday::ClientError
|
164
|
+
_(-> { link._get }).must_raise Faraday::ClientError
|
165
165
|
end
|
166
166
|
end
|
167
167
|
|
@@ -173,7 +173,7 @@ module Hyperclient
|
|
173
173
|
stub.options('http://api.example.org/productions/1') { [200, {}, nil] }
|
174
174
|
end
|
175
175
|
|
176
|
-
link._options.must_be_kind_of Resource
|
176
|
+
_(link._options).must_be_kind_of Resource
|
177
177
|
end
|
178
178
|
end
|
179
179
|
|
@@ -185,7 +185,7 @@ module Hyperclient
|
|
185
185
|
stub.head('http://api.example.org/productions/1') { [200, {}, nil] }
|
186
186
|
end
|
187
187
|
|
188
|
-
link._head.must_be_kind_of Resource
|
188
|
+
_(link._head).must_be_kind_of Resource
|
189
189
|
end
|
190
190
|
end
|
191
191
|
|
@@ -197,7 +197,7 @@ module Hyperclient
|
|
197
197
|
stub.delete('http://api.example.org/productions/1') { [200, {}, nil] }
|
198
198
|
end
|
199
199
|
|
200
|
-
link._delete.must_be_kind_of Resource
|
200
|
+
_(link._delete).must_be_kind_of Resource
|
201
201
|
end
|
202
202
|
end
|
203
203
|
|
@@ -209,7 +209,7 @@ module Hyperclient
|
|
209
209
|
stub.post('http://api.example.org/productions/1') { [200, {}, nil] }
|
210
210
|
end
|
211
211
|
|
212
|
-
link._post('foo' => 'bar').must_be_kind_of Resource
|
212
|
+
_(link._post('foo' => 'bar')).must_be_kind_of Resource
|
213
213
|
end
|
214
214
|
|
215
215
|
it 'defaults params to an empty hash' do
|
@@ -217,7 +217,7 @@ module Hyperclient
|
|
217
217
|
stub.post('http://api.example.org/productions/1') { [200, {}, nil] }
|
218
218
|
end
|
219
219
|
|
220
|
-
link._post.must_be_kind_of Resource
|
220
|
+
_(link._post).must_be_kind_of Resource
|
221
221
|
end
|
222
222
|
end
|
223
223
|
|
@@ -229,7 +229,7 @@ module Hyperclient
|
|
229
229
|
stub.put('http://api.example.org/productions/1', '{"foo":"bar"}') { [200, {}, nil] }
|
230
230
|
end
|
231
231
|
|
232
|
-
link._put('foo' => 'bar').must_be_kind_of Resource
|
232
|
+
_(link._put('foo' => 'bar')).must_be_kind_of Resource
|
233
233
|
end
|
234
234
|
|
235
235
|
it 'defaults params to an empty hash' do
|
@@ -237,7 +237,7 @@ module Hyperclient
|
|
237
237
|
stub.put('http://api.example.org/productions/1') { [200, {}, nil] }
|
238
238
|
end
|
239
239
|
|
240
|
-
link._put.must_be_kind_of Resource
|
240
|
+
_(link._put).must_be_kind_of Resource
|
241
241
|
end
|
242
242
|
end
|
243
243
|
|
@@ -249,7 +249,7 @@ module Hyperclient
|
|
249
249
|
stub.patch('http://api.example.org/productions/1', '{"foo":"bar"}') { [200, {}, nil] }
|
250
250
|
end
|
251
251
|
|
252
|
-
link._patch('foo' => 'bar').must_be_kind_of Resource
|
252
|
+
_(link._patch('foo' => 'bar')).must_be_kind_of Resource
|
253
253
|
end
|
254
254
|
|
255
255
|
it 'defaults params to an empty hash' do
|
@@ -257,7 +257,7 @@ module Hyperclient
|
|
257
257
|
stub.patch('http://api.example.org/productions/1') { [200, {}, nil] }
|
258
258
|
end
|
259
259
|
|
260
|
-
link._patch.must_be_kind_of Resource
|
260
|
+
_(link._patch).must_be_kind_of Resource
|
261
261
|
end
|
262
262
|
end
|
263
263
|
|
@@ -265,8 +265,8 @@ module Hyperclient
|
|
265
265
|
it 'outputs a custom-friendly output' do
|
266
266
|
link = Link.new('key', { 'href' => '/productions/1' }, 'foo')
|
267
267
|
|
268
|
-
link.inspect.must_include 'Link'
|
269
|
-
link.inspect.must_include '"href"=>"/productions/1"'
|
268
|
+
_(link.inspect).must_include 'Link'
|
269
|
+
_(link.inspect).must_include '"href"=>"/productions/1"'
|
270
270
|
end
|
271
271
|
end
|
272
272
|
|
@@ -279,8 +279,8 @@ module Hyperclient
|
|
279
279
|
stub.get('http://api.example.org/orders') { [200, {}, { '_embedded' => { 'orders' => [{ 'id' => 1 }] } }] }
|
280
280
|
end
|
281
281
|
|
282
|
-
resource.orders._embedded.orders.first.id.must_equal 1
|
283
|
-
resource.orders.first.id.must_equal 1
|
282
|
+
_(resource.orders._embedded.orders.first.id).must_equal 1
|
283
|
+
_(resource.orders.first.id).must_equal 1
|
284
284
|
end
|
285
285
|
|
286
286
|
it 'can handle false values in the response' do
|
@@ -290,7 +290,7 @@ module Hyperclient
|
|
290
290
|
stub.get('http://api.example.org/orders') { [200, {}, { 'any' => false }] }
|
291
291
|
end
|
292
292
|
|
293
|
-
resource.orders.any.must_equal false
|
293
|
+
_(resource.orders.any).must_equal false
|
294
294
|
end
|
295
295
|
|
296
296
|
it "doesn't delegate when link key doesn't match" do
|
@@ -300,8 +300,8 @@ module Hyperclient
|
|
300
300
|
stub.get('http://api.example.org/orders') { [200, {}, { '_embedded' => { 'orders' => [{ 'id' => 1 }] } }] }
|
301
301
|
end
|
302
302
|
|
303
|
-
resource.foos._embedded.orders.first.id.must_equal 1
|
304
|
-
resource.foos.first.must_be_nil
|
303
|
+
_(resource.foos._embedded.orders.first.id).must_equal 1
|
304
|
+
_(resource.foos.first).must_be_nil
|
305
305
|
end
|
306
306
|
|
307
307
|
it 'backtracks when navigating links' do
|
@@ -311,7 +311,7 @@ module Hyperclient
|
|
311
311
|
stub.get('http://api.example.org/page2') { [200, {}, { '_links' => { 'next' => { 'href' => 'http://api.example.org/page3' } } }] }
|
312
312
|
end
|
313
313
|
|
314
|
-
resource.next._links.next._url.must_equal 'http://api.example.org/page3'
|
314
|
+
_(resource.next._links.next._url).must_equal 'http://api.example.org/page3'
|
315
315
|
end
|
316
316
|
end
|
317
317
|
|
@@ -335,18 +335,18 @@ module Hyperclient
|
|
335
335
|
end
|
336
336
|
|
337
337
|
it 'raises an error when the method does not exist in the resource' do
|
338
|
-
-> { link.this_method_does_not_exist }.must_raise NoMethodError
|
338
|
+
_(-> { link.this_method_does_not_exist }).must_raise NoMethodError
|
339
339
|
end
|
340
340
|
|
341
341
|
it 'responds to missing methods' do
|
342
342
|
resource.expects(:respond_to?).with('orders').returns(false)
|
343
343
|
resource.expects(:respond_to?).with('embedded').returns(true)
|
344
|
-
link.respond_to?(:embedded).must_equal true
|
344
|
+
_(link.respond_to?(:embedded)).must_equal true
|
345
345
|
end
|
346
346
|
|
347
347
|
it 'does not delegate to_ary to resource' do
|
348
348
|
resource.expects(:to_ary).never
|
349
|
-
[[link, link]].flatten.must_equal [link, link]
|
349
|
+
_([[link, link]].flatten).must_equal [link, link]
|
350
350
|
end
|
351
351
|
end
|
352
352
|
end
|
@@ -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,23 +47,24 @@ 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
|
60
60
|
|
61
61
|
describe '_links' do
|
62
62
|
it '_expand' do
|
63
|
-
resource = Resource.new({ '_links' => { 'orders' => { 'href' => '/orders/{id}', 'templated' => true } } },
|
64
|
-
|
65
|
-
resource.orders._expand(id: 1)._url.must_equal '/orders/1'
|
66
|
-
resource.orders(id: 1)._url.must_equal '/orders/1'
|
63
|
+
resource = Resource.new({ '_links' => { 'orders' => { 'href' => '/orders/{id}', 'templated' => true } } },
|
64
|
+
entry_point)
|
65
|
+
_(resource._links.orders._expand(id: 1)._url).must_equal '/orders/1'
|
66
|
+
_(resource.orders._expand(id: 1)._url).must_equal '/orders/1'
|
67
|
+
_(resource.orders(id: 1)._url).must_equal '/orders/1'
|
67
68
|
end
|
68
69
|
end
|
69
70
|
|
@@ -74,84 +75,84 @@ module Hyperclient
|
|
74
75
|
|
75
76
|
describe 'links' do
|
76
77
|
it 'returns a LinkCollection' do
|
77
|
-
resource._links.must_be_kind_of LinkCollection
|
78
|
+
_(resource._links).must_be_kind_of LinkCollection
|
78
79
|
end
|
79
80
|
end
|
80
81
|
|
81
82
|
describe 'attributes' do
|
82
83
|
it 'returns a Attributes' do
|
83
|
-
resource._attributes.must_be_kind_of Attributes
|
84
|
+
_(resource._attributes).must_be_kind_of Attributes
|
84
85
|
end
|
85
86
|
end
|
86
87
|
|
87
88
|
describe 'embedded' do
|
88
89
|
it 'returns a ResourceCollection' do
|
89
|
-
resource._embedded.must_be_kind_of ResourceCollection
|
90
|
+
_(resource._embedded).must_be_kind_of ResourceCollection
|
90
91
|
end
|
91
92
|
end
|
92
93
|
|
93
94
|
describe 'method_missing' do
|
94
95
|
it 'delegates to attributes' do
|
95
96
|
resource._attributes.expects(:foo).returns('bar')
|
96
|
-
resource.foo.must_equal 'bar'
|
97
|
+
_(resource.foo).must_equal 'bar'
|
97
98
|
end
|
98
99
|
|
99
100
|
it 'delegates to links' do
|
100
101
|
resource._links.expects(:foo).returns('bar')
|
101
|
-
resource.foo.must_equal 'bar'
|
102
|
+
_(resource.foo).must_equal 'bar'
|
102
103
|
end
|
103
104
|
|
104
105
|
it 'delegates to embedded' do
|
105
106
|
resource._embedded.expects(:foo).returns('bar')
|
106
|
-
resource.foo.must_equal 'bar'
|
107
|
+
_(resource.foo).must_equal 'bar'
|
107
108
|
end
|
108
109
|
|
109
110
|
it 'delegates to attributes, links, embedded' do
|
110
111
|
resource._attributes.expects('respond_to?').with('foo').returns(false)
|
111
112
|
resource._links.expects('respond_to?').with('foo').returns(false)
|
112
113
|
resource._embedded.expects('respond_to?').with('foo').returns(false)
|
113
|
-
-> { resource.foo }.must_raise NoMethodError
|
114
|
+
_(-> { resource.foo }).must_raise NoMethodError
|
114
115
|
end
|
115
116
|
|
116
117
|
it 'delegates []' do
|
117
118
|
resource._attributes.expects(:foo).returns('bar')
|
118
|
-
resource['foo'].must_equal 'bar'
|
119
|
+
_(resource['foo']).must_equal 'bar'
|
119
120
|
end
|
120
121
|
|
121
122
|
describe '#fetch' do
|
122
123
|
it 'returns the value for keys that exist' do
|
123
124
|
resource._attributes.expects(:foo).returns('bar')
|
124
125
|
|
125
|
-
resource.fetch('foo').must_equal 'bar'
|
126
|
+
_(resource.fetch('foo')).must_equal 'bar'
|
126
127
|
end
|
127
128
|
|
128
129
|
it 'raises an error for missing keys' do
|
129
|
-
proc { resource.fetch('missing key') }.must_raise KeyError
|
130
|
+
_(proc { resource.fetch('missing key') }).must_raise KeyError
|
130
131
|
end
|
131
132
|
|
132
133
|
describe 'with a default value' do
|
133
134
|
it 'returns the value for keys that exist' do
|
134
135
|
resource._attributes.expects(:foo).returns('bar')
|
135
|
-
resource.fetch('foo', 'default value').must_equal 'bar'
|
136
|
+
_(resource.fetch('foo', 'default value')).must_equal 'bar'
|
136
137
|
end
|
137
138
|
|
138
139
|
it 'returns the default value for missing keys' do
|
139
|
-
resource.fetch('missing key', 'default value').must_equal 'default value'
|
140
|
+
_(resource.fetch('missing key', 'default value')).must_equal 'default value'
|
140
141
|
end
|
141
142
|
end
|
142
143
|
|
143
144
|
describe 'with a block' do
|
144
145
|
it 'returns the value for keys that exist' do
|
145
146
|
resource._attributes.expects(:foo).returns('bar')
|
146
|
-
resource.fetch('foo') { 'default value' }.must_equal 'bar'
|
147
|
+
_(resource.fetch('foo') { 'default value' }).must_equal 'bar'
|
147
148
|
end
|
148
149
|
|
149
150
|
it 'returns the value from the block' do
|
150
|
-
resource.fetch('z') { 'go fish!' }.must_equal 'go fish!'
|
151
|
+
_(resource.fetch('z') { 'go fish!' }).must_equal 'go fish!'
|
151
152
|
end
|
152
153
|
|
153
154
|
it 'returns the value with args from the block' do
|
154
|
-
resource.fetch('z') { |el| "go fish, #{el}" }.must_equal 'go fish, z'
|
155
|
+
_(resource.fetch('z') { |el| "go fish, #{el}" }).must_equal 'go fish, z'
|
155
156
|
end
|
156
157
|
end
|
157
158
|
end
|
@@ -179,7 +180,7 @@ module Hyperclient
|
|
179
180
|
end
|
180
181
|
|
181
182
|
it 'proxies to the response object' do
|
182
|
-
resource._success
|
183
|
+
_(resource._success?).must_equal true
|
183
184
|
end
|
184
185
|
end
|
185
186
|
|
@@ -189,7 +190,7 @@ module Hyperclient
|
|
189
190
|
end
|
190
191
|
|
191
192
|
it 'returns nil' do
|
192
|
-
resource._success
|
193
|
+
_(resource._success?).must_be_nil
|
193
194
|
end
|
194
195
|
end
|
195
196
|
end
|
@@ -205,7 +206,7 @@ module Hyperclient
|
|
205
206
|
end
|
206
207
|
|
207
208
|
it 'proxies to the response object' do
|
208
|
-
resource._status.must_equal 200
|
209
|
+
_(resource._status).must_equal 200
|
209
210
|
end
|
210
211
|
end
|
211
212
|
|
@@ -215,7 +216,7 @@ module Hyperclient
|
|
215
216
|
end
|
216
217
|
|
217
218
|
it 'returns nil' do
|
218
|
-
resource._status.must_be_nil
|
219
|
+
_(resource._status).must_be_nil
|
219
220
|
end
|
220
221
|
end
|
221
222
|
end
|
data/test/hyperclient_test.rb
CHANGED
@@ -13,30 +13,29 @@ describe Hyperclient do
|
|
13
13
|
let(:client) do
|
14
14
|
Hyperclient.new('http://api.example.org') do |client|
|
15
15
|
client.connection(default: true) do |conn|
|
16
|
-
conn.use Faraday::Request::
|
16
|
+
conn.use Faraday::Request::Instrumentation
|
17
17
|
end
|
18
18
|
client.headers['Access-Token'] = 'token'
|
19
19
|
end
|
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::
|
35
|
-
handlers.must_include Faraday::Response::RaiseError
|
36
|
-
handlers.must_include
|
37
|
-
handlers.must_include
|
38
|
-
handlers.must_include
|
39
|
-
handlers.must_include Faraday::Adapter::NetHttp
|
34
|
+
_(handlers).must_include Faraday::Request::Instrumentation
|
35
|
+
_(handlers).must_include Faraday::Response::RaiseError
|
36
|
+
_(handlers).must_include Faraday::FollowRedirects::Middleware
|
37
|
+
_(handlers).must_include Faraday::HalJson::Request
|
38
|
+
_(handlers).must_include Faraday::HalJson::Response
|
40
39
|
end
|
41
40
|
end
|
42
41
|
end
|
data/test/test_helper.rb
CHANGED
@@ -1,13 +1,36 @@
|
|
1
1
|
$LOAD_PATH << 'lib'
|
2
2
|
|
3
|
+
if ENV['COVERAGE']
|
4
|
+
require 'simplecov'
|
5
|
+
require 'simplecov-lcov'
|
6
|
+
SimpleCov.formatter = SimpleCov::Formatter::LcovFormatter
|
7
|
+
SimpleCov::Formatter::LcovFormatter.config do |c|
|
8
|
+
c.report_with_single_file = true
|
9
|
+
c.lcov_file_name = 'lcov.info'
|
10
|
+
c.single_report_path = 'coverage/lcov.info'
|
11
|
+
end
|
12
|
+
SimpleCov.start do
|
13
|
+
add_filter '/test/'
|
14
|
+
add_filter '/features/'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
3
18
|
require 'minitest/autorun'
|
4
19
|
require 'minitest/pride'
|
5
|
-
require '
|
20
|
+
require 'minitest/unit'
|
21
|
+
require 'mocha/minitest'
|
6
22
|
require 'json'
|
7
23
|
|
8
|
-
|
24
|
+
require 'faraday'
|
25
|
+
require 'faraday/request/instrumentation'
|
26
|
+
|
27
|
+
MiniTest::Assertions.class_eval do
|
9
28
|
def stub_request(conn, adapter_class = Faraday::Adapter::Test, &stubs_block)
|
10
29
|
adapter_handler = conn.builder.handlers.find { |h| h.klass < Faraday::Adapter }
|
11
|
-
|
30
|
+
if adapter_handler
|
31
|
+
conn.builder.swap(adapter_handler, adapter_class, &stubs_block)
|
32
|
+
else
|
33
|
+
conn.builder.adapter adapter_class, &stubs_block
|
34
|
+
end
|
12
35
|
end
|
13
36
|
end
|