2009-12-19 03:16:58 +01:00
|
|
|
require 'rack/cascade'
|
|
|
|
require 'rack/file'
|
2010-06-14 06:09:24 +02:00
|
|
|
require 'rack/urlmap'
|
|
|
|
require 'rack/mock'
|
2009-12-19 03:16:58 +01:00
|
|
|
|
2010-06-14 06:09:24 +02:00
|
|
|
describe Rack::Cascade do
|
2009-12-19 03:16:58 +01:00
|
|
|
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"}, [""]]})
|
|
|
|
|
2010-06-14 06:09:24 +02:00
|
|
|
should "dispatch onward on 404 by default" do
|
2009-12-19 03:16:58 +01:00
|
|
|
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
|
|
|
|
|
2010-06-14 06:09:24 +02:00
|
|
|
should "dispatch onward on whatever is passed" do
|
2009-12-19 03:16:58 +01:00
|
|
|
cascade = Rack::Cascade.new([app1, app2, app3], [404, 403])
|
|
|
|
Rack::MockRequest.new(cascade).get("/cgi/../bla").should.be.not_found
|
|
|
|
end
|
|
|
|
|
2010-06-14 06:09:24 +02:00
|
|
|
should "return 404 if empty" do
|
2009-12-26 21:00:18 +01:00
|
|
|
Rack::MockRequest.new(Rack::Cascade.new([])).get('/').should.be.not_found
|
2009-12-19 03:16:58 +01:00
|
|
|
end
|
|
|
|
|
2010-06-14 06:09:24 +02:00
|
|
|
should "append new app" do
|
2009-12-19 03:16:58 +01:00
|
|
|
cascade = Rack::Cascade.new([], [404, 403])
|
2009-12-26 21:00:18 +01:00
|
|
|
Rack::MockRequest.new(cascade).get('/').should.be.not_found
|
2009-12-19 03:16:58 +01:00
|
|
|
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
|