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

69 lines
2.1 KiB
Ruby
Raw Normal View History

2011-10-31 14:40:22 -07:00
require File.expand_path('../helper', __FILE__)
require File.expand_path('../integration_helper', __FILE__)
2011-10-31 14:40:22 -07:00
2012-03-07 23:05:37 +01: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 14:59:09 -07:00
it 'logs once in development mode' do
next if server.puma? or server.rainbows? 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
2016-01-31 20:51:16 +09:00
if server.net_http_server? || server.reel?
assert_equal 0, count
elsif server.webrick?
assert(count > 0)
else
assert_equal(1, count)
end
2011-10-31 14:59:09 -07:00
end
2012-03-07 22:58:59 +01:00
it 'streams' do
next if server.webrick? or server.trinidad?
times, chunks = [Time.now], []
2012-03-07 22:58:59 +01:00
server.get_stream do |chunk|
next if chunk.empty?
2012-03-07 22:58:59 +01:00
chunks << chunk
times << Time.now
end
assert_equal ["a", "b"], chunks
2012-03-07 22:58:59 +01:00
assert times[1] - times[0] < 1
assert times[2] - times[1] > 1
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 17:15:05 +01:00
2013-03-10 23:27:39 -03:00
# because Net HTTP Server logs to $stderr by default
assert_match exp, server.log unless server.net_http_server? || server.reel? || server.rainbows?
2012-03-07 17:15:05 +01:00
end
it 'does not generate warnings' do
assert_raises(OpenURI::HTTPError) { server.get '/' }
server.get '/app_file'
assert_equal [], server.warnings unless server.reel?
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-25 02: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-25 02:33:47 +04:00
end
end