Sha256: 6156665fc7eba6dff013f219c058bbf9269ddbb49eb61c3b27866cebae653ac7
Contents?: true
Size: 1.47 KB
Versions: 4
Compression:
Stored size: 1.47 KB
Contents
require 'test/spec' require 'sinatra/base' require 'sinatra/test' describe 'Static' do include Sinatra::Test F = ::File before do @app = mock_app { set :static, true set :public, F.dirname(__FILE__) } end it 'serves GET requests for files in the public directory' do get "/#{F.basename(__FILE__)}" should.be.ok body.should.equal File.read(__FILE__) response['Content-Length'].should.equal File.size(__FILE__).to_s response.headers.should.include 'Last-Modified' end it 'serves HEAD requests for files in the public directory' do head "/#{F.basename(__FILE__)}" should.be.ok body.should.be.empty response['Content-Length'].should.equal File.size(__FILE__).to_s response.headers.should.include 'Last-Modified' end it 'serves files in preference to custom routes' do @app.get("/#{F.basename(__FILE__)}") { 'Hello World' } get "/#{F.basename(__FILE__)}" should.be.ok body.should.not.equal 'Hello World' end it 'does not serve directories' do get "/" should.be.not_found end it 'passes to the next handler when the static option is disabled' do @app.set :static, false get "/#{F.basename(__FILE__)}" should.be.not_found end it 'passes to the next handler when the public option is nil' do @app.set :public, nil get "/#{F.basename(__FILE__)}" should.be.not_found end it '404s when a file is not found' do get "/foobarbaz.txt" should.be.not_found end end
Version data entries
4 entries across 4 versions & 3 rubygems
Version | Path |
---|---|
adamwiggins-sinatra-0.8.9 | test/static_test.rb |
bmizerany-sinatra-0.9.0 | test/static_test.rb |
rtomayko-sinatra-0.8.9 | test/static_test.rb |
rtomayko-sinatra-0.9.0 | test/static_test.rb |