faraday 0.17.3 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (133) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +52 -8
  3. data/LICENSE.md +1 -1
  4. data/README.md +18 -358
  5. data/Rakefile +1 -7
  6. data/examples/client_spec.rb +65 -0
  7. data/examples/client_test.rb +79 -0
  8. data/lib/faraday.rb +94 -175
  9. data/lib/faraday/adapter.rb +82 -22
  10. data/lib/faraday/adapter/em_http.rb +142 -99
  11. data/lib/faraday/adapter/em_http_ssl_patch.rb +24 -18
  12. data/lib/faraday/adapter/em_synchrony.rb +104 -60
  13. data/lib/faraday/adapter/em_synchrony/parallel_manager.rb +18 -15
  14. data/lib/faraday/adapter/excon.rb +98 -56
  15. data/lib/faraday/adapter/httpclient.rb +83 -59
  16. data/lib/faraday/adapter/net_http.rb +130 -63
  17. data/lib/faraday/adapter/net_http_persistent.rb +50 -27
  18. data/lib/faraday/adapter/patron.rb +80 -43
  19. data/lib/faraday/adapter/rack.rb +30 -13
  20. data/lib/faraday/adapter/test.rb +86 -53
  21. data/lib/faraday/adapter/typhoeus.rb +4 -1
  22. data/lib/faraday/adapter_registry.rb +30 -0
  23. data/lib/faraday/autoload.rb +47 -36
  24. data/lib/faraday/connection.rb +312 -182
  25. data/lib/faraday/dependency_loader.rb +37 -0
  26. data/lib/faraday/encoders/flat_params_encoder.rb +98 -0
  27. data/lib/faraday/encoders/nested_params_encoder.rb +171 -0
  28. data/lib/faraday/error.rb +9 -35
  29. data/lib/faraday/file_part.rb +128 -0
  30. data/lib/faraday/logging/formatter.rb +105 -0
  31. data/lib/faraday/middleware.rb +12 -28
  32. data/lib/faraday/middleware_registry.rb +129 -0
  33. data/lib/faraday/options.rb +32 -183
  34. data/lib/faraday/options/connection_options.rb +22 -0
  35. data/lib/faraday/options/env.rb +181 -0
  36. data/lib/faraday/options/proxy_options.rb +28 -0
  37. data/lib/faraday/options/request_options.rb +22 -0
  38. data/lib/faraday/options/ssl_options.rb +59 -0
  39. data/lib/faraday/param_part.rb +53 -0
  40. data/lib/faraday/parameters.rb +4 -197
  41. data/lib/faraday/rack_builder.rb +66 -55
  42. data/lib/faraday/request.rb +68 -36
  43. data/lib/faraday/request/authorization.rb +44 -30
  44. data/lib/faraday/request/basic_authentication.rb +14 -7
  45. data/lib/faraday/request/instrumentation.rb +45 -27
  46. data/lib/faraday/request/multipart.rb +79 -48
  47. data/lib/faraday/request/retry.rb +197 -171
  48. data/lib/faraday/request/token_authentication.rb +15 -10
  49. data/lib/faraday/request/url_encoded.rb +43 -23
  50. data/lib/faraday/response.rb +24 -14
  51. data/lib/faraday/response/logger.rb +22 -69
  52. data/lib/faraday/response/raise_error.rb +38 -18
  53. data/lib/faraday/utils.rb +36 -245
  54. data/lib/faraday/utils/headers.rb +139 -0
  55. data/lib/faraday/utils/params_hash.rb +61 -0
  56. data/spec/external_adapters/faraday_specs_setup.rb +14 -0
  57. data/spec/faraday/adapter/em_http_spec.rb +47 -0
  58. data/spec/faraday/adapter/em_synchrony_spec.rb +16 -0
  59. data/spec/faraday/adapter/excon_spec.rb +49 -0
  60. data/spec/faraday/adapter/httpclient_spec.rb +73 -0
  61. data/spec/faraday/adapter/net_http_persistent_spec.rb +57 -0
  62. data/spec/faraday/adapter/net_http_spec.rb +64 -0
  63. data/spec/faraday/adapter/patron_spec.rb +18 -0
  64. data/spec/faraday/adapter/rack_spec.rb +8 -0
  65. data/spec/faraday/adapter/typhoeus_spec.rb +7 -0
  66. data/spec/faraday/adapter_registry_spec.rb +28 -0
  67. data/spec/faraday/adapter_spec.rb +55 -0
  68. data/spec/faraday/composite_read_io_spec.rb +80 -0
  69. data/spec/faraday/connection_spec.rb +691 -0
  70. data/spec/faraday/error_spec.rb +0 -57
  71. data/spec/faraday/middleware_spec.rb +26 -0
  72. data/spec/faraday/options/env_spec.rb +70 -0
  73. data/spec/faraday/options/options_spec.rb +297 -0
  74. data/spec/faraday/options/proxy_options_spec.rb +37 -0
  75. data/spec/faraday/options/request_options_spec.rb +19 -0
  76. data/spec/faraday/params_encoders/flat_spec.rb +34 -0
  77. data/spec/faraday/params_encoders/nested_spec.rb +134 -0
  78. data/spec/faraday/rack_builder_spec.rb +196 -0
  79. data/spec/faraday/request/authorization_spec.rb +88 -0
  80. data/spec/faraday/request/instrumentation_spec.rb +76 -0
  81. data/spec/faraday/request/multipart_spec.rb +274 -0
  82. data/spec/faraday/request/retry_spec.rb +242 -0
  83. data/spec/faraday/request/url_encoded_spec.rb +83 -0
  84. data/spec/faraday/request_spec.rb +109 -0
  85. data/spec/faraday/response/logger_spec.rb +220 -0
  86. data/spec/faraday/response/middleware_spec.rb +68 -0
  87. data/spec/faraday/response/raise_error_spec.rb +15 -15
  88. data/spec/faraday/response_spec.rb +75 -0
  89. data/spec/faraday/utils/headers_spec.rb +82 -0
  90. data/spec/faraday/utils_spec.rb +56 -0
  91. data/spec/faraday_spec.rb +37 -0
  92. data/spec/spec_helper.rb +63 -36
  93. data/spec/support/disabling_stub.rb +14 -0
  94. data/spec/support/fake_safe_buffer.rb +15 -0
  95. data/spec/support/helper_methods.rb +133 -0
  96. data/spec/support/shared_examples/adapter.rb +104 -0
  97. data/spec/support/shared_examples/params_encoder.rb +18 -0
  98. data/spec/support/shared_examples/request_method.rb +234 -0
  99. data/spec/support/streaming_response_checker.rb +35 -0
  100. data/spec/support/webmock_rack_app.rb +68 -0
  101. metadata +66 -38
  102. data/lib/faraday/deprecate.rb +0 -107
  103. data/lib/faraday/upload_io.rb +0 -67
  104. data/spec/faraday/deprecate_spec.rb +0 -69
  105. data/test/adapters/default_test.rb +0 -14
  106. data/test/adapters/em_http_test.rb +0 -30
  107. data/test/adapters/em_synchrony_test.rb +0 -32
  108. data/test/adapters/excon_test.rb +0 -30
  109. data/test/adapters/httpclient_test.rb +0 -34
  110. data/test/adapters/integration.rb +0 -263
  111. data/test/adapters/logger_test.rb +0 -136
  112. data/test/adapters/net_http_persistent_test.rb +0 -114
  113. data/test/adapters/net_http_test.rb +0 -79
  114. data/test/adapters/patron_test.rb +0 -40
  115. data/test/adapters/rack_test.rb +0 -38
  116. data/test/adapters/test_middleware_test.rb +0 -157
  117. data/test/adapters/typhoeus_test.rb +0 -38
  118. data/test/authentication_middleware_test.rb +0 -65
  119. data/test/composite_read_io_test.rb +0 -109
  120. data/test/connection_test.rb +0 -738
  121. data/test/env_test.rb +0 -268
  122. data/test/helper.rb +0 -75
  123. data/test/live_server.rb +0 -67
  124. data/test/middleware/instrumentation_test.rb +0 -88
  125. data/test/middleware/retry_test.rb +0 -282
  126. data/test/middleware_stack_test.rb +0 -260
  127. data/test/multibyte.txt +0 -1
  128. data/test/options_test.rb +0 -333
  129. data/test/parameters_test.rb +0 -157
  130. data/test/request_middleware_test.rb +0 -126
  131. data/test/response_middleware_test.rb +0 -72
  132. data/test/strawberry.rb +0 -2
  133. data/test/utils_test.rb +0 -98
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Faraday
4
+ module StreamingResponseChecker
5
+ def check_streaming_response(streamed, options = {})
6
+ opts = {
7
+ prefix: '',
8
+ streaming?: true
9
+ }.merge(options)
10
+
11
+ expected_response = opts[:prefix] + big_string
12
+
13
+ chunks, sizes = streamed.transpose
14
+
15
+ # Check that the total size of the chunks (via the last size returned)
16
+ # is the same size as the expected_response
17
+ expect(sizes.last).to eq(expected_response.bytesize)
18
+
19
+ start_index = 0
20
+ expected_chunks = []
21
+ chunks.each do |actual_chunk|
22
+ expected_chunk = expected_response[start_index..((start_index + actual_chunk.bytesize) - 1)]
23
+ expected_chunks << expected_chunk
24
+ start_index += expected_chunk.bytesize
25
+ end
26
+
27
+ # it's easier to read a smaller portion, so we check that first
28
+ expect(expected_chunks[0][0..255]).to eq(chunks[0][0..255])
29
+
30
+ [expected_chunks, chunks].transpose.each do |expected, actual|
31
+ expect(actual).to eq(expected)
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Rack app used to test the Rack adapter.
4
+ # Uses Webmock to check if requests are registered, in which case it returns
5
+ # the registered response.
6
+ class WebmockRackApp
7
+ def call(env)
8
+ req_signature = WebMock::RequestSignature.new(
9
+ req_method(env),
10
+ req_uri(env),
11
+ body: req_body(env),
12
+ headers: req_headers(env)
13
+ )
14
+
15
+ WebMock::RequestRegistry
16
+ .instance
17
+ .requested_signatures
18
+ .put(req_signature)
19
+
20
+ process_response(req_signature)
21
+ end
22
+
23
+ def req_method(env)
24
+ env['REQUEST_METHOD'].downcase.to_sym
25
+ end
26
+
27
+ def req_uri(env)
28
+ scheme = env['rack.url_scheme']
29
+ host = env['SERVER_NAME']
30
+ port = env['SERVER_PORT']
31
+ path = env['PATH_INFO']
32
+ query = env['QUERY_STRING']
33
+
34
+ url = +"#{scheme}://#{host}:#{port}#{path}"
35
+ url += "?#{query}" if query
36
+
37
+ uri = WebMock::Util::URI.heuristic_parse(url)
38
+ uri.path = uri.normalized_path.gsub('[^:]//', '/')
39
+ uri
40
+ end
41
+
42
+ def req_headers(env)
43
+ http_headers = env.select { |k, _| k.start_with?('HTTP_') }
44
+ .map { |k, v| [k[5..-1], v] }
45
+ .to_h
46
+
47
+ special_headers = Faraday::Adapter::Rack::SPECIAL_HEADERS
48
+ http_headers.merge(env.select { |k, _| special_headers.include?(k) })
49
+ end
50
+
51
+ def req_body(env)
52
+ env['rack.input'].read
53
+ end
54
+
55
+ def process_response(req_signature)
56
+ res = WebMock::StubRegistry.instance.response_for_request(req_signature)
57
+
58
+ if res.nil? && req_signature.uri.host == 'localhost'
59
+ raise Faraday::ConnectionFailed, 'Trying to connect to localhost'
60
+ end
61
+
62
+ raise WebMock::NetConnectNotAllowedError, req_signature unless res
63
+
64
+ raise Faraday::TimeoutError if res.should_timeout
65
+
66
+ [res.status[0], res.headers || {}, [res.body || '']]
67
+ end
68
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: faraday
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.17.3
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - "@technoweenie"
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2019-12-31 00:00:00.000000000 Z
13
+ date: 2020-03-29 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: multipart-post
@@ -42,6 +42,8 @@ files:
42
42
  - LICENSE.md
