webmock 2.0.2 → 2.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/README.md +1 -0
- data/lib/webmock/http_lib_adapters/curb_adapter.rb +13 -1
- data/lib/webmock/http_lib_adapters/excon_adapter.rb +5 -0
- data/lib/webmock/request_body_diff.rb +3 -2
- data/lib/webmock/util/version_checker.rb +5 -1
- data/lib/webmock/version.rb +1 -1
- data/spec/acceptance/curb/curb_spec.rb +10 -0
- data/spec/acceptance/em_http_request/em_http_request_spec.rb +5 -5
- data/spec/acceptance/httpclient/httpclient_spec.rb +1 -1
- data/spec/acceptance/httpclient/httpclient_spec_helper.rb +13 -8
- data/spec/acceptance/net_http/net_http_spec_helper.rb +4 -4
- data/spec/acceptance/shared/returning_declared_responses.rb +6 -6
- data/spec/acceptance/shared/stubbing_requests.rb +2 -2
- data/spec/acceptance/typhoeus/typhoeus_hydra_spec.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 20d5a309586539a993335a28d74d8fc43495ec27
|
4
|
+
data.tar.gz: abfbec11bc296d461282f8698d18171b02a6c752
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a76bd8f96fd204ec2cae1784cfedafebe96b261010d15531518bbbd81ebe2ddae765652c5c72a0f0d8cc7f9b423f4936751a4d738d0115417de116f819a45e93
|
7
|
+
data.tar.gz: 3d1fc2113f0225f774e16406bb1fcd9ce1ee1067b26c8209737a761c7bb91737f083f721629e8ef37f8779653773ac879eec31155e05bfbde50bdf2a7b63374f
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,15 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 2.0.3
|
4
|
+
|
5
|
+
* Handling headers passed as an Array to Curl::Easy
|
6
|
+
|
7
|
+
Thanks to [Chelsea](https://github.com/grosscr) for reporting the issue.
|
8
|
+
|
9
|
+
* Removed Ruby warnings.
|
10
|
+
|
11
|
+
Thanks to [Aaron Kromer](https://github.com/cupakromer)
|
12
|
+
|
3
13
|
## 2.0.2
|
4
14
|
|
5
15
|
* Using `Base64.strict_encode64` instead of `Base64.encode64` to handle long user:pass basic auth credentials
|
data/README.md
CHANGED
@@ -1019,6 +1019,7 @@ People who submitted patches and new features or suggested improvements. Many th
|
|
1019
1019
|
* Taiki Ono
|
1020
1020
|
* Jonathan Schatz
|
1021
1021
|
* Jose Luis Honorato
|
1022
|
+
* Aaron Kromer
|
1022
1023
|
|
1023
1024
|
For a full list of contributors you can visit the
|
1024
1025
|
[contributors](https://github.com/bblimke/webmock/contributors) page.
|
@@ -98,11 +98,23 @@ if defined?(Curl)
|
|
98
98
|
method,
|
99
99
|
uri.to_s,
|
100
100
|
:body => request_body,
|
101
|
-
:headers => self.headers.merge(basic_auth_headers)
|
101
|
+
:headers => headers_as_hash(self.headers).merge(basic_auth_headers)
|
102
102
|
)
|
103
103
|
request_signature
|
104
104
|
end
|
105
105
|
|
106
|
+
def headers_as_hash(headers)
|
107
|
+
if headers.is_a?(Array)
|
108
|
+
headers.inject({}) {|hash, header|
|
109
|
+
name, value = header.split(":").map(&:strip)
|
110
|
+
hash[name] = value
|
111
|
+
hash
|
112
|
+
}
|
113
|
+
else
|
114
|
+
headers
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
106
118
|
def basic_auth_headers
|
107
119
|
if self.username
|
108
120
|
{'Authorization' => WebMock::Util::Headers.basic_auth_header(self.username, self.password)}
|
@@ -15,9 +15,10 @@ module WebMock
|
|
15
15
|
HashDiff.diff(request_signature_body_hash, request_stub_body_hash)
|
16
16
|
end
|
17
17
|
|
18
|
-
private
|
19
|
-
|
20
18
|
attr_reader :request_signature, :request_stub
|
19
|
+
private :request_signature, :request_stub
|
20
|
+
|
21
|
+
private
|
21
22
|
|
22
23
|
def request_signature_diffable?
|
23
24
|
request_signature.json_headers? && request_signature_parseable_json?
|
@@ -31,7 +31,11 @@ module WebMock
|
|
31
31
|
|
32
32
|
@major, @minor, @patch = parse_version(library_version)
|
33
33
|
@min_major, @min_minor, @min_patch = parse_version(min_patch_level)
|
34
|
-
|
34
|
+
if max_minor_version
|
35
|
+
@max_major, @max_minor = parse_version(max_minor_version)
|
36
|
+
else
|
37
|
+
@max_major, @max_minor = nil, nil
|
38
|
+
end
|
35
39
|
|
36
40
|
@comparison_result = compare_version
|
37
41
|
end
|
data/lib/webmock/version.rb
CHANGED
@@ -355,6 +355,16 @@ unless RUBY_PLATFORM =~ /java/
|
|
355
355
|
c.http(:GET)
|
356
356
|
expect(c.body).to eq("abc")
|
357
357
|
end
|
358
|
+
|
359
|
+
it "supports array headers passed to Curl::Easy" do
|
360
|
+
stub_request(:get, "www.example.com").with(headers: {'X-One' => '1'}).to_return(:body => "abc")
|
361
|
+
|
362
|
+
c = Curl::Easy.new
|
363
|
+
c.url = "http://www.example.com"
|
364
|
+
c.headers = ["X-One: 1"]
|
365
|
+
c.http(:GET)
|
366
|
+
expect(c.body).to eq("abc")
|
367
|
+
end
|
358
368
|
end
|
359
369
|
|
360
370
|
describe "using #http_* methods for requests" do
|
@@ -274,12 +274,12 @@ unless RUBY_PLATFORM =~ /java/
|
|
274
274
|
err = :success_from_timeout
|
275
275
|
EM.stop
|
276
276
|
end.errback do |resp|
|
277
|
-
conn.get(:path => "/foo").callback do |
|
278
|
-
expect(
|
279
|
-
body =
|
277
|
+
conn.get(:path => "/foo").callback do |retry_resp|
|
278
|
+
expect(retry_resp.response_header.status).to eq(200)
|
279
|
+
body = retry_resp.response
|
280
280
|
EM.stop
|
281
|
-
end.errback do |
|
282
|
-
err =
|
281
|
+
end.errback do |retry_resp|
|
282
|
+
err = retry_resp.error
|
283
283
|
EM.stop
|
284
284
|
end
|
285
285
|
end
|
@@ -188,7 +188,7 @@ describe "HTTPClient" do
|
|
188
188
|
|
189
189
|
it 'sets the full body on the webmock response' do
|
190
190
|
body = ''
|
191
|
-
|
191
|
+
HTTPClient.new.request(:get, 'http://www.example.com/') do |http_res, chunk|
|
192
192
|
body += chunk
|
193
193
|
end
|
194
194
|
expect(@response.body).to eq body
|
@@ -20,14 +20,7 @@ module HTTPClientSpecHelper
|
|
20
20
|
else
|
21
21
|
response = c.request(*params, &block)
|
22
22
|
end
|
23
|
-
headers = response
|
24
|
-
if !headers.has_key?(header[0])
|
25
|
-
headers[header[0]] = header[1]
|
26
|
-
else
|
27
|
-
headers[header[0]] = [headers[header[0]], header[1]].join(', ')
|
28
|
-
end
|
29
|
-
headers
|
30
|
-
end
|
23
|
+
headers = merge_headers(response)
|
31
24
|
OpenStruct.new({
|
32
25
|
:body => HTTPClientSpecHelper.async_mode ? response.content.read : response.content,
|
33
26
|
:headers => headers,
|
@@ -48,4 +41,16 @@ module HTTPClientSpecHelper
|
|
48
41
|
:httpclient
|
49
42
|
end
|
50
43
|
|
44
|
+
private
|
45
|
+
|
46
|
+
def merge_headers(response)
|
47
|
+
response.header.all.inject({}) do |headers, header|
|
48
|
+
if !headers.has_key?(header[0])
|
49
|
+
headers[header[0]] = header[1]
|
50
|
+
else
|
51
|
+
headers[header[0]] = [headers[header[0]], header[1]].join(', ')
|
52
|
+
end
|
53
|
+
headers
|
54
|
+
end
|
55
|
+
end
|
51
56
|
end
|
@@ -10,8 +10,8 @@ module NetHTTPSpecHelper
|
|
10
10
|
req = clazz.new("#{uri.path}#{uri.query ? '?' : ''}#{uri.query}", nil)
|
11
11
|
options[:headers].each do |k,v|
|
12
12
|
if v.is_a?(Array)
|
13
|
-
v.each_with_index do |
|
14
|
-
i == 0 ? (req[k] =
|
13
|
+
v.each_with_index do |e,i|
|
14
|
+
i == 0 ? (req[k] = e) : req.add_field(k, e)
|
15
15
|
end
|
16
16
|
else
|
17
17
|
req[k] = v
|
@@ -31,8 +31,8 @@ module NetHTTPSpecHelper
|
|
31
31
|
http.read_timeout = 60
|
32
32
|
end
|
33
33
|
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
34
|
-
response = http.start {|
|
35
|
-
|
34
|
+
response = http.start {|open_http|
|
35
|
+
open_http.request(req, options[:body], &block)
|
36
36
|
}
|
37
37
|
headers = {}
|
38
38
|
response.each_header {|name, value| headers[name] = value}
|
@@ -1,5 +1,11 @@
|
|
1
1
|
class MyException < StandardError; end;
|
2
2
|
|
3
|
+
class Responder
|
4
|
+
def call(request)
|
5
|
+
{:body => request.body}
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
3
9
|
shared_context "declared responses" do |*adapter_info|
|
4
10
|
describe "when request stub declares that request should raise exception" do
|
5
11
|
it "should raise exception" do
|
@@ -128,12 +134,6 @@ shared_context "declared responses" do |*adapter_info|
|
|
128
134
|
end
|
129
135
|
|
130
136
|
describe "when response was declared as lambda" do
|
131
|
-
class Responder
|
132
|
-
def call(request)
|
133
|
-
{:body => request.body}
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
137
|
it "should return evaluated response body" do
|
138
138
|
stub_request(:post, "www.example.com").to_return(lambda {|request|
|
139
139
|
{:body => request.body}
|
@@ -34,8 +34,8 @@ shared_examples_for "stubbing requests" do |*adapter_info|
|
|
34
34
|
begin
|
35
35
|
http_request(:get, "http://www.example.com/hello+/?#{NOT_ESCAPED_PARAMS}")
|
36
36
|
rescue WebMock::NetConnectNotAllowedError => e
|
37
|
-
expect(e.message).to match
|
38
|
-
expect(e.message).to match
|
37
|
+
expect(e.message).to match(/Unregistered request: GET http:\/\/www\.example\.com\/hello\+\/\?x=ab%20c&z='Stop!'%20said%20Fred%20m/m)
|
38
|
+
expect(e.message).to match(/stub_request\(:get, "http:\/\/www\.example\.com\/hello\+\/\?x=ab%20c&z='Stop!'%20said%20Fred%20m"\)/m)
|
39
39
|
end
|
40
40
|
|
41
41
|
stub_request(:get, "http://www.example.com/hello+/?x=ab%20c&z='Stop!'%20said%20Fred%20m")
|
@@ -104,8 +104,8 @@ unless RUBY_PLATFORM =~ /java/
|
|
104
104
|
test_body = nil
|
105
105
|
test_complete = nil
|
106
106
|
skip("This test requires a newer version of Typhoeus") unless @request.respond_to?(:on_body)
|
107
|
-
@request.on_body do |
|
108
|
-
test_body =
|
107
|
+
@request.on_body do |body_chunk, response|
|
108
|
+
test_body = body_chunk
|
109
109
|
end
|
110
110
|
@request.on_complete do |response|
|
111
111
|
test_complete = response.body
|
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: 2.0.
|
4
|
+
version: 2.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bartosz Blimke
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-05-
|
11
|
+
date: 2016-05-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|