faraday 1.1.0 → 1.10.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +104 -0
  3. data/README.md +1 -2
  4. data/examples/client_spec.rb +34 -2
  5. data/examples/client_test.rb +41 -2
  6. data/lib/faraday/adapter/test.rb +59 -43
  7. data/lib/faraday/adapter.rb +1 -12
  8. data/lib/faraday/autoload.rb +1 -9
  9. data/lib/faraday/connection.rb +34 -6
  10. data/lib/faraday/deprecate.rb +110 -0
  11. data/lib/faraday/error.rb +12 -6
  12. data/lib/faraday/methods.rb +6 -0
  13. data/lib/faraday/middleware.rb +14 -4
  14. data/lib/faraday/options/proxy_options.rb +4 -0
  15. data/lib/faraday/request/authorization.rb +14 -7
  16. data/lib/faraday/request/json.rb +55 -0
  17. data/lib/faraday/request.rb +10 -12
  18. data/lib/faraday/response/json.rb +54 -0
  19. data/lib/faraday/response/logger.rb +2 -4
  20. data/lib/faraday/response.rb +3 -7
  21. data/lib/faraday/version.rb +5 -0
  22. data/lib/faraday.rb +67 -40
  23. data/spec/faraday/adapter/em_http_spec.rb +39 -37
  24. data/spec/faraday/adapter/em_synchrony_spec.rb +11 -9
  25. data/spec/faraday/adapter/test_spec.rb +117 -0
  26. data/spec/faraday/connection_spec.rb +45 -0
  27. data/spec/faraday/deprecate_spec.rb +147 -0
  28. data/spec/faraday/error_spec.rb +15 -0
  29. data/spec/faraday/middleware_spec.rb +32 -6
  30. data/spec/faraday/options/proxy_options_spec.rb +7 -0
  31. data/spec/faraday/request/authorization_spec.rb +8 -0
  32. data/spec/faraday/request/json_spec.rb +111 -0
  33. data/spec/faraday/request_spec.rb +1 -1
  34. data/spec/faraday/response/json_spec.rb +119 -0
  35. data/spec/faraday/response/raise_error_spec.rb +30 -0
  36. data/spec/spec_helper.rb +2 -0
  37. data/spec/support/shared_examples/adapter.rb +2 -1
  38. data/spec/support/shared_examples/request_method.rb +36 -8
  39. metadata +143 -32
  40. data/lib/faraday/adapter/em_http.rb +0 -286
  41. data/lib/faraday/adapter/em_http_ssl_patch.rb +0 -62
  42. data/lib/faraday/adapter/em_synchrony/parallel_manager.rb +0 -69
  43. data/lib/faraday/adapter/em_synchrony.rb +0 -150
  44. data/lib/faraday/adapter/excon.rb +0 -124
  45. data/lib/faraday/adapter/httpclient.rb +0 -152
  46. data/lib/faraday/adapter/net_http.rb +0 -219
  47. data/lib/faraday/adapter/net_http_persistent.rb +0 -91
  48. data/lib/faraday/adapter/patron.rb +0 -132
  49. data/lib/faraday/adapter/rack.rb +0 -75
  50. data/lib/faraday/file_part.rb +0 -128
  51. data/lib/faraday/param_part.rb +0 -53
  52. data/lib/faraday/request/multipart.rb +0 -106
  53. data/lib/faraday/request/retry.rb +0 -239
  54. data/spec/faraday/adapter/net_http_persistent_spec.rb +0 -57
  55. data/spec/faraday/request/multipart_spec.rb +0 -302
  56. data/spec/faraday/request/retry_spec.rb +0 -242
@@ -1,47 +1,49 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- RSpec.describe Faraday::Adapter::EMHttp, unless: defined?(JRUBY_VERSION) do
4
- features :request_body_on_query_methods, :reason_phrase_parse, :trace_method,
5
- :skip_response_body_on_head, :parallel, :local_socket_binding
3
+ unless defined?(JRUBY_VERSION)
4
+ RSpec.describe Faraday::Adapter::EMHttp do
5
+ features :request_body_on_query_methods, :reason_phrase_parse, :trace_method,
6
+ :skip_response_body_on_head, :parallel, :local_socket_binding
6
7
 
