Permalink
Browse files

Generate an appropriate default HTTP status "message",

if the app doesn't supply one.
  • Loading branch information...
mdub committed Mar 25, 2013
1 parent a977db0 commit b7715d832becf95907aab11340de83c2c9819f6e
Showing with 32 additions and 7 deletions.
  1. +1 −0 lib/sham_rack/net_http.rb
  2. +31 −7 spec/sham_rack_spec.rb
@@ -74,6 +74,7 @@ def request_env(request, body)
def build_response(rack_response)
status, headers, body = rack_response
code, message = status.to_s.split(" ", 2)
+ message ||= Rack::Utils::HTTP_STATUS_CODES[code.to_i]
response = Net::HTTPResponse.send(:response_class, code).new("Sham", code, message)
response.instance_variable_set(:@body, assemble_body(body))
response.instance_variable_set(:@read, true)
View
@@ -148,32 +148,56 @@
before(:each) do
ShamRack.at("www.greetings.com") do
[
- "201 Created",
+ "456 Foo Bar",
{ "Content-Type" => "text/plain", "X-Foo" => "bar" },
["BODY"]
]
end
- @response = Net::HTTP.get_response(URI.parse("http://www.greetings.com/"))
end
+ let(:response) { Net::HTTP.get_response(URI.parse("http://www.greetings.com/")) }
+
it "has status returned by app" do
- @response.code.should == "201"
+ response.code.should == "456"
end
it "has status message returned by app" do
- @response.message.should == "Created"
+ response.message.should == "Foo Bar"
end
it "has body returned by app" do
- @response.body.should == "BODY"
+ response.body.should == "BODY"
end
it "has Content-Type returned by app" do
- @response.content_type.should == "text/plain"
+ response.content_type.should == "text/plain"
end
it "has other headers returned by app" do
- @response["x-foo"].should =="bar"
+ response["x-foo"].should =="bar"
+ end
+
+ context "when the app returns a numeric status" do
+
+ before(:each) do
+ ShamRack.at("www.greetings.com") do
+ [
+ 201,
+ { "Content-Type" => "text/plain" },
+ ["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
+
+ it "derives a status message" do
+ response.message.should == "Created"
+ end
+
end
end

0 comments on commit b7715d8

Please sign in to comment.