ry / ebb fork watch download tarball
public this repo is viewable by everyone
Description: web server
Homepage: http://ebb.rubyforge.org
Clone URL: git://github.com/ry/ebb.git
Fix up tests and runner

All ruby tests should pass now.
Ryan Dahl (author)
2 months ago
commit  d2ee83848661e9374c8736cb7411711ba3862c2d
tree    5538b2fef06dd84449375be6cc3608b915a6ea87
parent  7dcfc536c96e944907396069075db87ee422b206
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
 
...
1
2
 
 
 
3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
0
@@ -1,38 +1,4 @@
0
 #!/usr/bin/env ruby
0
 require File.dirname(__FILE__) + '/../ruby_lib/ebb'
0
-require 'optparse'
0
-require 'rubygems'
0
-require 'rack'
0
 
0
-module Rack
0
- module Adapter
0
- autoload :Rails, Ebb::LIBDIR + '/rack/adapter/rails'
0
- end
0
-end
0
-
0
-class EbbRails < Ebb::Runner
0
- def extra_options
0
- # defaults for ebb_rails
0
- @options.update(
0
- :environment => 'development',
0
- :port => 3000,
0
- # rails has a mutex lock around each request - threaded processing
0
- # will only slow things down
0
- :threaded_processing => false
0
- )
0
-
0
- @parser.on("-e", "--env ENV",
0
- "Rails environment (default: development)") do |env|
0
- @options[:environment] = env
0
- end
0
- @parser.on("-c", "--chdir DIR", "RAILS_ROOT directory") do |c|
0
- @options[:root] = c
0
- end
0
- end
0
-
0
- def app(options)
0
- Rack::Adapter::Rails.new(options)
0
- end
0
-end
0
-
0
-EbbRails.new(ARGV).run
0
+Ebb::Runner::Rails.new.run(ARGV)
...
21
22
23
24
 
25
26
27
...
74
75
76
77
78
 
 
79
80
81
82
 
 
 
 
 
 
 
 
83
84
85
...
21
22
23
 
24
25
26
27
...
74
75
76
 
 
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
0
@@ -21,7 +21,7 @@ module Ebb
0
     @running = true
0
     trap('INT') { stop_server }
0
     
0
- puts "Ebb listening at http://0.0.0.0:#{port}/ (#{threaded_processing ? 'threaded' : 'sequential'} processing, PID #{Process.pid})"
0
+ log.puts "Ebb listening at http://0.0.0.0:#{port}/ (#{threaded_processing ? 'threaded' : 'sequential'} processing, PID #{Process.pid})"
0
     
0
     while @running
0
       FFI::server_process_connections()
0
@@ -74,12 +74,20 @@ module Ebb
0
       client.body_written()
0
     end
0
   rescue => e
0
- puts "Ebb Error! #{e.class} #{e.message}"
0
- puts e.backtrace.join("\n")
0
+ log.puts "Ebb Error! #{e.class} #{e.message}"
0
+ log.puts e.backtrace.join("\n")
0
   ensure
0
     client.release
0
   end
0
   
0
+ @@log = STDOUT
0
+ def self.log=(output)
0
+ @@log = output
0
+ end
0
+ def self.log
0
+ @@log
0
+ end
0
+
0
   # This array is created and manipulated in the C extension.
0
   def FFI.waiting_clients
0
     @waiting_clients
...
20
21
22
 
 
 
 
23
24
25
...
28
29
30
31
 
32
33
 
34
35
36
 
37
38
39
...
43
44
45
46
 
47
48
49
50
51
52
 
 
 
53
54
55
...
58
59
60
61
62
 
63
64
65
...
74
75
76
77
 
78
79
80
81
 
82
83
84
85
 
 
 
 
 
86
87
 
88
89
90
 
 
91
92
 
93
94
95
...
105
106
107
108
 
109
110
111
...
114
115
116
117
118
 
 
119
120
121
...
124
125
126
 
