File: builder_spec.rb

package info (click to toggle)
thin 2.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,356 kB
  • sloc: javascript: 6,108; ruby: 5,126; ansic: 1,738; sh: 21; makefile: 8
file content (49 lines) | stat: -rw-r--r-- 1,219 bytes parent folder | download | duplicates (5)
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
require 'spec_helper'

describe Server, 'app builder' do

  before :all do
    Logging.debug = false
  end

  it "should build app from constructor" do
    app = proc {}
    server = Server.new('0.0.0.0', 3000, app)
    
    expect(server.app).to eq(app)
  end
  
  it "should build app from builder block" do
    server = Server.new '0.0.0.0', 3000 do
      run(proc { |env| :works })
    end
    
    expect(server.app.call({})).to eq(:works)
  end
  
  it "should use middlewares in builder block" do
    server = Server.new '0.0.0.0', 3000 do
      use Rack::ShowExceptions
      run(proc { |env| :works })
    end
    
    expect(server.app.class).to eq(Rack::ShowExceptions)
    expect(server.app.call({})).to eq(:works)
  end
  
  it "should work with Rack url mapper" do
    server = Server.new '0.0.0.0', 3000 do
      map '/test' do
        run(proc { |env| [200, {}, 'Found /test'] })
      end
    end
    
    default_env = { 'SCRIPT_NAME' => '' }
    
    expect(server.app.call(default_env.update('PATH_INFO' => '/'))[0]).to eq(404)
    
    status, headers, body = server.app.call(default_env.update('PATH_INFO' => '/test'))
    expect(status).to eq(200)
    expect(body).to eq('Found /test')
  end
end