From 485fe222d304c9a795141532596b0575c3d2e6ea Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 6 Oct 2009 12:03:11 -0700 Subject: tests for subclassing Rack::Lint will be relaxed in the next version to allow subclasses of String and Hash objects, so ensure we're good to go when the next version of Rack hits. --- test/test_clogger.rb | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/test/test_clogger.rb b/test/test_clogger.rb index 23d6e58..215256c 100644 --- a/test/test_clogger.rb +++ b/test/test_clogger.rb @@ -7,6 +7,11 @@ require "stringio" require "rack" require "clogger" + +# used to test subclasses +class FooString < String +end + class TestClogger < Test::Unit::TestCase include Clogger::Format @@ -392,6 +397,41 @@ class TestClogger < Test::Unit::TestCase assert_nothing_raised { cl.call(@req) } end + def test_subclass_hash + str = StringIO.new + req = Rack::Utils::HeaderHash.new(@req) + app = lambda { |env| [302, [ %w(a) ], []] } + cl = Clogger.new(app, :logger => str, :format => Rack_1_0) + assert_nothing_raised { cl.call(req).last.each {} } + assert str.size > 0 + end + + def test_subclassed_string_req + str = StringIO.new + req = {} + @req.each { |key,value| + req[FooString.new(key)] = value.kind_of?(String) ? + FooString.new(value) : value + } + app = lambda { |env| [302, [ %w(a) ], []] } + cl = Clogger.new(app, :logger => str, :format => Rack_1_0) + assert_nothing_raised { cl.call(req).last.each {} } + assert str.size > 0 + end + + def test_subclassed_string_in_body + str = StringIO.new + body = "hello" + r = nil + app = lambda { |env| [302, [ %w(a) ], [FooString.new(body)]] } + cl = Clogger.new(app, :logger => str, :format => '$body_bytes_sent') + assert_nothing_raised { cl.call(@req).last.each { |x| r = x } } + assert str.size > 0 + assert_equal body.size.to_s << "\n", str.string + assert_equal r, body + assert r.object_id != body.object_id + end + def test_http_09_request str = StringIO.new app = lambda { |env| [302, [ %w(a) ], []] } -- cgit v1.2.3-24-ge0c7