rack 1.1.6 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rack might be problematic. Click here for more details.

Files changed (105) hide show
  1. data/README +9 -205
  2. data/SPEC +3 -3
  3. data/lib/rack.rb +1 -24
  4. data/lib/rack/auth/abstract/request.rb +1 -5
  5. data/lib/rack/auth/digest/md5.rb +1 -2
  6. data/lib/rack/auth/digest/params.rb +1 -1
  7. data/lib/rack/content_length.rb +1 -1
  8. data/lib/rack/etag.rb +15 -6
  9. data/lib/rack/file.rb +3 -1
  10. data/lib/rack/handler/cgi.rb +8 -7
  11. data/lib/rack/handler/fastcgi.rb +1 -1
  12. data/lib/rack/handler/lsws.rb +1 -1
  13. data/lib/rack/handler/mongrel.rb +1 -1
  14. data/lib/rack/handler/scgi.rb +1 -4
  15. data/lib/rack/handler/webrick.rb +10 -6
  16. data/lib/rack/lint.rb +29 -37
  17. data/lib/rack/mime.rb +2 -0
  18. data/lib/rack/mock.rb +2 -1
  19. data/lib/rack/recursive.rb +4 -0
  20. data/lib/rack/request.rb +8 -6
  21. data/lib/rack/response.rb +1 -0
  22. data/lib/rack/rewindable_input.rb +13 -10
  23. data/lib/rack/sendfile.rb +8 -6
  24. data/lib/rack/server.rb +68 -9
  25. data/lib/rack/session/cookie.rb +1 -10
  26. data/lib/rack/session/memcache.rb +1 -1
  27. data/lib/rack/urlmap.rb +6 -7
  28. data/lib/rack/utils.rb +40 -71
  29. data/rack.gemspec +7 -11
  30. data/spec/cgi/lighttpd.conf +25 -0
  31. data/spec/cgi/rackup_stub.rb +6 -0
  32. data/spec/cgi/sample_rackup.ru +5 -0
  33. data/spec/cgi/test +9 -0
  34. data/spec/cgi/test.fcgi +8 -0
  35. data/spec/cgi/test.ru +5 -0
  36. data/spec/multipart/bad_robots +259 -0
  37. data/spec/multipart/binary +0 -0
  38. data/spec/multipart/empty +10 -0
  39. data/spec/multipart/fail_16384_nofile +814 -0
  40. data/spec/multipart/file1.txt +1 -0
  41. data/spec/multipart/filename_and_modification_param +7 -0
  42. data/spec/multipart/filename_with_escaped_quotes +6 -0
  43. data/spec/multipart/filename_with_escaped_quotes_and_modification_param +7 -0
  44. data/spec/multipart/filename_with_percent_escaped_quotes +6 -0
  45. data/spec/multipart/filename_with_unescaped_quotes +6 -0
  46. data/spec/multipart/ie +6 -0
  47. data/spec/multipart/nested +10 -0
  48. data/spec/multipart/none +9 -0
  49. data/spec/multipart/semicolon +6 -0
  50. data/spec/multipart/text +10 -0
  51. data/spec/rackup/config.ru +31 -0
  52. data/{test/spec_rack_auth_basic.rb → spec/spec_auth_basic.rb} +11 -14
  53. data/{test/spec_rack_auth_digest.rb → spec/spec_auth_digest.rb} +18 -27
  54. data/{test/spec_rack_builder.rb → spec/spec_builder.rb} +49 -10
  55. data/{test/spec_rack_cascade.rb → spec/spec_cascade.rb} +7 -10
  56. data/{test/spec_rack_cgi.rb → spec/spec_cgi.rb} +34 -32
  57. data/{test/spec_rack_chunked.rb → spec/spec_chunked.rb} +8 -10
  58. data/{test/spec_rack_commonlogger.rb → spec/spec_commonlogger.rb} +10 -15
  59. data/{test/spec_rack_conditionalget.rb → spec/spec_conditionalget.rb} +5 -7
  60. data/{test/spec_rack_config.rb → spec/spec_config.rb} +6 -7
  61. data/{test/spec_rack_content_length.rb → spec/spec_content_length.rb} +7 -8
  62. data/{test/spec_rack_content_type.rb → spec/spec_content_type.rb} +5 -6
  63. data/{test/spec_rack_deflater.rb → spec/spec_deflater.rb} +11 -13
  64. data/{test/spec_rack_directory.rb → spec/spec_directory.rb} +6 -10
  65. data/{test/spec_rack_etag.rb → spec/spec_etag.rb} +3 -5
  66. data/{test/spec_rack_fastcgi.rb → spec/spec_fastcgi.rb} +36 -29
  67. data/{test/spec_rack_file.rb → spec/spec_file.rb} +9 -13
  68. data/{test/spec_rack_handler.rb → spec/spec_handler.rb} +10 -12
  69. data/{test/spec_rack_head.rb → spec/spec_head.rb} +3 -3
  70. data/{test/spec_rack_lint.rb → spec/spec_lint.rb} +19 -32
  71. data/{test/spec_rack_lobster.rb → spec/spec_lobster.rb} +9 -11
  72. data/{test/spec_rack_lock.rb → spec/spec_lock.rb} +15 -17
  73. data/{test/spec_rack_logger.rb → spec/spec_logger.rb} +6 -7
  74. data/{test/spec_rack_methodoverride.rb → spec/spec_methodoverride.rb} +15 -17
  75. data/{test/spec_rack_mock.rb → spec/spec_mock.rb} +30 -32
  76. data/{test/spec_rack_mongrel.rb → spec/spec_mongrel.rb} +40 -46
  77. data/{test/spec_rack_nulllogger.rb → spec/spec_nulllogger.rb} +4 -5
  78. data/{test/spec_rack_recursive.rb → spec/spec_recursive.rb} +28 -36
  79. data/{test/spec_rack_request.rb → spec/spec_request.rb} +84 -98
  80. data/{test/spec_rack_response.rb → spec/spec_response.rb} +46 -27
  81. data/spec/spec_rewindable_input.rb +118 -0
  82. data/{test/spec_rack_runtime.rb → spec/spec_runtime.rb} +15 -11
  83. data/{test/spec_rack_sendfile.rb → spec/spec_sendfile.rb} +11 -14
  84. data/{test/spec_rack_session_cookie.rb → spec/spec_session_cookie.rb} +14 -36
  85. data/{test/spec_rack_session_memcache.rb → spec/spec_session_memcache.rb} +32 -26
  86. data/{test/spec_rack_session_pool.rb → spec/spec_session_pool.rb} +36 -31
  87. data/spec/spec_showexceptions.rb +23 -0
  88. data/spec/spec_showstatus.rb +79 -0
  89. data/{test/spec_rack_static.rb → spec/spec_static.rb} +5 -9
  90. data/{test/spec_rack_thin.rb → spec/spec_thin.rb} +30 -35
  91. data/{test/spec_rack_urlmap.rb → spec/spec_urlmap.rb} +6 -8
  92. data/{test/spec_rack_utils.rb → spec/spec_utils.rb} +134 -74
  93. data/{test/spec_rack_webrick.rb → spec/spec_webrick.rb} +28 -36
  94. data/spec/testrequest.rb +77 -0
  95. data/spec/unregistered_handler/rack/handler/unregistered.rb +7 -0
  96. data/spec/unregistered_handler/rack/handler/unregistered_long_one.rb +7 -0
  97. metadata +176 -191
  98. data/RDOX +0 -0
  99. data/lib/rack/adapter/camping.rb +0 -22
  100. data/test/spec_auth.rb +0 -57
  101. data/test/spec_rack_camping.rb +0 -55
  102. data/test/spec_rack_rewindable_input.rb +0 -118
  103. data/test/spec_rack_showexceptions.rb +0 -21
  104. data/test/spec_rack_showstatus.rb +0 -72
  105. data/test/spec_rackup.rb +0 -164
