Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 74 lines (63 sloc) 2.353 kb
923e9339 » raggi
2011-05-02 Add some basic Rack::Server tests, nothing like the oldies, but faster
1 require 'rack'
c73b4745 » lsegal
2010-06-19 Rack::Server should accept :app and override :config.
2 require 'rack/server'
923e9339 » raggi
2011-05-02 Add some basic Rack::Server tests, nothing like the oldies, but faster
3 require 'tempfile'
4 require 'socket'
5 require 'open-uri'
c73b4745 » lsegal
2010-06-19 Rack::Server should accept :app and override :config.
6
7 describe Rack::Server do
923e9339 » raggi
2011-05-02 Add some basic Rack::Server tests, nothing like the oldies, but faster
8
9 def app
a9beb476 » raggi
2011-05-02 1.9 lambdas care (yep, they're emo - rock on.)
10 lambda { |env| [200, {'Content-Type' => 'text/plain'}, ['success']] }
923e9339 » raggi
2011-05-02 Add some basic Rack::Server tests, nothing like the oldies, but faster
11 end
12
c73b4745 » lsegal
2010-06-19 Rack::Server should accept :app and override :config.
13 it "overrides :config if :app is passed in" do
14 server = Rack::Server.new(:app => "FOO")
15 server.app.should == "FOO"
16 end
923e9339 » raggi
2011-05-02 Add some basic Rack::Server tests, nothing like the oldies, but faster
17
18 should "not include Rack::Lint in deployment or none environments" do
19 server = Rack::Server.new(:app => 'foo')
20 server.middleware['deployment'].flatten.should.not.include(Rack::Lint)
21 server.middleware['none'].flatten.should.not.include(Rack::Lint)
22 end
23
24 should "not include Rack::ShowExceptions in deployment or none environments" do
25 server = Rack::Server.new(:app => 'foo')
26 server.middleware['deployment'].flatten.should.not.include(Rack::ShowExceptions)
27 server.middleware['none'].flatten.should.not.include(Rack::ShowExceptions)
28 end
29
30 should "support CGI" do
31 begin
32 o, ENV["REQUEST_METHOD"] = ENV["REQUEST_METHOD"], 'foo'
33 server = Rack::Server.new(:app => 'foo')
34 server.server.name =~ /CGI/
35 Rack::Server.logging_middleware.call(server).should.eql(nil)
36 ensure
37 ENV['REQUEST_METHOD'] = o
38 end
39 end
40
41 should "not force any middleware under the none configuration" do
42 server = Rack::Server.new(:app => 'foo')
43 server.middleware['none'].should.be.empty
44 end
45
46 should "use a full path to the pidfile" do
47 # avoids issues with daemonize chdir
48 opts = Rack::Server.new.send(:parse_options, %w[--pid testing.pid])
49 opts[:pid].should.eql(::File.expand_path('testing.pid'))
50 end
51
52 should "run a server" do
53 pidfile = Tempfile.open('pidfile') { |f| break f }.path
54 FileUtils.rm pidfile
55 server = Rack::Server.new(
56 :app => app,
57 :environment => 'none',
58 :pid => pidfile,
59 :Port => TCPServer.open('127.0.0.1', 0){|s| s.addr[1] },
60 :Host => '127.0.0.1',
61 :daemonize => false,
62 :server => 'webrick'
63 )
2f060084 » raggi
2011-12-21 Rack::Server#start passes any given block through to Handler#run.
64 t = Thread.new { server.start { |s| Thread.current[:server] = s } }
65 t.join(0.01) until t[:server] && t[:server].status != :Stop
923e9339 » raggi
2011-05-02 Add some basic Rack::Server tests, nothing like the oldies, but faster
66 body = open("http://127.0.0.1:#{server.options[:Port]}/") { |f| f.read }
67 body.should.eql('success')
68
69 Process.kill(:INT, $$)
70 t.join
71 open(pidfile) { |f| f.read.should.eql $$.to_s }
72 end
73
c73b4745 » lsegal
2010-06-19 Rack::Server should accept :app and override :config.
74 end
Something went wrong with that request. Please try again.