2 require File.dirname(__FILE__) + '/../ruby_lib/ebb'
10 Ebb.log = File.open('/dev/null','w')
17 commands = env['PATH_INFO'].split('/')
19 if commands.include?('bytes')
20 n = commands.last.to_i
21 raise "bytes called with n <= 0" if n <= 0
25 elsif commands.include?('test_post_length')
26 input_body = env['rack.input'].read
28 content_length_header = env['CONTENT_LENGTH'].to_i
30 if content_length_header == input_body.length
31 body = "Content-Length matches input length"
34 body = "Content-Length header is #{content_length_header} but body length is #{input_body.length}"
40 body = "Undefined url"
43 env['rack.input'] = env['rack.input'].read
44 env.delete('rack.errors')
46 env['status'] = status
48 [status, {'Content-Type' => 'text/json'}, env.to_json]
52 class Test::Unit::TestCase
54 response = Net::HTTP.get_response(URI.parse("http://0.0.0.0:#{TEST_PORT}#{path}"))
58 response = Net::HTTP.post_form(URI.parse("http://0.0.0.0:#{TEST_PORT}#{path}"), data)
62 class ServerTest < Test::Unit::TestCase
64 response = Net::HTTP.get_response(URI.parse("http://0.0.0.0:#{TEST_PORT}#{path}"))
65 env = JSON.parse(response.body)
69 response = Net::HTTP.post_form(URI.parse("http://0.0.0.0:#{TEST_PORT}#{path}"), data)
70 env = JSON.parse(response.body)
74 Thread.new { Ebb.start_server(HelperApp.new, :port => TEST_PORT) }
75 sleep 0.1 until Ebb.running?
80 sleep 0.1 while Ebb.running?
88 class ServerTestFD < ServerTest
90 @tcp_server = TCPServer.new('0.0.0.0', TEST_PORT);
91 Thread.new { Ebb.start_server(HelperApp.new, :fileno => @tcp_server.fileno) }
92 sleep 0.1 until Ebb.running?