@@ -1,12 +1,9 @@
1
- require 'test/spec'
2
-
3
1
  begin
4
2
  require 'rack/session/memcache'
5
3
  require 'rack/mock'
6
- require 'rack/response'
7
4
  require 'thread'
8
5
 
9
- context "Rack::Session::Memcache" do
6
+ describe Rack::Session::Memcache do
10
7
  session_key = Rack::Session::Memcache::DEFAULT_OPTIONS[:key]
11
8
  session_match = /#{session_key}=([0-9a-fA-F]+);/
12
9
  incrementor = lambda do |env|
@@ -27,30 +24,36 @@ begin
27
24
  incrementor.call(env)
28
25
  end
29
26
 
30
- specify "faults on no connection" do
27
+ it "faults on no connection" do
31
28
  if RUBY_VERSION < "1.9"
32
- lambda do
33
- Rack::Session::Memcache.new incrementor, :memcache_server => 'nosuchserver'
34
- end.should.raise
29
+ lambda{
30
+ Rack::Session::Memcache.new(incrementor, :memcache_server => 'nosuchserver')
31
+ }.should.raise
35
32
  else
36
- lambda do
37
- Rack::Session::Memcache.new incrementor, :memcache_server => 'nosuchserver'
38
- end.should.raise ArgumentError
33
+ lambda{
34
+ Rack::Session::Memcache.new(incrementor, :memcache_server => 'nosuchserver')
35
+ }.should.raise ArgumentError
39
36
  end
