restify 1.13.0 → 1.15.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +98 -6
  3. data/lib/restify/adapter/em.rb +6 -13
  4. data/lib/restify/adapter/pooled_em.rb +35 -40
  5. data/lib/restify/adapter/typhoeus.rb +57 -51
  6. data/lib/restify/context.rb +5 -9
  7. data/lib/restify/error.rb +24 -0
  8. data/lib/restify/global.rb +1 -0
  9. data/lib/restify/logging.rb +1 -1
  10. data/lib/restify/processors/base/parsing.rb +5 -9
  11. data/lib/restify/processors/base.rb +2 -6
  12. data/lib/restify/promise.rb +1 -3
  13. data/lib/restify/request.rb +13 -5
  14. data/lib/restify/resource.rb +2 -2
  15. data/lib/restify/response.rb +0 -2
  16. data/lib/restify/timeout.rb +1 -3
  17. data/lib/restify/version.rb +3 -3
  18. data/spec/restify/cache_spec.rb +2 -2
  19. data/spec/restify/context_spec.rb +10 -7
  20. data/spec/restify/error_spec.rb +10 -0
  21. data/spec/restify/features/head_requests_spec.rb +7 -7
  22. data/spec/restify/features/request_bodies_spec.rb +84 -0
  23. data/spec/restify/features/request_errors_spec.rb +19 -0
  24. data/spec/restify/features/request_headers_spec.rb +16 -17
  25. data/spec/restify/features/response_errors_spec.rb +127 -0
  26. data/spec/restify/global_spec.rb +6 -6
  27. data/spec/restify/link_spec.rb +9 -9
  28. data/spec/restify/processors/base_spec.rb +1 -0
  29. data/spec/restify/processors/json_spec.rb +2 -1
  30. data/spec/restify/processors/msgpack_spec.rb +8 -7
  31. data/spec/restify/promise_spec.rb +8 -4
  32. data/spec/restify/registry_spec.rb +2 -2
  33. data/spec/restify/relation_spec.rb +18 -17
  34. data/spec/restify/resource_spec.rb +9 -8
  35. data/spec/restify/timeout_spec.rb +4 -4
  36. data/spec/restify_spec.rb +52 -57
  37. data/spec/spec_helper.rb +11 -8
  38. data/spec/support/stub_server.rb +106 -0
  39. metadata +30 -23
  40. data/spec/restify/features/response_errors.rb +0 -79
@@ -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,15 +21,15 @@ describe Restify::Global do
21
21
  end
22
22
 
23
23
  context 'with registry symbol' do
24
- let(:name) { :registry_item_name }
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
- Restify::Registry.store name, uri, options
32
+ Restify::Registry.store(name, uri, **options)
33
33
 
34
34
  expect(subject).to be_a Restify::Relation
35
35
  expect(subject.pattern).to eq uri
@@ -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 'should parse link with quotes' do
8
+ it 'parses link with quotes' do
9
9
  links = described_class
10
- .parse('<http://example.org/search{?query}>; rel="search"')
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 'should parse link without quotes' do
17
+ it 'parses link without quotes' do
18
18
  links = described_class
19
- .parse('<http://example.org/search{?query}>; rel=search')
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 'should parse multiple links' do
26
+ it 'parses multiple links' do
27
27
  links = described_class
28
- .parse('<p://h.tld/p>; rel=abc, <p://h.tld/b>; a=b; c="d"')
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 'should parse link w/o meta' do
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 'should parse on invalid URI' do
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 'should error on invalid header' do
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
@@ -25,6 +25,7 @@ describe Restify::Processors::Base do
25
25
 
26
26
  describe '#resource' do
27
27
  subject { described_class.new(context, response).resource }
28
+
28
29
  before { allow(response).to receive(:body).and_return(body) }
29
30
 
30
31
  describe 'parsing' do
@@ -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
- is_expected.to eq \
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
- is_expected.to eq \
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
- {'name' => 'John', 'self_url' => '/users/john'},
104
- {'name' => 'Jane', 'self_url' => '/users/jane'}
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!(0.1) }.to raise_error ::Timeout::Error
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 'should equal pattern' do
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
- let(:params) { {id: 1337} }
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
- class ParamObject
25
- def to_param
26
- 42
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: ParamObject.new} }
32
+ let(:params) { {id: cls_to_param.new} }
32
33
 
33
- it { expect(subject.to_s).to eq 'http://test.host/resource/42' }
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(subject.to_s).to eq 'http://test.host/resource?a=1&b=2&c=3' }
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(subject.to_s).to eq 'http://test.host/resource/5?abc=cde' }
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: ParamObject.new} }
51
+ let(:params) { {id: '5', abc: cls_to_param.new} }
51
52
 