7
- it_behaves_like 'an adapter'
8
+ it_behaves_like 'an adapter'
8
9
 
9
- it 'allows to provide adapter specific configs' do
10
- url = URI('https://example.com:1234')
11
- adapter = described_class.new nil, inactivity_timeout: 20
12
- req = adapter.create_request(url: url, request: {})
10
+ it 'allows to provide adapter specific configs' do
11
+ url = URI('https://example.com:1234')
12
+ adapter = described_class.new nil, inactivity_timeout: 20
13
+ req = adapter.create_request(url: url, request: {})
13
14
 
14
- expect(req.connopts.inactivity_timeout).to eq(20)
15
- end
16
-
17
- context 'Options' do
18
- let(:request) { Faraday::RequestOptions.new }
19
- let(:env) { { request: request } }
20
- let(:options) { {} }
21
- let(:adapter) { Faraday::Adapter::EMHttp.new }
22
-
23
- it 'configures timeout' do
24
- request.timeout = 5
25
- adapter.configure_timeout(options, env)
26
- expect(options[:inactivity_timeout]).to eq(5)
27
- expect(options[:connect_timeout]).to eq(5)
28
- end
29
-
30
- it 'configures timeout and open_timeout' do
31
- request.timeout = 5
32
- request.open_timeout = 1
33
- adapter.configure_timeout(options, env)
34
- expect(options[:inactivity_timeout]).to eq(5)
35
- expect(options[:connect_timeout]).to eq(1)
15
+ expect(req.connopts.inactivity_timeout).to eq(20)
36
16
  end
37
17
 
38
- it 'configures all timeout settings' do
39
- request.timeout = 5
40
- request.read_timeout = 3
41
- request.open_timeout = 1
42
- adapter.configure_timeout(options, env)
43
- expect(options[:inactivity_timeout]).to eq(3)
44
- expect(options[:connect_timeout]).to eq(1)
18
+ context 'Options' do
19
+ let(:request) { Faraday::RequestOptions.new }
20
+ let(:env) { { request: request } }
21
+ let(:options) { {} }
22
+ let(:adapter) { Faraday::Adapter::EMHttp.new }
23
+
24
+ it 'configures timeout' do
25
+ request.timeout = 5
26
+ adapter.configure_timeout(options, env)
27
+ expect(options[:inactivity_timeout]).to eq(5)
28
+ expect(options[:connect_timeout]).to eq(5)
29
+ end
30
+
31
+ it 'configures timeout and open_timeout' do
32
+ request.timeout = 5
33
+ request.open_timeout = 1
34
+ adapter.configure_timeout(options, env)
35
+ expect(options[:inactivity_timeout]).to eq(5)
36
+ expect(options[:connect_timeout]).to eq(1)
37
+ end
38
+
39
+ it 'configures all timeout settings' do
40
+ request.timeout = 5
41
+ request.read_timeout = 3
42
+ request.open_timeout = 1
43
+ adapter.configure_timeout(options, env)
44
+ expect(options[:inactivity_timeout]).to eq(3)
45
+ expect(options[:connect_timeout]).to eq(1)
46
+ end
45
47
  end
46
48
  end
47
49
  end
@@ -1,16 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- RSpec.describe Faraday::Adapter::EMSynchrony, unless: defined?(JRUBY_VERSION) do
4
- features :request_body_on_query_methods, :reason_phrase_parse,
5
- :skip_response_body_on_head, :parallel, :local_socket_binding
3
+ unless defined?(JRUBY_VERSION)
4
+ RSpec.describe Faraday::Adapter::EMSynchrony do
5
+ features :request_body_on_query_methods, :reason_phrase_parse,
6
+ :skip_response_body_on_head, :parallel, :local_socket_binding
6
7
 
