static files
[sinatra.git] / test / static_test.rb
blobd8462fa0c6558c3328c5280cad8cda0cf007d8de
1 require File.dirname(__FILE__) + '/helper'
3 context "Static" do
4   
5   setup do
6     Sinatra.routes.clear
7     Sinatra.config = nil
8     Sinatra.setup_default_events!
9     
10     Sinatra.config[:root] = File.dirname(__FILE__)
11   end
12   
13   specify "sends files" do
14     
15     get_it '/foo.xml'
16     
17     should.be.ok
18     body.should.equal '<foo></foo>'
19     headers.should.equal 'Content-Type' => 'application/xml',
20                          'Content-Length' => '<foo></foo>'.size
21     
22   end
23   
24   specify "defaults to text/plain" do
25     
26     get_it '/foo.foo'
27     
28     should.be.ok
29     body.should.equal 'bar'
30     headers.should.equal 'Content-Type' => 'text/plain',
31                          'Content-Length' => 'bar'.size
32   end
33   
34   specify "default to user definied type" do
35     Sinatra.config[:default_static_mime_type] = 'foo/bar'
36     
37     get_it '/foo.foo'
38     
39     should.be.ok
40     body.should.equal 'bar'
41     headers.should.equal 'Content-Type' => 'foo/bar',
42                          'Content-Length' => 'bar'.size
43   end
44   
45   specify "handles files without ext" do
46     get_it '/xyz'
47     
48     should.be.ok
49     body.should.equal 'abc'
50     headers.should.equal 'Content-Type' => 'text/plain',
51                          'Content-Length' => 'bar'.size
52   end
53   
54   specify "should handle javascript correctly" do
55     
56     get_it '/test.js'
57       
58     should.be.ok
59     body.should.equal 'var i = 11;'
60     headers.should.equal 'Content-Type' => 'text/javascript',
61                          'Content-Length' => 'var i = 11;'.size
62     
63   end
64   
65 end