faraday 0.17.3 → 2.7.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (124) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +350 -8
  3. data/LICENSE.md +1 -1
  4. data/README.md +27 -367
  5. data/Rakefile +1 -7
  6. data/examples/client_spec.rb +119 -0
  7. data/examples/client_test.rb +144 -0
  8. data/lib/faraday/adapter/test.rb +170 -72
  9. data/lib/faraday/adapter.rb +69 -23
  10. data/lib/faraday/adapter_registry.rb +30 -0
  11. data/lib/faraday/connection.rb +309 -233
  12. data/lib/faraday/encoders/flat_params_encoder.rb +105 -0
  13. data/lib/faraday/encoders/nested_params_encoder.rb +183 -0
  14. data/lib/faraday/error.rb +31 -42
  15. data/lib/faraday/logging/formatter.rb +122 -0
  16. data/lib/faraday/methods.rb +6 -0
  17. data/lib/faraday/middleware.rb +21 -25
  18. data/lib/faraday/middleware_registry.rb +83 -0
  19. data/lib/faraday/options/connection_options.rb +22 -0
  20. data/lib/faraday/options/env.rb +205 -0
  21. data/lib/faraday/options/proxy_options.rb +32 -0
  22. data/lib/faraday/options/request_options.rb +22 -0
  23. data/lib/faraday/options/ssl_options.rb +69 -0
  24. data/lib/faraday/options.rb +38 -193
  25. data/lib/faraday/parameters.rb +4 -197
  26. data/lib/faraday/rack_builder.rb +91 -76
  27. data/lib/faraday/request/authorization.rb +42 -29
  28. data/lib/faraday/request/instrumentation.rb +47 -27
  29. data/lib/faraday/request/json.rb +55 -0
  30. data/lib/faraday/request/url_encoded.rb +48 -24
  31. data/lib/faraday/request.rb +64 -42
  32. data/lib/faraday/response/json.rb +54 -0
  33. data/lib/faraday/response/logger.rb +24 -67
  34. data/lib/faraday/response/raise_error.rb +57 -18
  35. data/lib/faraday/response.rb +26 -32
  36. data/lib/faraday/utils/headers.rb +144 -0
  37. data/lib/faraday/utils/params_hash.rb +61 -0
  38. data/lib/faraday/utils.rb +47 -251
  39. data/lib/faraday/version.rb +5 -0
  40. data/lib/faraday.rb +108 -198
  41. data/spec/external_adapters/faraday_specs_setup.rb +14 -0
  42. data/spec/faraday/adapter/test_spec.rb +442 -0
  43. data/spec/faraday/adapter_registry_spec.rb +28 -0
  44. data/spec/faraday/adapter_spec.rb +55 -0
  45. data/spec/faraday/connection_spec.rb +808 -0
  46. data/spec/faraday/error_spec.rb +12 -54
  47. data/spec/faraday/middleware_registry_spec.rb +31 -0
  48. data/spec/faraday/middleware_spec.rb +70 -0
  49. data/spec/faraday/options/env_spec.rb +76 -0
  50. data/spec/faraday/options/options_spec.rb +297 -0
  51. data/spec/faraday/options/proxy_options_spec.rb +44 -0
  52. data/spec/faraday/options/request_options_spec.rb +19 -0
  53. data/spec/faraday/params_encoders/flat_spec.rb +42 -0
  54. data/spec/faraday/params_encoders/nested_spec.rb +150 -0
  55. data/spec/faraday/rack_builder_spec.rb +317 -0
  56. data/spec/faraday/request/authorization_spec.rb +118 -0
  57. data/spec/faraday/request/instrumentation_spec.rb +74 -0
  58. data/spec/faraday/request/json_spec.rb +111 -0
  59. data/spec/faraday/request/url_encoded_spec.rb +93 -0
  60. data/spec/faraday/request_spec.rb +110 -0
  61. data/spec/faraday/response/json_spec.rb +117 -0
  62. data/spec/faraday/response/logger_spec.rb +248 -0
  63. data/spec/faraday/response/raise_error_spec.rb +81 -15
  64. data/spec/faraday/response_spec.rb +77 -0
  65. data/spec/faraday/utils/headers_spec.rb +100 -0
  66. data/spec/faraday/utils_spec.rb +118 -0
  67. data/spec/faraday_spec.rb +37 -0
  68. data/spec/spec_helper.rb +63 -36
  69. data/spec/support/disabling_stub.rb +14 -0
  70. data/spec/support/fake_safe_buffer.rb +15 -0
  71. data/spec/support/helper_methods.rb +96 -0
  72. data/spec/support/shared_examples/adapter.rb +105 -0
  73. data/spec/support/shared_examples/params_encoder.rb +18 -0
  74. data/spec/support/shared_examples/request_method.rb +263 -0
  75. data/spec/support/streaming_response_checker.rb +35 -0
  76. metadata +76 -59
  77. data/lib/faraday/adapter/em_http.rb +0 -243
  78. data/lib/faraday/adapter/em_http_ssl_patch.rb +0 -56
  79. data/lib/faraday/adapter/em_synchrony/parallel_manager.rb +0 -66
  80. data/lib/faraday/adapter/em_synchrony.rb +0 -106
  81. data/lib/faraday/adapter/excon.rb +0 -82
  82. data/lib/faraday/adapter/httpclient.rb +0 -128
  83. data/lib/faraday/adapter/net_http.rb +0 -152
  84. data/lib/faraday/adapter/net_http_persistent.rb +0 -68
  85. data/lib/faraday/adapter/patron.rb +0 -95
  86. data/lib/faraday/adapter/rack.rb +0 -58
  87. data/lib/faraday/adapter/typhoeus.rb +0 -12
  88. data/lib/faraday/autoload.rb +0 -84
  89. data/lib/faraday/deprecate.rb +0 -107
  90. data/lib/faraday/request/basic_authentication.rb +0 -13
  91. data/lib/faraday/request/multipart.rb +0 -68
  92. data/lib/faraday/request/retry.rb +0 -213
  93. data/lib/faraday/request/token_authentication.rb +0 -15
  94. data/lib/faraday/upload_io.rb +0 -67
  95. data/spec/faraday/deprecate_spec.rb +0 -69
  96. data/test/adapters/default_test.rb +0 -14
  97. data/test/adapters/em_http_test.rb +0 -30
  98. data/test/adapters/em_synchrony_test.rb +0 -32
  99. data/test/adapters/excon_test.rb +0 -30
  100. data/test/adapters/httpclient_test.rb +0 -34
  101. data/test/adapters/integration.rb +0 -263
  102. data/test/adapters/logger_test.rb +0 -136
  103. data/test/adapters/net_http_persistent_test.rb +0 -114
  104. data/test/adapters/net_http_test.rb +0 -79
  105. data/test/adapters/patron_test.rb +0 -40
  106. data/test/adapters/rack_test.rb +0 -38
  107. data/test/adapters/test_middleware_test.rb +0 -157
  108. data/test/adapters/typhoeus_test.rb +0 -38
  109. data/test/authentication_middleware_test.rb +0 -65
  110. data/test/composite_read_io_test.rb +0 -109
  111. data/test/connection_test.rb +0 -738
  112. data/test/env_test.rb +0 -268
  113. data/test/helper.rb +0 -75
  114. data/test/live_server.rb +0 -67
  115. data/test/middleware/instrumentation_test.rb +0 -88
  116. data/test/middleware/retry_test.rb +0 -282
  117. data/test/middleware_stack_test.rb +0 -260
  118. data/test/multibyte.txt +0 -1
  119. data/test/options_test.rb +0 -333
  120. data/test/parameters_test.rb +0 -157
  121. data/test/request_middleware_test.rb +0 -126
  122. data/test/response_middleware_test.rb +0 -72
  123. data/test/strawberry.rb +0 -2
  124. data/test/utils_test.rb +0 -98