7
- it_behaves_like 'an adapter'
8
+ it_behaves_like 'an adapter'
8
9
 
9
- it 'allows to provide adapter specific configs' do
10
- url = URI('https://example.com:1234')
11
- adapter = described_class.new nil, inactivity_timeout: 20
12
- req = adapter.create_request(url: url, request: {})
10
+ it 'allows to provide adapter specific configs' do
11
+ url = URI('https://example.com:1234')
12
+ adapter = described_class.new nil, inactivity_timeout: 20
13
+ req = adapter.create_request(url: url, request: {})
13
14
 
14
- expect(req.connopts.inactivity_timeout).to eq(20)
15
+ expect(req.connopts.inactivity_timeout).to eq(20)
16
+ end
15
17
  end
16
18
  end
@@ -257,4 +257,121 @@ RSpec.describe Faraday::Adapter::Test do
257
257
  it { expect { request }.to raise_error described_class::Stubs::NotFound }
258
258
  end
259
259
  end
260
+
261
+ describe 'for request with non default params encoder' do
262
+ let(:connection) do
263
+ Faraday.new(request: { params_encoder: Faraday::FlatParamsEncoder }) do |builder|
264
+ builder.adapter :test, stubs
265
+ end
266
+ end
267
+ let(:stubs) do
268
+ described_class::Stubs.new do |stubs|
269
+ stubs.get('/path?a=x&a=y&a=z') { [200, {}, 'a'] }
270
+ end
271
+ end
272
+
273
+ context 'when all flat param values are correctly set' do
274
+ subject(:request) { connection.get('/path?a=x&a=y&a=z') }
275
+
276
+ it { expect(request.status).to eq 200 }
277
+ end
278
+
279
+ shared_examples 'raise NotFound when params do not satisfy the flat param values' do |params|
280
+ subject(:request) { connection.get('/path', params) }
281
+
282
+ context "with #{params.inspect}" do
283
+ it { expect { request }.to raise_error described_class::Stubs::NotFound }
284
+ end
285
+ end
286
+
287
+ it_behaves_like 'raise NotFound when params do not satisfy the flat param values', { a: %w[x] }
288
+ it_behaves_like 'raise NotFound when params do not satisfy the flat param values', { a: %w[x y] }
289
+ it_behaves_like 'raise NotFound when params do not satisfy the flat param values', { a: %w[x z y] } # NOTE: The order of the value is also compared.
290
+ it_behaves_like 'raise NotFound when params do not satisfy the flat param values', { b: %w[x y z] }
291
+ end
292
+
293
+ describe 'strict_mode' do
294
+ let(:stubs) do
295
+ described_class::Stubs.new(strict_mode: true) do |stubs|
296
+ stubs.get('/strict?a=12&b=xy', 'Authorization' => 'Bearer m_ck', 'X-C' => 'hello') { [200, {}, 'a'] }
297
+ stubs.get('/with_user_agent?a=12&b=xy', authorization: 'Bearer m_ck', 'User-Agent' => 'My Agent') { [200, {}, 'a'] }
298
+ end
299
+ end
300
+
301
+ context 'when params and headers are exactly set' do
302
+ subject(:request) { connection.get('/strict', { a: '12', b: 'xy' }, { authorization: 'Bearer m_ck', x_c: 'hello' }) }
303
+
304
+ it { expect(request.status).to eq 200 }
305
+ end
306
+
307
+ context 'when params and headers are exactly set with a custom user agent' do
308
+ subject(:request) { connection.get('/with_user_agent', { a: '12', b: 'xy' }, { authorization: 'Bearer m_ck', 'User-Agent' => 'My Agent' }) }
309
+
310
+ it { expect(request.status).to eq 200 }
311
+ end
312
+
313
+ shared_examples 'raise NotFound when params do not satisfy the strict check' do |params|
314
+ subject(:request) { connection.get('/strict', params, { 'Authorization' => 'Bearer m_ck', 'X-C' => 'hello' }) }
315
+
316
+ context "with #{params.inspect}" do
317
+ it { expect { request }.to raise_error described_class::Stubs::NotFound }
318
+ end
319
+ end
320
+
321
+ it_behaves_like 'raise NotFound when params do not satisfy the strict check', { a: '12' }
322
+ it_behaves_like 'raise NotFound when params do not satisfy the strict check', { b: 'xy' }
323
+ it_behaves_like 'raise NotFound when params do not satisfy the strict check', { a: '123', b: 'xy' }
324
+ it_behaves_like 'raise NotFound when params do not satisfy the strict check', { a: '12', b: 'xyz' }
325
+ it_behaves_like 'raise NotFound when params do not satisfy the strict check', { a: '12', b: 'xy', c: 'hello' }
326
+ it_behaves_like 'raise NotFound when params do not satisfy the strict check', { additional: 'special', a: '12', b: 'xy', c: 'hello' }
327
+
328
+ shared_examples 'raise NotFound when headers do not satisfy the strict check' do |path, headers|
329
+ subject(:request) { connection.get(path, { a: 12, b: 'xy' }, headers) }
330
+
331
+ context "with #{headers.inspect}" do
332
+ it { expect { request }.to raise_error described_class::Stubs::NotFound }
333
+ end
334
+ end
335
+
336
+ it_behaves_like 'raise NotFound when headers do not satisfy the strict check', '/strict', { authorization: 'Bearer m_ck' }
337
+ it_behaves_like 'raise NotFound when headers do not satisfy the strict check', '/strict', { 'X-C' => 'hello' }
338
+ it_behaves_like 'raise NotFound when headers do not satisfy the strict check', '/strict', { authorization: 'Bearer m_ck', 'x-c': 'Hi' }
339
+ it_behaves_like 'raise NotFound when headers do not satisfy the strict check', '/strict', { authorization: 'Basic m_ck', 'x-c': 'hello' }
340
+ it_behaves_like 'raise NotFound when headers do not satisfy the strict check', '/strict', { authorization: 'Bearer m_ck', 'x-c': 'hello', x_special: 'special' }
341
+ it_behaves_like 'raise NotFound when headers do not satisfy the strict check', '/with_user_agent', { authorization: 'Bearer m_ck' }
342
+ it_behaves_like 'raise NotFound when headers do not satisfy the strict check', '/with_user_agent', { authorization: 'Bearer m_ck', user_agent: 'Unknown' }
343
+ it_behaves_like 'raise NotFound when headers do not satisfy the strict check', '/with_user_agent', { authorization: 'Bearer m_ck', user_agent: 'My Agent', x_special: 'special' }
344
+
345
+ context 'when strict_mode is disabled' do
346
+ before do
347
+ stubs.strict_mode = false
348
+ end
349
+
350
+ shared_examples 'does not raise NotFound even when params do not satisfy the strict check' do |params|
351
+ subject(:request) { connection.get('/strict', params, { 'Authorization' => 'Bearer m_ck', 'X-C' => 'hello' }) }
352
+
353
+ context "with #{params.inspect}" do
354
+ it { expect(request.status).to eq 200 }
355
+ end
356
+ end
357
+
358
+ it_behaves_like 'does not raise NotFound even when params do not satisfy the strict check', { a: '12', b: 'xy' }
359
+ it_behaves_like 'does not raise NotFound even when params do not satisfy the strict check', { a: '12', b: 'xy', c: 'hello' }
360
+ it_behaves_like 'does not raise NotFound even when params do not satisfy the strict check', { additional: 'special', a: '12', b: 'xy', c: 'hello' }
361
+
362
+ shared_examples 'does not raise NotFound even when headers do not satisfy the strict check' do |path, headers|
363
+ subject(:request) { connection.get(path, { a: 12, b: 'xy' }, headers) }
364
+
365
+ context "with #{headers.inspect}" do
366
+ it { expect(request.status).to eq 200 }
367
+ end
368
+ end
369
+
370
+ it_behaves_like 'does not raise NotFound even when headers do not satisfy the strict check', '/strict', { authorization: 'Bearer m_ck', 'x-c': 'hello' }
371
+ it_behaves_like 'does not raise NotFound even when headers do not satisfy the strict check', '/strict', { authorization: 'Bearer m_ck', 'x-c': 'hello', x_special: 'special' }
372
+ it_behaves_like 'does not raise NotFound even when headers do not satisfy the strict check', '/strict', { authorization: 'Bearer m_ck', 'x-c': 'hello', user_agent: 'Special Agent' }
373
+ it_behaves_like 'does not raise NotFound even when headers do not satisfy the strict check', '/with_user_agent', { authorization: 'Bearer m_ck', user_agent: 'My Agent' }
374
+ it_behaves_like 'does not raise NotFound even when headers do not satisfy the strict check', '/with_user_agent', { authorization: 'Bearer m_ck', user_agent: 'My Agent', x_special: 'special' }
375
+ end
376
+ end
260
377
  end