43
43
  - README.md
44
44
  - Rakefile
45
+ - examples/client_spec.rb
46
+ - examples/client_test.rb
45
47
  - lib/faraday.rb
46
48
  - lib/faraday/adapter.rb
47
49
  - lib/faraday/adapter/em_http.rb
@@ -56,12 +58,24 @@ files:
56
58
  - lib/faraday/adapter/rack.rb
57
59
  - lib/faraday/adapter/test.rb
58
60
  - lib/faraday/adapter/typhoeus.rb
61
+ - lib/faraday/adapter_registry.rb
59
62
  - lib/faraday/autoload.rb
60
63
  - lib/faraday/connection.rb
61
- - lib/faraday/deprecate.rb
64
+ - lib/faraday/dependency_loader.rb
65
+ - lib/faraday/encoders/flat_params_encoder.rb
66
+ - lib/faraday/encoders/nested_params_encoder.rb
62
67
  - lib/faraday/error.rb
68
+ - lib/faraday/file_part.rb
69
+ - lib/faraday/logging/formatter.rb
63
70
  - lib/faraday/middleware.rb
71
+ - lib/faraday/middleware_registry.rb
64
72
  - lib/faraday/options.rb
73
+ - lib/faraday/options/connection_options.rb
74
+ - lib/faraday/options/env.rb
75
+ - lib/faraday/options/proxy_options.rb
76
+ - lib/faraday/options/request_options.rb
77
+ - lib/faraday/options/ssl_options.rb
78
+ - lib/faraday/param_part.rb
65
79
  - lib/faraday/parameters.rb
