Skip to content
Browse files

Adapt to changes in Patron.

  • Loading branch information...
1 parent ea72c97 commit 8824008b443e1a596149264d1b163773dd2c0d59 @mdub committed
Showing with 27 additions and 24 deletions.
  1. +1 −1 Gemfile
  2. +11 −8 lib/sham_rack/patron.rb
  3. +15 −15 spec/sham_rack_spec.rb
View
2 Gemfile
@@ -10,5 +10,5 @@ group :test do
gem "sinatra"
gem "rest-client"
gem "mechanize"
- gem "patron"
+ gem "patron", ">= 0.4.16"
end
View
19 lib/sham_rack/patron.rb
@@ -34,13 +34,7 @@ def rack_env_for(patron_request)
def patron_response(rack_response)
status, headers, body = rack_response
- status_code = Rack::Utils::HTTP_STATUS_CODES[status.to_i]
- res = Patron::Response.new
- res.instance_variable_set(:@status, status)
- res.instance_variable_set(:@status_line, "HTTP/1.1 #{status} #{status_code}")
- res.instance_variable_set(:@body, assemble_body(body))
- res.instance_variable_set(:@headers, headers)
- res
+ Patron::Response.new("", status.to_i, 0, assemble_headers(status, headers), assemble_body(body))
end
def header_env(patron_request)
@@ -53,6 +47,15 @@ def header_env(patron_request)
env
end
+ def assemble_headers(status, headers)
+ status_code = Rack::Utils::HTTP_STATUS_CODES[status.to_i]
+ content = "HTTP/1.1 #{status} #{status_code}\r\n"
+ headers.each do |k, v|
+ content << "#{k}: #{v}\r\n"
+ end
+ content
+ end
+
def assemble_body(body)
content = ""
body.each { |fragment| content << fragment }
@@ -61,4 +64,4 @@ def assemble_body(body)
end
-end
+end
View
30 spec/sham_rack_spec.rb
@@ -100,7 +100,7 @@
end
end
end
-
+
it "mounts associated block as a Sinatra app" do
open("http://sinatra.xyz/hello/stranger").read.should == "Hello, stranger"
end
@@ -108,11 +108,11 @@
it "returns the app" do
@return_value.should respond_to(:call)
end
-
+
end
describe "#stub" do
-
+
before do
@return_value = ShamRack.at("stubbed.xyz").stub
end
@@ -120,28 +120,28 @@
it "mounts a StubWebService" do
ShamRack.application_for("stubbed.xyz").should be_kind_of(ShamRack::StubWebService)
end
-
+
it "returns the StubWebService" do
@return_value.should == ShamRack.application_for("stubbed.xyz")
end
-
+
end
-
+
end
describe "response" do
-
+
before(:each) do
ShamRack.at("www.greetings.com") do
[
- "201 Created",
+ "201 Created",
{ "Content-Type" => "text/plain", "X-Foo" => "bar" },
["BODY"]
]
end
@response = Net::HTTP.get_response(URI.parse("http://www.greetings.com/"))
end
-
+
it "has status returned by app" do
@response.code.should == "201"
end
@@ -149,17 +149,17 @@
it "has body returned by app" do
@response.body.should == "BODY"
end
-
+
it "has Content-Type returned by app" do
@response.content_type.should == "text/plain"
end
-
+
it "has other headers returned by app" do
@response["x-foo"].should =="bar"
end
-
+
end
-
+
describe "Rack environment" do
before(:each) do
@@ -232,8 +232,8 @@ def env
patron = Patron::Session.new
response = patron.post("http://env.xyz/resource", "<xml/>", "Content-Type" => "application/xml")
- response.status.should == "200 OK"
-
+ response.status.should == 200
+
env["REQUEST_METHOD"].should == "POST"
env["rack.input"].read.should == "<xml/>"
env["CONTENT_TYPE"].should == "application/xml"

0 comments on commit 8824008

Please sign in to comment.
Something went wrong with that request. Please try again.