@@ -18,6 +18,13 @@ shared_examples 'initializer with url' do
18
18
  it { expect(subject.path_prefix).to eq('/fish') }
19
19
  it { expect(subject.params).to eq('a' => '1') }
20
20
  end
21
+
22
+ context 'with IPv6 address' do
23
+ let(:address) { 'http://[::1]:85/' }
24
+
25
+ it { expect(subject.host).to eq('[::1]') }
26
+ it { expect(subject.port).to eq(85) }
27
+ end
21
28
  end
22
29
 
23
30
  shared_examples 'default connection options' do
@@ -246,6 +253,13 @@ RSpec.describe Faraday::Connection do
246
253
  expect(uri.path).to eq('/sake.html')
247
254
  end
248
255
 
256
+ it 'always returns new URI instance' do
257
+ conn.url_prefix = 'http://sushi.com'
258
+ uri1 = conn.build_exclusive_url(nil)
259
+ uri2 = conn.build_exclusive_url(nil)
260
+ expect(uri1).not_to equal(uri2)
261
+ end
262
+
249
263
  context 'with url_prefixed connection' do
250
264
  let(:url) { 'http://sushi.com/sushi/' }
251
265
 
@@ -270,6 +284,29 @@ RSpec.describe Faraday::Connection do
270
284
  expect(uri.to_s).to eq('http://sushi.com/sake/')
