Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

First test passes.

  • Loading branch information...
commit 227683b99480aa9b6199354397a21cc9ba785cd9 1 parent 96f704d
@mdub authored
Showing with 18 additions and 10 deletions.
  1. +1 −1  lib/sham_rack/net_http.rb
  2. +17 −9 lib/sham_rack/patron.rb
View
2  lib/sham_rack/net_http.rb
@@ -87,7 +87,7 @@ def build_response(rack_response)
def assemble_body(body)
content = ""
body.each { |fragment| content << fragment }
- return content
+ content
end
end
View
26 lib/sham_rack/patron.rb
@@ -21,21 +21,29 @@ def handle_request(patron_request)
private
def handle_request_with_rack(patron_request, rack_app)
- res = Patron::Response.new
- res.instance_variable_set(:@body, "hello World")
- # res.instance_variable_set(:@status, webmock_response.status[0])
- # res.instance_variable_set(:@status_line, webmock_response.status[1])
- # res.instance_variable_set(:@headers, webmock_response.headers)
- res
+ env = rack_env_for(patron_request)
+ rack_response = rack_app.call(env)
+ patron_response(rack_response)
end
- def create_rack_request(patron_request)
+ def rack_env_for(patron_request)
+ Rack::MockRequest.env_for(patron_request.url, :method => patron_request.action)
end
- def rack_env(patron_request)
+ def patron_response(rack_response)
+ status, headers, body = rack_response
+ res = Patron::Response.new
+ res.instance_variable_set(:@status, status)
+ res.instance_variable_set(:@body, assemble_body(body))
+ # res.instance_variable_set(:@status_line, webmock_response.status[1])
+ # res.instance_variable_set(:@headers, webmock_response.headers)
+ res
end
- def patron_response(rack_response)
+ def assemble_body(body)
+ content = ""
+ body.each { |fragment| content << fragment }
+ content
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.