File: rack_test.rb

package info (click to toggle)
ruby-sinatra 1.4.5-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,524 kB
  • ctags: 483
  • sloc: ruby: 9,521; makefile: 5
file content (45 lines) | stat: -rw-r--r-- 1,063 bytes parent folder | download | duplicates (3)
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
require File.expand_path('../helper', __FILE__)
require 'rack'

class RackTest < Test::Unit::TestCase
  setup do
    @foo = Sinatra.new { get('/foo') { 'foo' }}
    @bar = Sinatra.new { get('/bar') { 'bar' }}
  end

  def build(*middleware)
    endpoint = middleware.pop
    @app = Rack::Builder.app do
      middleware.each { |m| use m }
      run endpoint
    end
  end

  def check(*middleware)
    build(*middleware)
    assert get('/foo').ok?
    assert_body 'foo'
    assert get('/bar').ok?
    assert_body 'bar'
  end

  it 'works as middleware in front of Rack::Lock, with lock enabled' do
    @foo.enable :lock
    check(@foo, Rack::Lock, @bar)
  end

  it 'works as middleware behind Rack::Lock, with lock enabled' do
    @foo.enable :lock
    check(Rack::Lock, @foo, @bar)
  end

  it 'works as middleware in front of Rack::Lock, with lock disabled' do
    @foo.disable :lock
    check(@foo, Rack::Lock, @bar)
  end

  it 'works as middleware behind Rack::Lock, with lock disabled' do
    @foo.disable :lock
    check(Rack::Lock, @foo, @bar)
  end
end