...
20
21
22
23
24
25
26
27
28
29
...
32
33
34
 
35
36
 
37
38
39
 
40
41
42
43
...
47
48
49
 
50
51
52
53
54
 
 
55
56
57
58
59
60
...
63
64
65
 
 
66
67
68
69
...
78
79
80
 
81
82
83
84
 
85
86
87
88
 
89
90
91
92
93
94
 
95
96
 
 
97
98
99
 
100
101
102
103
...
113
114
115
 
116
117
118
119
...
122
123
124
 
 
125
126
127
128
129
...
132
133
134
135
0
@@ -20,6 +20,10 @@ end
0
 
0
 module Ebb
0
   class Runner
0
+ # Classes are modules and I hate this 'Base' class pattern. I'm putting
0
+ # other classes inside this one.
0
+ autoload :Rails, LIBDIR + '/ebb/runner/rails'
0
+
0
     # Kill the process which PID is stored in +pid_file+.
0
     def self.kill(pid_file, timeout=60)
0
       raise ArgumentError, 'You must specify a pid_file to stop deamonized server' unless pid_file
0
@@ -28,12 +32,12 @@ module Ebb
0
         pid = pid.to_i
0
         
0
         Process.kill('KILL', pid)
0
- puts "stopped!"
0
+ Ebb.log.puts "stopped!"
0
       else
0
- puts "Can't stop process, no PID found in #{@pid_file}"
0
+ Ebb.log.puts "Can't stop process, no PID found in #{@pid_file}"
0
       end
0
     rescue Errno::ESRCH # No such process
0
- puts "process not found!"
0
+ Ebb.log.puts "process not found!"
0
     ensure
0
       File.delete(pid_file) rescue nil
0
     end
0
@@ -43,13 +47,14 @@ module Ebb
0
     end
0
 
0
     def self.write_pid_file(file)
0
- puts ">> Writing PID to #{file}"
0
+ Ebb.log.puts ">> Writing PID to #{file}"
0
       open(file,"w+") { |f| f.write(Process.pid) }
0
       File.chmod(0644, file)
0
     end
0
     
0
- def initialize(argv)
0
- @argv = argv
0
+ attr_reader :options
0
+
0
+ def initialize
0
       @parser = OptionParser.new
0
       @options = {
0
         :port => 4001,
0
@@ -58,8 +63,7 @@ module Ebb
0
       }
0
     end
0
     
0
-
0
- def run
0
+ def parse_options(argv)
0
       @parser.banner = "Usage: #{self.class} [options] start | stop"
0
       @parser.separator ""
0
       extra_options if respond_to?(:extra_options)
0
@@ -74,22 +78,26 @@ module Ebb
0
       
0
       @parser.separator ""
0
       @parser.on_tail("-h", "--help", "Show this message") do
0
- puts @parser
0
+ Ebb.log.puts @parser
0
         exit
0
       end
0
       @parser.on_tail('-v', '--version', "Show version") do
0
- puts "Ebb #{Ebb::VERSION}"
0
+ Ebb.log.puts "Ebb #{Ebb::VERSION}"
0
         exit
0
       end
0
       
0
- @parser.parse!(@argv)
0
+ @parser.parse!(argv)
0
+ end
0
+
0
+ def run(argv)
0
+ parse_options(argv)
0
       
0
- case @argv[0]
0
+ case argv[0]
0
       when 'start'
0
- STDOUT.print("Ebb is loading the application...")
0
- STDOUT.flush()
0
+ Ebb.log.print("Ebb is loading the application...")
0
+ Ebb.log.flush()
0
         @app = app(@options)
0
- STDOUT.puts("loaded")
0
+ Ebb.log.puts("loaded")
0
         
0
         if @options[:daemonize]
0
           pwd = Dir.pwd # Current directory is changed during daemonization, so store it
0
@@ -105,7 +113,7 @@ module Ebb
0
         if @options[:pid_file]
