Skip to content

Commit 5f46eca

Browse files
committed
Fix specs with recent Async-http versions.
Recent versions of async-http (and its sub-libraries like request-http) are strict about content-length header: - Get requests should not have any content-length request header provided - POST requests with the body and all responses with stringio body have the content-length header appended automagically
1 parent aa747ba commit 5f46eca

4 files changed

Lines changed: 6 additions & 7 deletions

File tree

lib/webmock/http_lib_adapters/async_http_client_adapter.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ def webmock_responses
211211
def build_response(webmock_response)
212212
headers = (webmock_response.headers || {}).each_with_object([]) do |(k, value), o|
213213
Array(value).each do |v|
214-
o.push [k, v]
214+
o.push [k, v] unless k.downcase == 'content-length' # async-http appends the exact content-length automatically
215215
end
216216
end
217217

spec/acceptance/shared/stubbing_requests.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -366,10 +366,10 @@
366366

367367
describe "based on headers" do
368368
it "should match requests if headers are the same" do
369-
stub_request(:get, "www.example.com").with(headers: SAMPLE_HEADERS )
369+
stub_request(:get, "www.example.com").with(headers: { "Accept" => "application/json" } )
370370
expect(http_request(
371371
:get, "http://www.example.com/",
372-
headers: SAMPLE_HEADERS).status).to eq("200")
372+
headers: { "Accept" => "application/json" }).status).to eq("200")
373373
end
374374

375375
it "should match requests if headers are the same and declared as array" do
@@ -413,12 +413,12 @@
413413
end
414414

415415
it "should not match requests if headers are different" do
416-
stub_request(:get, "www.example.com").with(headers: SAMPLE_HEADERS)
416+
stub_request(:get, "www.example.com").with(headers: { "Accept" => "application/json" })
417417

418418
expect {
419419
http_request(
420420
:get, "http://www.example.com/",
421-
headers: { 'Content-Length' => '9999'})
421+
headers: { "Accept" => "text/html" })
422422
}.to raise_error(WebMock::NetConnectNotAllowedError, %r(Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/ with headers))
423423
end
424424

spec/acceptance/webmock_shared.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
require 'acceptance/shared/complex_cross_concern_behaviors'
1010

1111
unless defined? SAMPLE_HEADERS
12-
SAMPLE_HEADERS = { "Content-Length" => "8888", "Accept" => "application/json" }
12+
SAMPLE_HEADERS = { "Accept" => "application/json" }
1313
ESCAPED_PARAMS = "x=ab%20c&z=%27Stop%21%27%20said%20Fred%20m"
1414
NOT_ESCAPED_PARAMS = "z='Stop!' said Fred m&x=ab c"
1515
end

webmock.gemspec

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ Gem::Specification.new do |s|
4646
s.add_development_dependency 'rdoc', '> 3.5.0'
4747
s.add_development_dependency 'webrick'
4848
s.add_development_dependency 'rspec-retry'
49-
s.add_development_dependency 'protocol-http', '<= 0.50.0'
5049

5150
s.files = Dir["CHANGELOG.md", "LICENSE", "README.md", "lib/**/*"]
5251
s.require_path = "lib"

0 commit comments

Comments
 (0)