faraday 0.17.3 → 1.0.0.pre.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.md +1 -1
- data/README.md +18 -358
- data/lib/faraday.rb +93 -174
- data/lib/faraday/adapter.rb +36 -22
- data/lib/faraday/adapter/em_http.rb +142 -99
- data/lib/faraday/adapter/em_http_ssl_patch.rb +23 -17
- data/lib/faraday/adapter/em_synchrony.rb +104 -60
- data/lib/faraday/adapter/em_synchrony/parallel_manager.rb +18 -15
- data/lib/faraday/adapter/excon.rb +97 -57
- data/lib/faraday/adapter/httpclient.rb +61 -39
- data/lib/faraday/adapter/net_http.rb +104 -51
- data/lib/faraday/adapter/net_http_persistent.rb +49 -28
- data/lib/faraday/adapter/patron.rb +54 -35
- data/lib/faraday/adapter/rack.rb +28 -12
- data/lib/faraday/adapter/test.rb +86 -53
- data/lib/faraday/adapter/typhoeus.rb +4 -1
- data/lib/faraday/adapter_registry.rb +28 -0
- data/lib/faraday/autoload.rb +47 -36
- data/lib/faraday/connection.rb +321 -179
- data/lib/faraday/dependency_loader.rb +37 -0
- data/lib/faraday/encoders/flat_params_encoder.rb +94 -0
- data/lib/faraday/encoders/nested_params_encoder.rb +171 -0
- data/lib/faraday/error.rb +21 -79
- data/lib/faraday/logging/formatter.rb +92 -0
- data/lib/faraday/middleware.rb +4 -28
- data/lib/faraday/middleware_registry.rb +129 -0
- data/lib/faraday/options.rb +33 -184
- data/lib/faraday/options/connection_options.rb +22 -0
- data/lib/faraday/options/env.rb +181 -0
- data/lib/faraday/options/proxy_options.rb +28 -0
- data/lib/faraday/options/request_options.rb +21 -0
- data/lib/faraday/options/ssl_options.rb +59 -0
- data/lib/faraday/parameters.rb +4 -197
- data/lib/faraday/rack_builder.rb +66 -55
- data/lib/faraday/request.rb +68 -36
- data/lib/faraday/request/authorization.rb +42 -30
- data/lib/faraday/request/basic_authentication.rb +14 -7
- data/lib/faraday/request/instrumentation.rb +45 -27
- data/lib/faraday/request/multipart.rb +72 -49
- data/lib/faraday/request/retry.rb +197 -171
- data/lib/faraday/request/token_authentication.rb +15 -10
- data/lib/faraday/request/url_encoded.rb +41 -23
- data/lib/faraday/response.rb +22 -15
- data/lib/faraday/response/logger.rb +22 -69
- data/lib/faraday/response/raise_error.rb +36 -18
- data/lib/faraday/upload_io.rb +29 -18
- data/lib/faraday/utils.rb +28 -245
- data/lib/faraday/utils/headers.rb +139 -0
- data/lib/faraday/utils/params_hash.rb +61 -0
- data/spec/external_adapters/faraday_specs_setup.rb +14 -0
- metadata +25 -51
- data/CHANGELOG.md +0 -232
- data/Rakefile +0 -13
- data/lib/faraday/deprecate.rb +0 -107
- data/spec/faraday/deprecate_spec.rb +0 -69
- data/spec/faraday/error_spec.rb +0 -102
- data/spec/faraday/response/raise_error_spec.rb +0 -106
- data/spec/spec_helper.rb +0 -105
- data/test/adapters/default_test.rb +0 -14
- data/test/adapters/em_http_test.rb +0 -30
- data/test/adapters/em_synchrony_test.rb +0 -32
- data/test/adapters/excon_test.rb +0 -30
- data/test/adapters/httpclient_test.rb +0 -34
- data/test/adapters/integration.rb +0 -263
- data/test/adapters/logger_test.rb +0 -136
- data/test/adapters/net_http_persistent_test.rb +0 -114
- data/test/adapters/net_http_test.rb +0 -79
- data/test/adapters/patron_test.rb +0 -40
- data/test/adapters/rack_test.rb +0 -38
- data/test/adapters/test_middleware_test.rb +0 -157
- data/test/adapters/typhoeus_test.rb +0 -38
- data/test/authentication_middleware_test.rb +0 -65
- data/test/composite_read_io_test.rb +0 -109
- data/test/connection_test.rb +0 -738
- data/test/env_test.rb +0 -268
- data/test/helper.rb +0 -75
- data/test/live_server.rb +0 -67
- data/test/middleware/instrumentation_test.rb +0 -88
- data/test/middleware/retry_test.rb +0 -282
- data/test/middleware_stack_test.rb +0 -260
- data/test/multibyte.txt +0 -1
- data/test/options_test.rb +0 -333
- data/test/parameters_test.rb +0 -157
- data/test/request_middleware_test.rb +0 -126
- data/test/response_middleware_test.rb +0 -72
- data/test/strawberry.rb +0 -2
- data/test/utils_test.rb +0 -98
data/Rakefile
DELETED
data/lib/faraday/deprecate.rb
DELETED
@@ -1,107 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Faraday
|
4
|
-
# @param new_klass [Class] new Klass to use
|
5
|
-
#
|
6
|
-
# @return [Class] A modified version of new_klass that warns on
|
7
|
-
# usage about deprecation.
|
8
|
-
# @see Faraday::Deprecate
|
9
|
-
module DeprecatedClass
|
10
|
-
def self.proxy_class(origclass, ver = '1.0')
|
11
|
-
proxy = Class.new(origclass) do
|
12
|
-
class << self
|
13
|
-
extend Faraday::Deprecate
|
14
|
-
|
15
|
-
def ===(other)
|
16
|
-
other.is_a?(superclass) || super
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
proxy.singleton_class.send(:deprecate, :new, "#{origclass}.new", ver)
|
21
|
-
proxy.singleton_class.send(:deprecate, :inherited, origclass.name, ver)
|
22
|
-
proxy
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
# Deprecation using semver instead of date, based on Gem::Deprecate
|
27
|
-
# Provides a single method +deprecate+ to be used to declare when
|
28
|
-
# something is going away.
|
29
|
-
#
|
30
|
-
# class Legacy
|
31
|
-
# def self.klass_method
|
32
|
-
# # ...
|
33
|
-
# end
|
34
|
-
#
|
35
|
-
# def instance_method
|
36
|
-
# # ...
|
37
|
-
# end
|
38
|
-
#
|
39
|
-
# extend Faraday::Deprecate
|
40
|
-
# deprecate :instance_method, "X.z", '1.0'
|
41
|
-
#
|
42
|
-
# class << self
|
43
|
-
# extend Faraday::Deprecate
|
44
|
-
# deprecate :klass_method, :none, '1.0'
|
45
|
-
# end
|
46
|
-
# end
|
47
|
-
module Deprecate
|
48
|
-
def self.skip # :nodoc:
|
49
|
-
@skip ||= begin
|
50
|
-
case ENV['FARADAY_DEPRECATE'].to_s.downcase
|
51
|
-
when '1', 'warn' then :warn
|
52
|
-
else :skip
|
53
|
-
end
|
54
|
-
end
|
55
|
-
@skip == :skip
|
56
|
-
end
|
57
|
-
|
58
|
-
def self.skip=(value) # :nodoc:
|
59
|
-
@skip = value ? :skip : :warn
|
60
|
-
end
|
61
|
-
|
62
|
-
# Temporarily turn off warnings. Intended for tests only.
|
63
|
-
def skip_during
|
64
|
-
original = Faraday::Deprecate.skip
|
65
|
-
Faraday::Deprecate.skip, = true
|
66
|
-
yield
|
67
|
-
ensure
|
68
|
-
Faraday::Deprecate.skip = original
|
69
|
-
end
|
70
|
-
|
71
|
-
# Simple deprecation method that deprecates +name+ by wrapping it up
|
72
|
-
# in a dummy method. It warns on each call to the dummy method
|
73
|
-
# telling the user of +repl+ (unless +repl+ is :none) and the
|
74
|
-
# semver that it is planned to go away.
|
75
|
-
# @param name [Symbol] the method symbol to deprecate
|
76
|
-
# @param repl [#to_s, :none] the replacement to use, when `:none` it will
|
77
|
-
# alert the user that no replacemtent is present.
|
78
|
-
# @param ver [String] the semver the method will be removed.
|
79
|
-
def deprecate(name, repl, ver)
|
80
|
-
class_eval do
|
81
|
-
gem_ver = Gem::Version.new(ver)
|
82
|
-
old = "_deprecated_#{name}"
|
83
|
-
alias_method old, name
|
84
|
-
define_method name do |*args, &block|
|
85
|
-
mod = is_a? Module
|
86
|
-
target = mod ? "#{self}." : "#{self.class}#"
|
87
|
-
target_message = if name == :inherited
|
88
|
-
"Inheriting #{self}"
|
89
|
-
else
|
90
|
-
"#{target}#{name}"
|
91
|
-
end
|
92
|
-
|
93
|
-
msg = [
|
94
|
-
"NOTE: #{target_message} is deprecated",
|
95
|
-
repl == :none ? ' with no replacement' : "; use #{repl} instead. ",
|
96
|
-
"It will be removed in or after version #{gem_ver}",
|
97
|
-
"\n#{target}#{name} called from #{Gem.location_of_caller.join(':')}"
|
98
|
-
]
|
99
|
-
warn "#{msg.join}." unless Faraday::Deprecate.skip
|
100
|
-
send old, *args, &block
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
module_function :deprecate, :skip_during
|
106
|
-
end
|
107
|
-
end
|
@@ -1,69 +0,0 @@
|
|
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 {
|
39
|
-
with_warn_squelching { Class.new(SampleDeprecatedClass) }
|
40
|
-
}.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
|
-
|
60
|
-
def with_warn_squelching
|
61
|
-
stderr_catcher = StringIO.new
|
62
|
-
original_stderr = $stderr
|
63
|
-
$stderr = stderr_catcher
|
64
|
-
result = yield if block_given?
|
65
|
-
[stderr_catcher.tap(&:rewind).string, result]
|
66
|
-
ensure
|
67
|
-
$stderr = original_stderr
|
68
|
-
end
|
69
|
-
end
|
data/spec/faraday/error_spec.rb
DELETED
@@ -1,102 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe Faraday::ClientError do
|
4
|
-
describe '.initialize' do
|
5
|
-
subject { described_class.new(exception, response) }
|
6
|
-
let(:response) { nil }
|
7
|
-
|
8
|
-
context 'with exception only' do
|
9
|
-
let(:exception) { RuntimeError.new('test') }
|
10
|
-
|
11
|
-
it { expect(subject.wrapped_exception).to eq(exception) }
|
12
|
-
it { expect(subject.response).to be_nil }
|
13
|
-
it { expect(subject.message).to eq(exception.message) }
|
14
|
-
it { expect(subject.backtrace).to eq(exception.backtrace) }
|
15
|
-
it { expect(subject.inspect).to eq('#<Faraday::ClientError wrapped=#<RuntimeError: test>>') }
|
16
|
-
end
|
17
|
-
|
18
|
-
context 'with response hash' do
|
19
|
-
let(:exception) { { status: 400 } }
|
20
|
-
|
21
|
-
it { expect(subject.wrapped_exception).to be_nil }
|
22
|
-
it { expect(subject.response).to eq(exception) }
|
23
|
-
it { expect(subject.message).to eq('the server responded with status 400') }
|
24
|
-
it { expect(subject.inspect).to eq('#<Faraday::ClientError response={:status=>400}>') }
|
25
|
-
end
|
26
|
-
|
27
|
-
context 'with string' do
|
28
|
-
let(:exception) { 'custom message' }
|
29
|
-
|
30
|
-
it { expect(subject.wrapped_exception).to be_nil }
|
31
|
-
it { expect(subject.response).to be_nil }
|
32
|
-
it { expect(subject.message).to eq('custom message') }
|
33
|
-
it { expect(subject.inspect).to eq('#<Faraday::ClientError #<Faraday::ClientError: custom message>>') }
|
34
|
-
end
|
35
|
-
|
36
|
-
context 'with anything else #to_s' do
|
37
|
-
let(:exception) { %w[error1 error2] }
|
38
|
-
|
39
|
-
it { expect(subject.wrapped_exception).to be_nil }
|
40
|
-
it { expect(subject.response).to be_nil }
|
41
|
-
it { expect(subject.message).to eq('["error1", "error2"]') }
|
42
|
-
it { expect(subject.inspect).to eq('#<Faraday::ClientError #<Faraday::ClientError: ["error1", "error2"]>>') }
|
43
|
-
end
|
44
|
-
|
45
|
-
context 'maintains backward-compatibility until 1.0' do
|
46
|
-
it 'does not raise an error for error-namespaced classes but prints an error message' do
|
47
|
-
error_message, error = with_warn_squelching { Faraday::Error::ClientError.new('foo') }
|
48
|
-
|
49
|
-
expect(error).to be_a Faraday::ClientError
|
50
|
-
expect(error_message).to match(
|
51
|
-
Regexp.new(
|
52
|
-
'NOTE: Faraday::Error::ClientError.new is deprecated; '\
|
53
|
-
'use Faraday::ClientError.new instead. It will be removed in or after version 1.0'
|
54
|
-
)
|
55
|
-
)
|
56
|
-
end
|
57
|
-
|
58
|
-
it 'does not raise an error for inherited error-namespaced classes but prints an error message' do
|
59
|
-
error_message, = with_warn_squelching { Class.new(Faraday::Error::ClientError) }
|
60
|
-
|
61
|
-
expect(error_message).to match(
|
62
|
-
Regexp.new(
|
63
|
-
'NOTE: Inheriting Faraday::Error::ClientError is deprecated; '\
|
64
|
-
'use Faraday::ClientError instead. It will be removed in or after version 1.0'
|
65
|
-
)
|
66
|
-
)
|
67
|
-
end
|
68
|
-
|
69
|
-
it 'allows backward-compatible class to be subclassed' do
|
70
|
-
expect {
|
71
|
-
with_warn_squelching { Class.new(Faraday::Error::ClientError) }
|
72
|
-
}.not_to raise_error
|
73
|
-
end
|
74
|
-
|
75
|
-
it 'allows rescuing of a current error with a deprecated error' do
|
76
|
-
expect { raise Faraday::ClientError, nil }.to raise_error(Faraday::Error::ClientError)
|
77
|
-
end
|
78
|
-
|
79
|
-
it 'allows rescuing of a current error with a current error' do
|
80
|
-
expect { raise Faraday::ClientError, nil }.to raise_error(Faraday::ClientError)
|
81
|
-
end
|
82
|
-
|
83
|
-
it 'allows rescuing of a deprecated error with a deprecated error' do
|
84
|
-
expect { raise Faraday::Error::ClientError, nil }.to raise_error(Faraday::Error::ClientError)
|
85
|
-
end
|
86
|
-
|
87
|
-
it 'allows rescuing of a deprecated error with a current error' do
|
88
|
-
expect { raise Faraday::Error::ClientError, nil }.to raise_error(Faraday::ClientError)
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
def with_warn_squelching
|
93
|
-
stderr_catcher = StringIO.new
|
94
|
-
original_stderr = $stderr
|
95
|
-
$stderr = stderr_catcher
|
96
|
-
result = yield if block_given?
|
97
|
-
[stderr_catcher.tap(&:rewind).string, result]
|
98
|
-
ensure
|
99
|
-
$stderr = original_stderr
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
@@ -1,106 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe Faraday::Response::RaiseError do
|
4
|
-
let(:conn) do
|
5
|
-
Faraday.new do |b|
|
6
|
-
b.response :raise_error
|
7
|
-
b.adapter :test do |stub|
|
8
|
-
stub.get('ok') { [200, { 'Content-Type' => 'text/html' }, '<body></body>'] }
|
9
|
-
stub.get('bad-request') { [400, { 'X-Reason' => 'because' }, 'keep looking'] }
|
10
|
-
stub.get('unauthorized') { [401, { 'X-Reason' => 'because' }, 'keep looking'] }
|
11
|
-
stub.get('forbidden') { [403, { 'X-Reason' => 'because' }, 'keep looking'] }
|
12
|
-
stub.get('not-found') { [404, { 'X-Reason' => 'because' }, 'keep looking'] }
|
13
|
-
stub.get('proxy-error') { [407, { 'X-Reason' => 'because' }, 'keep looking'] }
|
14
|
-
stub.get('conflict') { [409, { 'X-Reason' => 'because' }, 'keep looking'] }
|
15
|
-
stub.get('unprocessable-entity') { [422, { 'X-Reason' => 'because' }, 'keep looking'] }
|
16
|
-
stub.get('4xx') { [499, { 'X-Reason' => 'because' }, 'keep looking'] }
|
17
|
-
stub.get('nil-status') { [nil, { 'X-Reason' => 'nil' }, 'fail'] }
|
18
|
-
stub.get('server-error') { [500, { 'X-Error' => 'bailout' }, 'fail'] }
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'raises no exception for 200 responses' do
|
24
|
-
expect { conn.get('ok') }.not_to raise_error
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'raises Faraday::ClientError for 400 responses' do
|
28
|
-
expect { conn.get('bad-request') }.to raise_error(Faraday::ClientError) do |ex|
|
29
|
-
expect(ex.message).to eq('the server responded with status 400')
|
30
|
-
expect(ex.response[:headers]['X-Reason']).to eq('because')
|
31
|
-
expect(ex.response[:status]).to eq(400)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'raises Faraday::ClientError for 401 responses' do
|
36
|
-
expect { conn.get('unauthorized') }.to raise_error(Faraday::ClientError) do |ex|
|
37
|
-
expect(ex.message).to eq('the server responded with status 401')
|
38
|
-
expect(ex.response[:headers]['X-Reason']).to eq('because')
|
39
|
-
expect(ex.response[:status]).to eq(401)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
it 'raises Faraday::ClientError for 403 responses' do
|
44
|
-
expect { conn.get('forbidden') }.to raise_error(Faraday::ClientError) do |ex|
|
45
|
-
expect(ex.message).to eq('the server responded with status 403')
|
46
|
-
expect(ex.response[:headers]['X-Reason']).to eq('because')
|
47
|
-
expect(ex.response[:status]).to eq(403)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
it 'raises Faraday::ResourceNotFound for 404 responses' do
|
52
|
-
expect { conn.get('not-found') }.to raise_error(Faraday::ResourceNotFound) do |ex|
|
53
|
-
expect(ex.message).to eq('the server responded with status 404')
|
54
|
-
expect(ex.response[:headers]['X-Reason']).to eq('because')
|
55
|
-
expect(ex.response[:status]).to eq(404)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
it 'raises Faraday::ConnectionFailed for 407 responses' do
|
60
|
-
expect { conn.get('proxy-error') }.to raise_error(Faraday::ConnectionFailed) do |ex|
|
61
|
-
expect(ex.message).to eq('407 "Proxy Authentication Required "')
|
62
|
-
expect(ex.response[:headers]['X-Reason']).to eq('because')
|
63
|
-
expect(ex.response[:status]).to eq(407)
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
it 'raises Faraday::ClientError for 409 responses' do
|
68
|
-
expect { conn.get('conflict') }.to raise_error(Faraday::ClientError) do |ex|
|
69
|
-
expect(ex.message).to eq('the server responded with status 409')
|
70
|
-
expect(ex.response[:headers]['X-Reason']).to eq('because')
|
71
|
-
expect(ex.response[:status]).to eq(409)
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
it 'raises Faraday::ClientError for 422 responses' do
|
76
|
-
expect { conn.get('unprocessable-entity') }.to raise_error(Faraday::ClientError) do |ex|
|
77
|
-
expect(ex.message).to eq('the server responded with status 422')
|
78
|
-
expect(ex.response[:headers]['X-Reason']).to eq('because')
|
79
|
-
expect(ex.response[:status]).to eq(422)
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
it 'raises Faraday::NilStatusError for nil status in response' do
|
84
|
-
expect { conn.get('nil-status') }.to raise_error(Faraday::NilStatusError) do |ex|
|
85
|
-
expect(ex.message).to eq('http status could not be derived from the server response')
|
86
|
-
expect(ex.response[:headers]['X-Reason']).to eq('nil')
|
87
|
-
expect(ex.response[:status]).to be_nil
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
it 'raises Faraday::ClientError for other 4xx responses' do
|
92
|
-
expect { conn.get('4xx') }.to raise_error(Faraday::ClientError) do |ex|
|
93
|
-
expect(ex.message).to eq('the server responded with status 499')
|
94
|
-
expect(ex.response[:headers]['X-Reason']).to eq('because')
|
95
|
-
expect(ex.response[:status]).to eq(499)
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
it 'raises Faraday::ClientError for 500 responses' do
|
100
|
-
expect { conn.get('server-error') }.to raise_error(Faraday::ClientError) do |ex|
|
101
|
-
expect(ex.message).to eq('the server responded with status 500')
|
102
|
-
expect(ex.response[:headers]['X-Error']).to eq('bailout')
|
103
|
-
expect(ex.response[:status]).to eq(500)
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,105 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'faraday'
|
4
|
-
Faraday::Deprecate.skip = false
|
5
|
-
|
6
|
-
# This file was generated by the `rspec --init` command. Conventionally, all
|
7
|
-
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
8
|
-
# The generated `.rspec` file contains `--require spec_helper` which will cause
|
9
|
-
# this file to always be loaded, without a need to explicitly require it in any
|
10
|
-
# files.
|
11
|
-
#
|
12
|
-
# Given that it is always loaded, you are encouraged to keep this file as
|
13
|
-
# light-weight as possible. Requiring heavyweight dependencies from this file
|
14
|
-
# will add to the boot time of your test suite on EVERY test run, even for an
|
15
|
-
# individual file that may not need all of that loaded. Instead, consider making
|
16
|
-
# a separate helper file that requires the additional dependencies and performs
|
17
|
-
# the additional setup, and require it from the spec files that actually need
|
18
|
-
# it.
|
19
|
-
#
|
20
|
-
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
21
|
-
RSpec.configure do |config|
|
22
|
-
# rspec-expectations config goes here. You can use an alternate
|
23
|
-
# assertion/expectation library such as wrong or the stdlib/minitest
|
24
|
-
# assertions if you prefer.
|
25
|
-
config.expect_with :rspec do |expectations|
|
26
|
-
# This option will default to `true` in RSpec 4. It makes the `description`
|
27
|
-
# and `failure_message` of custom matchers include text for helper methods
|
28
|
-
# defined using `chain`, e.g.:
|
29
|
-
# be_bigger_than(2).and_smaller_than(4).description
|
30
|
-
# # => "be bigger than 2 and smaller than 4"
|
31
|
-
# ...rather than:
|
32
|
-
# # => "be bigger than 2"
|
33
|
-
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
34
|
-
end
|
35
|
-
|
36
|
-
# rspec-mocks config goes here. You can use an alternate test double
|
37
|
-
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
38
|
-
config.mock_with :rspec do |mocks|
|
39
|
-
# Prevents you from mocking or stubbing a method that does not exist on
|
40
|
-
# a real object. This is generally recommended, and will default to
|
41
|
-
# `true` in RSpec 4.
|
42
|
-
mocks.verify_partial_doubles = true
|
43
|
-
end
|
44
|
-
|
45
|
-
# This option will default to `:apply_to_host_groups` in RSpec 4 (and will
|
46
|
-
# have no way to turn it off -- the option exists only for backwards
|
47
|
-
# compatibility in RSpec 3). It causes shared context metadata to be
|
48
|
-
# inherited by the metadata hash of host groups and examples, rather than
|
49
|
-
# triggering implicit auto-inclusion in groups with matching metadata.
|
50
|
-
config.shared_context_metadata_behavior = :apply_to_host_groups
|
51
|
-
|
52
|
-
# Run specs in random order to surface order dependencies. If you find an
|
53
|
-
# order dependency and want to debug it, you can fix the order by providing
|
54
|
-
# the seed, which is printed after each run.
|
55
|
-
# --seed 1234
|
56
|
-
config.order = :random
|
57
|
-
|
58
|
-
# Seed global randomization in this process using the `--seed` CLI option.
|
59
|
-
# Setting this allows you to use `--seed` to deterministically reproduce
|
60
|
-
# test failures related to randomization by passing the same `--seed` value
|
61
|
-
# as the one that triggered the failure.
|
62
|
-
Kernel.srand config.seed
|
63
|
-
|
64
|
-
# Limits the available syntax to the non-monkey patched syntax that is
|
65
|
-
# recommended. For more details, see:
|
66
|
-
# - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
|
67
|
-
# - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
68
|
-
# - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
|
69
|
-
config.disable_monkey_patching!
|
70
|
-
|
71
|
-
# The settings below are suggested to provide a good initial experience
|
72
|
-
# with RSpec, but feel free to customize to your heart's content.
|
73
|
-
=begin
|
74
|
-
# This allows you to limit a spec run to individual examples or groups
|
75
|
-
# you care about by tagging them with `:focus` metadata. When nothing
|
76
|
-
# is tagged with `:focus`, all examples get run. RSpec also provides
|
77
|
-
# aliases for `it`, `describe`, and `context` that include `:focus`
|
78
|
-
# metadata: `fit`, `fdescribe` and `fcontext`, respectively.
|
79
|
-
config.filter_run_when_matching :focus
|
80
|
-
|
81
|
-
# Allows RSpec to persist some state between runs in order to support
|
82
|
-
# the `--only-failures` and `--next-failure` CLI options. We recommend
|
83
|
-
# you configure your source control system to ignore this file.
|
84
|
-
config.example_status_persistence_file_path = "spec/examples.txt"
|
85
|
-
|
86
|
-
# This setting enables warnings. It's recommended, but in some cases may
|
87
|
-
# be too noisy due to issues in dependencies.
|
88
|
-
config.warnings = true
|
89
|
-
|
90
|
-
# Many RSpec users commonly either run the entire suite or an individual
|
91
|
-
# file, and it's useful to allow more verbose output when running an
|
92
|
-
# individual spec file.
|
93
|
-
if config.files_to_run.one?
|
94
|
-
# Use the documentation formatter for detailed output,
|
95
|
-
# unless a formatter has already been configured
|
96
|
-
# (e.g. via a command-line flag).
|
97
|
-
config.default_formatter = "doc"
|
98
|
-
end
|
99
|
-
|
100
|
-
# Print the 10 slowest examples and example groups at the
|
101
|
-
# end of the spec run, to help surface which specs are running
|
102
|
-
# particularly slow.
|
103
|
-
config.profile_examples = 10
|
104
|
-
=end
|
105
|
-
end
|