2009-12-19 03:16:58 +01:00
|
|
|
require 'rack/static'
|
|
|
|
require 'rack/mock'
|
|
|
|
|
|
|
|
class DummyApp
|
|
|
|
def call(env)
|
|
|
|
[200, {}, ["Hello World"]]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-06-14 06:09:24 +02:00
|
|
|
describe Rack::Static do
|
2009-12-19 03:16:58 +01:00
|
|
|
root = File.expand_path(File.dirname(__FILE__))
|
|
|
|
OPTIONS = {:urls => ["/cgi"], :root => root}
|
|
|
|
|
2010-06-14 06:09:24 +02:00
|
|
|
@request = Rack::MockRequest.new(Rack::Static.new(DummyApp.new, OPTIONS))
|
2009-12-19 03:16:58 +01:00
|
|
|
|
2010-06-14 06:09:24 +02:00
|
|
|
it "serves files" do
|
2009-12-19 03:16:58 +01:00
|
|
|
res = @request.get("/cgi/test")
|
|
|
|
res.should.be.ok
|
|
|
|
res.body.should =~ /ruby/
|
|
|
|
end
|
|
|
|
|
2010-06-14 06:09:24 +02:00
|
|
|
it "404s if url root is known but it can't find the file" do
|
2009-12-19 03:16:58 +01:00
|
|
|
res = @request.get("/cgi/foo")
|
|
|
|
res.should.be.not_found
|
|
|
|
end
|
|
|
|
|
2010-06-14 06:09:24 +02:00
|
|
|
it "calls down the chain if url root is not known" do
|
2009-12-19 03:16:58 +01:00
|
|
|
res = @request.get("/something/else")
|
|
|
|
res.should.be.ok
|
|
|
|
res.body.should == "Hello World"
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|