From 9ecded1c91cc88e9c6c3df376bea1713a5ec3d05 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 29 Mar 2009 13:17:31 -0700 Subject: test_response: ensure response body is closed This is in the Rack specification and a good idea. Remind ourselves to prevent file descriptor or other resource leaks in case the body is not an Array. --- test/unit/test_response.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/test/unit/test_response.rb b/test/unit/test_response.rb index 17732fe..203ae4d 100644 --- a/test/unit/test_response.rb +++ b/test/unit/test_response.rb @@ -54,5 +54,15 @@ class ResponseTest < Test::Unit::TestCase assert_match(/^X-Whatever: stuff\r\nX-Whatever: bleh\r\n/, out.string) end -end + def test_body_closed + expect_body = %w(1 2 3 4).join("\n") + body = StringIO.new(expect_body) + body.rewind + out = StringIO.new + HttpResponse.write(out,[200, {}, body]) + assert out.closed? + assert body.closed? + assert_match(expect_body, out.string.split(/\r\n/).last) + end +end -- cgit v1.2.3-24-ge0c7