restify 1.15.1 → 1.15.2
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/CHANGELOG.md +78 -14
- data/lib/restify/adapter/em.rb +3 -8
- data/lib/restify/adapter/pooled_em.rb +4 -5
- data/lib/restify/adapter/typhoeus.rb +3 -11
- data/lib/restify/context.rb +5 -9
- data/lib/restify/global.rb +1 -0
- data/lib/restify/logging.rb +1 -1
- data/lib/restify/processors/base/parsing.rb +3 -3
- data/lib/restify/resource.rb +1 -1
- data/lib/restify/response.rb +0 -2
- data/lib/restify/version.rb +2 -2
- data/spec/restify/cache_spec.rb +2 -2
- data/spec/restify/context_spec.rb +10 -7
- data/spec/restify/error_spec.rb +10 -0
- data/spec/restify/features/head_requests_spec.rb +2 -1
- data/spec/restify/features/request_bodies_spec.rb +7 -6
- data/spec/restify/features/request_headers_spec.rb +11 -11
- data/spec/restify/features/response_errors_spec.rb +1 -1
- data/spec/restify/global_spec.rb +5 -5
- data/spec/restify/link_spec.rb +9 -9
- data/spec/restify/processors/base_spec.rb +1 -0
- data/spec/restify/processors/json_spec.rb +2 -1
- data/spec/restify/processors/msgpack_spec.rb +8 -7
- data/spec/restify/promise_spec.rb +8 -4
- data/spec/restify/registry_spec.rb +2 -2
- data/spec/restify/relation_spec.rb +18 -17
- data/spec/restify/resource_spec.rb +9 -8
- data/spec/restify/timeout_spec.rb +4 -4
- data/spec/restify_spec.rb +2 -2
- data/spec/spec_helper.rb +2 -2
- data/spec/support/stub_server.rb +3 -3
- metadata +20 -19
@@ -14,6 +14,7 @@ describe Restify do
|
|
14
14
|
|
15
15
|
describe 'Request body' do
|
16
16
|
subject { Restify.new('http://localhost:9292/base').post(body, {}, {headers: headers}).value! }
|
17
|
+
|
17
18
|
let(:headers) { {} }
|
18
19
|
|
19
20
|
context 'with JSON-like data structures' do
|
@@ -23,7 +24,7 @@ describe Restify do
|
|
23
24
|
subject
|
24
25
|
|
25
26
|
expect(
|
26
|
-
request_stub.with(body: '{"a":"b","c":"d"}')
|
27
|
+
request_stub.with(body: '{"a":"b","c":"d"}'),
|
27
28
|
).to have_been_requested
|
28
29
|
end
|
29
30
|
|
@@ -31,7 +32,7 @@ describe Restify do
|
|
31
32
|
subject
|
32
33
|
|
33
34
|
expect(
|
34
|
-
request_stub.with(headers: {'Content-Type' => 'application/json'})
|
35
|
+
request_stub.with(headers: {'Content-Type' => 'application/json'}),
|
35
36
|
).to have_been_requested
|
36
37
|
end
|
37
38
|
|
@@ -42,7 +43,7 @@ describe Restify do
|
|
42
43
|
subject
|
43
44
|
|
44
45
|
expect(
|
45
|
-
request_stub.with(headers: {'Content-Type' => 'application/vnd.api+json'})
|
46
|
+
request_stub.with(headers: {'Content-Type' => 'application/vnd.api+json'}),
|
46
47
|
).to have_been_requested
|
47
48
|
end
|
48
49
|
end
|
@@ -55,7 +56,7 @@ describe Restify do
|
|
55
56
|
subject
|
56
57
|
|
57
58
|
expect(
|
58
|
-
request_stub.with(body: 'a=b&c=d')
|
59
|
+
request_stub.with(body: 'a=b&c=d'),
|
59
60
|
).to have_been_requested
|
60
61
|
end
|
61
62
|
|
@@ -63,7 +64,7 @@ describe Restify do
|
|
63
64
|
subject
|
64
65
|
|
65
66
|
expect(
|
66
|
-
request_stub.with {|req| req.headers['Content-Type'] !~ /json/ }
|
67
|
+
request_stub.with {|req| req.headers['Content-Type'] !~ /json/ },
|
67
68
|
).to have_been_requested
|
68
69
|
end
|
69
70
|
|
@@ -74,7 +75,7 @@ describe Restify do
|
|
74
75
|
subject
|
75
76
|
|
76
77
|
expect(
|
77
|
-
request_stub.with(headers: {'Content-Type' => 'application/text'})
|
78
|
+
request_stub.with(headers: {'Content-Type' => 'application/text'}),
|
78
79
|
).to have_been_requested
|
79
80
|
end
|
80
81
|
end
|
@@ -4,7 +4,7 @@ require 'spec_helper'
|
|
4
4
|
|
5
5
|
describe Restify do
|
6
6
|
let!(:request_stub) do
|
7
|
-
stub_request(:get,
|
7
|
+
stub_request(:get, 'http://stubserver/base').to_return do
|
8
8
|
<<~HTTP
|
9
9
|
HTTP/1.1 200 OK
|
10
10
|
Content-Type: application/json
|
@@ -21,14 +21,14 @@ describe Restify do
|
|
21
21
|
it 'sends the headers only for that request' do
|
22
22
|
root = context.get(
|
23
23
|
{},
|
24
|
-
{headers: {'Accept' => 'application/msgpack, application/json'}}
|
24
|
+
{headers: {'Accept' => 'application/msgpack, application/json'}},
|
25
25
|
).value!
|
26
26
|
|
27
27
|
root.rel(:self).get.value!
|
28
28
|
|
29
29
|
expect(request_stub).to have_been_requested.twice
|
30
30
|
expect(
|
31
|
-
request_stub.with(headers: {'Accept' => 'application/msgpack, application/json'})
|
31
|
+
request_stub.with(headers: {'Accept' => 'application/msgpack, application/json'}),
|
32
32
|
).to have_been_requested.once
|
33
33
|
end
|
34
34
|
end
|
@@ -37,7 +37,7 @@ describe Restify do
|
|
37
37
|
let(:context) do
|
38
38
|
Restify.new(
|
39
39
|
'http://localhost:9292/base',
|
40
|
-
headers: {'Accept' => 'application/msgpack, application/json'}
|
40
|
+
headers: {'Accept' => 'application/msgpack, application/json'},
|
41
41
|
)
|
42
42
|
end
|
43
43
|
|
@@ -47,39 +47,39 @@ describe Restify do
|
|
47
47
|
root.rel(:self).get.value!
|
48
48
|
|
49
49
|
expect(
|
50
|
-
request_stub.with(headers: {'Accept' => 'application/msgpack, application/json'})
|
50
|
+
request_stub.with(headers: {'Accept' => 'application/msgpack, application/json'}),
|
51
51
|
).to have_been_requested.twice
|
52
52
|
end
|
53
53
|
|
54
54
|
it 'can overwrite headers for single requests' do
|
55
55
|
root = context.get(
|
56
56
|
{},
|
57
|
-
{headers: {'Accept' => 'application/xml'}}
|
57
|
+
{headers: {'Accept' => 'application/xml'}},
|
58
58
|
).value!
|
59
59
|
|
60
60
|
root.rel(:self).get.value!
|
61
61
|
|
62
62
|
expect(
|
63
|
-
request_stub.with(headers: {'Accept' => 'application/xml'})
|
63
|
+
request_stub.with(headers: {'Accept' => 'application/xml'}),
|
64
64
|
).to have_been_requested.once
|
65
65
|
expect(
|
66
|
-
request_stub.with(headers: {'Accept' => 'application/msgpack, application/json'})
|
66
|
+
request_stub.with(headers: {'Accept' => 'application/msgpack, application/json'}),
|
67
67
|
).to have_been_requested.once
|
68
68
|
end
|
69
69
|
|
70
70
|
it 'can add additional headers for single requests' do
|
71
71
|
root = context.get(
|
72
72
|
{},
|
73
|
-
{headers: {'X-Custom' => 'foobar'}}
|
73
|
+
{headers: {'X-Custom' => 'foobar'}},
|
74
74
|
).value!
|
75
75
|
|
76
76
|
root.rel(:self).get.value!
|
77
77
|
|
78
78
|
expect(
|
79
|
-
request_stub.with(headers: {'Accept' => 'application/msgpack, application/json'})
|
79
|
+
request_stub.with(headers: {'Accept' => 'application/msgpack, application/json'}),
|
80
80
|
).to have_been_requested.twice
|
81
81
|
expect(
|
82
|
-
request_stub.with(headers: {'Accept' => 'application/msgpack, application/json', 'X-Custom' => 'foobar'})
|
82
|
+
request_stub.with(headers: {'Accept' => 'application/msgpack, application/json', 'X-Custom' => 'foobar'}),
|
83
83
|
).to have_been_requested.once
|
84
84
|
end
|
85
85
|
end
|
data/spec/restify/global_spec.rb
CHANGED
@@ -7,11 +7,11 @@ describe Restify::Global do
|
|
7
7
|
|
8
8
|
describe '#new' do
|
9
9
|
context 'with string URI' do
|
10
|
+
subject { global.new uri, **options }
|
11
|
+
|
10
12
|
let(:uri) { 'http://api.github.com/' }
|
11
13
|
let(:options) { {accept: 'application.vnd.github.v3+json'} }
|
12
14
|
|
13
|
-
subject { global.new uri, **options }
|
14
|
-
|
15
15
|
it 'returns relation for URI' do
|
16
16
|
expect(subject).to be_a Restify::Relation
|
17
17
|
expect(subject.pattern).to eq uri
|
@@ -21,13 +21,13 @@ describe Restify::Global do
|
|
21
21
|
end
|
22
22
|
|
23
23
|
context 'with registry symbol' do
|
24
|
-
|
24
|
+
subject { global.new(name, **options) }
|
25
|
+
|
26
|
+
let(:name) { :registry_item_name }
|
25
27
|
let(:uri) { 'http://api.github.com/' }
|
26
28
|
let(:options) { {accept: 'application.vnd.github.v3+json'} }
|
27
29
|
let(:context) { Restify::Context.new uri, **options }
|
28
30
|
|
29
|
-
subject { global.new(name, **options) }
|
30
|
-
|
31
31
|
it 'returns relation for stored registry item' do
|
32
32
|
Restify::Registry.store(name, uri, **options)
|
33
33
|
|
data/spec/restify/link_spec.rb
CHANGED
@@ -5,27 +5,27 @@ require 'spec_helper'
|
|
5
5
|
describe Restify::Link do
|
6
6
|
describe 'class' do
|
7
7
|
describe '#parse' do
|
8
|
-
it '
|
8
|
+
it 'parses link with quotes' do
|
9
9
|
links = described_class
|
10
|
-
|
10
|
+
.parse('<http://example.org/search{?query}>; rel="search"')
|
11
11
|
|
12
12
|
expect(links).to have(1).item
|
13
13
|
expect(links[0].uri).to eq 'http://example.org/search{?query}'
|
14
14
|
expect(links[0].metadata).to eq 'rel' => 'search'
|
15
15
|
end
|
16
16
|
|
17
|
-
it '
|
17
|
+
it 'parses link without quotes' do
|
18
18
|
links = described_class
|
19
|
-
|
19
|
+
.parse('<http://example.org/search{?query}>; rel=search')
|
20
20
|
|
21
21
|
expect(links).to have(1).item
|
22
22
|
expect(links[0].uri).to eq 'http://example.org/search{?query}'
|
23
23
|
expect(links[0].metadata).to eq 'rel' => 'search'
|
24
24
|
end
|
25
25
|
|
26
|
-
it '
|
26
|
+
it 'parses multiple links' do
|
27
27
|
links = described_class
|
28
|
-
|
28
|
+
.parse('<p://h.tld/p>; rel=abc, <p://h.tld/b>; a=b; c="d"')
|
29
29
|
|
30
30
|
expect(links).to have(2).item
|
31
31
|
expect(links[0].uri).to eq 'p://h.tld/p'
|
@@ -34,19 +34,19 @@ describe Restify::Link do
|
|
34
34
|
expect(links[1].metadata).to eq 'a' => 'b', 'c' => 'd'
|
35
35
|
end
|
36
36
|
|
37
|
-
it '
|
37
|
+
it 'parses link w/o meta' do
|
38
38
|
links = described_class.parse('<p://h.tld/b>')
|
39
39
|
|
40
40
|
expect(links[0].uri).to eq 'p://h.tld/b'
|
41
41
|
end
|
42
42
|
|
43
|
-
it '
|
43
|
+
it 'parses on invalid URI' do
|
44
44
|
links = described_class.parse('<hp://:&*^/fwbhg3>')
|
45
45
|
|
46
46
|
expect(links[0].uri).to eq 'hp://:&*^/fwbhg3'
|
47
47
|
end
|
48
48
|
|
49
|
-
it '
|
49
|
+
it 'errors on invalid header' do
|
50
50
|
expect { described_class.parse('</>; rel="s", abc-invalid') }
|
51
51
|
.to raise_error ArgumentError, /Invalid token at \d+:/i
|
52
52
|
end
|
@@ -29,6 +29,7 @@ describe Restify::Processors::Json do
|
|
29
29
|
|
30
30
|
describe '#resource' do
|
31
31
|
subject { described_class.new(context, response).resource }
|
32
|
+
|
32
33
|
before { allow(response).to receive(:body).and_return(body) }
|
33
34
|
|
34
35
|
describe 'parsing' do
|
@@ -52,7 +53,7 @@ describe Restify::Processors::Json do
|
|
52
53
|
end
|
53
54
|
|
54
55
|
it do
|
55
|
-
|
56
|
+
expect(subject).to eq \
|
56
57
|
'json' => 'value', 'search_url' => 'https://google.com{?q}'
|
57
58
|
end
|
58
59
|
|
@@ -39,6 +39,7 @@ describe Restify::Processors::Msgpack do
|
|
39
39
|
|
40
40
|
describe '#resource' do
|
41
41
|
subject { described_class.new(context, response).resource }
|
42
|
+
|
42
43
|
before { allow(response).to receive(:body).and_return(body) }
|
43
44
|
|
44
45
|
describe 'parsing' do
|
@@ -56,12 +57,12 @@ describe Restify::Processors::Msgpack do
|
|
56
57
|
let(:body) do
|
57
58
|
::MessagePack.dump(
|
58
59
|
'msg' => 'value',
|
59
|
-
'search_url' => 'https://google.com{?q}'
|
60
|
+
'search_url' => 'https://google.com{?q}',
|
60
61
|
)
|
61
62
|
end
|
62
63
|
|
63
64
|
it do
|
64
|
-
|
65
|
+
expect(subject).to eq \
|
65
66
|
'msg' => 'value', 'search_url' => 'https://google.com{?q}'
|
66
67
|
end
|
67
68
|
|
@@ -72,7 +73,7 @@ describe Restify::Processors::Msgpack do
|
|
72
73
|
context 'object with implicit self relation' do
|
73
74
|
let(:body) do
|
74
75
|
::MessagePack.dump(
|
75
|
-
'url' => '/self'
|
76
|
+
'url' => '/self',
|
76
77
|
)
|
77
78
|
end
|
78
79
|
|
@@ -100,9 +101,9 @@ describe Restify::Processors::Msgpack do
|
|
100
101
|
context 'array with resources' do
|
101
102
|
let(:body) do
|
102
103
|
::MessagePack.dump([
|
103
|
-
|
104
|
-
|
105
|
-
|
104
|
+
{'name' => 'John', 'self_url' => '/users/john'},
|
105
|
+
{'name' => 'Jane', 'self_url' => '/users/jane'},
|
106
|
+
])
|
106
107
|
end
|
107
108
|
|
108
109
|
it 'parses objects as resources' do
|
@@ -119,7 +120,7 @@ describe Restify::Processors::Msgpack do
|
|
119
120
|
let(:body) do
|
120
121
|
::MessagePack.dump(
|
121
122
|
'john' => {'name' => 'John'},
|
122
|
-
'jane' => {'name' => 'Jane'}
|
123
|
+
'jane' => {'name' => 'Jane'},
|
123
124
|
)
|
124
125
|
end
|
125
126
|
|
@@ -8,6 +8,7 @@ describe Restify::Promise do
|
|
8
8
|
describe 'factory methods' do
|
9
9
|
describe '#fulfilled' do
|
10
10
|
subject { described_class.fulfilled(fulfill_value) }
|
11
|
+
|
11
12
|
let(:fulfill_value) { 42 }
|
12
13
|
|
13
14
|
it 'returns a fulfilled promise' do
|
@@ -22,6 +23,7 @@ describe Restify::Promise do
|
|
22
23
|
|
23
24
|
describe '#rejected' do
|
24
25
|
subject { described_class.rejected(rejection_reason) }
|
26
|
+
|
25
27
|
let(:rejection_reason) { ArgumentError }
|
26
28
|
|
27
29
|
it 'returns a rejected promise' do
|
@@ -104,6 +106,7 @@ describe Restify::Promise do
|
|
104
106
|
|
105
107
|
describe 'result' do
|
106
108
|
subject { described_class.new(*dependencies, &task).value! }
|
109
|
+
|
107
110
|
let(:dependencies) { [] }
|
108
111
|
let(:task) { nil }
|
109
112
|
|
@@ -125,7 +128,7 @@ describe Restify::Promise do
|
|
125
128
|
[
|
126
129
|
Restify::Promise.fulfilled(1),
|
127
130
|
Restify::Promise.fulfilled(2),
|
128
|
-
Restify::Promise.fulfilled(3)
|
131
|
+
Restify::Promise.fulfilled(3),
|
129
132
|
]
|
130
133
|
end
|
131
134
|
|
@@ -139,7 +142,7 @@ describe Restify::Promise do
|
|
139
142
|
[[
|
140
143
|
Restify::Promise.fulfilled(1),
|
141
144
|
Restify::Promise.fulfilled(2),
|
142
|
-
Restify::Promise.fulfilled(3)
|
145
|
+
Restify::Promise.fulfilled(3),
|
143
146
|
]]
|
144
147
|
end
|
145
148
|
|
@@ -152,7 +155,7 @@ describe Restify::Promise do
|
|
152
155
|
let(:dependencies) do
|
153
156
|
[
|
154
157
|
Restify::Promise.fulfilled(5),
|
155
|
-
Restify::Promise.fulfilled(12)
|
158
|
+
Restify::Promise.fulfilled(12),
|
156
159
|
]
|
157
160
|
end
|
158
161
|
let(:task) do
|
@@ -168,6 +171,7 @@ describe Restify::Promise do
|
|
168
171
|
# dependencies is built dynamically.
|
169
172
|
context 'with an empty array of dependencies and without task' do
|
170
173
|
subject { described_class.new([]).value! }
|
174
|
+
|
171
175
|
it { is_expected.to eq [] }
|
172
176
|
end
|
173
177
|
end
|
@@ -180,7 +184,7 @@ describe Restify::Promise do
|
|
180
184
|
|
181
185
|
describe '#value' do
|
182
186
|
it 'can time out' do
|
183
|
-
expect { promise.value
|
187
|
+
expect { promise.value(0.1) }.to raise_error ::Timeout::Error
|
184
188
|
end
|
185
189
|
end
|
186
190
|
|
@@ -36,12 +36,12 @@ describe Restify::Registry do
|
|
36
36
|
end
|
37
37
|
|
38
38
|
describe '#store / #fetch' do
|
39
|
+
subject { registry.store name, uri, **opts }
|
40
|
+
|
39
41
|
let(:name) { 'remote' }
|
40
42
|
let(:uri) { 'http://remote/entry/point' }
|
41
43
|
let(:opts) { {accept: 'application/vnd.remote+json'} }
|
42
44
|
|
43
|
-
subject { registry.store name, uri, **opts }
|
44
|
-
|
45
45
|
it 'stores registry item' do
|
46
46
|
subject
|
47
47
|
|
@@ -3,53 +3,54 @@
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
describe Restify::Relation do
|
6
|
+
subject(:relation) { described_class.new context, pattern }
|
7
|
+
|
6
8
|
let(:context) { Restify::Context.new('http://test.host/') }
|
7
9
|
let(:pattern) { '/resource/{id}' }
|
8
|
-
let(:relation) { described_class.new context, pattern }
|
9
|
-
subject { relation }
|
10
10
|
|
11
11
|
describe '#==' do
|
12
|
-
it '
|
12
|
+
it 'equals pattern' do
|
13
13
|
expect(subject).to eq pattern
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
17
|
describe '#expand' do
|
18
|
-
|
19
|
-
|
20
|
-
subject { relation.expand params }
|
21
|
-
|
22
|
-
it { is_expected.to be_a Addressable::URI }
|
18
|
+
subject(:expaned) { relation.expand params }
|
23
19
|
|
24
|
-
|
25
|
-
|
26
|
-
|
20
|
+
let(:params) { {id: 1337} }
|
21
|
+
let(:cls_to_param) do
|
22
|
+
Class.new do
|
23
|
+
def to_param
|
24
|
+
42
|
25
|
+
end
|
27
26
|
end
|
28
27
|
end
|
29
28
|
|
29
|
+
it { is_expected.to be_a Addressable::URI }
|
30
|
+
|
30
31
|
context 'with #to_param object' do
|
31
|
-
let(:params) { {id:
|
32
|
+
let(:params) { {id: cls_to_param.new} }
|
32
33
|
|
33
|
-
it { expect(
|
34
|
+
it { expect(expaned.to_s).to eq 'http://test.host/resource/42' }
|
34
35
|
end
|
35
36
|
|
36
37
|
context 'with unknown additional query parameter' do
|
37
38
|
let(:pattern) { '/resource{?a,b}' }
|
38
39
|
let(:params) { {a: 1, b: 2, c: 3} }
|
39
40
|
|
40
|
-
it { expect(
|
41
|
+
it { expect(expaned.to_s).to eq 'http://test.host/resource?a=1&b=2&c=3' }
|
41
42
|
end
|
42
43
|
|
43
44
|
context 'with additional parameters' do
|
44
45
|
let(:params) { {id: '5', abc: 'cde'} }
|
45
46
|
|
46
|
-
it { expect(
|
47
|
+
it { expect(expaned.to_s).to eq 'http://test.host/resource/5?abc=cde' }
|
47
48
|
end
|
48
49
|
|
49
50
|
context 'with additional #to_param parameter' do
|
50
|
-
let(:params) { {id: '5', abc:
|
51
|
+
let(:params) { {id: '5', abc: cls_to_param.new} }
|
51
52
|
|
52
|
-
it { expect(
|
53
|
+
it { expect(expaned.to_s).to eq 'http://test.host/resource/5?abc=42' }
|
53
54
|
end
|
54
55
|
end
|
55
56
|
end
|
@@ -3,12 +3,13 @@
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
describe Restify::Resource do
|
6
|
+
subject { resource }
|
7
|
+
|
6
8
|
let(:data) { {} }
|
7
9
|
let(:relations) { {} }
|
8
10
|
let(:context) { double 'context' }
|
9
11
|
let(:response) { double 'response' }
|
10
12
|
let(:resource) { described_class.new(context, response: response, data: data, relations: relations) }
|
11
|
-
subject { resource }
|
12
13
|
|
13
14
|
before do
|
14
15
|
allow(context).to receive(:relation?).and_return(false)
|
@@ -19,12 +20,12 @@ describe Restify::Resource do
|
|
19
20
|
let(:relations) do
|
20
21
|
{
|
21
22
|
'users' => 'http://example.org/users',
|
22
|
-
'projects' => 'http://example.org/projects'
|
23
|
+
'projects' => 'http://example.org/projects',
|
23
24
|
}
|
24
25
|
end
|
25
26
|
|
26
27
|
describe '#relation?' do
|
27
|
-
it '
|
28
|
+
it 'matches relations' do
|
28
29
|
expect(subject.relation?(:users)).to eq true
|
29
30
|
expect(subject.relation?('users')).to eq true
|
30
31
|
expect(subject.relation?(:projects)).to eq true
|
@@ -46,7 +47,7 @@ describe Restify::Resource do
|
|
46
47
|
end
|
47
48
|
|
48
49
|
describe '#relation' do
|
49
|
-
it '
|
50
|
+
it 'returns relation' do
|
50
51
|
expect(subject.rel(:users)).to be_a Restify::Relation
|
51
52
|
|
52
53
|
expect(subject.rel(:users)).to eq 'http://example.org/users'
|
@@ -80,7 +81,7 @@ describe Restify::Resource do
|
|
80
81
|
end
|
81
82
|
end
|
82
83
|
|
83
|
-
|
84
|
+
describe '#follow!' do
|
84
85
|
let(:relations) { {_restify_follow: 'http://localhost/10'} }
|
85
86
|
|
86
87
|
it 'returns follow relation' do
|
@@ -103,14 +104,14 @@ describe Restify::Resource do
|
|
103
104
|
context 'data' do
|
104
105
|
let(:data) { double 'data' }
|
105
106
|
|
106
|
-
it '
|
107
|
+
it 'delegates methods (I)' do
|
107
108
|
expect(data).to receive(:some_method).and_return(42)
|
108
109
|
|
109
110
|
expect(subject).to respond_to :some_method
|
110
111
|
expect(subject.some_method).to eq 42
|
111
112
|
end
|
112
113
|
|
113
|
-
it '
|
114
|
+
it 'delegates methods (II)' do
|
114
115
|
expect(data).to receive(:[]).with(1).and_return(2)
|
115
116
|
|
116
117
|
expect(subject).to respond_to :[]
|
@@ -118,7 +119,7 @@ describe Restify::Resource do
|
|
118
119
|
end
|
119
120
|
|
120
121
|
describe '#data' do
|
121
|
-
it '
|
122
|
+
it 'returns data' do
|
122
123
|
expect(subject.data).to equal data
|
123
124
|
end
|
124
125
|
end
|
@@ -8,13 +8,13 @@ describe Restify::Timeout do
|
|
8
8
|
describe '#timeout!' do
|
9
9
|
context 'before having timed out' do
|
10
10
|
it 'do nothing' do
|
11
|
-
expect { timer.timeout! }.
|
11
|
+
expect { timer.timeout! }.not_to raise_error
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
15
|
context 'after having timed out' do
|
16
16
|
it 'calls given block' do
|
17
|
-
expect { timer.timeout! }.
|
17
|
+
expect { timer.timeout! }.not_to raise_error
|
18
18
|
sleep timer.send(:wait_interval)
|
19
19
|
expect { timer.timeout! }.to raise_error ::Restify::Timeout::Error
|
20
20
|
end
|
@@ -40,7 +40,7 @@ describe Restify::Timeout do
|
|
40
40
|
Thread.new { ivar.set :success }
|
41
41
|
expect(timer.wait_on!(ivar)).to eq :success
|
42
42
|
end
|
43
|
-
end.
|
43
|
+
end.not_to raise_error
|
44
44
|
end
|
45
45
|
|
46
46
|
it 'does nothing on successful Promise' do
|
@@ -48,7 +48,7 @@ describe Restify::Timeout do
|
|
48
48
|
Restify::Promise.fulfilled(:success).tap do |p|
|
49
49
|
expect(timer.wait_on!(p)).to eq :success
|
50
50
|
end
|
51
|
-
end.
|
51
|
+
end.not_to raise_error
|
52
52
|
end
|
53
53
|
end
|
54
54
|
end
|
data/spec/restify_spec.rb
CHANGED
@@ -97,7 +97,7 @@ describe Restify do
|
|
97
97
|
end
|
98
98
|
|
99
99
|
context 'within threads' do
|
100
|
-
it '
|
100
|
+
it 'consumes the API' do
|
101
101
|
# Let's get all users
|
102
102
|
|
103
103
|
# First request the entry resource usually the
|
@@ -185,7 +185,7 @@ describe Restify do
|
|
185
185
|
end
|
186
186
|
|
187
187
|
context 'within EM-synchrony' do
|
188
|
-
it '
|
188
|
+
it 'consumes the API' do
|
189
189
|
skip 'Seems to be impossible to detect EM scheduled fibers from within'
|
190
190
|
|
191
191
|
EM.synchrony do
|
data/spec/spec_helper.rb
CHANGED
@@ -43,14 +43,14 @@ RSpec.configure do |config|
|
|
43
43
|
::Restify::Timeout.default_timeout = 1.0
|
44
44
|
end
|
45
45
|
|
46
|
-
config.before
|
46
|
+
config.before do |example|
|
47
47
|
next unless (adapter = example.metadata[:adapter])
|
48
48
|
next if Restify.adapter.is_a?(adapter)
|
49
49
|
|
50
50
|
skip 'Spec not enabled for current adapter'
|
51
51
|
end
|
52
52
|
|
53
|
-
config.before
|
53
|
+
config.before do
|
54
54
|
Ethon.logger = ::Logging.logger[Ethon] if defined?(Ethon)
|
55
55
|
|
56
56
|
::Logging.logger.root.level = :debug
|
data/spec/support/stub_server.rb
CHANGED
@@ -17,10 +17,10 @@ module Stub
|
|
17
17
|
#
|
18
18
|
# If no stub is found a special HTTP 599 error code will be returned.
|
19
19
|
class Handler
|
20
|
-
def call(env)
|
20
|
+
def call(env)
|
21
21
|
signature = WebMock::RequestSignature.new(
|
22
22
|
env['REQUEST_METHOD'].downcase,
|
23
|
-
"http://stubserver#{env['REQUEST_URI']}"
|
23
|
+
"http://stubserver#{env['REQUEST_URI']}",
|
24
24
|
)
|
25
25
|
|
26
26
|
# Extract request headers from rack env. Most header should start with
|
@@ -99,7 +99,7 @@ RSpec.configure do |config|
|
|
99
99
|
WebMock.disable!(except: %i[net_http])
|
100
100
|
end
|
101
101
|
|
102
|
-
config.around
|
102
|
+
config.around do |example|
|
103
103
|
example.run
|
104
104
|
WebMock.reset!
|
105
105
|
end
|