40
37
  end
41
38
 
42
- specify "connect to existing server" do
43
- test_pool = MemCache.new incrementor, :namespace => 'test:rack:session'
39
+ it "connects to existing server" do
40
+ test_pool = MemCache.new(incrementor, :namespace => 'test:rack:session')
41
+ test_pool.namespace.should.equal 'test:rack:session'
42
+ end
43
+
44
+ it "passes options to MemCache" do
45
+ pool = Rack::Session::Memcache.new(incrementor, :namespace => 'test:rack:session')
46
+ pool.pool.namespace.should.equal 'test:rack:session'
44
47
  end
45
48
 
46
- specify "creates a new cookie" do
49
+ it "creates a new cookie" do
47
50
  pool = Rack::Session::Memcache.new(incrementor)
48
51
  res = Rack::MockRequest.new(pool).get("/")
49
- res["Set-Cookie"].should.match("#{session_key}=")
52
+ res["Set-Cookie"].should.include("#{session_key}=")
50
53
  res.body.should.equal '{"counter"=>1}'
51
54
  end
52
55
 
53
- specify "determines session from a cookie" do
56
+ it "determines session from a cookie" do
54
57
  pool = Rack::Session::Memcache.new(incrementor)
55
58
  req = Rack::MockRequest.new(pool)
56
59
  res = req.get("/")
@@ -61,7 +64,7 @@ begin
61
64
  body.should.equal '{"counter"=>3}'
62
65
  end
63
66
 
64
- specify "survives nonexistant cookies" do
67
+ it "survives nonexistant cookies" do
65
68
  bad_cookie = "rack.session=blarghfasel"
66
69
  pool = Rack::Session::Memcache.new(incrementor)
67
70
  res = Rack::MockRequest.new(pool).
