webmock 3.17.1 → 3.18.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e4cbe1f0f2f191bea7fda094073e265aeff44e1669d1222da5cb724e5124eb55
4
- data.tar.gz: e631266b6f082b93800e815a9dc0aa071a60a89c1f803bf3eee739e6b97820a2
3
+ metadata.gz: 3a7e964f28dd42787fd854c5fcc87dba4cd61ef214c3dee485d9bd0d71fc1cdd
4
+ data.tar.gz: f6921a9b14ccd71f18b4674aca8d4d24bf377545a4ef8c56862f95cc56b6e8a7
5
5
  SHA512:
6
- metadata.gz: 4911f51bd82520812df827796996ab8cf9975f1bee625a158f4644f8c121bbf34172266cd3097ef0609750d51d0c987ea7a645df077f936924f2ea0915f1c0a1
7
- data.tar.gz: bc053c6d94f668d75c1e97629dd9ba38f018ffb2355f5cd97e1f5e54015f6adf02c6f9cac2abf6b5c13d7d4fcd69d1bae77b45cffa2b2b8488fa4d0a1c53e1b3
6
+ metadata.gz: 80e85d1bb83018bdaab80aed649134757ee8ac591b98e9ccf1b6df10c0d8930db167dd5fd3bb039dd56a955d22c0cc6b1a1227bb88e8f3e56d31d0e1c9d7708e
7
+ data.tar.gz: c67f1f8486d6ee932bd9d01dff2bfcec35d9c3e3ed937e50e1f56d34f664ca11db4c9399c51e82da9316245c1d4727c726b9e307646aef80477764609ecf95ee
data/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ # 3.18.1
4
+
5
+ * Reverted simplified connection handing in Net::HTTP adapter due to https://github.com/bblimke/webmock/issues/999
6
+
7
+ # 3.18.0
8
+
9
+ * Net::BufferedIO is not replaced anymore.
10
+
11
+ Thanks to [Ray Zane](https://github.com/rzane)
12
+
13
+ * Simplified connection handing in Net::HTTP adapter.
14
+
15
+ Thanks to [Ray Zane](https://github.com/rzane)
16
+
3
17
  # 3.17.1
4
18
 
5
19
  * Fixed Syntax Error
@@ -30,7 +44,11 @@
30
44
 
31
45
  Thanks to [Cedric Sohrauer](https://github.com/cedrics)
32
46
 
33
- # 3.16.0
47
+ # 3.16.2
48
+
49
+ * Minimum required Ruby version is 2.0.
50
+
51
+ # 3.16.0 (yanked)
34
52
 
35
53
  * Fix leaky file descriptors and reuse socket for persistent connections.
36
54
 
@@ -40,7 +58,11 @@
40
58
 
41
59
  Thanks to [Ray Zane](https://github.com/rzane)
42
60
 
43
- # 3.15.0
61
+ # 3.15.2
62
+
63
+ * Minimum required Ruby version is 2.0.
64
+
65
+ # 3.15.0 (yanked)
44
66
 
45
67
  * fixed async-http adapter on Windows
46
68
 
data/README.md CHANGED
@@ -1176,7 +1176,7 @@ For a full list of contributors you can visit the
1176
1176
 
1177
1177
  ## Background
1178
1178
 
1179
- Thank you Fakeweb! This library was inspired by [FakeWeb](http://fakeweb.rubyforge.org).
1179
+ Thank you Fakeweb! This library was inspired by [FakeWeb](https://github.com/chrisk/fakeweb).
1180
1180
  I imported some solutions from that project to WebMock. I also copied some code i.e Net:HTTP adapter.
1181
1181
  Fakeweb architecture unfortunately didn't allow me to extend it easily with the features I needed.
1182
1182
  I also preferred some things to work differently i.e request stub precedence.
@@ -10,24 +10,19 @@ module WebMock
10
10
  adapter_for :net_http
11
11
 
12
12
  OriginalNetHTTP = Net::HTTP unless const_defined?(:OriginalNetHTTP)
13
- OriginalNetBufferedIO = Net::BufferedIO unless const_defined?(:OriginalNetBufferedIO)
14
13
 
15
14
  def self.enable!
16
- Net.send(:remove_const, :BufferedIO)
17
15
  Net.send(:remove_const, :HTTP)
18
16
  Net.send(:remove_const, :HTTPSession)
19
17
  Net.send(:const_set, :HTTP, @webMockNetHTTP)
20
18
  Net.send(:const_set, :HTTPSession, @webMockNetHTTP)
21
- Net.send(:const_set, :BufferedIO, Net::WebMockNetBufferedIO)
22
19
  end
23
20
 
24
21
  def self.disable!
25
- Net.send(:remove_const, :BufferedIO)
26
22
  Net.send(:remove_const, :HTTP)
27
23
  Net.send(:remove_const, :HTTPSession)
28
24
  Net.send(:const_set, :HTTP, OriginalNetHTTP)
29
25
  Net.send(:const_set, :HTTPSession, OriginalNetHTTP)
30
- Net.send(:const_set, :BufferedIO, OriginalNetBufferedIO)
31
26
 
32
27
  #copy all constants from @webMockNetHTTP to original Net::HTTP
33
28
  #in case any constants were added to @webMockNetHTTP instead of Net::HTTP
@@ -208,19 +203,6 @@ module WebMock
208
203
  end
209
204
  end
210
205
 
211
- # patch for StringIO behavior in Ruby 2.2.3
212
- # https://github.com/bblimke/webmock/issues/558
213
- class PatchedStringIO < StringIO #:nodoc:
214
-
215
- alias_method :orig_read_nonblock, :read_nonblock
216
-
217
- def read_nonblock(size, *args, **kwargs)
218
- args.reject! {|arg| !arg.is_a?(Hash)}
219
- orig_read_nonblock(size, *args, **kwargs)
220
- end
221
-
222
- end
223
-
224
206
  class StubSocket #:nodoc:
225
207
 
226
208
  attr_accessor :read_timeout, :continue_timeout, :write_timeout
@@ -254,54 +236,6 @@ class StubSocket #:nodoc:
254
236
  end
255
237
  end
256
238
 
257
- module Net #:nodoc: all
258
-
259
- class WebMockNetBufferedIO < BufferedIO
260
- def initialize(io, *args, **kwargs)
261
- io = case io
262
- when Socket, OpenSSL::SSL::SSLSocket, IO
263
- io
264
- when StringIO
265
- PatchedStringIO.new(io.string)
266
- when String
267
- PatchedStringIO.new(io)
268
- end
269
- raise "Unable to create local socket" unless io
270
-
271
- # Prior to 2.4.0 `BufferedIO` only takes a single argument (`io`) with no
272
- # options. Here we pass through our full set of arguments only if we're
273
- # on 2.4.0 or later, and use a simplified invocation otherwise.
274
- if RUBY_VERSION >= '2.4.0'
275
- super
276
- else
277
- super(io)
278
- end
279
- end
280
-
281
- if RUBY_VERSION >= '2.6.0'
282
- # https://github.com/ruby/ruby/blob/7d02441f0d6e5c9d0a73a024519eba4f69e36dce/lib/net/protocol.rb#L208
283
- # Modified version of method from ruby, so that nil is always passed into orig_read_nonblock to avoid timeout
284
- def rbuf_fill
285
- case rv = @io.read_nonblock(BUFSIZE, nil, exception: false)
286
- when String
287
- return if rv.nil?
288
- @rbuf << rv
289
- rv.clear
290
- return
291
- when :wait_readable
292
- @io.to_io.wait_readable(@read_timeout) or raise Net::ReadTimeout
293
- when :wait_writable
294
- @io.to_io.wait_writable(@read_timeout) or raise Net::ReadTimeout
295
- when nil
296
- raise EOFError, 'end of file reached'
297
- end while true
298
- end
299
- end
300
- end
301
-
302
- end
303
-
304
-
305
239
  module WebMock
306
240
  module NetHTTPUtility
307
241
 
@@ -14,8 +14,11 @@ module WebMock
14
14
 
15
15
  class Response
16
16
  def initialize(options = {})
17
- if options.is_a?(IO) || options.is_a?(String)
17
+ case options
18
+ when IO, StringIO
18
19
  self.options = read_raw_response(options)
20
+ when String
21
+ self.options = read_raw_response(StringIO.new(options))
19
22
  else
20
23
  self.options = options
21
24
  end
@@ -120,13 +123,8 @@ module WebMock
120
123
  end
121
124
  end
122
125
 
123
- def read_raw_response(raw_response)
124
- if raw_response.is_a?(IO)
125
- string = raw_response.read
126
- raw_response.close
127
- raw_response = string
128
- end
129
- socket = ::Net::BufferedIO.new(raw_response)
126
+ def read_raw_response(io)
127
+ socket = ::Net::BufferedIO.new(io)
130
128
  response = ::Net::HTTPResponse.read_new(socket)
131
129
  transfer_encoding = response.delete('transfer-encoding') #chunks were already read by curl
132
130
  response.reading_body(socket, true) {}
@@ -138,6 +136,8 @@ module WebMock
138
136
  options[:body] = response.read_body
139
137
  options[:status] = [response.code.to_i, response.message]
140
138
  options
139
+ ensure
140
+ socket.close
141
141
  end
142
142
 
143
143
  InvalidBody = Class.new(StandardError)
@@ -1,3 +1,3 @@
1
1
  module WebMock
2
- VERSION = '3.17.1' unless defined?(::WebMock::VERSION)
2
+ VERSION = '3.18.1' unless defined?(::WebMock::VERSION)
3
3
  end
@@ -142,6 +142,34 @@ describe WebMock::Response do
142
142
  end
143
143
 
144
144
  describe "from raw response" do
145
+ describe "when input is a StringIO" do
146
+ before(:each) do
147
+ @io = StringIO.new(File.read(CURL_EXAMPLE_OUTPUT_PATH))
148
+ @response = WebMock::Response.new(@io)
149
+ end
150
+
151
+ it "should read status" do
152
+ expect(@response.status).to eq([202, "OK"])
153
+ end
154
+
155
+ it "should read headers" do
156
+ expect(@response.headers).to eq(
157
+ "Date"=>"Sat, 23 Jan 2010 01:01:05 GMT",
158
+ "Content-Type"=>"text/html; charset=UTF-8",
159
+ "Content-Length"=>"419",
160
+ "Connection"=>"Keep-Alive",
161
+ "Accept"=>"image/jpeg, image/png"
162
+ )
163
+ end
164
+
165
+ it "should read body" do
166
+ expect(@response.body.size).to eq(419)
167
+ end
168
+
169
+ it "should close IO" do
170
+ expect(@io).to be_closed
171
+ end
172
+ end
145
173
 
146
174
  describe "when input is IO" do
147
175
  before(:each) do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webmock
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.17.1
4
+ version: 3.18.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bartosz Blimke
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-08-09 00:00:00.000000000 Z
11
+ date: 2022-08-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -421,9 +421,9 @@ licenses:
421
421
  - MIT
422
422
  metadata:
423
423
  bug_tracker_uri: https://github.com/bblimke/webmock/issues
424
- changelog_uri: https://github.com/bblimke/webmock/blob/v3.17.1/CHANGELOG.md
425
- documentation_uri: https://www.rubydoc.info/gems/webmock/3.17.1
426
- source_code_uri: https://github.com/bblimke/webmock/tree/v3.17.1
424
+ changelog_uri: https://github.com/bblimke/webmock/blob/v3.18.1/CHANGELOG.md
425
+ documentation_uri: https://www.rubydoc.info/gems/webmock/3.18.1
426
+ source_code_uri: https://github.com/bblimke/webmock/tree/v3.18.1
427
427
  wiki_uri: https://github.com/bblimke/webmock/wiki
428
428
  post_install_message:
429
429
  rdoc_options: []