faraday 0.17.6 → 1.0.0.pre.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.md +1 -1
  3. data/README.md +18 -358
  4. data/lib/faraday/adapter/em_http.rb +142 -99
  5. data/lib/faraday/adapter/em_http_ssl_patch.rb +23 -17
  6. data/lib/faraday/adapter/em_synchrony/parallel_manager.rb +18 -15
  7. data/lib/faraday/adapter/em_synchrony.rb +104 -60
  8. data/lib/faraday/adapter/excon.rb +97 -57
  9. data/lib/faraday/adapter/httpclient.rb +61 -39
  10. data/lib/faraday/adapter/net_http.rb +103 -51
  11. data/lib/faraday/adapter/net_http_persistent.rb +49 -28
  12. data/lib/faraday/adapter/patron.rb +54 -35
  13. data/lib/faraday/adapter/rack.rb +28 -12
  14. data/lib/faraday/adapter/test.rb +86 -53
  15. data/lib/faraday/adapter/typhoeus.rb +4 -1
  16. data/lib/faraday/adapter.rb +36 -22
  17. data/lib/faraday/adapter_registry.rb +28 -0
  18. data/lib/faraday/autoload.rb +47 -36
  19. data/lib/faraday/connection.rb +321 -179
  20. data/lib/faraday/dependency_loader.rb +37 -0
  21. data/lib/faraday/encoders/flat_params_encoder.rb +94 -0
  22. data/lib/faraday/encoders/nested_params_encoder.rb +171 -0
  23. data/lib/faraday/error.rb +21 -79
  24. data/lib/faraday/logging/formatter.rb +92 -0
  25. data/lib/faraday/middleware.rb +4 -28
  26. data/lib/faraday/middleware_registry.rb +129 -0
  27. data/lib/faraday/options/connection_options.rb +22 -0
  28. data/lib/faraday/options/env.rb +181 -0
  29. data/lib/faraday/options/proxy_options.rb +28 -0
  30. data/lib/faraday/options/request_options.rb +21 -0
  31. data/lib/faraday/options/ssl_options.rb +59 -0
  32. data/lib/faraday/options.rb +33 -184
  33. data/lib/faraday/parameters.rb +4 -197
  34. data/lib/faraday/rack_builder.rb +66 -55
  35. data/lib/faraday/request/authorization.rb +42 -30
  36. data/lib/faraday/request/basic_authentication.rb +14 -7
  37. data/lib/faraday/request/instrumentation.rb +45 -27
  38. data/lib/faraday/request/multipart.rb +72 -49
  39. data/lib/faraday/request/retry.rb +197 -171
  40. data/lib/faraday/request/token_authentication.rb +15 -10
  41. data/lib/faraday/request/url_encoded.rb +41 -23
  42. data/lib/faraday/request.rb +68 -38
  43. data/lib/faraday/response/logger.rb +22 -69
  44. data/lib/faraday/response/raise_error.rb +36 -18
  45. data/lib/faraday/response.rb +22 -15
  46. data/lib/faraday/upload_io.rb +31 -30
  47. data/lib/faraday/utils/headers.rb +139 -0
  48. data/lib/faraday/utils/params_hash.rb +61 -0
  49. data/lib/faraday/utils.rb +28 -245
  50. data/lib/faraday.rb +93 -174
  51. data/spec/external_adapters/faraday_specs_setup.rb +14 -0
  52. metadata +25 -51
  53. data/CHANGELOG.md +0 -232
  54. data/Rakefile +0 -13
  55. data/lib/faraday/deprecate.rb +0 -109
  56. data/spec/faraday/deprecate_spec.rb +0 -147
  57. data/spec/faraday/error_spec.rb +0 -102
  58. data/spec/faraday/response/raise_error_spec.rb +0 -106
  59. data/spec/spec_helper.rb +0 -105
  60. data/test/adapters/default_test.rb +0 -14
  61. data/test/adapters/em_http_test.rb +0 -30
  62. data/test/adapters/em_synchrony_test.rb +0 -32
  63. data/test/adapters/excon_test.rb +0 -30
  64. data/test/adapters/httpclient_test.rb +0 -34
  65. data/test/adapters/integration.rb +0 -263
  66. data/test/adapters/logger_test.rb +0 -136
  67. data/test/adapters/net_http_persistent_test.rb +0 -114
  68. data/test/adapters/net_http_test.rb +0 -79
  69. data/test/adapters/patron_test.rb +0 -40
  70. data/test/adapters/rack_test.rb +0 -38
  71. data/test/adapters/test_middleware_test.rb +0 -157
  72. data/test/adapters/typhoeus_test.rb +0 -38
  73. data/test/authentication_middleware_test.rb +0 -65
  74. data/test/composite_read_io_test.rb +0 -109
  75. data/test/connection_test.rb +0 -738
  76. data/test/env_test.rb +0 -268
  77. data/test/helper.rb +0 -75
  78. data/test/live_server.rb +0 -67
  79. data/test/middleware/instrumentation_test.rb +0 -88
  80. data/test/middleware/retry_test.rb +0 -282
  81. data/test/middleware_stack_test.rb +0 -260
  82. data/test/multibyte.txt +0 -1
  83. data/test/options_test.rb +0 -333
  84. data/test/parameters_test.rb +0 -157
  85. data/test/request_middleware_test.rb +0 -126
  86. data/test/response_middleware_test.rb +0 -72
  87. data/test/strawberry.rb +0 -2
  88. data/test/utils_test.rb +0 -98