@@ -71,7 +74,7 @@ begin
71
74
  cookie.should.not.match(/#{bad_cookie}/)
72
75
  end
73
76
 
74
- specify "maintains freshness" do
77
+ it "maintains freshness" do
75
78
  pool = Rack::Session::Memcache.new(incrementor, :expire_after => 3)
76
79
  res = Rack::MockRequest.new(pool).get('/')
77
80
  res.body.should.include '"counter"=>1'
@@ -86,7 +89,7 @@ begin
86
89
  res.body.should.include '"counter"=>1'
87
90
  end
88
91
 
89
- specify "deletes cookies with :drop option" do
92
+ it "deletes cookies with :drop option" do
90
93
  pool = Rack::Session::Memcache.new(incrementor)
91
94
  req = Rack::MockRequest.new(pool)
92
95
  drop = Rack::Utils::Context.new(pool, drop_session)
@@ -109,7 +112,7 @@ begin
109
112
  res3.body.should.equal '{"counter"=>1}'
110
113
  end
111
114
 
112
- specify "provides new session id with :renew option" do
115
+ it "provides new session id with :renew option" do
113
116
  pool = Rack::Session::Memcache.new(incrementor)
114
117
  req = Rack::MockRequest.new(pool)
115
118
  renew = Rack::Utils::Context.new(pool, renew_session)
@@ -134,7 +137,7 @@ begin
134
137
  res3.body.should.equal '{"counter"=>4}'
135
138
  end
136
139
 
137
- specify "omits cookie with :defer option" do
140
+ it "omits cookie with :defer option" do
138
141
  pool = Rack::Session::Memcache.new(incrementor)
139
142
  req = Rack::MockRequest.new(pool)
140
143
  defer = Rack::Utils::Context.new(pool, defer_session)
@@ -157,7 +160,7 @@ begin
157
160
  res3.body.should.equal '{"counter"=>4}'
158
161
  end
159
162
 
160
- specify "deep hashes are correctly updated" do
163
+ it "updates deep hashes correctly" do
161
164
  store = nil
162
165
  hash_check = proc do |env|
163
166
  session = env['rack.session']
@@ -183,8 +186,11 @@ begin
183
186
  end
184
187
 
185
188
  # anyone know how to do this better?
186
- specify "multithread: should cleanly merge sessions" do
187
- next unless $DEBUG
189
+ it "cleanly merges sessions when multithreaded" do
190
+ unless $DEBUG
191
+ 1.should.equal 1 # fake assertion to appease the mighty bacon
192
+ next
193
+ end
188
194
  warn 'Running multithread test for Session::Memcache'
189
195
  pool = Rack::Session::Memcache.new(incrementor)
190
196
  req = Rack::MockRequest.new(pool)
@@ -215,8 +221,8 @@ begin
215
221
  end
216
222
 
217
223
  session = pool.pool.get(session_id)
218
- session.size.should.be tnum+1 # counter
219
- session['counter'].should.be 2 # meeeh
224
+ session.size.should.equal tnum+1 # counter
225
+ session['counter'].should.equal 2 # meeeh
220
226
 
221
227
  tnum = rand(7).to_i+5
222
228
  r = Array.new(tnum) do |i|
@@ -1,39 +1,40 @@
1
- require 'test/spec'
2
-
3
- require 'rack/session/pool'
4
- require 'rack/mock'
5
- require 'rack/response'
6
1
  require 'thread'
2
+ require 'rack/mock'
3
+ require 'rack/session/pool'
7
4
 
8
- context "Rack::Session::Pool" do
5
+ describe Rack::Session::Pool do
9
6
  session_key = Rack::Session::Pool::DEFAULT_OPTIONS[:key]
10
7
  session_match = /#{session_key}=[0-9a-fA-F]+;/
8
+
11
9
  incrementor = lambda do |env|
12
10
  env["rack.session"]["counter"] ||= 0
13
11
  env["rack.session"]["counter"] += 1
14
12
  Rack::Response.new(env["rack.session"].inspect).to_a
15
13
  end
16
- drop_session = proc do |env|
14
+
15
+ drop_session = lambda do |env|
17
16
  env['rack.session.options'][:drop] = true
18
17
  incrementor.call(env)
19
18
  end
20
- renew_session = proc do |env|
19
+
20
+ renew_session = lambda do |env|
21
21
  env['rack.session.options'][:renew] = true
22
22
  incrementor.call(env)
23
23
  end
24
- defer_session = proc do |env|
24
+
25
+ defer_session = lambda do |env|
25
26
  env['rack.session.options'][:defer] = true
26
27
  incrementor.call(env)
27
28
  end
28
29
 
29
- specify "creates a new cookie" do
30
+ it "creates a new cookie" do
30
31
  pool = Rack::Session::Pool.new(incrementor)
31
32
  res = Rack::MockRequest.new(pool).get("/")
32
33
  res["Set-Cookie"].should.match session_match
33
34
  res.body.should.equal '{"counter"=>1}'
34
35
  end
35
36
 
36
- specify "determines session from a cookie" do
37
+ it "determines session from a cookie" do
37
38
  pool = Rack::Session::Pool.new(incrementor)
38
39
  req = Rack::MockRequest.new(pool)
39
40
  cookie = req.get("/")["Set-Cookie"]
@@ -43,14 +44,14 @@ context "Rack::Session::Pool" do
43
44
  body.should.equal '{"counter"=>3}'
44
45
  end
45
46
 
46
- specify "survives nonexistant cookies" do
47
+ it "survives nonexistant cookies" do
47
48
  pool = Rack::Session::Pool.new(incrementor)
48
49
  res = Rack::MockRequest.new(pool).
49
50
  get("/", "HTTP_COOKIE" => "#{session_key}=blarghfasel")
50
51
  res.body.should.equal '{"counter"=>1}'
51
52
  end
52
53
 
53
- specify "deletes cookies with :drop option" do
54
+ it "deletes cookies with :drop option" do
54
55
  pool = Rack::Session::Pool.new(incrementor)
55
56
  req = Rack::MockRequest.new(pool)
56
57
  drop = Rack::Utils::Context.new(pool, drop_session)
@@ -59,25 +60,25 @@ context "Rack::Session::Pool" do
59
60
  res0 = req.get("/")
60
61
  session = (cookie = res0["Set-Cookie"])[session_match]
61
62
  res0.body.should.equal '{"counter"=>1}'
62
- pool.pool.size.should.be 1
63
+ pool.pool.size.should.equal 1
63
64
 
64
65
  res1 = req.get("/", "HTTP_COOKIE" => cookie)
65
66
  res1["Set-Cookie"][session_match].should.equal session
66
67
  res1.body.should.equal '{"counter"=>2}'
67
- pool.pool.size.should.be 1
68
+ pool.pool.size.should.equal 1
68
69
 
69
70
  res2 = dreq.get("/", "HTTP_COOKIE" => cookie)
70
71
  res2["Set-Cookie"].should.equal nil
71
72
  res2.body.should.equal '{"counter"=>3}'
72
- pool.pool.size.should.be 0
73
+ pool.pool.size.should.equal 0
73
74
 
74
75
  res3 = req.get("/", "HTTP_COOKIE" => cookie)
75
76
  res3["Set-Cookie"][session_match].should.not.equal session
76
77
  res3.body.should.equal '{"counter"=>1}'
77
- pool.pool.size.should.be 1
78
+ pool.pool.size.should.equal 1
78
79
  end
79
80
 
80
- specify "provides new session id with :renew option" do
81
+ it "provides new session id with :renew option" do
81
82
  pool = Rack::Session::Pool.new(incrementor)
82
83
  req = Rack::MockRequest.new(pool)
83
84
  renew = Rack::Utils::Context.new(pool, renew_session)
@@ -86,27 +87,27 @@ context "Rack::Session::Pool" do
86
87
  res0 = req.get("/")
87
88
  session = (cookie = res0["Set-Cookie"])[session_match]
88
89
  res0.body.should.equal '{"counter"=>1}'
89
- pool.pool.size.should.be 1
90
+ pool.pool.size.should.equal 1
90
91
 
91
92
  res1 = req.get("/", "HTTP_COOKIE" => cookie)
92
93
  res1["Set-Cookie"][session_match].should.equal session
93
94
  res1.body.should.equal '{"counter"=>2}'
94
- pool.pool.size.should.be 1
95
+ pool.pool.size.should.equal 1
95
96
 
96
97
  res2 = rreq.get("/", "HTTP_COOKIE" => cookie)
97
98
  new_cookie = res2["Set-Cookie"]
98
99
  new_session = new_cookie[session_match]
99
100
  new_session.should.not.equal session
100
101
  res2.body.should.equal '{"counter"=>3}'
101
- pool.pool.size.should.be 1
102
+ pool.pool.size.should.equal 1
102
103
 
103
104
  res3 = req.get("/", "HTTP_COOKIE" => new_cookie)
104
105
  res3["Set-Cookie"][session_match].should.equal new_session
105
106
  res3.body.should.equal '{"counter"=>4}'
106
- pool.pool.size.should.be 1
107
+ pool.pool.size.should.equal 1
107
108
  end
108
109
 
109
- specify "omits cookie with :defer option" do
110
+ it "omits cookie with :defer option" do
110
111
  pool = Rack::Session::Pool.new(incrementor)
111
112
  req = Rack::MockRequest.new(pool)
112
113
  defer = Rack::Utils::Context.new(pool, defer_session)
@@ -115,27 +116,31 @@ context "Rack::Session::Pool" do
115
116
  res0 = req.get("/")
116
117
  session = (cookie = res0["Set-Cookie"])[session_match]
117
118
  res0.body.should.equal '{"counter"=>1}'
118
- pool.pool.size.should.be 1
119
+ pool.pool.size.should.equal 1
119
120
 
120
121
  res1 = req.get("/", "HTTP_COOKIE" => cookie)
121
122
  res1["Set-Cookie"][session_match].should.equal session
122
123
  res1.body.should.equal '{"counter"=>2}'
123
- pool.pool.size.should.be 1
124
+ pool.pool.size.should.equal 1
124
125
 
125
126
  res2 = dreq.get("/", "HTTP_COOKIE" => cookie)
126
127
  res2["Set-Cookie"].should.equal nil
127
128
  res2.body.should.equal '{"counter"=>3}'
128
- pool.pool.size.should.be 1
129
+ pool.pool.size.should.equal 1
129
130
 
130
131
  res3 = req.get("/", "HTTP_COOKIE" => cookie)
131
132
  res3["Set-Cookie"][session_match].should.equal session
132
133
  res3.body.should.equal '{"counter"=>4}'
133
- pool.pool.size.should.be 1
134
+ pool.pool.size.should.equal 1
134
135
  end
135
136
 
136
137
  # anyone know how to do this better?
137
- specify "multithread: should merge sessions" do
138
- next unless $DEBUG
138
+ it "should merge sessions when multithreaded" do
139
+ unless $DEBUG
140
+ 1.should.equal 1
141
+ next
142
+ end
143
+
139
144
  warn 'Running multithread tests for Session::Pool'
140
145
  pool = Rack::Session::Pool.new(incrementor)
141
146
  req = Rack::MockRequest.new(pool)
@@ -166,7 +171,7 @@ context "Rack::Session::Pool" do
166
171
  end
167
172
 
168
173
  session = pool.pool[sess_id]
169
- session.size.should.be tnum+1 # counter
170
- session['counter'].should.be 2 # meeeh
174
+ session.size.should.equal tnum+1 # counter
175
+ session['counter'].should.equal 2 # meeeh
171
176
  end
172
177
  end
@@ -0,0 +1,23 @@
1
+ require 'rack/showexceptions'
2
+ require 'rack/mock'
3
+
4
+ describe Rack::ShowExceptions do
5
+ it "catches exceptions" do
6
+ res = nil
7
+
8
+ req = Rack::MockRequest.new(
9
+ Rack::ShowExceptions.new(
10
+ lambda{|env| raise RuntimeError }
11
+ ))
12
+
13
+ lambda{
14
+ res = req.get("/")
15
+ }.should.not.raise
16
+
17
+ res.should.be.a.server_error
18
+ res.status.should.equal 500
19
+
20
+ res.should =~ /RuntimeError/
21
+ res.should =~ /ShowExceptions/
22
+ end
23
+ end
@@ -0,0 +1,79 @@
1
+ require 'rack/showstatus'
2
+ require 'rack/mock'
3
+
4
+ describe Rack::ShowStatus do
5
+ should "provide a default status message" do
6
+ req = Rack::MockRequest.new(
7
+ Rack::ShowStatus.new(lambda{|env|
8
+ [404, {"Content-Type" => "text/plain", "Content-Length" => "0"}, []]
9
+ }))
10
+
11
+ res = req.get("/", :lint => true)
12
+ res.should.be.not_found
13
+ res.should.be.not.empty
14
+
15
+ res["Content-Type"].should.equal("text/html")
16
+ res.should =~ /404/
17
+ res.should =~ /Not Found/
18
+ end
19
+
20
+ should "let the app provide additional information" do
21
+ req = Rack::MockRequest.new(
22
+ Rack::ShowStatus.new(
23
+ lambda{|env|
24
+ env["rack.showstatus.detail"] = "gone too meta."
25
+ [404, {"Content-Type" => "text/plain", "Content-Length" => "0"}, []]
26
+ }))
27
+
28
+ res = req.get("/", :lint => true)
29
+ res.should.be.not_found
30
+ res.should.be.not.empty
31
+
32
+ res["Content-Type"].should.equal("text/html")
33
+ res.should =~ /404/
34
+ res.should =~ /Not Found/
35
+ res.should =~ /too meta/
36
+ end
37
+
38
+ should "not replace existing messages" do
39
+ req = Rack::MockRequest.new(
40
+ Rack::ShowStatus.new(
41
+ lambda{|env|
42
+ [404, {"Content-Type" => "text/plain", "Content-Length" => "4"}, ["foo!"]]
43
+ }))
44
+
45
+ res = req.get("/", :lint => true)
46
+ res.should.be.not_found
47
+
48
+ res.body.should == "foo!"
49
+ end
50
+
51
+ should "pass on original headers" do
52
+ headers = {"WWW-Authenticate" => "Basic blah"}
53
+
54
+ req = Rack::MockRequest.new(
55
+ Rack::ShowStatus.new(lambda{|env| [401, headers, []] }))
56
+ res = req.get("/", :lint => true)
57
+
58
+ res["WWW-Authenticate"].should.equal("Basic blah")
59
+ end
60
+
61
+ should "replace existing messages if there is detail" do
62
+ req = Rack::MockRequest.new(
63
+ Rack::ShowStatus.new(
64
+ lambda{|env|
65
+ env["rack.showstatus.detail"] = "gone too meta."
66
+ [404, {"Content-Type" => "text/plain", "Content-Length" => "4"}, ["foo!"]]
67
+ }))
68
+
69
+ res = req.get("/", :lint => true)
70
+ res.should.be.not_found
71
+ res.should.be.not.empty
72
+
73
+ res["Content-Type"].should.equal("text/html")
74
+ res["Content-Length"].should.not.equal("4")
75
+ res.should =~ /404/
76
+ res.should =~ /too meta/
77
+ res.body.should.not =~ /foo/
78
+ end
79
+ end
@@ -1,5 +1,3 @@
1
- require 'test/spec'
2
-
3
1
  require 'rack/static'
4
2
  require 'rack/mock'
5
3
 
@@ -9,26 +7,24 @@ class DummyApp
9
7
  end
10
8
  end
11
9
 
12
- context "Rack::Static" do
10
+ describe Rack::Static do
13
11
  root = File.expand_path(File.dirname(__FILE__))
14
12
  OPTIONS = {:urls => ["/cgi"], :root => root}
15
13
 
16
- setup do
17
- @request = Rack::MockRequest.new(Rack::Static.new(DummyApp.new, OPTIONS))
18
- end
14
+ @request = Rack::MockRequest.new(Rack::Static.new(DummyApp.new, OPTIONS))
19
15
 
20
- specify "serves files" do
16
+ it "serves files" do
21
17
  res = @request.get("/cgi/test")
22
18
  res.should.be.ok
23
19
  res.body.should =~ /ruby/
24
20
  end
25
21
 
26
- specify "404s if url root is known but it can't find the file" do
22
+ it "404s if url root is known but it can't find the file" do
27
23
  res = @request.get("/cgi/foo")
28
24
  res.should.be.not_found
29
25
  end
30
26
 
31
- specify "calls down the chain if url root is not known" do
27
+ it "calls down the chain if url root is not known" do
32
28
  res = @request.get("/something/else")
33
29
  res.should.be.ok
34
30
  res.body.should == "Hello World"