271
285
  end
272
286
  end
287
+
288
+ context 'with colon in path' do
289
+ let(:url) { 'http://service.com' }
290
+
291
+ it 'joins url to base when used absolute path' do
292
+ conn = Faraday.new(url: url)
293
+ uri = conn.build_exclusive_url('/service:search?limit=400')
294
+ expect(uri.to_s).to eq('http://service.com/service:search?limit=400')
295
+ end
296
+
297
+ it 'joins url to base when used relative path' do
298
+ conn = Faraday.new(url: url)
299
+ uri = conn.build_exclusive_url('service:search?limit=400')
300
+ expect(uri.to_s).to eq('http://service.com/service%3Asearch?limit=400')
301
+ end
302
+
303
+ it 'joins url to base when used with path prefix' do
304
+ conn = Faraday.new(url: url)
305
+ conn.path_prefix = '/api'
306
+ uri = conn.build_exclusive_url('service:search?limit=400')
307
+ expect(uri.to_s).to eq('http://service.com/api/service%3Asearch?limit=400')
308
+ end
309
+ end
273
310
  end
274
311
 
275
312
  describe '#build_url' do
@@ -412,6 +449,14 @@ RSpec.describe Faraday::Connection do
412
449
  end
413
450
  end
414
451
 
452
+ it 'allows when url in no proxy list with url_prefix' do
453
+ with_env 'http_proxy' => 'http://proxy.com', 'no_proxy' => 'example.com' do
454
+ conn = Faraday::Connection.new
455
+ conn.url_prefix = 'http://example.com'
456
+ expect(conn.proxy).to be_nil
457
+ end
458
+ end
459
+
415
460
  it 'allows when prefixed url is not in no proxy list' do