0
           Runner.write_pid_file(@options[:pid_file])
0
           at_exit do
0
- puts ">> Exiting!"
0
+ Ebb.log.puts ">> Exiting!"
0
             Runner.remove_pid_file(@options[:pid_file])
0
           end
0
         end
0
@@ -114,8 +122,8 @@ module Ebb
0
       when 'stop'
0
         Ebb::Runner.kill @options[:pid_file], @options[:timeout]
0
       when nil
0
- puts "Command required"
0
- puts @parser
0
+ Ebb.log.puts "Command required"
0
+ Ebb.log.puts @parser
0
         exit 1
0
       else
0
         abort "Invalid command : #{argv[0]}"
0
@@ -124,3 +132,4 @@ module Ebb
0
     end
0
   end
0
 end
0
+
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
0
@@ -0,0 +1,34 @@
0
+module Rack
0
+ module Adapter
0
+ autoload :Rails, Ebb::LIBDIR + '/rack/adapter/rails'
0
+ end
0
+end
0
+
0
+module Ebb
0
+ class Runner
0
+ class Rails < Runner
0
+ def extra_options
0
+ # defaults for ebb_rails
0
+ @options.update(
0
+ :environment => 'development',
0
+ :port => 3000,
0
+ # rails has a mutex lock around each request - threaded processing
0
+ # will only slow things down
0
+ :threaded_processing => false
0
+ )
0
+
0
+ @parser.on("-e", "--env ENV",
0
+ "Rails environment (default: development)") do |env|
0
+ @options[:environment] = env
0
+ end
0
+ @parser.on("-c", "--chdir DIR", "RAILS_ROOT directory") do |c|
0
+ @options[:root] = c
0
+ end
0
+ end
0
+
0
+ def app(options)
0
+ Rack::Adapter::Rails.new(options)
0
+ end
0
+ end
0
+ end
0
+end
0
\ No newline at end of file
...
1
 
 
2
3
4
...
1
2
3
4
5
6
0
@@ -1,4 +1,6 @@
0
 require 'cgi'
0
+require 'rubygems'
0
+require 'rack'
0
 
0
 # Adapter to run a Rails app with any supported Rack handler.
0
 # By default it will try to load the Rails application in the
...
1
 
2
3
4
5
6
7
 
8
9
10
11
12
13
 
14
15
16
17
18
19
 
20
21
22
23
24
25
26
 
27
28
29
...
 
1
2
3
4
5
6
 
7
8
9
10
11
12
 
13
14
15
16
17
18
 
19
20
21
22
23
24
25
 
26
27
28
29
0
@@ -1,29 +1,29 @@
0
-require File.dirname(__FILE__) + '/helper'
0
+require File.dirname(__FILE__) + '/helper'
0
 
0
 class BasicTest < ServerTest
0
   def test_get_bytes
0
     [1,10,1000].each do |i|
0
       response = get("/bytes/#{i}")
0
- assert_equal "#{'C'*i.to_i}", response.body
0
+ assert_equal "#{'C'*i.to_i}", response['output']
0
     end
0
   end
0
   
0
   def test_get_unknown
0
     response = get('/blah')
0
- assert_equal "Undefined url", response.body
0
+ assert_equal "Undefined url", response['output']
0
   end
0
   
0
   def test_small_posts
0
     [1,10,321,123,1000].each do |i|
0
       response = post("/test_post_length", 'C'*i)
0
- assert_equal 200, response.code.to_i, response.body
0
+ assert_equal 200, response['status']
0
     end
0
   end
0
   
0
   def test_large_post
0
     [50,60,100].each do |i|
0
       response = post("/test_post_length", 'C'*1024*i)
0
- assert_equal 200, response.code.to_i, response.body
0
+ assert_equal 200, response['status']
0
     end
0
   end
