1
0
Fork 0
mirror of https://github.com/sinatra/sinatra synced 2023-03-27 23:18:01 -04:00
sinatra/test/integration_test.rb

105 lines
2.9 KiB
Ruby
Raw Normal View History

2011-10-31 17:40:22 -04:00
require File.expand_path('../helper', __FILE__)
require File.expand_path('../integration_helper', __FILE__)
2011-10-31 17:40:22 -04:00
2012-03-07 17:05:37 -05:00
# These tests start a real server and talk to it over TCP.
# Every test runs with every detected server.
#
# See test/integration/app.rb for the code of the app we test against.
class IntegrationTest < Minitest::Test
extend IntegrationHelper
attr_accessor :server
it('sets the app_file') { assert_equal server.app_file, server.get("/app_file") }
it('only extends main') { assert_equal "true", server.get("/mainonly") }
2011-10-31 17:59:09 -04:00
it 'logs once in development mode' do
2012-05-13 16:32:18 -04:00
next if server.puma? or RUBY_ENGINE == 'jruby'
random = "%064x" % Kernel.rand(2**256-1)
server.get "/ping?x=#{random}"
count = server.log.scan("GET /ping?x=#{random}").count
if server.net_http_server?
assert_equal 0, count
elsif server.webrick?
assert(count > 0)
else
assert_equal(1, count)
end
2011-10-31 17:59:09 -04:00
end
2012-03-07 16:58:59 -05:00
it 'streams' do
next if server.webrick? or server.trinidad?
times, chunks = [Time.now], []
2012-03-07 16:58:59 -05:00
server.get_stream do |chunk|
next if chunk.empty?
2012-03-07 16:58:59 -05:00
chunks << chunk
times << Time.now
end
assert_equal ["a", "b"], chunks
2012-03-07 16:58:59 -05:00
assert times[1] - times[0] < 1
assert times[2] - times[1] > 1
end
2012-03-08 03:57:08 -05:00
it 'streams async' do
next unless server.thin?
2012-03-08 03:57:08 -05:00
Timeout.timeout(3) do
chunks = []
server.get_stream '/async' do |chunk|
next if chunk.empty?
chunks << chunk
case chunk
when "hi!" then server.get "/send?msg=hello"
when "hello" then server.get "/send?close=1"
end
end
assert_equal ['hi!', 'hello'], chunks
end
end
it 'streams async from subclass' do
next unless server.thin?
2012-03-08 03:57:08 -05:00
Timeout.timeout(3) do
chunks = []
server.get_stream '/subclass/async' do |chunk|
next if chunk.empty?
chunks << chunk
case chunk
when "hi!" then server.get "/subclass/send?msg=hello"
when "hello" then server.get "/subclass/send?close=1"
end
end
assert_equal ['hi!', 'hello'], chunks
end
end
it 'starts the correct server' do
exp = %r{
==\sSinatra\s\(v#{Sinatra::VERSION}\)\s
has\staken\sthe\sstage\son\s\d+\sfor\sdevelopment\s
with\sbackup\sfrom\s#{server}
}ix
2012-03-07 11:15:05 -05:00
2013-03-10 22:27:39 -04:00
# because Net HTTP Server logs to $stderr by default
assert_match exp, server.log unless server.net_http_server?
2012-03-07 11:15:05 -05:00
end
it 'does not generate warnings' do
assert_raises(OpenURI::HTTPError) { server.get '/' }
server.get '/app_file'
2012-03-18 08:22:24 -04:00
assert_equal [], server.warnings
end
it 'sets the Content-Length response header when sending files' do
response = server.get_response '/send_file'
assert response['Content-Length']
end
2013-09-24 18:33:47 -04:00
it "doesn't ignore Content-Length header when streaming" do
response = server.get_response '/streaming'
assert_equal '46', response['Content-Length']
2013-09-24 18:33:47 -04:00
end
end