416
461
  with_env 'http_proxy' => 'http://proxy.com', 'no_proxy' => 'example.com' do
417
462
  conn = Faraday::Connection.new('http://prefixedexample.com')
@@ -0,0 +1,147 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe Faraday::DeprecatedClass do
4
+ class SampleClass < StandardError
5
+ attr_accessor :foo
6
+
7
+ def initialize(foo = nil)
8
+ @foo = foo || :foo
9
+ end
10
+ end
11
+
12
+ SampleDeprecatedClass = Faraday::DeprecatedClass.proxy_class(SampleClass)
13
+
14
+ it 'does not raise error for deprecated classes but prints an error message' do
15
+ error_message, foobar = with_warn_squelching { SampleDeprecatedClass.new(:foo_bar) }
16
+ expect(foobar).to be_a(SampleClass)
17
+ expect(foobar.foo).to eq(:foo_bar)
18
+ expect(error_message).to match(
19
+ Regexp.new(
20
+ 'NOTE: SampleDeprecatedClass.new is deprecated; '\
21
+ 'use SampleClass.new instead. It will be removed in or after version 1.0'
22
+ )
23
+ )
24
+ end
25
+
26
+ it 'does not raise an error for inherited error-namespaced classes but prints an error message' do
27
+ error_message, = with_warn_squelching { Class.new(SampleDeprecatedClass) }
28
+
29
+ expect(error_message).to match(
30
+ Regexp.new(
31
+ 'NOTE: Inheriting SampleDeprecatedClass is deprecated; '\
32
+ 'use SampleClass instead. It will be removed in or after version 1.0'
33
+ )
34
+ )
35
+ end
36
+
37
+ it 'allows backward-compatible class to be subclassed' do
38
+ expect do
39
+ with_warn_squelching { Class.new(SampleDeprecatedClass) }
40
+ end.not_to raise_error
41
+ end
42
+
43
+ it 'allows rescuing of a current error with a deprecated error' do
44
+ expect { raise SampleClass, nil }.to raise_error(SampleDeprecatedClass)
45
+ end
46
+
47
+ it 'allows rescuing of a current error with a current error' do
48
+ expect { raise SampleClass, nil }.to raise_error(SampleClass)
49
+ end
50
+
51
+ it 'allows rescuing of a deprecated error with a deprecated error' do
52
+ expect { raise SampleDeprecatedClass, nil }.to raise_error(SampleDeprecatedClass)
53
+ end
54
+
55
+ it 'allows rescuing of a deprecated error with a current error' do
56
+ expect { raise SampleDeprecatedClass, nil }.to raise_error(SampleClass)
57
+ end
58
+
59
+ describe 'match behavior' do
60
+ class SampleDeprecatedClassA < SampleDeprecatedClass; end
61
+ class SampleDeprecatedClassB < SampleDeprecatedClass; end
62
+
63
+ class SampleDeprecatedClassAX < SampleDeprecatedClassA; end
64
+
65
+ class SampleClassA < SampleClass; end
66
+
67
+ describe 'undeprecated class' do
68
+ it 'is === to instance of deprecated class' do
69
+ expect(SampleDeprecatedClass.new.is_a?(SampleClass)).to be true
70
+ end
71
+
72
+ it 'is === to instance of subclass of deprecated class' do
73
+ expect(SampleDeprecatedClassA.new.is_a?(SampleClass)).to be true
74
+ end
75
+
76
+ it 'is === to instance of subclass of subclass of deprecated class' do
77
+ expect(SampleDeprecatedClassAX.new.is_a?(SampleClass)).to be true
78
+ end
79
+ end
80
+
81
+ describe 'subclass of undeprecated class' do
82
+ it 'is not === to instance of undeprecated class' do
83
+ expect(SampleClass.new.is_a?(SampleClassA)).to be false
84
+ end
85
+
86
+ it 'is not === to instance of deprecated class' do
87
+ expect(SampleDeprecatedClass.new.is_a?(SampleClassA)).to be false
88
+ end
89
+ end
90
+
91
+ describe 'deprecated class' do
92
+ it 'is === to instance of undeprecated class' do
93
+ expect(SampleDeprecatedClass.new.is_a?(SampleClass)).to be true
94
+ end
95
+
96
+ it 'is === to instance of subclass of undeprecated class' do
97
+ expect(SampleClassA.superclass == SampleDeprecatedClass.superclass).to be true
98
+ end
99
+
100
+ it 'is === to instance of subclass of deprecated class' do
101
+ expect(SampleDeprecatedClassA.new.is_a?(SampleDeprecatedClass)).to be true
102
+ end
103
+
104
+ it 'is === to instance of subclass of subclass of deprecated class' do
105
+ expect(SampleDeprecatedClassAX.new.is_a?(SampleDeprecatedClass)).to be true
106
+ end
107
+ end
108
+
109
+ describe 'subclass of deprecated class' do
110
+ it 'is not === to instance of subclass of undeprecated class' do
111
+ expect(SampleClass.new.is_a?(SampleDeprecatedClassA)).to be false
112
+ end
113
+
114
+ it 'is not === to instance of another subclass of deprecated class' do
115
+ expect(SampleDeprecatedClassB.new.is_a?(SampleDeprecatedClassA)).to be false
116
+ end
117
+
118
+ it 'is === to instance of its subclass' do
119
+ expect(SampleDeprecatedClassAX.new.is_a?(SampleDeprecatedClassA)).to be true
120
+ end
121
+
122
+ it 'is === to instance of deprecated class' do
123
+ expect(SampleDeprecatedClassB.new.is_a?(SampleDeprecatedClass)).to be true
124
+ end
125
+ end
126
+
127
+ describe 'subclass of subclass of deprecated class' do
128
+ it 'is not === to instance of subclass of another subclass of deprecated class' do
129
+ expect(SampleDeprecatedClassB.new.is_a?(SampleDeprecatedClassAX)).to be false
130
+ end
131
+
132
+ it 'is not === to instance of its superclass' do
133
+ expect(SampleDeprecatedClass.new.is_a?(SampleDeprecatedClassA)).to be false
134
+ end
135
+ end
136
+ end
137
+
138
+ def with_warn_squelching
139
+ stderr_catcher = StringIO.new
140
+ original_stderr = $stderr
141
+ $stderr = stderr_catcher
142
+ result = yield if block_given?
143
+ [stderr_catcher.tap(&:rewind).string, result]
144
+ ensure
145
+ $stderr = original_stderr
146
+ end
147
+ end
@@ -13,6 +13,7 @@ RSpec.describe Faraday::ClientError do
13
13
  it { expect(subject.message).to eq(exception.message) }