@@ -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,13 +0,0 @@
1
- require 'base64'
2
-
3
- module Faraday
4
- class Request::BasicAuthentication < Request.load_middleware(:authorization)
5
- # Public
6
- def self.header(login, pass)
7
- value = Base64.encode64([login, pass].join(':'))
8
- value.gsub!("\n", '')
9
- super(:Basic, value)
10
- end
11
- end
12
- end
13
-
@@ -1,68 +0,0 @@
1
- require File.expand_path("../url_encoded", __FILE__)
2
- require 'securerandom'
3
-
4
- module Faraday
5
- class Request::Multipart < Request::UrlEncoded
6
- self.mime_type = 'multipart/form-data'.freeze
7
- DEFAULT_BOUNDARY_PREFIX = "-----------RubyMultipartPost".freeze unless defined? DEFAULT_BOUNDARY_PREFIX
8
-
9
- def call(env)
10
- match_content_type(env) do |params|
11
- env.request.boundary ||= unique_boundary
12
- env.request_headers[CONTENT_TYPE] += "; boundary=#{env.request.boundary}"
13
- env.body = create_multipart(env, params)
14
- end
15
- @app.call env
16
- end
17
-
18
- def process_request?(env)
19
- type = request_type(env)
20
- env.body.respond_to?(:each_key) and !env.body.empty? and (
21
- (type.empty? and has_multipart?(env.body)) or
22
- type == self.class.mime_type
23
- )
24
- end
25
-
26
- def has_multipart?(obj)
27
- # string is an enum in 1.8, returning list of itself
28
- if obj.respond_to?(:each) && !obj.is_a?(String)
29
- (obj.respond_to?(:values) ? obj.values : obj).each do |val|
30
- return true if (val.respond_to?(:content_type) || has_multipart?(val))
31
- end
32
- end
33
- false
34
- end
35
-
36
- def create_multipart(env, params)
37
- boundary = env.request.boundary
38
- parts = process_params(params) do |key, value|
39
- Faraday::Parts::Part.new(boundary, key, value)
40
- end
41
- parts << Faraday::Parts::EpiloguePart.new(boundary)
42
-
43
- body = Faraday::CompositeReadIO.new(parts)
44
- env.request_headers[Faraday::Env::ContentLength] = body.length.to_s
45
- return body
46
- end
47
-
48
- def unique_boundary
49
- "#{DEFAULT_BOUNDARY_PREFIX}-#{SecureRandom.hex}"
50
- end
51
-
52
- def process_params(params, prefix = nil, pieces = nil, &block)
53
- params.inject(pieces || []) do |all, (key, value)|
54
- key = "#{prefix}[#{key}]" if prefix
55
-
56
- case value
57
- when Array
58
- values = value.inject([]) { |a,v| a << [nil, v] }
59
- process_params(values, key, all, &block)
60
- when Hash
61
- process_params(value, key, all, &block)
62
- else
63
- all << block.call(key, value)
64
- end
65
- end
66
- end
67
- end
68
- end
@@ -1,213 +0,0 @@
1
- require 'date'
2
-
3
- module Faraday
4
- # Catches exceptions and retries each request a limited number of times.
5
- #
6
- # By default, it retries 2 times and handles only timeout exceptions. It can
7
- # be configured with an arbitrary number of retries, a list of exceptions to
8
- # handle, a retry interval, a percentage of randomness to add to the retry
9
- # interval, and a backoff factor.
10
- #
11
- # Examples
12
- #
13
- # Faraday.new do |conn|
14
- # conn.request :retry, max: 2, interval: 0.05,
15
- # interval_randomness: 0.5, backoff_factor: 2,
16
- # exceptions: [CustomException, 'Timeout::Error']
17
- # conn.adapter ...
18
- # end
19
- #
20
- # This example will result in a first interval that is random between 0.05 and 0.075 and a second
21
- # interval that is random between 0.1 and 0.15
22
- #
23
- class Request::Retry < Faraday::Middleware
24
- DEFAULT_EXCEPTIONS = [Errno::ETIMEDOUT, 'Timeout::Error',
25
- Faraday::TimeoutError, Faraday::RetriableResponse
26
- ].freeze
27
- IDEMPOTENT_METHODS = [:delete, :get, :head, :options, :put]
28
-
29
- class Options < Faraday::Options.new(:max, :interval, :max_interval, :interval_randomness,
30
- :backoff_factor, :exceptions, :methods, :retry_if, :retry_block,
31
- :retry_statuses)
32
-
33
- DEFAULT_CHECK = lambda { |env,exception| false }
34
-
35
- def self.from(value)
36
- if Integer === value
37
- new(value)
38
- else
39
- super(value)
40
- end
41
- end
42
-
43
- def max
44
- (self[:max] ||= 2).to_i
45
- end
46
-
47
- def interval
48
- (self[:interval] ||= 0).to_f
49
- end
50
-
51
- def max_interval
52
- (self[:max_interval] ||= Float::MAX).to_f
53
- end
54
-
55
- def interval_randomness
56
- (self[:interval_randomness] ||= 0).to_f
57
- end
58
-
59
- def backoff_factor
60
- (self[:backoff_factor] ||= 1).to_f
61
- end
62
-
63
- def exceptions
64
- Array(self[:exceptions] ||= DEFAULT_EXCEPTIONS)
65
- end
66
-
67
- def methods
68
- Array(self[:methods] ||= IDEMPOTENT_METHODS)
69
- end
70
-
71
- def retry_if
72
- self[:retry_if] ||= DEFAULT_CHECK
73
- end
74
-
75
- def retry_block
76
- self[:retry_block] ||= Proc.new {}
77
- end
78
-
79
- def retry_statuses
80
- Array(self[:retry_statuses] ||= [])
81
- end
82
- end
83
-
84
- # Public: Initialize middleware
85
- #
86
- # Options:
87
- # max - Maximum number of retries (default: 2)
88
- # interval - Pause in seconds between retries (default: 0)
89
- # interval_randomness - The maximum random interval amount expressed
90
- # as a float between 0 and 1 to use in addition to the
91
- # interval. (default: 0)
92
- # max_interval - An upper limit for the interval (default: Float::MAX)
93
- # backoff_factor - The amount to multiple each successive retry's
94
- # interval amount by in order to provide backoff
95
- # (default: 1)
96
- # exceptions - The list of exceptions to handle. Exceptions can be
97
- # given as Class, Module, or String. (default:
98
- # [Errno::ETIMEDOUT, 'Timeout::Error',
99
- # Faraday::TimeoutError, Faraday::RetriableResponse])
100
- # methods - A list of HTTP methods to retry without calling retry_if. Pass
101
- # an empty Array to call retry_if for all exceptions.
102
- # (defaults to the idempotent HTTP methods in IDEMPOTENT_METHODS)
103
- # retry_if - block that will receive the env object and the exception raised
104
- # and should decide if the code should retry still the action or
105
- # not independent of the retry count. This would be useful
106
- # if the exception produced is non-recoverable or if the
107
- # the HTTP method called is not idempotent.
108
- # (defaults to return false)
109
- # retry_block - block that is executed after every retry. Request environment, middleware options,
110
- # current number of retries and the exception is passed to the block as parameters.
111
- def initialize(app, options = nil)
112
- super(app)
113
- @options = Options.from(options)
114
- @errmatch = build_exception_matcher(@options.exceptions)
115
- end
116
-
117
- def calculate_sleep_amount(retries, env)
118
- retry_after = calculate_retry_after(env)
119
- retry_interval = calculate_retry_interval(retries)
120
-
121
- return if retry_after && retry_after > @options.max_interval
122
-
123
- retry_after && retry_after >= retry_interval ? retry_after : retry_interval
124
- end
125
-
126
- def call(env)
127
- retries = @options.max
128
- request_body = env[:body]
129
- begin
130
- env[:body] = request_body # after failure env[:body] is set to the response body
131
- @app.call(env).tap do |resp|
132
- raise Faraday::RetriableResponse.new(nil, resp) if @options.retry_statuses.include?(resp.status)
133
- end
134
- rescue @errmatch => exception
135
- if retries > 0 && retry_request?(env, exception)
136
- retries -= 1
137
- rewind_files(request_body)
138
- @options.retry_block.call(env, @options, retries, exception)
139
- if (sleep_amount = calculate_sleep_amount(retries + 1, env))
140
- sleep sleep_amount
141
- retry
142
- end
143
- end
144
-
145
- if exception.is_a?(Faraday::RetriableResponse)
146
- exception.response
147
- else
148
- raise
149
- end
150
- end
151
- end
152
-
153
- # Private: construct an exception matcher object.
154
- #
155
- # An exception matcher for the rescue clause can usually be any object that
156
- # responds to `===`, but for Ruby 1.8 it has to be a Class or Module.
157
- def build_exception_matcher(exceptions)
158
- matcher = Module.new
159
- (class << matcher; self; end).class_eval do
160
- define_method(:===) do |error|
161
- exceptions.any? do |ex|
162
- if ex.is_a? Module
163
- error.is_a? ex
164
- else
165
- error.class.to_s == ex.to_s
166
- end
167
- end
168
- end
169
- end
170
- matcher
171
- end
172
-
173
- private
174
-
175
- def retry_request?(env, exception)
176
- @options.methods.include?(env[:method]) || @options.retry_if.call(env, exception)
177
- end
178
-
179
- def rewind_files(body)
180
- return unless body.is_a?(Hash)
181
- body.each do |_, value|
182
- if value.is_a? UploadIO
183
- value.rewind
184
- end
185
- end
186
- end
187
-
188
- # MDN spec for Retry-After header: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After
189
- def calculate_retry_after(env)
190
- response_headers = env[:response_headers]
191
- return unless response_headers
192
-
193
- retry_after_value = env[:response_headers]["Retry-After"]
194
-
195
- # Try to parse date from the header value
196
- begin
197
- datetime = DateTime.rfc2822(retry_after_value)
198
- datetime.to_time - Time.now.utc
199
- rescue ArgumentError
200
- retry_after_value.to_f
201
- end
202
- end
203
-
204
- def calculate_retry_interval(retries)
205
- retry_index = @options.max - retries
206
- current_interval = @options.interval * (@options.backoff_factor ** retry_index)
207
- current_interval = [current_interval, @options.max_interval].min
208
- random_interval = rand * @options.interval_randomness.to_f * @options.interval
209
-
210
- current_interval + random_interval
211
- end
212
- end
213
- end
@@ -1,15 +0,0 @@
1
- module Faraday
2
- class Request::TokenAuthentication < Request.load_middleware(:authorization)
3
- # Public
4
- def self.header(token, options = nil)
5
- options ||= {}
6
- options[:token] = token
7
- super(:Token, options)
8
- end
9
-
10
- def initialize(app, token, options = nil)
11
- super(app, token, options)
12
- end
13
- end
14
- end
15
-
@@ -1,67 +0,0 @@
1
- begin
2
- require 'composite_io'
3
- require 'parts'
4
- require 'stringio'
5
- rescue LoadError
6
- $stderr.puts "Install the multipart-post gem."
7
- raise
8
- end
9
-
10
- module Faraday
11
- # Similar but not compatible with ::CompositeReadIO provided by multipart-post.
12
- class CompositeReadIO
13
- def initialize(*parts)
14
- @parts = parts.flatten
15
- @ios = @parts.map { |part| part.to_io }
16
- @index = 0
17
- end
18
-
19
- def length
20
- @parts.inject(0) { |sum, part| sum + part.length }
21
- end
22
-
23
- def rewind
24
- @ios.each { |io| io.rewind }
25
- @index = 0
26
- end
27
-
28
- # Read from IOs in order until `length` bytes have been received.
29
- def read(length = nil, outbuf = nil)
30
- got_result = false
31
- outbuf = outbuf ? outbuf.replace("") : ""
32
-
33
- while io = current_io
34
- if result = io.read(length)
35
- got_result ||= !result.nil?
36
- result.force_encoding("BINARY") if result.respond_to?(:force_encoding)
37
- outbuf << result
38
- length -= result.length if length
39
- break if length == 0
40
- end
41
- advance_io
42
- end
43
- (!got_result && length) ? nil : outbuf
44
- end
45
-
46
- def close
47
- @ios.each { |io| io.close }
48
- end
49
-
50
- def ensure_open_and_readable
51
- # Rubinius compatibility
52
- end
53
-
54
- private
55
-
56
- def current_io
57
- @ios[@index]
58
- end
59
-
60
- def advance_io
61
- @index += 1
62
- end
63
- end
64
-
65
- UploadIO = ::UploadIO
66
- Parts = ::Parts
67
- 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
@@ -1,14 +0,0 @@
1
- require File.expand_path('../integration', __FILE__)
2
-
3
- module Adapters
4
- class DefaultTest < Faraday::TestCase
5
-
6
- def adapter() :default end
7
-
8
- Integration.apply(self, :NonParallel) do
9
- # default stack is not configured with Multipart
10
- undef :test_POST_sends_files
11
- end
12
-
13
- end
14
- end
@@ -1,30 +0,0 @@
1
- require File.expand_path('../integration', __FILE__)
2
-
3
- module Adapters
4
- class EMHttpTest < Faraday::TestCase
5
-
6
- def adapter() :em_http end
7
-
8
- Integration.apply(self, :Parallel) do
9
- # https://github.com/eventmachine/eventmachine/pull/289
10
- undef :test_timeout
11
-
12
- def test_binds_local_socket
13
- host = '1.2.3.4'
14
- conn = create_connection :request => { :bind => { :host => host } }
15
- assert_equal host, conn.options[:bind][:host]
16
- end
17
- end unless jruby? and ssl_mode?
18
- # https://github.com/eventmachine/eventmachine/issues/180
19
-
20
- def test_custom_adapter_config
21
- url = URI('https://example.com:1234')
22
-
23
- adapter = Faraday::Adapter::EMHttp.new nil, inactivity_timeout: 20
24
-
25
- req = adapter.create_request(url: url, request: {})
26
-
27
- assert_equal 20, req.connopts.inactivity_timeout
28
- end
29
- end
30
- end
@@ -1,32 +0,0 @@
1
- require File.expand_path('../integration', __FILE__)
2
-
3
- module Adapters
4
- class EMSynchronyTest < Faraday::TestCase
5
-
6
- def adapter() :em_synchrony end
7
-
8
- unless jruby?
9
- Integration.apply(self, :Parallel) do
10
- # https://github.com/eventmachine/eventmachine/pull/289
11
- undef :test_timeout
12
-
13
- def test_binds_local_socket
14
- host = '1.2.3.4'
15
- conn = create_connection :request => { :bind => { :host => host } }
16
- #put conn.get('/who-am-i').body
17
- assert_equal host, conn.options[:bind][:host]
18
- end
19
- end
20
- end
21
-
22
- def test_custom_adapter_config
23
- url = URI('https://example.com:1234')
24
-
25
- adapter = Faraday::Adapter::EMSynchrony.new nil, inactivity_timeout: 20
26
-
27
- req = adapter.create_request(url: url, request: {})
28
-
29
- assert_equal 20, req.connopts.inactivity_timeout
30
- end
31
- end
32
- end
@@ -1,30 +0,0 @@
1
- require File.expand_path('../integration', __FILE__)
2
-
3
- module Adapters
4
- class ExconTest < Faraday::TestCase
5
-
6
- def adapter() :excon end
7
-
8
- Integration.apply(self, :NonParallel) do
9
- # https://github.com/geemus/excon/issues/126 ?
10
- undef :test_timeout if ssl_mode?
11
-
12
- # Excon lets OpenSSL::SSL::SSLError be raised without any way to
13
- # distinguish whether it happened because of a 407 proxy response
14
- undef :test_proxy_auth_fail if ssl_mode?
15
-
16
- # https://github.com/geemus/excon/issues/358
17
- undef :test_connection_error if RUBY_VERSION >= '2.1.0'
18
- end
19
-
20
- def test_custom_adapter_config
21
- url = URI('https://example.com:1234')
22
-
23
- adapter = Faraday::Adapter::Excon.new nil, debug_request: true
24
-
25
- conn = adapter.create_connection({url: url}, {})
26
-
27
- assert_equal true, conn.data[:debug_request]
28
- end
29
- end
30
- end
@@ -1,34 +0,0 @@
1
- require File.expand_path('../integration', __FILE__)
2
-
3
- module Adapters
4
- class HttpclientTest < Faraday::TestCase
5
-
6
- def adapter() :httpclient end
7
-
8
- Integration.apply(self, :NonParallel, :Compression) do
9
- def setup
10
- require 'httpclient' unless defined?(HTTPClient)
11
- HTTPClient::NO_PROXY_HOSTS.delete('localhost')
12
- end
13
-
14
- def test_binds_local_socket
15
- host = '1.2.3.4'
16
- conn = create_connection :request => { :bind => { :host => host } }
17
- assert_equal host, conn.options[:bind][:host]
18
- end
19
-
20
- def test_custom_adapter_config
21
- adapter = Faraday::Adapter::HTTPClient.new do |client|
22
- client.keep_alive_timeout = 20
23
- client.ssl_config.timeout = 25
24
- end
25
-
26
- client = adapter.client
27
- adapter.configure_client
28
-
29
- assert_equal 20, client.keep_alive_timeout
30
- assert_equal 25, client.ssl_config.timeout
31
- end
32
- end
33
- end
34
- end