Skip to content

Commit

Permalink
Fix HTTP Gem replayed Response object's init
Browse files Browse the repository at this point in the history
0.6.x version introduced optional last argument of Response object:
request's uri. That allows for example to figure out a real URI after
following redirects. This patch brinsg this ability to HTTP Gem adapter.
  • Loading branch information
ixti committed May 28, 2014
1 parent 0cd6a12 commit 321bd54
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
5 changes: 3 additions & 2 deletions lib/webmock/http_lib_adapters/http_gem/response.rb
Expand Up @@ -10,12 +10,13 @@ def to_webmock
webmock_response
end

def self.from_webmock(webmock_response)
def self.from_webmock(webmock_response, request_signature = nil)
status = webmock_response.status.first
headers = webmock_response.headers || {}
body = Body.new Streamer.new webmock_response.body
uri = URI request_signature.uri.to_s if request_signature

new(status, "1.1", headers, body)
new(status, "1.1", headers, body, uri)
end
end
end
2 changes: 1 addition & 1 deletion lib/webmock/http_lib_adapters/http_gem/webmock.rb
Expand Up @@ -37,7 +37,7 @@ def replay
webmock_response.raise_error_if_any

invoke_callbacks(webmock_response, :real_request => false)
::HTTP::Response.from_webmock webmock_response
::HTTP::Response.from_webmock webmock_response, request_signature
end

def perform
Expand Down
9 changes: 9 additions & 0 deletions spec/acceptance/http_gem/http_gem_spec.rb
Expand Up @@ -47,4 +47,13 @@
expect(headers).to include "Host" => "www.example.com"
end
end

it "restores request uri on replayed response object" do
uri = URI "http://example.com/foo"

stub_request :get, "example.com/foo"
response = HTTP.get uri

expect(response.uri).to eq uri
end
end

0 comments on commit 321bd54

Please sign in to comment.