14
14
  it { expect(subject.backtrace).to eq(exception.backtrace) }
15
15
  it { expect(subject.inspect).to eq('#<Faraday::ClientError wrapped=#<RuntimeError: test>>') }
16
+ it { expect(subject.response_status).to be_nil }
16
17
  end
17
18
 
18
19
  context 'with response hash' do
@@ -22,6 +23,7 @@ RSpec.describe Faraday::ClientError do
22
23
  it { expect(subject.response).to eq(exception) }
23
24
  it { expect(subject.message).to eq('the server responded with status 400') }
24
25
  it { expect(subject.inspect).to eq('#<Faraday::ClientError response={:status=>400}>') }
26
+ it { expect(subject.response_status).to eq(400) }
25
27
  end
26
28
 
27
29
  context 'with string' do
@@ -31,6 +33,7 @@ RSpec.describe Faraday::ClientError do
31
33
  it { expect(subject.response).to be_nil }
32
34
  it { expect(subject.message).to eq('custom message') }
33
35
  it { expect(subject.inspect).to eq('#<Faraday::ClientError #<Faraday::ClientError: custom message>>') }
36
+ it { expect(subject.response_status).to be_nil }
34
37
  end
35
38
 
36
39
  context 'with anything else #to_s' do
@@ -40,6 +43,18 @@ RSpec.describe Faraday::ClientError do
40
43
  it { expect(subject.response).to be_nil }