66
80
  - lib/faraday/rack_builder.rb
67
81
  - lib/faraday/request.rb
@@ -75,65 +89,79 @@ files:
75
89
  - lib/faraday/response.rb
76
90
  - lib/faraday/response/logger.rb
77
91
  - lib/faraday/response/raise_error.rb
78
- - lib/faraday/upload_io.rb
79
92
  - lib/faraday/utils.rb
80
- - spec/faraday/deprecate_spec.rb
93
+ - lib/faraday/utils/headers.rb
94
+ - lib/faraday/utils/params_hash.rb
95
+ - spec/external_adapters/faraday_specs_setup.rb
96
+ - spec/faraday/adapter/em_http_spec.rb
97
+ - spec/faraday/adapter/em_synchrony_spec.rb
98
+ - spec/faraday/adapter/excon_spec.rb
99
+ - spec/faraday/adapter/httpclient_spec.rb
100
+ - spec/faraday/adapter/net_http_persistent_spec.rb
101
+ - spec/faraday/adapter/net_http_spec.rb
102
+ - spec/faraday/adapter/patron_spec.rb
103
+ - spec/faraday/adapter/rack_spec.rb
104
+ - spec/faraday/adapter/typhoeus_spec.rb
105
+ - spec/faraday/adapter_registry_spec.rb
106
+ - spec/faraday/adapter_spec.rb
107
+ - spec/faraday/composite_read_io_spec.rb
108
+ - spec/faraday/connection_spec.rb
81
109
  - spec/faraday/error_spec.rb