data/CHANGELOG.md DELETED
@@ -1,232 +0,0 @@
1
- # Faraday Changelog
2
-
3
- ## v0.17.3
4
-
5
- Fixes:
6
-
7
- * Reverts changes in error classes hierarchy. #1092 (@iMacTia)
8
- * Fix Ruby 1.9 syntax errors and improve Error class testing #1094 (@BanzaiMan,
9
- @mrexox, @technoweenie)
10
-
11
- Misc:
12
-
13
- * Stops using `&Proc.new` for block forwarding. #1083 (@olleolleolle)
14
- * Update CI to test against ruby 2.0-2.7 #1087, #1099 (@iMacTia, @olleolleolle,
15
- @technoweenie)
16
- * require FARADAY_DEPRECATE=warn to show Faraday v1.0 deprecation warnings
17
- #1098 (@technoweenie)
18
-
19
- ## v0.17.1
20
-
21
- Final release before Faraday v1.0, with important fixes for Ruby 2.7.
22
-
23
- Fixes:
24
-
25
- * RaiseError response middleware raises exception if HTTP client returns a nil
26
- status. #1042 (@jonnyom, @BobbyMcWho)
27
-
28
- Misc:
29
-
30
- * Fix Ruby 2.7 warnings (#1009)
31
- * Add `Faraday::Deprecate` to warn about upcoming v1.0 changes. (#1054, #1059,
32
- #1076, #1077)
33
- * Add release notes up to current in CHANGELOG.md (#1066)
34
- * Port minimal rspec suite from main branch to run backported tests. (#1058)
35
-
36
- ## v0.17.0
37
-
38
- This release is the same as v0.15.4. It was pushed to cover up releases
39
- v0.16.0-v0.16.2.
40
-
41
- ## v0.15.4
42
-
43
- * Expose `pool_size` as a option for the NetHttpPersistent adapter (#834)
44
-
45
- ## v0.15.3
46
-
47
- * Make Faraday::Request serialisable with Marshal. (#803)
48
- * Add DEFAULT_EXCEPTIONS constant to Request::Retry (#814)
49
- * Add support for Ruby 2.6 Net::HTTP write_timeout (#824)
50
-
51
- ## v0.15.2
52
-
53
- * Prevents `Net::HTTP` adapters to retry request internally by setting `max_retries` to 0 if available (Ruby 2.5+). (#799)
54
- * Fixes `NestedParamsEncoder` handling of empty array values (#801)
55
-
56
- ## v0.15.1
57
-
58
- * NetHttpPersistent adapter better reuse of SSL connections (#793)
59
- * Refactor: inline cached_connection (#797)
60
- * Logger middleware: use $stdout instead of STDOUT (#794)
61
- * Fix: do not memoize/reuse Patron session (#796)
62
-
63
- Also in this release:
64
-
65
- * Allow setting min/max ssl version for Net::HTTP (#792)
66
- * Allow setting min/max ssl version for Excon (#795)
67
-
68
- ## v0.15.0
69
-
70
- Features:
71
-
72
- * Added retry block option to retry middleware. (#770)
73
- * Retry middleware improvements (honour Retry-After header, retry statuses) (#773)
74
- * Improve response logger middleware output (#784)
75
-
76
- Fixes:
77
-
78
- * Remove unused class error (#767)
79
- * Fix minor typo in README (#760)
80
- * Reuse persistent connections when using net-http-persistent (#778)
81
- * Fix Retry middleware documentation (#781)
82
- * Returns the http response when giving up on retrying by status (#783)
83
-
84
- ## v0.14.0
85
-
86
- Features:
87
-
88
- * Allow overriding env proxy (#754)
89
- * Remove legacy Typhoeus adapter (#715)
90
- * External Typhoeus Adapter Compatibility (#748)
91
- * Warn about missing adapter when making a request (#743)
92
- * Faraday::Adapter::Test stubs now support entire urls (with host) (#741)
93
-
94
- Fixes:
95
-
96
- * If proxy is manually provided, this takes priority over `find_proxy` (#724)
97
- * Fixes the behaviour for Excon's open_timeout (not setting write_timeout anymore) (#731)
98
- * Handle all connection timeout messages in Patron (#687)
99
-
100
- ## v0.13.1
101
-
102
- * Fixes an incompatibility with Addressable::URI being used as uri_parser
103
-
104
- ## v0.13.0
105
-
106
- Features:
107
-
108
- * Dynamically reloads the proxy when performing a request on an absolute domain (#701)
109
- * Adapter support for Net::HTTP::Persistent v3.0.0 (#619)
110
-
111
- Fixes:
112
-
113
- * Prefer #hostname over #host. (#714)
114
- * Fixes an edge-case issue with response headers parsing (missing HTTP header) (#719)
115
-
116
- ## v0.12.2
117
-
118
- * Parse headers from aggregated proxy requests/responses (#681)
119
- * Guard against invalid middleware configuration with warning (#685)
120
- * Do not use :insecure option by default in Patron (#691)
121
- * Fixes an issue with HTTPClient not raising a `Faraday::ConnectionFailed` (#702)
122
- * Fixes YAML serialization/deserialization for `Faraday::Utils::Headers` (#690)
123
- * Fixes an issue with Options having a nil value (#694)
124
- * Fixes an issue with Faraday.default_connection not using Faraday.default_connection_options (#698)
125
- * Fixes an issue with Options.merge! and Faraday instrumentation middleware (#710)
126
-
127
- ## v0.12.1
128
-
129
- * Fix an issue with Patron tests failing on jruby
130
- * Fix an issue with new `rewind_files` feature that was causing an exception when the body was not an Hash
131
- * Expose wrapped_exception in all client errors
132
- * Add Authentication Section to the ReadMe
133
-
134
- ## v0.12.0.1
135
-
136
- * Hotfix release to address an issue with TravisCI deploy on Rubygems
137
-
138
- ## v0.12.0
139
-
140
- Features:
141
-
142
- * Proxy feature now relies on Ruby `URI::Generic#find_proxy` and can use `no_proxy` ENV variable (not compatible with ruby < 2.0)
143
- * Adds support for `context` request option to pass arbitrary information to middlewares
144
-
145
- Fixes:
146
-
147
- * Fix an issue with options that was causing new options to override defaults ones unexpectedly
148
- * Rewind `UploadIO`s on retry to fix a compatibility issue
149
- * Make multipart boundary unique
150
- * Improvements in `README.md`
151
-
152
- ## v0.11.0
153
-
154
- Features:
155
-
156
- * Add `filter` method to Logger middleware
157
- * Add support for Ruby2.4 and Minitest 6
158
- * Introduce block syntax to customise the adapter
159
-
160
- Fixes:
161
-
162
- * Fix an issue that was allowing to override `default_connection_options` from a connection instance
163
- * Fix a bug that was causing newline escape characters ("\n") to be used when building the Authorization header
164
-
165
- ## v0.10.1
166
-
167
- - Fix an issue with HTTPClient adapter that was causing the SSL to be reset on every request
168
- - Rescue `IOError` instead of specific subclass
169
- - `Faraday::Utils::Headers` can now be successfully serialised in YAML
170
- - Handle `default_connection_options` set with hash
171
-
172
- ## v0.10.0
173
-
174
- Breaking changes:
175
- - Drop support for Ruby 1.8
176
-
177
- Features:
178
- - Include wrapped exception/reponse in ClientErrors
179
- - Add `response.reason_phrase`
180
- - Provide option to selectively skip logging request/response headers
181
- - Add regex support for pattern matching in `test` adapter
182
-
183
- Fixes:
184
- - Add `Faraday.respond_to?` to find methods managed by `method_missing`
185
- - em-http: `request.host` instead of `connection.host` should be taken for SSL validations
186
- - Allow `default_connection_options` to be merged when options are passed as url parameter
187
- - Improve splitting key-value pairs in raw HTTP headers
188
-
189
- ## v0.9.2
190
-
191
- Adapters:
192
- - Enable gzip compression for httpclient
193
- - Fixes default certificate store for httpclient not having default paths.
194
- - Make excon adapter compatible with 0.44 excon version
195
- - Add compatibility with Patron 0.4.20
196
- - Determine default port numbers in Net::HTTP adapters (Addressable compatibility)
197
- - em-http: wrap "connection closed by server" as ConnectionFailed type
198
- - Wrap Errno::ETIMEDOUT in Faraday::Error::TimeoutError
199
-
200
- Utils:
201
- - Add Rack-compatible support for parsing `a[][b]=c` nested queries
202
- - Encode nil values in queries different than empty strings. Before: `a=`; now: `a`.
203
- - Have `Faraday::Utils::Headers#replace` clear internal key cache
204
- - Dup the internal key cache when a Headers hash is copied
205
-
206
- Env and middleware:
207
- - Ensure `env` stored on middleware response has reference to the response
208
- - Ensure that Response properties are initialized during `on_complete` (VCR compatibility)
209
- - Copy request options in Faraday::Connection#dup
210
- - Env custom members should be copied by Env.from(env)
211
- - Honour per-request `request.options.params_encoder`
212
- - Fix `interval_randomness` data type for Retry middleware
213
- - Add maximum interval option for Retry middleware
214
-
215
- ## v0.9.1
216
-
217
- * Refactor Net:HTTP adapter so that with_net_http_connection can be overridden to allow pooled connections. (@Ben-M)
218
- * Add configurable methods that bypass `retry_if` in the Retry request middleware. (@mike-bourgeous)
219
-
220
- ## v0.9.0
221
-
222
- * Add HTTPClient adapter (@hakanensari)
223
- * Improve Retry handler (@mislav)
224
- * Remove autoloading by default (@technoweenie)
225
- * Improve internal docs (@technoweenie, @mislav)
226
- * Respect user/password in http proxy string (@mislav)
227
- * Adapter options are structs. Reinforces consistent options across adapters
228
- (@technoweenie)
229
- * Stop stripping trailing / off base URLs in a Faraday::Connection. (@technoweenie)
230
- * Add a configurable URI parser. (@technoweenie)
231
- * Remove need to manually autoload when using the authorization header helpers on `Faraday::Connection`. (@technoweenie)
232
- * `Faraday::Adapter::Test` respects the `Faraday::RequestOptions#params_encoder` option. (@technoweenie)
data/Rakefile DELETED
@@ -1,13 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rake/testtask'
4
- require 'rspec/core/rake_task'
5
-
6
- RSpec::Core::RakeTask.new(:spec)
7
-
8
- task :default => :test
9
-
10
- desc "Run all tests"
11
- task :test => :spec do
12
- exec 'script/test'
13
- end
@@ -1,109 +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
- const_set("ORIG_CLASS", origclass)
13
-
14
- class << self
15
- extend Faraday::Deprecate
16
-
17
- def ===(other)
18
- (superclass == const_get("ORIG_CLASS") && other.is_a?(superclass)) || super
19
- end
20
- end
21
- end
22
- proxy.singleton_class.send(:deprecate, :new, "#{origclass}.new", ver)
23
- proxy.singleton_class.send(:deprecate, :inherited, origclass.name, ver)
24
- proxy
25
- end
26
- end
27
-
28
- # Deprecation using semver instead of date, based on Gem::Deprecate
29
- # Provides a single method +deprecate+ to be used to declare when
30
- # something is going away.
31
- #
32
- # class Legacy
33
- # def self.klass_method
34
- # # ...
35
- # end
36
- #
37
- # def instance_method
38
- # # ...
39
- # end
40
- #
41
- # extend Faraday::Deprecate
42
- # deprecate :instance_method, "X.z", '1.0'
43
- #
44
- # class << self
45
- # extend Faraday::Deprecate
46
- # deprecate :klass_method, :none, '1.0'
47
- # end
48
- # end
49
- module Deprecate
50
- def self.skip # :nodoc:
51
- @skip ||= begin
52
- case ENV['FARADAY_DEPRECATE'].to_s.downcase
53
- when '1', 'warn' then :warn
54
- else :skip
55
- end
56
- end
57
- @skip == :skip
58
- end
59
-
60
- def self.skip=(value) # :nodoc:
61
- @skip = value ? :skip : :warn
62
- end
63
-
64
- # Temporarily turn off warnings. Intended for tests only.
65
- def skip_during
66
- original = Faraday::Deprecate.skip
67
- Faraday::Deprecate.skip, = true
68
- yield
69
- ensure
70
- Faraday::Deprecate.skip = original
71
- end
72
-
73
- # Simple deprecation method that deprecates +name+ by wrapping it up
74
- # in a dummy method. It warns on each call to the dummy method
75
- # telling the user of +repl+ (unless +repl+ is :none) and the
76
- # semver that it is planned to go away.
77
- # @param name [Symbol] the method symbol to deprecate
78
- # @param repl [#to_s, :none] the replacement to use, when `:none` it will
79
- # alert the user that no replacemtent is present.
80
- # @param ver [String] the semver the method will be removed.
81
- def deprecate(name, repl, ver)
82
- class_eval do
83
- gem_ver = Gem::Version.new(ver)
84
- old = "_deprecated_#{name}"
85
- alias_method old, name
86
- define_method name do |*args, &block|
87
- mod = is_a? Module
88
- target = mod ? "#{self}." : "#{self.class}#"
89
- target_message = if name == :inherited
90
- "Inheriting #{self}"
91
- else
92
- "#{target}#{name}"
93
- end
94
-
95
- msg = [
96
- "NOTE: #{target_message} is deprecated",
97
- repl == :none ? ' with no replacement' : "; use #{repl} instead. ",
98
- "It will be removed in or after version #{gem_ver}",
99
- "\n#{target}#{name} called from #{Gem.location_of_caller.join(':')}"
100
- ]
101
- warn "#{msg.join}." unless Faraday::Deprecate.skip
102
- send old, *args, &block
103
- end
104
- end
105
- end
106
-
107
- module_function :deprecate, :skip_during
108
- end
109
- end
@@ -1,147 +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
- 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(SampleClass === SampleDeprecatedClass.new).to be true
70
- end
71
-
72
- it 'is === to instance of subclass of deprecated class' do
73
- expect(SampleClass === SampleDeprecatedClassA.new).to be true
74
- end
75
-
76
- it 'is === to instance of subclass of subclass of deprecated class' do
77
- expect(SampleClass === SampleDeprecatedClassAX.new).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(SampleClassA === SampleClass.new).to be false
84
- end
85
-
86
- it 'is not === to instance of deprecated class' do
87
- expect(SampleClassA === SampleDeprecatedClass.new).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 === SampleClass.new).to be true
94
- end
95
-
96
- it 'is === to instance of subclass of undeprecated class' do
97
- expect(SampleDeprecatedClass === SampleClassA.new).to be true
98
- end
99
-
100
- it 'is === to instance of subclass of deprecated class' do
101
- expect(SampleDeprecatedClass === SampleDeprecatedClassA.new).to be true
102
- end
103
-
104
- it 'is === to instance of subclass of subclass of deprecated class' do
105
- expect(SampleDeprecatedClass === SampleDeprecatedClassAX.new).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(SampleDeprecatedClassA === SampleClass.new).to be false
112
- end
113
-
114
- it 'is not === to instance of another subclass of deprecated class' do
115
- expect(SampleDeprecatedClassA === SampleDeprecatedClassB.new).to be false
116
- end
117
-
118
- it 'is === to instance of its subclass' do
119
- expect(SampleDeprecatedClassA === SampleDeprecatedClassAX.new).to be true
120
- end
121
-
122
- it 'is === to instance of deprecated class' do
123
- expect(SampleDeprecatedClass === SampleDeprecatedClassB.new).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(SampleDeprecatedClassAX === SampleDeprecatedClassB.new).to be false
130
- end
131
-
132
- it 'is not === to instance of its superclass' do
133
- expect(SampleDeprecatedClassA === SampleDeprecatedClass.new).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
@@ -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