41
44
  it { expect(subject.message).to eq('["error1", "error2"]') }
42
45
  it { expect(subject.inspect).to eq('#<Faraday::ClientError #<Faraday::ClientError: ["error1", "error2"]>>') }
46
+ it { expect(subject.response_status).to be_nil }
47
+ end
48
+
49
+ context 'with exception string and response hash' do
50
+ let(:exception) { 'custom message' }
51
+ let(:response) { { status: 400 } }
52
+
53
+ it { expect(subject.wrapped_exception).to be_nil }
54
+ it { expect(subject.response).to eq(response) }
55
+ it { expect(subject.message).to eq('custom message') }
56
+ it { expect(subject.inspect).to eq('#<Faraday::ClientError response={:status=>400}>') }
57
+ it { expect(subject.response_status).to eq(400) }
43
58
  end
44
59
  end
45
60
  end
@@ -2,23 +2,49 @@
2
2
 
3
3
  RSpec.describe Faraday::Middleware do
4
4
  subject { described_class.new(app) }
5
+ let(:app) { double }
6
+
7
+ describe 'options' do
8
+ context 'when options are passed to the middleware' do
9
+ subject { described_class.new(app, options) }
10
+ let(:options) { { field: 'value' } }
11
+
12
+ it 'accepts options when initialized' do
13
+ expect(subject.options[:field]).to eq('value')
14
+ end
15
+ end
16
+ end
17
+
18
+ describe '#on_request' do
19
+ subject do
20
+ Class.new(described_class) do
21
+ def on_request(env)
22
+ # do nothing
23
+ end
24
+ end.new(app)
25
+ end
26
+
27
+ it 'is called by #call' do
28
+ expect(app).to receive(:call).and_return(app)
29
+ expect(app).to receive(:on_complete)
30
+ is_expected.to receive(:call).and_call_original
31
+ is_expected.to receive(:on_request)
32
+ subject.call(double)
33
+ end
34
+ end
5
35
 
6
36
  describe '#close' do
7
37
  context "with app that doesn't support \#close" do
8
- let(:app) { double }
9
-
10
38
  it 'should issue warning' do
11
- expect(subject).to receive(:warn)
39
+ is_expected.to receive(:warn)
12
40
  subject.close
13
41
  end
14
42
  end
15
43
 
16
44
  context "with app that supports \#close" do
17
- let(:app) { double }
18
-
19
45
  it 'should issue warning' do
20
46
  expect(app).to receive(:close)
21
- expect(subject).to_not receive(:warn)
47
+ is_expected.to_not receive(:warn)
22
48
  subject.close
23
49
  end
24
50
  end
@@ -14,6 +14,13 @@ RSpec.describe Faraday::ProxyOptions do
14
14
  expect(options.inspect).to match('#<Faraday::ProxyOptions uri=')
15
15
  end
16
16
 
17
+ it 'defaults to http' do
18
+ options = Faraday::ProxyOptions.from 'example.org'
19
+ expect(options.port).to eq(80)
20
+ expect(options.host).to eq('example.org')
21
+ expect(options.scheme).to eq('http')
22
+ end
23
+
17
24
  it 'works with nil' do
18
25
  options = Faraday::ProxyOptions.from nil
19
26
  expect(options).to be_a_kind_of(Faraday::ProxyOptions)
@@ -84,5 +84,13 @@ RSpec.describe Faraday::Request::Authorization do
84
84
 
85
85
  include_examples 'does not interfere with existing authentication'
86
86
  end
87
+
88
+ context 'when passed a string and a proc' do
89
+ let(:auth_config) { ['Bearer', -> { 'custom_from_proc' }] }
90
+
91
+ it { expect(response.body).to eq('Bearer custom_from_proc') }
92
+
93
+ include_examples 'does not interfere with existing authentication'
94
+ end
87
95
  end
88
96
  end