Sha256: 8afab5c124d4ab5880ccc08f72ab7c133232ba2f9f5cff603b3ebca51073f964

Contents?: true

Size: 901 Bytes

Versions: 3

Compression:

Stored size: 901 Bytes

Contents

# -*- 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)

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
io_splice-4.2.0 test/test_rack_file_compat.rb
io_splice-4.1.1 test/test_rack_file_compat.rb
io_splice-4.1.0 test/test_rack_file_compat.rb