about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2012-06-08 15:37:38 -0700
committerEric Wong <normalperson@yhbt.net>2012-06-08 15:37:38 -0700
commite1bed92891f7db5c2d24040778fe31f76d723efe (patch)
tree0ba7c0a61ff3816d8f3cfc810d6c1fffc647e69a
parenteaa531a0e014aa8e4318e11b793f8665ce1509d0 (diff)
downloadclogger-e1bed92891f7db5c2d24040778fe31f76d723efe.tar.gz
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.
-rw-r--r--test/test_clogger.rb20
1 files changed, 20 insertions, 0 deletions
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) ], []] }