2 require File.dirname(__FILE__) + '/../ruby_lib/ebb'
12 Ebb.log = File.open('/dev/null','w')
19 commands = env['PATH_INFO'].split('/')
21 if commands.include?('bytes')
22 n = commands.last.to_i
23 raise "bytes called with n <= 0" if n <= 0
27 elsif commands.include?('test_post_length')
28 input_body = env['rack.input'].read
30 content_length_header = env['HTTP_CONTENT_LENGTH'].to_i
32 if content_length_header == input_body.length
33 body = "Content-Length matches input length"
36 body = "Content-Length header is #{content_length_header} but body length is #{input_body.length}"
42 body = "Undefined url"
45 env['rack.input'] = env['rack.input'].read
46 env.delete('rack.errors')
48 env['status'] = status
50 [status, {'Content-Type' => 'text/json'}, env.to_json]
54 class Test::Unit::TestCase
56 response = Net::HTTP.get_response(URI.parse("http://0.0.0.0:#{TEST_PORT}#{path}"))
60 response = Net::HTTP.post_form(URI.parse("http://0.0.0.0:#{TEST_PORT}#{path}"), data)
64 class ServerTest < Test::Unit::TestCase
66 response = Net::HTTP.get_response(URI.parse("http://0.0.0.0:#{TEST_PORT}#{path}"))
67 env = JSON.parse(response.body)
71 response = Net::HTTP.post_form(URI.parse("http://0.0.0.0:#{TEST_PORT}#{path}"), data)
72 env = JSON.parse(response.body)
76 Thread.new { Ebb.start_server(HelperApp.new, :port => TEST_PORT) }
77 sleep 0.1 until Ebb.running?
82 sleep 0.1 while Ebb.running?