52
- it { expect(subject.to_s).to eq 'http://test.host/resource/5?abc=42' }
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 'should match relations' do
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 'should return relation' do
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
- context '#follow!' do
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 'should delegate methods (I)' do
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 'should delegate methods (II)' do
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 'should return data' do
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! }.to_not raise_error
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! }.to_not raise_error
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.to_not raise_error
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.to_not raise_error
51
+ end.not_to raise_error
52
52
  end
53
53
  end
54
54
  end
data/spec/restify_spec.rb CHANGED
@@ -5,109 +5,104 @@ require 'spec_helper'
5
5
  describe Restify do
6
6
  context 'as a dynamic HATEOAS client' do
7
7
  before do
8
- stub_request(:get, 'http://localhost/base').to_return do
9
- <<-RESPONSE.gsub(/^ {10}/, '')
8
+ stub_request(:get, 'http://stubserver/base').to_return do
9
+ <<~HTTP
10
10
  HTTP/1.1 200 OK
11
11
  Content-Type: application/json
12
- Transfer-Encoding: chunked
13
- Link: <http://localhost/base/users{/id}>; rel="users"
14
- Link: <http://localhost/base/courses{/id}>; rel="courses"
12
+ Link: <http://localhost:9292/base/users{/id}>; rel="users"
13
+ Link: <http://localhost:9292/base/courses{/id}>; rel="courses"
15
14
 
16
15
  {
17
- "profile_url": "http://localhost/base/profile",
18
- "search_url": "http://localhost/base/search?q={query}",
16
+ "profile_url": "http://localhost:9292/base/profile",
17
+ "search_url": "http://localhost:9292/base/search?q={query}",
19
18
  "mirror_url": null
20
19
  }
21
- RESPONSE
20
+ HTTP
22
21
  end
23
22
 
24
- stub_request(:get, 'http://localhost/base/users').to_return do
25
- <<-RESPONSE.gsub(/^ {10}/, '')
23
+ stub_request(:get, 'http://stubserver/base/users')
24
+ .to_return do
25
+ <<~HTTP
26
26
  HTTP/1.1 200 OK
27
27
  Content-Type: application/json
28
- Transfer-Encoding: chunked
29
28
 
30
29
  [{
31
- "name": "John Smith",
32
- "url": "http://localhost/base/users/john.smith",
33
- "blurb_url": "http://localhost/base/users/john.smith/blurb",
34
- "languages": ["de", "en"]
35
- },
36
- {
37
- "name": "Jane Smith",
38
- "self_url": "http://localhost/base/user/jane.smith"
39
- }]
40
- RESPONSE
30
+ "name": "John Smith",
31
+ "url": "http://localhost:9292/base/users/john.smith",
32
+ "blurb_url": "http://localhost:9292/base/users/john.smith/blurb",
33
+ "languages": ["de", "en"]
34
+ },
35
+ {
36
+ "name": "Jane Smith",
37
+ "self_url": "http://localhost:9292/base/user/jane.smith"
38
+ }]
39
+ HTTP
41
40
  end
42
41
 
43
- stub_request(:post, 'http://localhost/base/users')
42
+ stub_request(:post, 'http://stubserver/base/users')
44
43
  .with(body: {})
45
44
  .to_return do
46
- <<-RESPONSE.gsub(/^ {12}/, '')
47
- HTTP/1.1 422 Unprocessable Entity
48
- Content-Type: application/json
49
- Transfer-Encoding: chunked
45
+ <<~HTTP
46
+ HTTP/1.1 422 Unprocessable Entity
47
+ Content-Type: application/json
50
48
 
51
- {"errors":{"name":["can't be blank"]}}
52
- RESPONSE
49
+ {"errors":{"name":["can't be blank"]}}
50
+ HTTP
53
51
  end
54
52
 
55
- stub_request(:post, 'http://localhost/base/users')
53
+ stub_request(:post, 'http://stubserver/base/users')
56
54
  .with(body: {name: 'John Smith'})
57
55
  .to_return do
58
- <<-RESPONSE.gsub(/^ {12}/, '')
59
- HTTP/1.1 201 Created
60
- Content-Type: application/json
61
- Location: http://localhost/base/users/john.smith
62
- Transfer-Encoding: chunked
63
-
64
- {
65
- "name": "John Smith",
66
- "url": "http://localhost/base/users/john.smith",
67
- "blurb_url": "http://localhost/base/users/john.smith/blurb",
68
- "languages": ["de", "en"]
69
- }
70
- RESPONSE
56
+ <<~HTTP
57
+ HTTP/1.1 201 Created
58
+ Content-Type: application/json
59
+ Location: http://localhost:9292/base/users/john.smith
60
+
61
+ {
62
+ "name": "John Smith",
63
+ "url": "http://localhost:9292/base/users/john.smith",
64
+ "blurb_url": "http://localhost:9292/base/users/john.smith/blurb",
65
+ "languages": ["de", "en"]
66
+ }
67
+ HTTP
71
68
  end
