vendor/rack/test/spec_rack_mongrel.rb in relevance-castronaut-0.5.4 vs vendor/rack/test/spec_rack_mongrel.rb in relevance-castronaut-0.6.0
- old
+ new
@@ -3,11 +3,12 @@
begin
require 'rack/handler/mongrel'
require 'rack/urlmap'
require 'rack/lint'
require 'testrequest'
-
+require 'timeout'
+
Thread.abort_on_exception = true
$tcp_defer_accept_opts = nil
$tcp_cork_opts = nil
context "Rack::Handler::Mongrel" do
@@ -15,10 +16,12 @@
setup do
server = Mongrel::HttpServer.new(@host='0.0.0.0', @port=9201)
server.register('/test',
Rack::Handler::Mongrel.new(Rack::Lint.new(TestRequest.new)))
+ server.register('/stream',
+ Rack::Handler::Mongrel.new(Rack::Lint.new(StreamingRequest)))
@acc = server.run
end
specify "should respond" do
lambda {
@@ -156,9 +159,25 @@
block_ran = true
}
}
sleep 1
block_ran.should.be true
+ end
+
+ specify "should stream #each part of the response" do
+ body = ''
+ begin
+ Timeout.timeout(1) do
+ Net::HTTP.start(@host, @port) do |http|
+ get = Net::HTTP::Get.new('/stream')
+ http.request(get) do |response|
+ response.read_body { |part| body << part }
+ end
+ end
+ end
+ rescue Timeout::Error
+ end
+ body.should.not.be.empty
end
teardown do
@acc.raise Mongrel::StopServer
end