hyperclient 0.9.1 → 1.0.1
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 +4 -4
- data/.rubocop.yml +3 -3
- data/.rubocop_todo.yml +12 -19
- data/.travis.yml +8 -9
- data/CHANGELOG.md +19 -0
- data/Gemfile +3 -1
- data/README.md +12 -6
- data/features/api_navigation.feature +5 -0
- data/features/steps/api_navigation.rb +16 -3
- data/features/steps/default_config.rb +2 -2
- data/features/support/api.rb +7 -1
- data/features/support/fixtures.rb +96 -2
- data/hyperclient.gemspec +0 -2
- data/lib/hyperclient/entry_point.rb +6 -5
- data/lib/hyperclient/link.rb +21 -0
- data/lib/hyperclient/link_collection.rb +3 -1
- data/lib/hyperclient/resource.rb +3 -1
- data/lib/hyperclient/resource_collection.rb +3 -1
- 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 +44 -47
- 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 +26 -26
- data/test/hyperclient_test.rb +9 -10
- data/test/test_helper.rb +6 -2
- metadata +6 -37
- 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,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
|
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
|
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
|