110
+ - spec/faraday/middleware_spec.rb
111
+ - spec/faraday/options/env_spec.rb
112
+ - spec/faraday/options/options_spec.rb
113
+ - spec/faraday/options/proxy_options_spec.rb
114
+ - spec/faraday/options/request_options_spec.rb
115
+ - spec/faraday/params_encoders/flat_spec.rb
116
+ - spec/faraday/params_encoders/nested_spec.rb
117
+ - spec/faraday/rack_builder_spec.rb
118
+ - spec/faraday/request/authorization_spec.rb
119
+ - spec/faraday/request/instrumentation_spec.rb
120
+ - spec/faraday/request/multipart_spec.rb
121
+ - spec/faraday/request/retry_spec.rb
122
+ - spec/faraday/request/url_encoded_spec.rb
123
+ - spec/faraday/request_spec.rb
124
+ - spec/faraday/response/logger_spec.rb
125
+ - spec/faraday/response/middleware_spec.rb
82
126
  - spec/faraday/response/raise_error_spec.rb
127
+ - spec/faraday/response_spec.rb
128
+ - spec/faraday/utils/headers_spec.rb
129
+ - spec/faraday/utils_spec.rb
130
+ - spec/faraday_spec.rb
83
131
  - spec/spec_helper.rb
84
- - test/adapters/default_test.rb
85
- - test/adapters/em_http_test.rb
86
- - test/adapters/em_synchrony_test.rb
87
- - test/adapters/excon_test.rb
88
- - test/adapters/httpclient_test.rb
89
- - test/adapters/integration.rb
90
- - test/adapters/logger_test.rb
91
- - test/adapters/net_http_persistent_test.rb
92
- - test/adapters/net_http_test.rb
93
- - test/adapters/patron_test.rb
94
- - test/adapters/rack_test.rb
95
- - test/adapters/test_middleware_test.rb
96
- - test/adapters/typhoeus_test.rb
97
- - test/authentication_middleware_test.rb
98
- - test/composite_read_io_test.rb
99
- - test/connection_test.rb
100
- - test/env_test.rb
101
- - test/helper.rb
102
- - test/live_server.rb
103
- - test/middleware/instrumentation_test.rb
104
- - test/middleware/retry_test.rb
105
- - test/middleware_stack_test.rb
106
- - test/multibyte.txt
107
- - test/options_test.rb
108
- - test/parameters_test.rb
109
- - test/request_middleware_test.rb
110
- - test/response_middleware_test.rb
111
- - test/strawberry.rb
112
- - test/utils_test.rb
132
+ - spec/support/disabling_stub.rb
133
+ - spec/support/fake_safe_buffer.rb
134
+ - spec/support/helper_methods.rb
135
+ - spec/support/shared_examples/adapter.rb
136
+ - spec/support/shared_examples/params_encoder.rb
137
+ - spec/support/shared_examples/request_method.rb
138
+ - spec/support/streaming_response_checker.rb
139
+ - spec/support/webmock_rack_app.rb
113
140
  homepage: https://lostisland.github.io/faraday
