webmock 3.14.0 → 3.15.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 +4 -4
- data/.github/workflows/CI.yml +1 -0
- data/CHANGELOG.md +26 -0
- data/README.md +4 -0
- data/lib/webmock/http_lib_adapters/async_http_client_adapter.rb +6 -1
- data/lib/webmock/http_lib_adapters/curb_adapter.rb +2 -2
- data/lib/webmock/http_lib_adapters/http_rb/client.rb +1 -3
- data/lib/webmock/http_lib_adapters/http_rb/response.rb +4 -1
- data/lib/webmock/http_lib_adapters/http_rb/streamer.rb +4 -2
- data/lib/webmock/http_lib_adapters/http_rb/webmock.rb +6 -2
- data/lib/webmock/request_signature.rb +2 -2
- data/lib/webmock/request_stub.rb +15 -0
- data/lib/webmock/version.rb +1 -1
- data/minitest/webmock_spec.rb +1 -1
- data/spec/acceptance/async_http_client/async_http_client_spec.rb +5 -5
- data/spec/acceptance/curb/curb_spec.rb +11 -0
- data/spec/acceptance/em_http_request/em_http_request_spec.rb +1 -1
- data/spec/acceptance/em_http_request/em_http_request_spec_helper.rb +1 -1
- data/spec/acceptance/excon/excon_spec.rb +2 -2
- data/spec/acceptance/shared/allowing_and_disabling_net_connect.rb +14 -14
- data/spec/acceptance/shared/callbacks.rb +2 -2
- data/spec/acceptance/shared/complex_cross_concern_behaviors.rb +1 -1
- data/spec/unit/request_signature_spec.rb +21 -1
- data/spec/unit/request_stub_spec.rb +35 -0
- data/spec/unit/response_spec.rb +1 -1
- data/webmock.gemspec +3 -3
- metadata +28 -28
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 274ccdd3743ccba22fe13bf76137ced523c1b5a209c0064bed56ff8ddd90b055
|
4
|
+
data.tar.gz: 8734f4fa651f617420d5d751cb762cb3f076b3a2f24904af27b37ba2fb11e0d0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 834fc1dcf4b6f7e3ba4223574825b06a75101b64a0b42391579c6134b13c27119a1715136e3232031876f63f375c43be07bbb7bb6195cf540771bf3180871d00
|
7
|
+
data.tar.gz: 1fb420f44b1e21df023152f95628dc18e3b5dc87496974c8de5d470e25d07964170e0107fa025b75021ed8e1a10d9ef65e69d7f25bcc5d62be4e7c1123665497
|
data/.github/workflows/CI.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,31 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
# 3.15.1
|
4
|
+
|
5
|
+
* Minimum required Ruby version is 2.3
|
6
|
+
|
7
|
+
# 3.15.0
|
8
|
+
|
9
|
+
* fixed async-http adapter on Windows
|
10
|
+
|
11
|
+
Tyanks to [Pavel Rosický](https://github.com/ahorek)
|
12
|
+
|
13
|
+
* Support for http.rb >= 5.0.2
|
14
|
+
|
15
|
+
Thanks to [ojab](https://github.com/ojab)
|
16
|
+
|
17
|
+
* Curb adapter supports headers with `:` character in the header value
|
18
|
+
|
19
|
+
Thanks to [Giorgio Gambino](https://github.com/mrbuzz)
|
20
|
+
|
21
|
+
* Support for matching body of JSON or application/x-www-form-urlencoded requests with content type header including charset.
|
22
|
+
|
23
|
+
Thanks to [Timmitry](https://github.com/Timmitry)
|
24
|
+
|
25
|
+
* Prevent double-wrapping http.rb features on non-stubbed requests
|
26
|
+
|
27
|
+
Thanks to [Michael Fairley](https://github.com/michaelfairley)
|
28
|
+
|
3
29
|
# 3.14.0
|
4
30
|
|
5
31
|
* Bump Addressable from 2.3.6 to 2.8.0
|
data/README.md
CHANGED
@@ -1161,6 +1161,10 @@ People who submitted patches and new features or suggested improvements. Many th
|
|
1161
1161
|
* Alex Vondrak
|
1162
1162
|
* Will Storey
|
1163
1163
|
* Eduardo Hernandez
|
1164
|
+
* ojab
|
1165
|
+
* Giorgio Gambino
|
1166
|
+
* Timmitry
|
1167
|
+
* Michael Fairley
|
1164
1168
|
|
1165
1169
|
For a full list of contributors you can visit the
|
1166
1170
|
[contributors](https://github.com/bblimke/webmock/contributors) page.
|
@@ -151,7 +151,12 @@ if defined?(Async::HTTP)
|
|
151
151
|
private
|
152
152
|
|
153
153
|
def create_connected_sockets
|
154
|
-
|
154
|
+
pair = begin
|
155
|
+
Async::IO::Socket.pair(Socket::AF_UNIX, Socket::SOCK_STREAM)
|
156
|
+
rescue Errno::EAFNOSUPPORT
|
157
|
+
Async::IO::Socket.pair(Socket::AF_INET, Socket::SOCK_STREAM)
|
158
|
+
end
|
159
|
+
pair.tap do |sockets|
|
155
160
|
sockets.each do |socket|
|
156
161
|
socket.instance_variable_set :@alpn_protocol, nil
|
157
162
|
socket.instance_eval do
|
@@ -5,7 +5,7 @@ rescue LoadError
|
|
5
5
|
end
|
6
6
|
|
7
7
|
if defined?(Curl)
|
8
|
-
WebMock::VersionChecker.new('Curb', Curl::CURB_VERSION, '0.7.16', '0.
|
8
|
+
WebMock::VersionChecker.new('Curb', Curl::CURB_VERSION, '0.7.16', '1.0.1', ['0.8.7']).check_version!
|
9
9
|
|
10
10
|
module WebMock
|
11
11
|
module HttpLibAdapters
|
@@ -128,7 +128,7 @@ if defined?(Curl)
|
|
128
128
|
def headers_as_hash(headers)
|
129
129
|
if headers.is_a?(Array)
|
130
130
|
headers.inject({}) {|hash, header|
|
131
|
-
name, value = header.split(":").map(&:strip)
|
131
|
+
name, value = header.split(":", 2).map(&:strip)
|
132
132
|
hash[name] = value
|
133
133
|
hash
|
134
134
|
}
|
@@ -5,9 +5,7 @@ module HTTP
|
|
5
5
|
def perform(request, options)
|
6
6
|
return __perform__(request, options) unless webmock_enabled?
|
7
7
|
|
8
|
-
|
9
|
-
options.features.each { |_name, feature| response = feature.wrap_response(response) }
|
10
|
-
response
|
8
|
+
WebMockPerform.new(request, options) { __perform__(request, options) }.exec
|
11
9
|
end
|
12
10
|
|
13
11
|
def webmock_enabled?
|
@@ -24,7 +24,10 @@ module HTTP
|
|
24
24
|
elsif HTTP::VERSION < "3.0.0"
|
25
25
|
Body.new(Streamer.new(webmock_response.body), webmock_response.body.encoding)
|
26
26
|
else
|
27
|
-
Body.new(
|
27
|
+
Body.new(
|
28
|
+
Streamer.new(webmock_response.body, encoding: webmock_response.body.encoding),
|
29
|
+
encoding: webmock_response.body.encoding
|
30
|
+
)
|
28
31
|
end
|
29
32
|
|
30
33
|
return new(status, "1.1", headers, body, uri) if HTTP::VERSION < "1.0.0"
|
@@ -1,8 +1,9 @@
|
|
1
1
|
module HTTP
|
2
2
|
class Response
|
3
3
|
class Streamer
|
4
|
-
def initialize(str)
|
4
|
+
def initialize(str, encoding: Encoding::BINARY)
|
5
5
|
@io = StringIO.new str
|
6
|
+
@encoding = encoding
|
6
7
|
end
|
7
8
|
|
8
9
|
def readpartial(size = nil, outbuf = nil)
|
@@ -14,7 +15,8 @@ module HTTP
|
|
14
15
|
end
|
15
16
|
end
|
16
17
|
|
17
|
-
@io.read size, outbuf
|
18
|
+
chunk = @io.read size, outbuf
|
19
|
+
chunk.force_encoding(@encoding) if chunk
|
18
20
|
end
|
19
21
|
|
20
22
|
def close
|
@@ -1,7 +1,8 @@
|
|
1
1
|
module HTTP
|
2
2
|
class WebMockPerform
|
3
|
-
def initialize(request, &perform)
|
3
|
+
def initialize(request, options, &perform)
|
4
4
|
@request = request
|
5
|
+
@options = options
|
5
6
|
@perform = perform
|
6
7
|
@request_signature = nil
|
7
8
|
end
|
@@ -38,7 +39,10 @@ module HTTP
|
|
38
39
|
webmock_response.raise_error_if_any
|
39
40
|
|
40
41
|
invoke_callbacks(webmock_response, real_request: false)
|
41
|
-
::HTTP::Response.from_webmock @request, webmock_response, request_signature
|
42
|
+
response = ::HTTP::Response.from_webmock @request, webmock_response, request_signature
|
43
|
+
|
44
|
+
@options.features.each { |_name, feature| response = feature.wrap_response(response) }
|
45
|
+
response
|
42
46
|
end
|
43
47
|
|
44
48
|
def raise_timeout_error
|
@@ -35,11 +35,11 @@ module WebMock
|
|
35
35
|
alias == eql?
|
36
36
|
|
37
37
|
def url_encoded?
|
38
|
-
!!(headers
|
38
|
+
!!(headers&.fetch('Content-Type', nil)&.start_with?('application/x-www-form-urlencoded'))
|
39
39
|
end
|
40
40
|
|
41
41
|
def json_headers?
|
42
|
-
!!(headers
|
42
|
+
!!(headers&.fetch('Content-Type', nil)&.start_with?('application/json'))
|
43
43
|
end
|
44
44
|
|
45
45
|
private
|
data/lib/webmock/request_stub.rb
CHANGED
@@ -24,6 +24,21 @@ module WebMock
|
|
24
24
|
end
|
25
25
|
alias_method :and_return, :to_return
|
26
26
|
|
27
|
+
def to_return_json(*response_hashes)
|
28
|
+
raise ArgumentError, '#to_return_json does not support passing a block' if block_given?
|
29
|
+
|
30
|
+
json_response_hashes = [*response_hashes].flatten.map do |resp_h|
|
31
|
+
headers, body = resp_h.values_at(:headers, :body)
|
32
|
+
resp_h.merge(
|
33
|
+
headers: {content_type: 'application/json'}.merge(headers.to_h),
|
34
|
+
body: body.is_a?(Hash) ? body.to_json : body
|
35
|
+
)
|
36
|
+
end
|
37
|
+
|
38
|
+
to_return(json_response_hashes)
|
39
|
+
end
|
40
|
+
alias_method :and_return_json, :to_return_json
|
41
|
+
|
27
42
|
def to_rack(app, options={})
|
28
43
|
@responses_sequences << ResponsesSequence.new([RackResponse.new(app)])
|
29
44
|
end
|
data/lib/webmock/version.rb
CHANGED
data/minitest/webmock_spec.rb
CHANGED
@@ -20,7 +20,7 @@ require File.expand_path(File.dirname(__FILE__) + '/test_helper')
|
|
20
20
|
end
|
21
21
|
|
22
22
|
it "should raise error on non stubbed request" do
|
23
|
-
|
23
|
+
expect { http_request(:get, "http://www.example.net/") }.must_raise(WebMock::NetConnectNotAllowedError)
|
24
24
|
end
|
25
25
|
|
26
26
|
it "should verify that expected request occured" do
|
@@ -248,7 +248,7 @@ unless RUBY_PLATFORM =~ /java/
|
|
248
248
|
end
|
249
249
|
|
250
250
|
context 'multiple requests' do
|
251
|
-
let(:endpoint) { Async::HTTP::Endpoint.parse('http://www.example.com') }
|
251
|
+
let!(:endpoint) { Async::HTTP::Endpoint.parse('http://www.example.com') }
|
252
252
|
let(:requests_count) { 3 }
|
253
253
|
|
254
254
|
shared_examples :common do
|
@@ -300,13 +300,13 @@ unless RUBY_PLATFORM =~ /java/
|
|
300
300
|
end
|
301
301
|
|
302
302
|
context 'HTTP1 protocol' do
|
303
|
-
let(:protocol) { Async::HTTP::Protocol::HTTP1 }
|
303
|
+
let!(:protocol) { Async::HTTP::Protocol::HTTP1 }
|
304
304
|
|
305
305
|
include_examples :common
|
306
306
|
end
|
307
307
|
|
308
308
|
context 'HTTP2 protocol' do
|
309
|
-
let(:protocol) { Async::HTTP::Protocol::HTTP2 }
|
309
|
+
let!(:protocol) { Async::HTTP::Protocol::HTTP2 }
|
310
310
|
|
311
311
|
include_examples :common
|
312
312
|
end
|
@@ -331,13 +331,13 @@ unless RUBY_PLATFORM =~ /java/
|
|
331
331
|
end
|
332
332
|
|
333
333
|
context 'HTTP1 protocol' do
|
334
|
-
let(:protocol) { Async::HTTP::Protocol::HTTP1 }
|
334
|
+
let!(:protocol) { Async::HTTP::Protocol::HTTP1 }
|
335
335
|
|
336
336
|
include_examples :common
|
337
337
|
end
|
338
338
|
|
339
339
|
context 'HTTP2 protocol' do
|
340
|
-
let(:protocol) { Async::HTTP::Protocol::HTTP2 }
|
340
|
+
let!(:protocol) { Async::HTTP::Protocol::HTTP2 }
|
341
341
|
|
342
342
|
include_examples :common
|
343
343
|
end
|
@@ -383,6 +383,17 @@ unless RUBY_PLATFORM =~ /java/
|
|
383
383
|
expect(c.body).to eq("abc")
|
384
384
|
end
|
385
385
|
|
386
|
+
it "supports headers containing the ':' character" do
|
387
|
+
stub_request(:get, "www.example.com").with(headers: {'Referer'=>'http://www.example.com'}).to_return(body: "abc")
|
388
|
+
|
389
|
+
c = Curl::Easy.new
|
390
|
+
c.url = "http://www.example.com"
|
391
|
+
c.headers = ["Referer: http://www.example.com"]
|
392
|
+
c.http(:GET)
|
393
|
+
expect(c.body).to eq("abc")
|
394
|
+
expect(c.headers).to eq(["Referer: http://www.example.com"])
|
395
|
+
end
|
396
|
+
|
386
397
|
describe 'match request body' do
|
387
398
|
it 'for post' do
|
388
399
|
stub_request(:post, "www.example.com").with(body: 'foo=nhe').to_return(body: "abc")
|
@@ -22,7 +22,7 @@ unless RUBY_PLATFORM =~ /java/
|
|
22
22
|
|
23
23
|
def make_request
|
24
24
|
EM.run do
|
25
|
-
request = EM::HttpRequest.new(http_url).get(redirects: 1)
|
25
|
+
request = EM::HttpRequest.new(http_url, ssl: {verify_peer: true}).get(redirects: 1)
|
26
26
|
request.callback { EM.stop }
|
27
27
|
end
|
28
28
|
end
|
@@ -16,7 +16,7 @@ module EMHttpRequestSpecHelper
|
|
16
16
|
error_set = false
|
17
17
|
uri = Addressable::URI.heuristic_parse(uri)
|
18
18
|
EventMachine.run {
|
19
|
-
request = EventMachine::HttpRequest.new("#{uri.normalize.to_s}")
|
19
|
+
request = EventMachine::HttpRequest.new("#{uri.normalize.to_s}", ssl: {verify_peer: true})
|
20
20
|
http = request.send(method, {
|
21
21
|
timeout: 30,
|
22
22
|
body: options[:body],
|
@@ -20,7 +20,7 @@ describe "Excon" do
|
|
20
20
|
it "should support excon response_block for real requests", net_connect: true do
|
21
21
|
a = []
|
22
22
|
WebMock.allow_net_connect!
|
23
|
-
r = Excon.new('
|
23
|
+
r = Excon.new('https://httpstat.us/200', headers: { "Accept" => "*" }).
|
24
24
|
get(response_block: lambda {|e, remaining, total| a << e}, chunk_size: 1)
|
25
25
|
expect(a).to eq(["2", "0", "0", " ", "O", "K"])
|
26
26
|
expect(r.body).to eq("")
|
@@ -41,7 +41,7 @@ describe "Excon" do
|
|
41
41
|
WebMock.after_request { |_, res|
|
42
42
|
response = res
|
43
43
|
}
|
44
|
-
r = Excon.new('
|
44
|
+
r = Excon.new('https://httpstat.us/200', headers: { "Accept" => "*" }).
|
45
45
|
get(response_block: lambda {|e, remaining, total| a << e}, chunk_size: 1)
|
46
46
|
expect(response.body).to eq("200 OK")
|
47
47
|
expect(a).to eq(["2", "0", "0", " ", "O", "K"])
|
@@ -91,7 +91,7 @@ shared_context "allowing and disabling net connect" do |*adapter_info|
|
|
91
91
|
describe "is not allowed, with exceptions" do
|
92
92
|
describe "allowing by host string" do
|
93
93
|
before :each do
|
94
|
-
WebMock.disable_net_connect!(allow: 'httpstat.us')
|
94
|
+
WebMock.disable_net_connect!(allow: 'https://httpstat.us')
|
95
95
|
end
|
96
96
|
|
97
97
|
context "when the host is not allowed" do
|
@@ -109,13 +109,13 @@ shared_context "allowing and disabling net connect" do |*adapter_info|
|
|
109
109
|
|
110
110
|
context "when the host is allowed" do
|
111
111
|
it "should return stubbed response if request was stubbed" do
|
112
|
-
stub_request(:get, 'httpstat.us/200').to_return(body: "abc")
|
113
|
-
expect(http_request(:get, "
|
112
|
+
stub_request(:get, 'https://httpstat.us/200').to_return(body: "abc")
|
113
|
+
expect(http_request(:get, "https://httpstat.us/200").body).to eq("abc")
|
114
114
|
end
|
115
115
|
|
116
116
|
# WARNING: this makes a real HTTP request!
|
117
117
|
it "should make a real request to allowed host", net_connect: true do
|
118
|
-
expect(http_request(:get, "
|
118
|
+
expect(http_request(:get, "https://httpstat.us/200").status).to eq('200')
|
119
119
|
end
|
120
120
|
end
|
121
121
|
end
|
@@ -229,13 +229,13 @@ shared_context "allowing and disabling net connect" do |*adapter_info|
|
|
229
229
|
|
230
230
|
context "when the host is allowed" do
|
231
231
|
it "should return stubbed response if request was stubbed" do
|
232
|
-
stub_request(:get, 'httpstat.us/200').to_return(body: "abc")
|
233
|
-
expect(http_request(:get, "
|
232
|
+
stub_request(:get, 'https://httpstat.us/200').to_return(body: "abc")
|
233
|
+
expect(http_request(:get, "https://httpstat.us/200").body).to eq("abc")
|
234
234
|
end
|
235
235
|
|
236
236
|
# WARNING: this makes a real HTTP request!
|
237
237
|
it "should make a real request to allowed host", net_connect: true do
|
238
|
-
expect(http_request(:get, "
|
238
|
+
expect(http_request(:get, "https://httpstat.us/200").status).to eq('200')
|
239
239
|
end
|
240
240
|
|
241
241
|
it "should make a real request if request is allowed by path regexp and url contains default port", net_connect: true do
|
@@ -266,20 +266,20 @@ shared_context "allowing and disabling net connect" do |*adapter_info|
|
|
266
266
|
|
267
267
|
context "when the host is allowed" do
|
268
268
|
it "should return stubbed response if request was stubbed" do
|
269
|
-
stub_request(:get, 'httpstat.us/200').to_return(body: "abc")
|
270
|
-
expect(http_request(:get, "
|
269
|
+
stub_request(:get, 'https://httpstat.us/200').to_return(body: "abc")
|
270
|
+
expect(http_request(:get, "https://httpstat.us/200").body).to eq("abc")
|
271
271
|
end
|
272
272
|
|
273
273
|
# WARNING: this makes a real HTTP request!
|
274
274
|
it "should make a real request to allowed host", net_connect: true do
|
275
|
-
expect(http_request(:get, "
|
275
|
+
expect(http_request(:get, "https://httpstat.us/200").status).to eq('200')
|
276
276
|
end
|
277
277
|
end
|
278
278
|
end
|
279
279
|
|
280
280
|
describe "allowing by a list of the above" do
|
281
281
|
before :each do
|
282
|
-
WebMock.disable_net_connect!(allow: [lambda{|_| false }, %r{foobar}, 'httpstat.us'])
|
282
|
+
WebMock.disable_net_connect!(allow: [lambda{|_| false }, %r{foobar}, 'https://httpstat.us'])
|
283
283
|
end
|
284
284
|
|
285
285
|
context "when the host is not allowed" do
|
@@ -297,13 +297,13 @@ shared_context "allowing and disabling net connect" do |*adapter_info|
|
|
297
297
|
|
298
298
|
context "when the host is allowed" do
|
299
299
|
it "should return stubbed response if request was stubbed" do
|
300
|
-
stub_request(:get, 'httpstat.us/200').to_return(body: "abc")
|
301
|
-
expect(http_request(:get, "
|
300
|
+
stub_request(:get, 'https://httpstat.us/200').to_return(body: "abc")
|
301
|
+
expect(http_request(:get, "https://httpstat.us/200").body).to eq("abc")
|
302
302
|
end
|
303
303
|
|
304
304
|
# WARNING: this makes a real HTTP request!
|
305
305
|
it "should make a real request to allowed host", net_connect: true do
|
306
|
-
expect(http_request(:get, "
|
306
|
+
expect(http_request(:get, "https://httpstat.us/200").status).to eq('200')
|
307
307
|
end
|
308
308
|
end
|
309
309
|
end
|
@@ -102,7 +102,7 @@ shared_context "callbacks" do |*adapter_info|
|
|
102
102
|
WebMock.after_request(except: [:other_lib]) do |_, response|
|
103
103
|
@response = response
|
104
104
|
end
|
105
|
-
http_request(:get, "
|
105
|
+
http_request(:get, "https://httpstat.us/201", headers: { "Accept" => "*" })
|
106
106
|
end
|
107
107
|
|
108
108
|
it "should pass real response to callback with status and message" do
|
@@ -111,7 +111,7 @@ shared_context "callbacks" do |*adapter_info|
|
|
111
111
|
end
|
112
112
|
|
113
113
|
it "should pass real response to callback with headers" do
|
114
|
-
expect(@response.headers["
|
114
|
+
expect(@response.headers["Server"]).to eq( "Kestrel")
|
115
115
|
expect(@response.headers["Content-Length"]).to eq("11") unless adapter_info.include?(:no_content_length_header)
|
116
116
|
end
|
117
117
|
|
@@ -18,7 +18,7 @@ shared_context "complex cross-concern behaviors" do |*adapter_info|
|
|
18
18
|
expect(played_back_response).to eq(real_response)
|
19
19
|
end
|
20
20
|
|
21
|
-
let(:no_content_url) { '
|
21
|
+
let(:no_content_url) { 'https://httpstat.us/204' }
|
22
22
|
[nil, ''].each do |stub_val|
|
23
23
|
it "returns the same value (nil or "") for a request stubbed as #{stub_val.inspect} that a real empty response has", net_connect: true do
|
24
24
|
unless http_library == :curb
|
@@ -18,7 +18,7 @@ describe WebMock::RequestSignature do
|
|
18
18
|
end
|
19
19
|
|
20
20
|
it "assigns normalized headers" do
|
21
|
-
|
21
|
+
allow(WebMock::Util::Headers).to receive(:normalize_headers).with({'A' => 'a'}.freeze).and_return('B' => 'b')
|
22
22
|
expect(
|
23
23
|
WebMock::RequestSignature.new(:get, "www.example.com", headers: {'A' => 'a'}).headers
|
24
24
|
).to eq({'B' => 'b'})
|
@@ -125,11 +125,21 @@ describe WebMock::RequestSignature do
|
|
125
125
|
expect(subject.url_encoded?).to be true
|
126
126
|
end
|
127
127
|
|
128
|
+
it "returns true if the headers are urlencoded with a specified charset" do
|
129
|
+
subject.headers = { "Content-Type" => "application/x-www-form-urlencoded; charset=UTF-8" }
|
130
|
+
expect(subject.url_encoded?).to be true
|
131
|
+
end
|
132
|
+
|
128
133
|
it "returns false if the headers are NOT urlencoded" do
|
129
134
|
subject.headers = { "Content-Type" => "application/made-up-format" }
|
130
135
|
expect(subject.url_encoded?).to be false
|
131
136
|
end
|
132
137
|
|
138
|
+
it "returns false when no content type header is present" do
|
139
|
+
subject.headers = { "Some-Header" => "some-value" }
|
140
|
+
expect(subject.url_encoded?).to be false
|
141
|
+
end
|
142
|
+
|
133
143
|
it "returns false when no headers are set" do
|
134
144
|
subject.headers = nil
|
135
145
|
expect(subject.url_encoded?).to be false
|
@@ -142,11 +152,21 @@ describe WebMock::RequestSignature do
|
|
142
152
|
expect(subject.json_headers?).to be true
|
143
153
|
end
|
144
154
|
|
155
|
+
it "returns true if the headers are json with a specified charset" do
|
156
|
+
subject.headers = { "Content-Type" => "application/json; charset=UTF-8" }
|
157
|
+
expect(subject.json_headers?).to be true
|
158
|
+
end
|
159
|
+
|
145
160
|
it "returns false if the headers are NOT json" do
|
146
161
|
subject.headers = { "Content-Type" => "application/made-up-format" }
|
147
162
|
expect(subject.json_headers?).to be false
|
148
163
|
end
|
149
164
|
|
165
|
+
it "returns false when no content type header is present" do
|
166
|
+
subject.headers = { "Some-Header" => "some-value" }
|
167
|
+
expect(subject.json_headers?).to be false
|
168
|
+
end
|
169
|
+
|
150
170
|
it "returns false when no headers are set" do
|
151
171
|
subject.headers = nil
|
152
172
|
expect(subject.json_headers?).to be false
|
@@ -50,6 +50,41 @@ describe WebMock::RequestStub do
|
|
50
50
|
|
51
51
|
end
|
52
52
|
|
53
|
+
describe "to_return_json" do
|
54
|
+
|
55
|
+
it "should raise if a block is given" do
|
56
|
+
expect {
|
57
|
+
@request_stub.to_return_json(body: "abc", status: 500) { puts "don't call me" }
|
58
|
+
}.to raise_error(ArgumentError, '#to_return_json does not support passing a block')
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should assign responses normally" do
|
62
|
+
@request_stub.to_return_json([{body: "abc"}, {body: "def"}])
|
63
|
+
expect([@request_stub.response.body, @request_stub.response.body]).to eq(["abc", "def"])
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should json-ify a Hash body" do
|
67
|
+
@request_stub.to_return_json(body: {abc: "def"}, status: 500)
|
68
|
+
expect(@request_stub.response.body).to eq({abc: "def"}.to_json)
|
69
|
+
expect(@request_stub.response.status).to eq([500, ""])
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should apply the content_type header" do
|
73
|
+
@request_stub.to_return_json(body: {abc: "def"}, status: 500)
|
74
|
+
expect(@request_stub.response.headers).to eq({"Content-Type"=>"application/json"})
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should preserve existing headers" do
|
78
|
+
@request_stub.to_return_json(headers: {"A" => "a"}, body: "")
|
79
|
+
expect(@request_stub.response.headers).to eq({"A"=>"a", "Content-Type"=>"application/json"})
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should allow callsites to override content_type header" do
|
83
|
+
@request_stub.to_return_json(headers: {content_type: 'application/super-special-json'})
|
84
|
+
expect(@request_stub.response.headers).to eq({"Content-Type"=>"application/super-special-json"})
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
53
88
|
describe "then" do
|
54
89
|
it "should return stub without any modifications, acting as syntactic sugar" do
|
55
90
|
expect(@request_stub.then).to eq(@request_stub)
|
data/spec/unit/response_spec.rb
CHANGED
@@ -31,7 +31,7 @@ describe WebMock::Response do
|
|
31
31
|
end
|
32
32
|
|
33
33
|
it "should report normalized headers" do
|
34
|
-
|
34
|
+
allow(WebMock::Util::Headers).to receive(:normalize_headers).with({'A' => 'a'}.freeze).and_return('B' => 'b')
|
35
35
|
@response = WebMock::Response.new(headers: {'A' => 'a'})
|
36
36
|
expect(@response.headers).to eq({'B' => 'b'})
|
37
37
|
end
|
data/webmock.gemspec
CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |s|
|
|
21
21
|
'wiki_uri' => 'https://github.com/bblimke/webmock/wiki'
|
22
22
|
}
|
23
23
|
|
24
|
-
s.required_ruby_version = '>= 2.
|
24
|
+
s.required_ruby_version = '>= 2.3'
|
25
25
|
|
26
26
|
s.add_dependency 'addressable', '>= 2.8.0'
|
27
27
|
s.add_dependency 'crack', '>= 0.3.2'
|
@@ -31,6 +31,8 @@ Gem::Specification.new do |s|
|
|
31
31
|
s.add_development_dependency 'patron', '>= 0.4.18'
|
32
32
|
s.add_development_dependency 'curb', '>= 0.7.16'
|
33
33
|
s.add_development_dependency 'typhoeus', '>= 0.5.0'
|
34
|
+
s.add_development_dependency 'em-http-request', '>= 1.0.2'
|
35
|
+
s.add_development_dependency 'em-synchrony', '>= 1.0.0'
|
34
36
|
end
|
35
37
|
|
36
38
|
s.add_development_dependency 'http', '>= 0.8.0'
|
@@ -38,8 +40,6 @@ Gem::Specification.new do |s|
|
|
38
40
|
s.add_development_dependency 'rack', ((RUBY_VERSION < '2.2.2') ? '1.6.0' : '> 1.6')
|
39
41
|
s.add_development_dependency 'rspec', '>= 3.1.0'
|
40
42
|
s.add_development_dependency 'httpclient', '>= 2.2.4'
|
41
|
-
s.add_development_dependency 'em-http-request', '>= 1.0.2'
|
42
|
-
s.add_development_dependency 'em-synchrony', '>= 1.0.0'
|
43
43
|
s.add_development_dependency 'excon', '>= 0.27.5'
|
44
44
|
s.add_development_dependency 'async-http', '>= 0.48.0'
|
45
45
|
s.add_development_dependency 'minitest', '>= 5.0.0'
|
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.
|
4
|
+
version: 3.15.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:
|
11
|
+
date: 2022-08-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|
@@ -101,89 +101,89 @@ dependencies:
|
|
101
101
|
- !ruby/object:Gem::Version
|
102
102
|
version: 0.5.0
|
103
103
|
- !ruby/object:Gem::Dependency
|
104
|
-
name: http
|
104
|
+
name: em-http-request
|
105
105
|
requirement: !ruby/object:Gem::Requirement
|
106
106
|
requirements:
|
107
107
|
- - ">="
|
108
108
|
- !ruby/object:Gem::Version
|
109
|
-
version: 0.
|
109
|
+
version: 1.0.2
|
110
110
|
type: :development
|
111
111
|
prerelease: false
|
112
112
|
version_requirements: !ruby/object:Gem::Requirement
|
113
113
|
requirements:
|
114
114
|
- - ">="
|
115
115
|
- !ruby/object:Gem::Version
|
116
|
-
version: 0.
|
116
|
+
version: 1.0.2
|
117
117
|
- !ruby/object:Gem::Dependency
|
118
|
-
name:
|
118
|
+
name: em-synchrony
|
119
119
|
requirement: !ruby/object:Gem::Requirement
|
120
120
|
requirements:
|
121
|
-
- - "
|
121
|
+
- - ">="
|
122
122
|
- !ruby/object:Gem::Version
|
123
|
-
version:
|
123
|
+
version: 1.0.0
|
124
124
|
type: :development
|
125
125
|
prerelease: false
|
126
126
|
version_requirements: !ruby/object:Gem::Requirement
|
127
127
|
requirements:
|
128
|
-
- - "
|
128
|
+
- - ">="
|
129
129
|
- !ruby/object:Gem::Version
|
130
|
-
version:
|
130
|
+
version: 1.0.0
|
131
131
|
- !ruby/object:Gem::Dependency
|
132
|
-
name:
|
132
|
+
name: http
|
133
133
|
requirement: !ruby/object:Gem::Requirement
|
134
134
|
requirements:
|
135
135
|
- - ">="
|
136
136
|
- !ruby/object:Gem::Version
|
137
|
-
version:
|
137
|
+
version: 0.8.0
|
138
138
|
type: :development
|
139
139
|
prerelease: false
|
140
140
|
version_requirements: !ruby/object:Gem::Requirement
|
141
141
|
requirements:
|
142
142
|
- - ">="
|
143
143
|
- !ruby/object:Gem::Version
|
144
|
-
version:
|
144
|
+
version: 0.8.0
|
145
145
|
- !ruby/object:Gem::Dependency
|
146
|
-
name:
|
146
|
+
name: rack
|
147
147
|
requirement: !ruby/object:Gem::Requirement
|
148
148
|
requirements:
|
149
|
-
- - "
|
149
|
+
- - ">"
|
150
150
|
- !ruby/object:Gem::Version
|
151
|
-
version:
|
151
|
+
version: '1.6'
|
152
152
|
type: :development
|
153
153
|
prerelease: false
|
154
154
|
version_requirements: !ruby/object:Gem::Requirement
|
155
155
|
requirements:
|
156
|
-
- - "
|
156
|
+
- - ">"
|
157
157
|
- !ruby/object:Gem::Version
|
158
|
-
version:
|
158
|
+
version: '1.6'
|
159
159
|
- !ruby/object:Gem::Dependency
|
160
|
-
name:
|
160
|
+
name: rspec
|
161
161
|
requirement: !ruby/object:Gem::Requirement
|
162
162
|
requirements:
|
163
163
|
- - ">="
|
164
164
|
- !ruby/object:Gem::Version
|
165
|
-
version: 1.0
|
165
|
+
version: 3.1.0
|
166
166
|
type: :development
|
167
167
|
prerelease: false
|
168
168
|
version_requirements: !ruby/object:Gem::Requirement
|
169
169
|
requirements:
|
170
170
|
- - ">="
|
171
171
|
- !ruby/object:Gem::Version
|
172
|
-
version: 1.0
|
172
|
+
version: 3.1.0
|
173
173
|
- !ruby/object:Gem::Dependency
|
174
|
-
name:
|
174
|
+
name: httpclient
|
175
175
|
requirement: !ruby/object:Gem::Requirement
|
176
176
|
requirements:
|
177
177
|
- - ">="
|
178
178
|
- !ruby/object:Gem::Version
|
179
|
-
version:
|
179
|
+
version: 2.2.4
|
180
180
|
type: :development
|
181
181
|
prerelease: false
|
182
182
|
version_requirements: !ruby/object:Gem::Requirement
|
183
183
|
requirements:
|
184
184
|
- - ">="
|
185
185
|
- !ruby/object:Gem::Version
|
186
|
-
version:
|
186
|
+
version: 2.2.4
|
187
187
|
- !ruby/object:Gem::Dependency
|
188
188
|
name: excon
|
189
189
|
requirement: !ruby/object:Gem::Requirement
|
@@ -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.
|
425
|
-
documentation_uri: https://www.rubydoc.info/gems/webmock/3.
|
426
|
-
source_code_uri: https://github.com/bblimke/webmock/tree/v3.
|
424
|
+
changelog_uri: https://github.com/bblimke/webmock/blob/v3.15.1/CHANGELOG.md
|
425
|
+
documentation_uri: https://www.rubydoc.info/gems/webmock/3.15.1
|
426
|
+
source_code_uri: https://github.com/bblimke/webmock/tree/v3.15.1
|
427
427
|
wiki_uri: https://github.com/bblimke/webmock/wiki
|
428
428
|
post_install_message:
|
429
429
|
rdoc_options: []
|
@@ -433,7 +433,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
433
433
|
requirements:
|
434
434
|
- - ">="
|
435
435
|
- !ruby/object:Gem::Version
|
436
|
-
version: '2.
|
436
|
+
version: '2.3'
|
437
437
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
438
438
|
requirements:
|
439
439
|
- - ">="
|