about summary refs log tree commit homepage
path: root/test/test_rack_file_compat.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/test_rack_file_compat.rb')
-rw-r--r--test/test_rack_file_compat.rb31
1 files changed, 31 insertions, 0 deletions
diff --git a/test/test_rack_file_compat.rb b/test/test_rack_file_compat.rb
new file mode 100644
index 0000000..5505262
--- /dev/null
+++ b/test/test_rack_file_compat.rb
@@ -0,0 +1,31 @@
+# -*- encoding: binary -*-
+require "rack"
+require "test/unit"
+require "socket"
+require "io/splice"
+
+class TestRackFileCompat < Test::Unit::TestCase
+  def setup
+    @app = Rack::File.new(File.dirname(__FILE__))
+    @req = Rack::MockRequest.new(@app)
+    @base_file = File.basename(__FILE__)
+    @r, @w = UNIXSocket.pair
+  end
+
+  def teardown
+    [ @r, @w ].each { |io| io.closed? or io.close }
+  end
+
+  def test_get_rack_file
+    env = Rack::MockRequest.env_for "http://example.com/#@base_file"
+    status, headers, body = @app.call(env)
+    assert_equal 200, status.to_i
+    headers.each { |k,v|
+      assert_instance_of String, k.to_str
+      assert_instance_of String, v.to_str
+    }
+    thr = Thread.new { @r.read(File.size(__FILE__)) }
+    assert_equal File.size(__FILE__), IO::Splice.copy_stream(body, @w)
+    assert_equal File.read(__FILE__), thr.value
+  end
+end if IO.respond_to?(:copy_stream)