0
 end
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
0
@@ -0,0 +1,34 @@
0
+require File.dirname(__FILE__) + '/helper'
0
+
0
+APP_DIR = File.dirname(__FILE__) + "/rails_app"
0
+EBB_RAILS = "#{Ebb::LIBDIR}/../bin/ebb_rails"
0
+class EbbRailsTest < Test::Unit::TestCase
0
+ # just to make sure there isn't some load error
0
+ def test_version
0
+ out = %x{ruby #{EBB_RAILS} -v}
0
+ assert_match %r{Ebb #{Ebb::VERSION}}, out
0
+ end
0
+
0
+ def test_parser
0
+ runner = Ebb::Runner::Rails.new
0
+ runner.parse_options("start -c #{APP_DIR} -p #{TEST_PORT}".split)
0
+ assert_equal TEST_PORT, runner.options[:port].to_i
0
+ assert_equal APP_DIR, runner.options[:root]
0
+ end
0
+
0
+
0
+ def test_start_app
0
+ Thread.new do
0
+ runner = Ebb::Runner::Rails.new
0
+ runner.run("start -c #{APP_DIR} -p #{TEST_PORT}".split)
0
+ end
0
+ sleep 0.1 until Ebb.running?
0
+
0
+ response = get '/'
0
+ assert_equal 200, response.code.to_i
0
+
0
+ ensure
0
+ Ebb.stop_server
0
+ sleep 0.1 while Ebb.running?
0
+ end
0
+end
0
\ No newline at end of file
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0
@@ -1,15 +0,0 @@
0
-require 'rubygems'
0
-require 'json'
0
-require File.dirname(__FILE__) + '/../ruby_lib/ebb'
0
-
0
-
0
-class EchoApp
0
- def call(env)
0
- env['rack.input'] = env['rack.input'].read(1000000)
0
- env.delete('rack.errors')
0
- [200, {'Content-Type' => 'text/json'}, env.to_json]
0
- end
0
-end
0
-
0
-
0
-server = Ebb::start_server(EchoApp.new, :port => 4037, :workers => 10)
...
 
1
2
3
4
5
6
7
8
9
10
11
12
13
 
14
15
16
...
36
37
38
39
 
40
41
42
...
48
49
50
51
 
52
53
54
55
56
57
58
 
59
60
61
...
69
70
71
72
 
73
74
75
...
1
2
3
4
5
6
 
 
 
 
 
 
7
 
8
9
10
11
...
31
32
33
 
34
35
36
37
...
43
44
45
 
46
47
48
49
50
51
52
 
53
54
55
56
...
64
65
66
 
67
68
69
70
0
@@ -1,16 +1,11 @@
0
+require File.dirname(__FILE__) + '/helper'
0
 require 'socket'
0
 require 'rubygems'
0
 require 'json'
0
 require 'test/unit'
0
 
0
-PORT = 4037
0
-
0
-# This test depends on echo_server running at port 4037. I do this so that
0
-# I can run a Python server at that port with a similar application and reuse
0
-# these tests.
0
-
0
 def send_request(request_string)
0
- socket = TCPSocket.new("0.0.0.0", PORT)
0
+ socket = TCPSocket.new("0.0.0.0", TEST_PORT)
0
   socket.write(request_string)
0
   lines = []
0
   out = socket.read(5000000)
0
@@ -36,7 +31,7 @@ def drops_request?(request_string)
0
   :fail == send_request(request_string)
0
 end
0
 
0
-class HttpParserTest < Test::Unit::TestCase
0
+class HttpParserTest < ServerTest
0
   
0
   def test_parse_simple
0
     env = send_request("GET / HTTP/1.1\r\n\r\n")
0
@@ -48,14 +43,14 @@ class HttpParserTest < Test::Unit::TestCase
0
     assert_equal 'GET', env['REQUEST_METHOD']
0
     assert_nil env['FRAGMENT']
0
     assert_nil env['QUERY_STRING']
0
- assert_nil env['rack.input']
0
+ assert_equal "", env['rack.input']
0
   end
0
   
0
   def test_parse_dumbfuck_headers
0
     should_be_good = "GET / HTTP/1.1\r\naaaaaaaaaaaaa:++++++++++\r\n\r\n"
0
     env = send_request(should_be_good)
0
     assert_equal "++++++++++", env["HTTP_AAAAAAAAAAAAA"]
0
- assert_nil env['rack.input']
0
+ assert_equal "", env['rack.input']
0
     
0
     nasty_pound_header = "GET / HTTP/1.1\r\nX-SSL-Bullshit: -----BEGIN CERTIFICATE-----\r\n\tMIIFbTCCBFWgAwIBAgICH4cwDQYJKoZIhvcNAQEFBQAwcDELMAkGA1UEBhMCVUsx\r\n\tETAPBgNVBAoTCGVTY2llbmNlMRIwEAYDVQQLEwlBdXRob3JpdHkxCzAJBgNVBAMT\r\n\tAkNBMS0wKwYJKoZIhvcNAQkBFh5jYS1vcGVyYXRvckBncmlkLXN1cHBvcnQuYWMu\r\n\tdWswHhcNMDYwNzI3MTQxMzI4WhcNMDcwNzI3MTQxMzI4WjBbMQswCQYDVQQGEwJV\r\n\tSzERMA8GA1UEChMIZVNjaWVuY2UxEzARBgNVBAsTCk1hbmNoZXN0ZXIxCzAJBgNV\r\n\tBAcTmrsogriqMWLAk1DMRcwFQYDVQQDEw5taWNoYWVsIHBhcmQYJKoZIhvcNAQEB\r\n\tBQADggEPADCCAQoCggEBANPEQBgl1IaKdSS1TbhF3hEXSl72G9J+WC/1R64fAcEF\r\n\tW51rEyFYiIeZGx/BVzwXbeBoNUK41OK65sxGuflMo5gLflbwJtHBRIEKAfVVp3YR\r\n\tgW7cMA/s/XKgL1GEC7rQw8lIZT8RApukCGqOVHSi/F1SiFlPDxuDfmdiNzL31+sL\r\n\t0iwHDdNkGjy5pyBSB8Y79dsSJtCW/iaLB0/n8Sj7HgvvZJ7x0fr+RQjYOUUfrePP\r\n\tu2MSpFyf+9BbC/aXgaZuiCvSR+8Snv3xApQY+fULK/xY8h8Ua51iXoQ5jrgu2SqR\r\n\twgA7BUi3G8LFzMBl8FRCDYGUDy7M6QaHXx1ZWIPWNKsCAwEAAaOCAiQwggIgMAwG\r\n\tA1UdEwEB/wQCMAAwEQYJYIZIAYb4QgEBBAQDAgWgMA4GA1UdDwEB/wQEAwID6DAs\r\n\tBglghkgBhvhCAQ0EHxYdVUsgZS1TY2llbmNlIFVzZXIgQ2VydGlmaWNhdGUwHQYD\r\n\tVR0OBBYEFDTt/sf9PeMaZDHkUIldrDYMNTBZMIGaBgNVHSMEgZIwgY+AFAI4qxGj\r\n\tloCLDdMVKwiljjDastqooXSkcjBwMQswCQYDVQQGEwJVSzERMA8GA1UEChMIZVNj\r\n\taWVuY2UxEjAQBgNVBAsTCUF1dGhvcml0eTELMAkGA1UEAxMCQ0ExLTArBgkqhkiG\r\n\t9w0BCQEWHmNhLW9wZXJhdG9yQGdyaWQtc3VwcG9ydC5hYy51a4IBADApBgNVHRIE\r\n\tIjAggR5jYS1vcGVyYXRvckBncmlkLXN1cHBvcnQuYWMudWswGQYDVR0gBBIwEDAO\r\n\tBgwrBgEEAdkvAQEBAQYwPQYJYIZIAYb4QgEEBDAWLmh0dHA6Ly9jYS5ncmlkLXN1\r\n\tcHBvcnQuYWMudmT4sopwqlBWsvcHViL2NybC9jYWNybC5jcmwwPQYJYIZIAYb4QgEDBDAWLmh0\r\n\tdHA6Ly9jYS5ncmlkLXN1cHBvcnQuYWMudWsvcHViL2NybC9jYWNybC5jcmwwPwYD\r\n\tVR0fBDgwNjA0oDKgMIYuaHR0cDovL2NhLmdyaWQt5hYy51ay9wdWIv\r\n\tY3JsL2NhY3JsLmNybDANBgkqhkiG9w0BAQUFAAOCAQEAS/U4iiooBENGW/Hwmmd3\r\n\tXCy6Zrt08YjKCzGNjorT98g8uGsqYjSxv/hmi0qlnlHs+k/3Iobc3LjS5AMYr5L8\r\n\tUO7OSkgFFlLHQyC9JzPfmLCAugvzEbyv4Olnsr8hbxF1MbKZoQxUZtMVu29wjfXk\r\n\thTeApBv7eaKCWpSp7MCbvgzm74izKhu3vlDk9w6qVrxePfGgpKPqfHiOoGhFnbTK\r\n\twTC6o2xq5y0qZ03JonF7OJspEd3I5zKY3E+ov7/ZhW6DqT8UFvsAdjvQbXyhV8Eu\r\n\tYhixw1aKEPzNjNowuIseVogKOLXxWI5vAi5HgXdS0/ES5gDGsABo4fqovUKlgop3\r\n\tRA==\r\n\t-----END CERTIFICATE-----\r\n\r\n"
0
     assert drops_request?(nasty_pound_header) # Correct?
0
@@ -69,7 +64,7 @@ class HttpParserTest < Test::Unit::TestCase
0
     env = send_request("GET /forums/1/topics/2375?page=1#posts-17408 HTTP/1.1\r\n\r\n")
0
     assert_equal '/forums/1/topics/2375?page=1', env['REQUEST_URI']
0
     assert_equal 'posts-17408', env['FRAGMENT']
0
- assert_nil env['rack.input']
0
+ assert_equal "", env['rack.input']
0
   end
0
   
0
   # lame random garbage maker
...
5
6
7
 
 
8
9
 
 
10
11
12
13
14
15
16
17
18
19
20
21
22
...
40
41
42
43
 
44
45
46
47
48
49
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
51
52
53
 
 
 
 
 
 
 
 
 
 
54
55
56
...
60
61
62
 
 
 
 
63
...
5
6
7
8
9
10
 
11
12
13
14
15
 
 
 
 
 
 
 
16
17
18
...
36
37
38
 
39
40
41
42
43
44
 
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
...
81
82
83
84
85
86
87
88
0
@@ -5,18 +5,14 @@ require 'net/http'
0
 require 'socket'
0
 require 'rubygems'
0
 require 'json'
0
+require 'ruby-debug'
0
+Debugger.start
0
 
0
-include Ebb
0
+
0
+Ebb.log = File.open('/dev/null','w')
0
 
0
 TEST_PORT = 4044
0
 
0
-def get(path)
0
- Net::HTTP.get_response(URI.parse("http://0.0.0.0:#{TEST_PORT}#{path}"))
0
-end
0
-
0
-def post(path, data)
0
- Net::HTTP.post_form(URI.parse("http://0.0.0.0:#{TEST_PORT}#{path}"), data)
0
-end
0
 
0
 class HelperApp
0
   def call(env)
0
@@ -40,17 +36,42 @@ class HelperApp
0
         body = "Content-Length header is #{content_length_header} but body length is #{input_body.length}"
0
         status = 500
0
       end
0
-
0
+
0
     else
0
       status = 404
0
       body = "Undefined url"
0
     end
0
     
0
- [status, {'Content-Type' => 'text/plain'}, body]
0
+ env['rack.input'] = env['rack.input'].read
0
+ env.delete('rack.errors')
0
+ env['output'] = body
0
+ env['status'] = status
0
+
0
+ [status, {'Content-Type' => 'text/json'}, env.to_json]
0
+ end
0
+end
0
+
0
+class Test::Unit::TestCase
0
+ def get(path)
0
+ response = Net::HTTP.get_response(URI.parse("http://0.0.0.0:#{TEST_PORT}#{path}"))
0
+ end
0
+
0
+ def post(path, data)
0
+ response = Net::HTTP.post_form(URI.parse("http://0.0.0.0:#{TEST_PORT}#{path}"), data)
0
   end
0
 end
0
 
0
 class ServerTest < Test::Unit::TestCase
0
+ def get(path)
0
+ response = Net::HTTP.get_response(URI.parse("http://0.0.0.0:#{TEST_PORT}#{path}"))
0
+ env = JSON.parse(response.body)
0
+ end
0
+
0
+ def post(path, data)
0
+ response = Net::HTTP.post_form(URI.parse("http://0.0.0.0:#{TEST_PORT}#{path}"), data)
0
+ env = JSON.parse(response.body)
0
+ end
0
+
0
   def setup
0
     Thread.new { Ebb.start_server(HelperApp.new, :port => TEST_PORT) }
0
     sleep 0.1 until Ebb.running?
0
@@ -60,4 +81,8 @@ class ServerTest < Test::Unit::TestCase
0
     Ebb.stop_server
0
     sleep 0.1 while Ebb.running?
0
   end
0
+
0
+ def default_test
0
+ assert true
0
+ end
0
 end
...
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
0
@@ -0,0 +1,10 @@
0
+# Filters added to this controller apply to all controllers in the application.
0
+# Likewise, all the methods added will be available for all controllers.
0
+
0
+class ApplicationController < ActionController::Base
0
+ helper :all # include all helpers, all the time
0
+
0
+ # See ActionController::RequestForgeryProtection for details
0
+ # Uncomment the :secret if you're not using the cookie session store
0
+ # protect_from_forgery # :secret => 'a8af303b8dabf2d2d8f1a7912ac04d7d'
0
+end
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
0
@@ -0,0 +1,19 @@
0
+class SimpleController < ApplicationController
0
+ caches_page :cached
0
+
0
+ def index
0
+ end
0
+
0
+ def post_form
0
+ render :text => params.to_yaml
0
+ end
0
+
0
+ def set_cookie
0
+ cookies[params[:name]] = params[:value] if params[:name]
0
+ render :text => cookies.to_yaml
0
+ end
0
+
0
+ def cached
0
+ render :text => params[:value]
0
+ end
0
+end
...
 
 
 
...
1
2
3
0
@@ -0,0 +1,3 @@
0
+# Methods added to this helper will be available to all templates in the application.
0
+module ApplicationHelper
0
+end
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
0
@@ -0,0 +1,15 @@
0
+<h1>Simple#index</h1>
0
+
0
+<h2>ENV</h2>
0
+<%= request.env.to_yaml %>
0
+
0
+<h2>Cookies</h2>
0
+<%= request.cookies.to_yaml %>
0
+
0
+<h2>Params</h2>
0
+<%= params.to_yaml %>
0
+
0
+<% form_tag '/simple' do %>
0
+ <%= text_field_tag :a %>
0
+ <%= submit_tag 'Submit' %>
0
+<% end %>
0
\ No newline at end of file
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
0
@@ -0,0 +1,109 @@
0
+# Don't change this file!
0
+# Configure your app in config/environment.rb and config/environments/*.rb
0
+
0
+RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)
0
+
0
+module Rails
0
+ class << self
0
+ def boot!
0
+ unless booted?
0
+ preinitialize
0
+ pick_boot.run
0
+ end
0
+ end
0
+
0
+ def booted?
0
+ defined? Rails::Initializer
0
+ end
0
+
0
+ def pick_boot
0
+ (vendor_rails? ? VendorBoot : GemBoot).new
0
+ end
0
+
0
+ def vendor_rails?
0
+ File.exist?("#{RAILS_ROOT}/vendor/rails")
0
+ end
0
+
0
+ # FIXME : Ruby 1.9
0
+ def preinitialize
0
+ load(preinitializer_path) if File.exists?(preinitializer_path)
0
+ end
0
+
0
+ def preinitializer_path
0
+ "#{RAILS_ROOT}/config/preinitializer.rb"
0
+ end
0
+ end
0
+
0
+ class Boot
0
+ def run
0
+ load_initializer
0
+ Rails::Initializer.run(:set_load_path)
0
+ end
0
+ end
0
+
0
+ class VendorBoot < Boot
0
+ def load_initializer
0
+ require "#{RAILS_ROOT}/vendor/rails/railties/lib/initializer"
0
+ end
0
+ end
0
+
0
+ class GemBoot < Boot
0
+ def load_initializer
0
+ self.class.load_rubygems
0
+ load_rails_gem
0
+ require 'initializer'
0
+ end
0
+
0
+ def load_rails_gem
0
+ if version = self.class.gem_version
0
+ gem 'rails', version
0
+ else
0
+ gem 'rails'
0
+ end
0
+ rescue Gem::LoadError => load_error
0
+ $stderr.puts %(Missing the Rails #{version} gem. Please `gem install -v=#{version} rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.)
0
+ exit 1
0
+ end
0
+
0
+ class << self
0
+ def rubygems_version
0
+ Gem::RubyGemsVersion if defined? Gem::RubyGemsVersion
0
+ end
0
+
0
+ def gem_version
0
+ if defined? RAILS_GEM_VERSION
0
+ RAILS_GEM_VERSION
0
+ elsif ENV.include?('RAILS_GEM_VERSION')
0
+ ENV['RAILS_GEM_VERSION']
0
+ else
0
+ parse_gem_version(read_environment_rb)
0
+ end
0
+ end
0
+
0
+ def load_rubygems
0
+ require 'rubygems'
0
+
0
+ unless rubygems_version >= '0.9.4'
0
+ $stderr.puts %(Rails requires RubyGems >= 0.9.4 (you have #{rubygems_version}). Please `gem update --system` and try again.)
0
+ exit 1
0
+ end
0
+
0
+ rescue LoadError
0
+ $stderr.puts %(Rails requires RubyGems >= 0.9.4. Please install RubyGems and try again: http://rubygems.rubyforge.org)
0
+ exit 1
0
+ end
0
+
0
+ def parse_gem_version(text)
0
+ $1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/
0
+ end
0
+
0
+ private
0
+ def read_environment_rb
0
+ File.read("#{RAILS_ROOT}/config/environment.rb")
0
+ end
0
+ end
0
+ end
0
+end
0
+
0
+# All that for this:
0
+Rails.boot!
...
 
 
 
 
 
 
 
 
 
 
0
...
1
2
3
4
5
6
7
8
9
10
11
0
@@ -0,0 +1,10 @@
0
+#!/usr/local/bin/ruby
0
+
0
+require File.dirname(__FILE__) + "/../config/environment" unless defined?(RAILS_ROOT)
0
+
0
+# If you're using RubyGems and mod_ruby, this require should be changed to an absolute path one, like:
0
+# "/usr/local/lib/ruby/gems/1.8/gems/rails-0.8.0/lib/dispatcher" -- otherwise performance is severely impaired
0
+require "dispatcher"
0
+
0
+ADDITIONAL_LOAD_PATHS.reverse.each { |dir| $:.unshift(dir) if File.directory?(dir) } if defined?(Apache::RubyRun)
0
+Dispatcher.dispatch
0
\ No newline at end of file
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 <