File: rack_spec.rb

package info (click to toggle)
ruby-mustermann19 0.4.3%2Bgit20160621-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 756 kB
  • ctags: 445
  • sloc: ruby: 7,197; makefile: 3
file content (39 lines) | stat: -rw-r--r-- 1,287 bytes parent folder | download
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
require 'mustermann/router/rack'

describe Mustermann::Router::Rack do
  include Rack::Test::Methods
  subject(:app) { Mustermann::Router::Rack.new }

  context 'matching' do
    before { app.on('/foo') { [418, {'Content-Type' => 'text/plain'}, 'bar'] } }
    example { get('/foo').status.should be == 418 }
    example { get('/bar').status.should be == 404 }
  end

  context "params" do
    before { app.on('/:name') { |e| [200, {'Content-Type' => 'text/plain'}, e['mustermann.params']['name']] } }
    example { get('/foo').body.should be == 'foo' }
    example { get('/bar').body.should be == 'bar' }
  end

  context 'X-Cascade: pass' do
    before do
      app.on('/') { [200, { 'X-Cascade'    => 'pass'       }, ['a']] }
      app.on('/') { [200, { 'x-cascade'    => 'pass'       }, ['b']] }
      app.on('/') { [200, { 'Content-Type' => 'text/plain' }, ['c']] }
      app.on('/') { [200, { 'Content-Type' => 'text/plain' }, ['d']] }
    end

    example { get('/').body.should be == 'c' }
  end

  context 'throw :pass' do
    before do
      app.on('/') { throw :pass }
      app.on('/') { [200, { 'Content-Type' => 'text/plain' }, ['b']] }
      app.on('/') { [200, { 'Content-Type' => 'text/plain' }, ['c']] }
    end

    example { get('/').body.should be == 'b' }
  end
end