Sha256: f65963c7b9070af5fcef04baeab9a8d42be5cdd6251da2fc0f4a38a5c55e9861

Contents?: true

Size: 1.78 KB

Versions: 52

Compression:

Stored size: 1.78 KB

Contents

require 'test/spec'

require 'rack/cascade'
require 'rack/mock'

require 'rack/urlmap'
require 'rack/file'

context "Rack::Cascade" do
  docroot = File.expand_path(File.dirname(__FILE__))
  app1 = Rack::File.new(docroot)

  app2 = Rack::URLMap.new("/crash" => lambda { |env| raise "boom" })

  app3 = Rack::URLMap.new("/foo" => lambda { |env|
                            [200, { "Content-Type" => "text/plain"}, [""]]})

  specify "should dispatch onward on 404 by default" do
    cascade = Rack::Cascade.new([app1, app2, app3])
    Rack::MockRequest.new(cascade).get("/cgi/test").should.be.ok
    Rack::MockRequest.new(cascade).get("/foo").should.be.ok
    Rack::MockRequest.new(cascade).get("/toobad").should.be.not_found
    Rack::MockRequest.new(cascade).get("/cgi/../bla").should.be.forbidden
  end

  specify "should dispatch onward on whatever is passed" do
    cascade = Rack::Cascade.new([app1, app2, app3], [404, 403])
    Rack::MockRequest.new(cascade).get("/cgi/../bla").should.be.not_found
  end

  specify "should fail if empty" do
    lambda { Rack::MockRequest.new(Rack::Cascade.new([])).get("/") }.
      should.raise(ArgumentError)
  end

  specify "should append new app" do
    cascade = Rack::Cascade.new([], [404, 403])
    lambda { Rack::MockRequest.new(cascade).get('/cgi/test') }.
      should.raise(ArgumentError)
    cascade << app2
    Rack::MockRequest.new(cascade).get('/cgi/test').should.be.not_found
    Rack::MockRequest.new(cascade).get('/cgi/../bla').should.be.not_found
    cascade << app1
    Rack::MockRequest.new(cascade).get('/cgi/test').should.be.ok
    Rack::MockRequest.new(cascade).get('/cgi/../bla').should.be.forbidden
    Rack::MockRequest.new(cascade).get('/foo').should.be.not_found
    cascade << app3
    Rack::MockRequest.new(cascade).get('/foo').should.be.ok
  end
end

Version data entries

52 entries across 52 versions & 13 rubygems

Version Path
merb-core-1.1.0.pre spec10/public/webrat/test_app/gems/gems/rack-0.4.0/test/spec_rack_cascade.rb
middleman-0.10.17 vendor/gems/gems/rack-1.0.1/test/spec_rack_cascade.rb
middleman-0.10.16 vendor/gems/gems/rack-1.0.1/test/spec_rack_cascade.rb
middleman-0.10.15 vendor/gems/gems/rack-1.0.1/test/spec_rack_cascade.rb
rackjour-0.1.8 vendor/gems/gems/rack-1.0.1/test/spec_rack_cascade.rb
middleman-0.10.14 vendor/gems/gems/rack-1.0.1/test/spec_rack_cascade.rb
rack-1.0.1 test/spec_rack_cascade.rb
rack-0.9.0 test/spec_rack_cascade.rb
rack-0.4.0 test/spec_rack_cascade.rb
rack-0.9.1 test/spec_rack_cascade.rb
rack-1.0.0 test/spec_rack_cascade.rb
sinatra-0.2.2 vendor/rack/test/spec_rack_cascade.rb