72
69
 
73
- stub_request(:get, 'http://localhost/base/users/john.smith')
70
+ stub_request(:get, 'http://stubserver/base/users/john.smith')
74
71
  .to_return do
75
- <<-RESPONSE.gsub(/^ {10}/, '')
72
+ <<~HTTP
76
73
  HTTP/1.1 200 OK
77
74
  Content-Type: application/json
78
- Link: <http://localhost/base/users/john.smith>; rel="self"
79
- Transfer-Encoding: chunked
75
+ Link: <http://localhost:9292/base/users/john.smith>; rel="self"
80
76
 
81
77
  {
82
78
  "name": "John Smith",
83
- "url": "http://localhost/base/users/john.smith"
79
+ "url": "http://localhost:9292/base/users/john.smith"
84
80
  }
85
- RESPONSE
81
+ HTTP
86
82
  end
87
83
 
88
- stub_request(:get, 'http://localhost/base/users/john.smith/blurb')
84
+ stub_request(:get, 'http://stubserver/base/users/john.smith/blurb')
89
85
  .to_return do
90
- <<-RESPONSE.gsub(/^ {10}/, '')
86
+ <<~HTTP
91
87
  HTTP/1.1 200 OK
92
88
  Content-Type: application/json
93
- Link: <http://localhost/base/users/john.smith>; rel="user"
94
- Transfer-Encoding: chunked
89
+ Link: <http://localhost:9292/base/users/john.smith>; rel="user"
95
90
 
96
91
  {
97
92
  "title": "Prof. Dr. John Smith",
98
93
  "image": "http://example.org/avatar.png"
99
94
  }
100
- RESPONSE
95
+ HTTP
101
96
  end
102
97
  end
103
98
 
104
99
  context 'within threads' do
105
- it 'should consume the API' do
100
+ it 'consumes the API' do
106
101
  # Let's get all users
107
102
 
108
103
  # First request the entry resource usually the
109
104
  # root using GET and wait for it.
110
- root = Restify.new('http://localhost/base').get.value!
105
+ root = Restify.new('http://localhost:9292/base').get.value!
111
106
 
112
107
  # Therefore we need the `users` relations of our root
113
108
  # resource.
@@ -190,11 +185,11 @@ describe Restify do
190
185
  end
191
186
 
192
187
  context 'within EM-synchrony' do
193
- it 'should consume the API' do
188
+ it 'consumes the API' do
194
189
  skip 'Seems to be impossible to detect EM scheduled fibers from within'
195
190
 
196
191
  EM.synchrony do
197
- root = Restify.new('http://localhost/base').get.value!
192
+ root = Restify.new('http://localhost:9292/base').get.value!
198
193
 
199
194
  users_relation = root.rel(:users)
200
195
 
data/spec/spec_helper.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'rspec'
4
- require 'webmock/rspec'
4
+ require 'rspec/collection_matchers'
5
5
 
6
6
  require 'simplecov'
7
7
  SimpleCov.start do
@@ -34,20 +34,23 @@ if ENV['ADAPTER']
34
34
  end
35
35
  end
36
36
 
37
- require 'webmock/rspec'
38
- require 'rspec/collection_matchers'
39
- require 'em-synchrony'
40
-
41
- Dir[File.expand_path('spec/support/**/*.rb')].sort.each {|f| require f }
37
+ require_relative 'support/stub_server'
42
38
 
43
39
  RSpec.configure do |config|
44
40
  config.order = 'random'
45
41
 
46
42
  config.before(:suite) do
47
- ::Restify::Timeout.default_timeout = 2
43
+ ::Restify::Timeout.default_timeout = 1.0
44
+ end
45
+
46
+ config.before do |example|
47
+ next unless (adapter = example.metadata[:adapter])
48
+ next if Restify.adapter.is_a?(adapter)
49
+
50
+ skip 'Spec not enabled for current adapter'
48
51
  end
49
52
 
50
- config.before(:each) do
53
+ config.before do
51
54
  Ethon.logger = ::Logging.logger[Ethon] if defined?(Ethon)
52
55
 
53
56
  ::Logging.logger.root.level = :debug