test/test_clogger.rb in clogger-1.1.0 vs test/test_clogger.rb in clogger-1.2.0

- old
+ new

@@ -479,10 +479,30 @@ assert_equal body.size.to_s << "\n", str.string assert_equal r, body 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) ], []] } cl = Clogger.new(app, :logger => str, :format => '$request') req = @req.dup @@ -814,7 +834,24 @@ cl = Clogger.new(app, :logger => s, :format => format) @req["HTTP_HOST"] = "example.com" status, headers, body = cl.call(@req) expect = "\"GET http://example.com/hello?goodbye=true HTTP/1.0\"\n" assert_equal [ expect ], s + end + + def test_lint_error_wrapper + require 'rack/lobster' + @req["SERVER_NAME"] = "FOO" + @req["SERVER_PORT"] = "666" + @req["rack.version"] = [1,1] + @req["rack.multithread"] = true + @req["rack.multiprocess"] = true + @req["rack.run_once"] = false + app = Rack::ContentLength.new(Rack::ContentType.new(Rack::Lobster.new)) + cl = Clogger.new(app, :format => :Combined) + @req["rack.errors"] = err = StringIO.new + status, headers, body = r = Rack::Lint.new(cl).call(@req) + body.each { |x| assert_kind_of String, x.to_str } + body.close # might raise here + assert_match(%r{GET /hello}, err.string) end end