Skip to content

Commit

Permalink
Support http.rb 5.x
Browse files Browse the repository at this point in the history
5.0.0 had a breaking change.

Fixes #940
  • Loading branch information
horgh committed May 13, 2021
1 parent ab85203 commit 3e81062
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
15 changes: 13 additions & 2 deletions lib/webmock/http_lib_adapters/http_rb/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def to_webmock
end

class << self
def from_webmock(webmock_response, request_signature = nil)
def from_webmock(request, webmock_response, request_signature = nil)
status = Status.new(webmock_response.status.first)
headers = webmock_response.headers || {}
uri = normalize_uri(request_signature && request_signature.uri)
Expand All @@ -29,12 +29,23 @@ def from_webmock(webmock_response, request_signature = nil)

return new(status, "1.1", headers, body, uri) if HTTP::VERSION < "1.0.0"

# 5.0.0 had a breaking change to require request instead of uri.
if HTTP::VERSION < '5.0.0'
return new({
status: status,
version: "1.1",
headers: headers,
body: body,
uri: uri
})
end

new({
status: status,
version: "1.1",
headers: headers,
body: body,
uri: uri
request: request,
})
end

Expand Down
2 changes: 1 addition & 1 deletion lib/webmock/http_lib_adapters/http_rb/webmock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def replay
webmock_response.raise_error_if_any

invoke_callbacks(webmock_response, real_request: false)
::HTTP::Response.from_webmock webmock_response, request_signature
::HTTP::Response.from_webmock @request, webmock_response, request_signature
end

def raise_timeout_error
Expand Down

0 comments on commit 3e81062

Please sign in to comment.