114
141
  licenses:
115
142
  - MIT
116
143
  metadata:
117
144
  homepage_uri: https://lostisland.github.io/faraday
118
- changelog_uri: https://github.com/lostisland/faraday/blob/master/CHANGELOG.md
119
- source_code_uri: https://github.com/lostisland/faraday/
145
+ changelog_uri: https://github.com/lostisland/faraday/releases/tag/v1.0.1
146
+ source_code_uri: https://github.com/lostisland/faraday
120
147
  bug_tracker_uri: https://github.com/lostisland/faraday/issues
121
148
  post_install_message:
122
149
  rdoc_options: []
123
150
  require_paths:
124
151
  - lib
152
+ - spec/external_adapters
125
153
  required_ruby_version: !ruby/object:Gem::Requirement
126
154
  requirements:
127
155
  - - ">="
128
156
  - !ruby/object:Gem::Version
129
- version: '1.9'
157
+ version: '2.3'
130
158
  required_rubygems_version: !ruby/object:Gem::Requirement
131
159
  requirements:
132
160
  - - ">="
133
161
  - !ruby/object:Gem::Version
134
162
  version: '0'
135
163
  requirements: []
136
- rubygems_version: 3.1.2
164
+ rubygems_version: 3.0.3
137
165
  signing_key:
138
166
  specification_version: 4
139
167
  summary: HTTP/REST API client library.
@@ -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,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