From: Eric Wong Date: Fri, 8 Jun 2012 22:37:38 +0000 (-0700) Subject: test case to simulate Rack::BodyProxy usage pattern X-Git-Tag: v1.2.0~5 X-Git-Url: https://repo.or.cz/w/clogger.git/commitdiff_plain/e1bed92891f7db5c2d24040778fe31f76d723efe test case to simulate Rack::BodyProxy usage pattern The use of Rack::BodyProxy#method_missing causes failures under mainline Ruby 1.9.2 and 1.9.1, but not 1.9.3. This test case exists to document this (now-fixed) bug for users stuck on older Rubies. On a side note, our usage of rb_iterate() should be rewritten to use rb_block_call() as rb_iterate() is deprecated in 1.9. A Ruby 1.9.2-p290 user privately reported this issue. --- diff --git a/test/test_clogger.rb b/test/test_clogger.rb index 14613e0..10c587a 100644 --- a/test/test_clogger.rb +++ b/test/test_clogger.rb @@ -481,6 +481,26 @@ class TestClogger < Test::Unit::TestCase assert r.object_id != body.object_id end + # Rack::BodyProxy does this thing with method_missing + # This test fails under MRI 1.9.1 and 1.9.2, but works under 1.9.3 + def test_each_with_external_block + foo = Object.new + foo.instance_variable_set(:@body, ["BodyProxy"]) + def foo.method_missing(*args, &block) + @body.__send__(*args, &block) + end + app = lambda { |env| [302, [], foo] } + str = StringIO.new + cl = Clogger.new(app, :logger => str, :format => '$body_bytes_sent') + r = nil + assert_nothing_raised { r = cl.call(@req) } + body = [] + r[2].each { |x| body << x } + r[2].close + assert_equal %w(BodyProxy), body + assert_equal "9\n", str.string + end + def test_http_09_request str = StringIO.new app = lambda { |env| [302, [ %w(a) ], []] }