rack 1.6.13 → 2.0.1

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 (144) hide show
  1. checksums.yaml +5 -5
  2. data/COPYING +1 -1
  3. data/HISTORY.md +138 -8
  4. data/README.rdoc +17 -25
  5. data/Rakefile +6 -14
  6. data/SPEC +8 -9
  7. data/contrib/rack_logo.svg +164 -111
  8. data/example/protectedlobster.rb +1 -1
  9. data/example/protectedlobster.ru +1 -1
  10. data/lib/rack/auth/abstract/request.rb +5 -1
  11. data/lib/rack/auth/digest/params.rb +2 -3
  12. data/lib/rack/auth/digest/request.rb +1 -1
  13. data/lib/rack/body_proxy.rb +14 -9
  14. data/lib/rack/builder.rb +3 -3
  15. data/lib/rack/chunked.rb +5 -5
  16. data/lib/rack/{commonlogger.rb → common_logger.rb} +3 -3
  17. data/lib/rack/{conditionalget.rb → conditional_get.rb} +0 -0
  18. data/lib/rack/content_length.rb +2 -2
  19. data/lib/rack/deflater.rb +4 -4
  20. data/lib/rack/directory.rb +66 -54
  21. data/lib/rack/etag.rb +4 -3
  22. data/lib/rack/events.rb +154 -0
  23. data/lib/rack/file.rb +63 -39
  24. data/lib/rack/handler/cgi.rb +15 -16
  25. data/lib/rack/handler/fastcgi.rb +13 -14
  26. data/lib/rack/handler/lsws.rb +11 -11
  27. data/lib/rack/handler/scgi.rb +15 -15
  28. data/lib/rack/handler/thin.rb +3 -0
  29. data/lib/rack/handler/webrick.rb +22 -24
  30. data/lib/rack/handler.rb +3 -25
  31. data/lib/rack/head.rb +15 -17
  32. data/lib/rack/lint.rb +38 -38
  33. data/lib/rack/lobster.rb +1 -1
  34. data/lib/rack/lock.rb +6 -10
  35. data/lib/rack/logger.rb +2 -2
  36. data/lib/rack/media_type.rb +38 -0
  37. data/lib/rack/{methodoverride.rb → method_override.rb} +4 -11
  38. data/lib/rack/mime.rb +18 -5
  39. data/lib/rack/mock.rb +35 -53
  40. data/lib/rack/multipart/generator.rb +5 -5
  41. data/lib/rack/multipart/parser.rb +272 -158
  42. data/lib/rack/multipart/uploaded_file.rb +1 -2
  43. data/lib/rack/multipart.rb +35 -6
  44. data/lib/rack/{nulllogger.rb → null_logger.rb} +1 -1
  45. data/lib/rack/query_parser.rb +192 -0
  46. data/lib/rack/recursive.rb +8 -8
  47. data/lib/rack/request.rb +383 -307
  48. data/lib/rack/response.rb +129 -56
  49. data/lib/rack/rewindable_input.rb +1 -12
  50. data/lib/rack/runtime.rb +10 -18
  51. data/lib/rack/sendfile.rb +5 -7
  52. data/lib/rack/server.rb +31 -25
  53. data/lib/rack/session/abstract/id.rb +95 -135
  54. data/lib/rack/session/cookie.rb +26 -28
  55. data/lib/rack/session/memcache.rb +8 -14
  56. data/lib/rack/session/pool.rb +14 -21
  57. data/lib/rack/show_exceptions.rb +386 -0
  58. data/lib/rack/{showstatus.rb → show_status.rb} +3 -3
  59. data/lib/rack/static.rb +30 -5
  60. data/lib/rack/tempfile_reaper.rb +2 -2
  61. data/lib/rack/urlmap.rb +15 -14
  62. data/lib/rack/utils.rb +135 -210
  63. data/lib/rack.rb +70 -21
  64. data/rack.gemspec +7 -5
  65. data/test/builder/an_underscore_app.rb +5 -0
  66. data/test/builder/options.ru +1 -1
  67. data/test/cgi/test.fcgi +1 -0
  68. data/test/cgi/test.gz +0 -0
  69. data/test/helper.rb +34 -0
  70. data/test/multipart/filename_with_encoded_words +7 -0
  71. data/test/multipart/{filename_with_null_byte → filename_with_single_quote} +1 -1
  72. data/test/multipart/quoted +15 -0
  73. data/test/multipart/rack-logo.png +0 -0
  74. data/test/multipart/unity3d_wwwform +11 -0
  75. data/test/registering_handler/rack/handler/registering_myself.rb +1 -1
  76. data/test/spec_auth_basic.rb +27 -19
  77. data/test/spec_auth_digest.rb +47 -46
  78. data/test/spec_body_proxy.rb +27 -27
  79. data/test/spec_builder.rb +51 -41
  80. data/test/spec_cascade.rb +24 -22
  81. data/test/spec_cgi.rb +49 -67
  82. data/test/spec_chunked.rb +36 -34
  83. data/test/{spec_commonlogger.rb → spec_common_logger.rb} +23 -21
  84. data/test/{spec_conditionalget.rb → spec_conditional_get.rb} +29 -28
  85. data/test/spec_config.rb +3 -2
  86. data/test/spec_content_length.rb +18 -17
  87. data/test/spec_content_type.rb +13 -12
  88. data/test/spec_deflater.rb +66 -40
  89. data/test/spec_directory.rb +87 -27
  90. data/test/spec_etag.rb +32 -31
  91. data/test/spec_events.rb +133 -0
  92. data/test/spec_fastcgi.rb +50 -72
  93. data/test/spec_file.rb +107 -77
  94. data/test/spec_handler.rb +19 -34
  95. data/test/spec_head.rb +15 -14
  96. data/test/spec_lint.rb +162 -197
  97. data/test/spec_lobster.rb +24 -23
  98. data/test/spec_lock.rb +69 -39
  99. data/test/spec_logger.rb +4 -3
  100. data/test/spec_media_type.rb +42 -0
  101. data/test/spec_method_override.rb +83 -0
  102. data/test/spec_mime.rb +19 -19
  103. data/test/spec_mock.rb +196 -151
  104. data/test/spec_multipart.rb +317 -201
  105. data/test/{spec_nulllogger.rb → spec_null_logger.rb} +5 -4
  106. data/test/spec_recursive.rb +17 -14
  107. data/test/spec_request.rb +768 -607
  108. data/test/spec_response.rb +214 -111
  109. data/test/spec_rewindable_input.rb +50 -40
  110. data/test/spec_runtime.rb +11 -10
  111. data/test/spec_sendfile.rb +30 -35
  112. data/test/spec_server.rb +78 -52
  113. data/test/spec_session_abstract_id.rb +11 -33
  114. data/test/spec_session_abstract_session_hash.rb +28 -0
  115. data/test/spec_session_cookie.rb +97 -65
  116. data/test/spec_session_memcache.rb +63 -101
  117. data/test/spec_session_pool.rb +48 -84
  118. data/test/spec_show_exceptions.rb +80 -0
  119. data/test/{spec_showstatus.rb → spec_show_status.rb} +36 -35
  120. data/test/spec_static.rb +71 -32
  121. data/test/spec_tempfile_reaper.rb +11 -10
  122. data/test/spec_thin.rb +55 -50
  123. data/test/spec_urlmap.rb +79 -78
  124. data/test/spec_utils.rb +441 -346
  125. data/test/spec_version.rb +2 -8
  126. data/test/spec_webrick.rb +91 -67
  127. data/test/static/foo.html +1 -0
  128. data/test/testrequest.rb +1 -1
  129. data/test/unregistered_handler/rack/handler/unregistered.rb +1 -1
  130. data/test/unregistered_handler/rack/handler/unregistered_long_one.rb +1 -1
  131. metadata +103 -69
  132. data/KNOWN-ISSUES +0 -44
  133. data/lib/rack/backports/uri/common_18.rb +0 -56
  134. data/lib/rack/backports/uri/common_192.rb +0 -52
  135. data/lib/rack/backports/uri/common_193.rb +0 -29
  136. data/lib/rack/handler/evented_mongrel.rb +0 -8
  137. data/lib/rack/handler/mongrel.rb +0 -106
  138. data/lib/rack/handler/swiftiplied_mongrel.rb +0 -8
  139. data/lib/rack/showexceptions.rb +0 -387
  140. data/lib/rack/utils/okjson.rb +0 -600
  141. data/test/spec_methodoverride.rb +0 -111
  142. data/test/spec_mongrel.rb +0 -182
  143. data/test/spec_session_persisted_secure_secure_session_hash.rb +0 -73
  144. data/test/spec_showexceptions.rb +0 -98
@@ -1,4 +1,5 @@
1
- require 'rack/showstatus'
1
+ require 'minitest/autorun'
2
+ require 'rack/show_status'
2
3
  require 'rack/lint'
3
4
  require 'rack/mock'
4
5
  require 'rack/utils'
@@ -7,23 +8,23 @@ describe Rack::ShowStatus do
7
8
  def show_status(app)
8
9
  Rack::Lint.new Rack::ShowStatus.new(app)
9
10
  end
10
-
11
- should "provide a default status message" do
11
+
12
+ it "provide a default status message" do
12
13
  req = Rack::MockRequest.new(
13
14
  show_status(lambda{|env|
14
15
  [404, {"Content-Type" => "text/plain", "Content-Length" => "0"}, []]
15
16
  }))
16
17
 
17
18
  res = req.get("/", :lint => true)
18
- res.should.be.not_found
19
- res.should.be.not.empty
19
+ res.must_be :not_found?
20
+ res.wont_be_empty
20
21
 
21
- res["Content-Type"].should.equal("text/html")
22
- res.should =~ /404/
23
- res.should =~ /Not Found/
22
+ res["Content-Type"].must_equal "text/html"
23
+ assert_match(res, /404/)
24
+ assert_match(res, /Not Found/)
24
25
  end
25
26
 
26
- should "let the app provide additional information" do
27
+ it "let the app provide additional information" do
27
28
  req = Rack::MockRequest.new(
28
29
  show_status(
29
30
  lambda{|env|
@@ -32,16 +33,16 @@ describe Rack::ShowStatus do
32
33
  }))
33
34
 
34
35
  res = req.get("/", :lint => true)
35
- res.should.be.not_found
36
- res.should.be.not.empty
36
+ res.must_be :not_found?
37
+ res.wont_be_empty
37
38
 
38
- res["Content-Type"].should.equal("text/html")
39
- res.should =~ /404/
40
- res.should =~ /Not Found/
41
- res.should =~ /too meta/
39
+ res["Content-Type"].must_equal "text/html"
40
+ assert_match(res, /404/)
41
+ assert_match(res, /Not Found/)
42
+ assert_match(res, /too meta/)
42
43
  end
43
44
 
44
- should "escape error" do
45
+ it "escape error" do
45
46
  detail = "<script>alert('hi \"')</script>"
46
47
  req = Rack::MockRequest.new(
47
48
  show_status(
@@ -51,15 +52,15 @@ describe Rack::ShowStatus do
51
52
  }))
52
53
 
53
54
  res = req.get("/", :lint => true)
54
- res.should.be.not.empty
55
+ res.wont_be_empty
55
56
 
56
- res["Content-Type"].should.equal("text/html")
57
- res.should =~ /500/
58
- res.should.not.include detail
59
- res.body.should.include Rack::Utils.escape_html(detail)
57
+ res["Content-Type"].must_equal "text/html"
58
+ assert_match(res, /500/)
59
+ res.wont_include detail
60
+ res.body.must_include Rack::Utils.escape_html(detail)
60
61
  end
61
62
 
62
- should "not replace existing messages" do
63
+ it "not replace existing messages" do
63
64
  req = Rack::MockRequest.new(
64
65
  show_status(
65
66
  lambda{|env|
@@ -67,22 +68,22 @@ describe Rack::ShowStatus do
67
68
  }))
68
69
 
69
70
  res = req.get("/", :lint => true)
70
- res.should.be.not_found
71
+ res.must_be :not_found?
71
72
 
72
- res.body.should == "foo!"
73
+ res.body.must_equal "foo!"
73
74
  end
74
75
 
75
- should "pass on original headers" do
76
+ it "pass on original headers" do
76
77
  headers = {"WWW-Authenticate" => "Basic blah"}
77
78
 
78
79
  req = Rack::MockRequest.new(
79
80
  show_status(lambda{|env| [401, headers, []] }))
80
81
  res = req.get("/", :lint => true)
81
82
 
82
- res["WWW-Authenticate"].should.equal("Basic blah")
83
+ res["WWW-Authenticate"].must_equal "Basic blah"
83
84
  end
84
85
 
85
- should "replace existing messages if there is detail" do
86
+ it "replace existing messages if there is detail" do
86
87
  req = Rack::MockRequest.new(
87
88
  show_status(
88
89
  lambda{|env|
@@ -91,13 +92,13 @@ describe Rack::ShowStatus do
91
92
  }))
92
93
 
93
94
  res = req.get("/", :lint => true)
94
- res.should.be.not_found
95
- res.should.be.not.empty
96
-
97
- res["Content-Type"].should.equal("text/html")
98
- res["Content-Length"].should.not.equal("4")
99
- res.should =~ /404/
100
- res.should =~ /too meta/
101
- res.body.should.not =~ /foo/
95
+ res.must_be :not_found?
96
+ res.wont_be_empty
97
+
98
+ res["Content-Type"].must_equal "text/html"
99
+ res["Content-Length"].wont_equal "4"
100
+ assert_match(res, /404/)
101
+ assert_match(res, /too meta/)
102
+ res.body.wont_match(/foo/)
102
103
  end
103
104
  end
data/test/spec_static.rb CHANGED
@@ -1,6 +1,9 @@
1
+ require 'minitest/autorun'
1
2
  require 'rack/static'
2
3
  require 'rack/lint'
3
4
  require 'rack/mock'
5
+ require 'zlib'
6
+ require 'stringio'
4
7
 
5
8
  class DummyApp
6
9
  def call(env)
@@ -18,64 +21,101 @@ describe Rack::Static do
18
21
  OPTIONS = {:urls => ["/cgi"], :root => root}
19
22
  STATIC_OPTIONS = {:urls => [""], :root => "#{root}/static", :index => 'index.html'}
20
23
  HASH_OPTIONS = {:urls => {"/cgi/sekret" => 'cgi/test'}, :root => root}
24
+ HASH_ROOT_OPTIONS = {:urls => {"/" => "static/foo.html"}, :root => root}
25
+ GZIP_OPTIONS = {:urls => ["/cgi"], :root => root, :gzip=>true}
21
26
 
27
+ before do
22
28
  @request = Rack::MockRequest.new(static(DummyApp.new, OPTIONS))
23
29
  @static_request = Rack::MockRequest.new(static(DummyApp.new, STATIC_OPTIONS))
24
30
  @hash_request = Rack::MockRequest.new(static(DummyApp.new, HASH_OPTIONS))
31
+ @hash_root_request = Rack::MockRequest.new(static(DummyApp.new, HASH_ROOT_OPTIONS))
32
+ @gzip_request = Rack::MockRequest.new(static(DummyApp.new, GZIP_OPTIONS))
33
+ @header_request = Rack::MockRequest.new(static(DummyApp.new, HEADER_OPTIONS))
34
+ end
25
35
 
26
36
  it "serves files" do
27
37
  res = @request.get("/cgi/test")
28
- res.should.be.ok
29
- res.body.should =~ /ruby/
38
+ res.must_be :ok?
39
+ res.body.must_match(/ruby/)
30
40
  end
31
41
 
32
42
  it "404s if url root is known but it can't find the file" do
33
43
  res = @request.get("/cgi/foo")
34
- res.should.be.not_found
44
+ res.must_be :not_found?
35
45
  end
36
46
 
37
47
  it "calls down the chain if url root is not known" do
38
48
  res = @request.get("/something/else")
39
- res.should.be.ok
40
- res.body.should == "Hello World"
49
+ res.must_be :ok?
50
+ res.body.must_equal "Hello World"
41
51
  end
42
52
 
43
53
  it "calls index file when requesting root in the given folder" do
44
54
  res = @static_request.get("/")
45
- res.should.be.ok
46
- res.body.should =~ /index!/
55
+ res.must_be :ok?
56
+ res.body.must_match(/index!/)
47
57
 
48
58
  res = @static_request.get("/other/")
49
- res.should.be.not_found
59
+ res.must_be :not_found?
50
60
 
51
61
  res = @static_request.get("/another/")
52
- res.should.be.ok
53
- res.body.should =~ /another index!/
62
+ res.must_be :ok?
63
+ res.body.must_match(/another index!/)
54
64
  end
55
65
 
56
66
  it "doesn't call index file if :index option was omitted" do
57
67
  res = @request.get("/")
58
- res.body.should == "Hello World"
68
+ res.body.must_equal "Hello World"
59
69
  end
60
70
 
61
71
  it "serves hidden files" do
62
72
  res = @hash_request.get("/cgi/sekret")
63
- res.should.be.ok
64
- res.body.should =~ /ruby/
73
+ res.must_be :ok?
74
+ res.body.must_match(/ruby/)
65
75
  end
66
76
 
67
77
  it "calls down the chain if the URI is not specified" do
68
78
  res = @hash_request.get("/something/else")
69
- res.should.be.ok
70
- res.body.should == "Hello World"
79
+ res.must_be :ok?
80
+ res.body.must_equal "Hello World"
81
+ end
82
+
83
+ it "allows the root URI to be configured via hash options" do
84
+ res = @hash_root_request.get("/")
85
+ res.must_be :ok?
86
+ res.body.must_match(/foo.html!/)
87
+ end
88
+
89
+ it "serves gzipped files if client accepts gzip encoding and gzip files are present" do
90
+ res = @gzip_request.get("/cgi/test", 'HTTP_ACCEPT_ENCODING'=>'deflate, gzip')
91
+ res.must_be :ok?
92
+ res.headers['Content-Encoding'].must_equal 'gzip'
93
+ res.headers['Content-Type'].must_equal 'text/plain'
94
+ Zlib::GzipReader.wrap(StringIO.new(res.body), &:read).must_match(/ruby/)
95
+ end
96
+
97
+ it "serves regular files if client accepts gzip encoding and gzip files are not present" do
98
+ res = @gzip_request.get("/cgi/rackup_stub.rb", 'HTTP_ACCEPT_ENCODING'=>'deflate, gzip')
99
+ res.must_be :ok?
100
+ res.headers['Content-Encoding'].must_equal nil
101
+ res.headers['Content-Type'].must_equal 'text/x-script.ruby'
102
+ res.body.must_match(/ruby/)
103
+ end
104
+
105
+ it "serves regular files if client does not accept gzip encoding" do
106
+ res = @gzip_request.get("/cgi/test")
107
+ res.must_be :ok?
108
+ res.headers['Content-Encoding'].must_equal nil
109
+ res.headers['Content-Type'].must_equal 'text/plain'
110
+ res.body.must_match(/ruby/)
71
111
  end
72
112
 
73
113
  it "supports serving fixed cache-control (legacy option)" do
74
114
  opts = OPTIONS.merge(:cache_control => 'public')
75
115
  request = Rack::MockRequest.new(static(DummyApp.new, opts))
76
116
  res = request.get("/cgi/test")
77
- res.should.be.ok
78
- res.headers['Cache-Control'].should == 'public'
117
+ res.must_be :ok?
118
+ res.headers['Cache-Control'].must_equal 'public'
79
119
  end
80
120
 
81
121
  HEADER_OPTIONS = {:urls => ["/cgi"], :root => root, :header_rules => [
@@ -86,47 +126,46 @@ describe Rack::Static do
86
126
  ['cgi/assets/javascripts', {'Cache-Control' => 'public, max-age=500'}],
87
127
  [/\.(css|erb)\z/, {'Cache-Control' => 'public, max-age=600'}]
88
128
  ]}
89
- @header_request = Rack::MockRequest.new(static(DummyApp.new, HEADER_OPTIONS))
90
129
 
91
130
  it "supports header rule :all" do
92
131
  # Headers for all files via :all shortcut
93
132
  res = @header_request.get('/cgi/assets/index.html')
94
- res.should.be.ok
95
- res.headers['Cache-Control'].should == 'public, max-age=100'
133
+ res.must_be :ok?
134
+ res.headers['Cache-Control'].must_equal 'public, max-age=100'
96
135
  end
97
136
 
98
137
  it "supports header rule :fonts" do
99
138
  # Headers for web fonts via :fonts shortcut
100
139
  res = @header_request.get('/cgi/assets/fonts/font.eot')
101
- res.should.be.ok
102
- res.headers['Cache-Control'].should == 'public, max-age=200'
140
+ res.must_be :ok?
141
+ res.headers['Cache-Control'].must_equal 'public, max-age=200'
103
142
  end
104
143
 
105
144
  it "supports file extension header rules provided as an Array" do
106
145
  # Headers for file extensions via array
107
146
  res = @header_request.get('/cgi/assets/images/image.png')
108
- res.should.be.ok
109
- res.headers['Cache-Control'].should == 'public, max-age=300'
147
+ res.must_be :ok?
148
+ res.headers['Cache-Control'].must_equal 'public, max-age=300'
110
149
  end
111
150
 
112
151
  it "supports folder rules provided as a String" do
113
152
  # Headers for files in folder via string
114
153
  res = @header_request.get('/cgi/assets/folder/test.js')
115
- res.should.be.ok
116
- res.headers['Cache-Control'].should == 'public, max-age=400'
154
+ res.must_be :ok?
155
+ res.headers['Cache-Control'].must_equal 'public, max-age=400'
117
156
  end
118
157
 
119
158
  it "supports folder header rules provided as a String not starting with a slash" do
120
159
  res = @header_request.get('/cgi/assets/javascripts/app.js')
121
- res.should.be.ok
122
- res.headers['Cache-Control'].should == 'public, max-age=500'
160
+ res.must_be :ok?
161
+ res.headers['Cache-Control'].must_equal 'public, max-age=500'
123
162
  end
124
163
 
125
164
  it "supports flexible header rules provided as Regexp" do
126
165
  # Flexible Headers via Regexp
127
166
  res = @header_request.get('/cgi/assets/stylesheets/app.css')
128
- res.should.be.ok
129
- res.headers['Cache-Control'].should == 'public, max-age=600'
167
+ res.must_be :ok?
168
+ res.headers['Cache-Control'].must_equal 'public, max-age=600'
130
169
  end
131
170
 
132
171
  it "prioritizes header rules over fixed cache-control setting (legacy option)" do
@@ -138,8 +177,8 @@ describe Rack::Static do
138
177
 
139
178
  request = Rack::MockRequest.new(static(DummyApp.new, opts))
140
179
  res = request.get("/cgi/test")
141
- res.should.be.ok
142
- res.headers['Cache-Control'].should == 'public, max-age=42'
180
+ res.must_be :ok?
181
+ res.headers['Cache-Control'].must_equal 'public, max-age=42'
143
182
  end
144
183
 
145
184
  end
@@ -1,3 +1,4 @@
1
+ require 'minitest/autorun'
1
2
  require 'rack/tempfile_reaper'
2
3
  require 'rack/lint'
3
4
  require 'rack/mock'
@@ -23,33 +24,33 @@ describe Rack::TempfileReaper do
23
24
  Rack::Lint.new(Rack::TempfileReaper.new(app)).call(@env)
24
25
  end
25
26
 
26
- should 'do nothing (i.e. not bomb out) without env[rack.tempfiles]' do
27
+ it 'do nothing (i.e. not bomb out) without env[rack.tempfiles]' do
27
28
  app = lambda { |_| [200, {}, ['Hello, World!']] }
28
29
  response = call(app)
29
30
  response[2].close
30
- response[0].should.equal(200)
31
+ response[0].must_equal 200
31
32
  end
32
33
 
33
- should 'close env[rack.tempfiles] when body is closed' do
34
+ it 'close env[rack.tempfiles] when body is closed' do
34
35
  tempfile1, tempfile2 = MockTempfile.new, MockTempfile.new
35
36
  @env['rack.tempfiles'] = [ tempfile1, tempfile2 ]
36
37
  app = lambda { |_| [200, {}, ['Hello, World!']] }
37
38
  call(app)[2].close
38
- tempfile1.closed.should.equal true
39
- tempfile2.closed.should.equal true
39
+ tempfile1.closed.must_equal true
40
+ tempfile2.closed.must_equal true
40
41
  end
41
42
 
42
- should 'initialize env[rack.tempfiles] when not already present' do
43
+ it 'initialize env[rack.tempfiles] when not already present' do
43
44
  tempfile = MockTempfile.new
44
45
  app = lambda do |env|
45
46
  env['rack.tempfiles'] << tempfile
46
47
  [200, {}, ['Hello, World!']]
47
48
  end
48
49
  call(app)[2].close
49
- tempfile.closed.should.equal true
50
+ tempfile.closed.must_equal true
50
51
  end
51
52
 
52
- should 'append env[rack.tempfiles] when already present' do
53
+ it 'append env[rack.tempfiles] when already present' do
53
54
  tempfile1, tempfile2 = MockTempfile.new, MockTempfile.new
54
55
  @env['rack.tempfiles'] = [ tempfile1 ]
55
56
  app = lambda do |env|
@@ -57,7 +58,7 @@ describe Rack::TempfileReaper do
57
58
  [200, {}, ['Hello, World!']]
58
59
  end
59
60
  call(app)[2].close
60
- tempfile1.closed.should.equal true
61
- tempfile2.closed.should.equal true
61
+ tempfile1.closed.must_equal true
62
+ tempfile2.closed.must_equal true
62
63
  end
63
64
  end
data/test/spec_thin.rb CHANGED
@@ -1,89 +1,94 @@
1
+ require 'minitest/autorun'
1
2
  begin
2
3
  require 'rack/handler/thin'
3
4
  require File.expand_path('../testrequest', __FILE__)
4
5
  require 'timeout'
5
6
 
6
7
  describe Rack::Handler::Thin do
7
- extend TestRequest::Helpers
8
+ include TestRequest::Helpers
8
9
 
9
- @app = Rack::Lint.new(TestRequest.new)
10
- @server = nil
11
- Thin::Logging.silent = true
10
+ before do
11
+ @app = Rack::Lint.new(TestRequest.new)
12
+ @server = nil
13
+ Thin::Logging.silent = true
12
14
 
13
- @thread = Thread.new do
14
- Rack::Handler::Thin.run(@app, :Host => @host='127.0.0.1', :Port => @port=9204, :tag => "tag") do |server|
15
- @server = server
15
+ @thread = Thread.new do
16
+ Rack::Handler::Thin.run(@app, :Host => @host='127.0.0.1', :Port => @port=9204, :tag => "tag") do |server|
17
+ @server = server
18
+ end
16
19
  end
20
+
21
+ Thread.pass until @server && @server.running?
22
+ end
23
+
24
+ after do
25
+ @server.stop!
26
+ @thread.join
17
27
  end
18
28
 
19
- Thread.pass until @server && @server.running?
20
29
 
21
- should "respond" do
30
+ it "respond" do
22
31
  GET("/")
23
- response.should.not.be.nil
32
+ response.wont_be :nil?
24
33
  end
25
34
 
26
- should "be a Thin" do
35
+ it "be a Thin" do
27
36
  GET("/")
28
- status.should.equal 200
29
- response["SERVER_SOFTWARE"].should =~ /thin/
30
- response["HTTP_VERSION"].should.equal "HTTP/1.1"
31
- response["SERVER_PROTOCOL"].should.equal "HTTP/1.1"
32
- response["SERVER_PORT"].should.equal "9204"
33
- response["SERVER_NAME"].should.equal "127.0.0.1"
37
+ status.must_equal 200
38
+ response["SERVER_SOFTWARE"].must_match(/thin/)
39
+ response["HTTP_VERSION"].must_equal "HTTP/1.1"
40
+ response["SERVER_PROTOCOL"].must_equal "HTTP/1.1"
41
+ response["SERVER_PORT"].must_equal "9204"
42
+ response["SERVER_NAME"].must_equal "127.0.0.1"
34
43
  end
35
44
 
36
- should "have rack headers" do
45
+ it "have rack headers" do
37
46
  GET("/")
38
- response["rack.version"].should.equal [1,0]
39
- response["rack.multithread"].should.equal false
40
- response["rack.multiprocess"].should.equal false
41
- response["rack.run_once"].should.equal false
47
+ response["rack.version"].must_equal [1,0]
48
+ response["rack.multithread"].must_equal false
49
+ response["rack.multiprocess"].must_equal false
50
+ response["rack.run_once"].must_equal false
42
51
  end
43
52
 
44
- should "have CGI headers on GET" do
53
+ it "have CGI headers on GET" do
45
54
  GET("/")
46
- response["REQUEST_METHOD"].should.equal "GET"
47
- response["REQUEST_PATH"].should.equal "/"
48
- response["PATH_INFO"].should.be.equal "/"
49
- response["QUERY_STRING"].should.equal ""
50
- response["test.postdata"].should.equal ""
55
+ response["REQUEST_METHOD"].must_equal "GET"
56
+ response["REQUEST_PATH"].must_equal "/"
57
+ response["PATH_INFO"].must_equal "/"
58
+ response["QUERY_STRING"].must_equal ""
59
+ response["test.postdata"].must_equal ""
51
60
 
52
61
  GET("/test/foo?quux=1")
53
- response["REQUEST_METHOD"].should.equal "GET"
54
- response["REQUEST_PATH"].should.equal "/test/foo"
55
- response["PATH_INFO"].should.equal "/test/foo"
56
- response["QUERY_STRING"].should.equal "quux=1"
62
+ response["REQUEST_METHOD"].must_equal "GET"
63
+ response["REQUEST_PATH"].must_equal "/test/foo"
64
+ response["PATH_INFO"].must_equal "/test/foo"
65
+ response["QUERY_STRING"].must_equal "quux=1"
57
66
  end
58
67
 
59
- should "have CGI headers on POST" do
68
+ it "have CGI headers on POST" do
60
69
  POST("/", {"rack-form-data" => "23"}, {'X-test-header' => '42'})
61
- status.should.equal 200
62
- response["REQUEST_METHOD"].should.equal "POST"
63
- response["REQUEST_PATH"].should.equal "/"
64
- response["QUERY_STRING"].should.equal ""
65
- response["HTTP_X_TEST_HEADER"].should.equal "42"
66
- response["test.postdata"].should.equal "rack-form-data=23"
70
+ status.must_equal 200
71
+ response["REQUEST_METHOD"].must_equal "POST"
72
+ response["REQUEST_PATH"].must_equal "/"
73
+ response["QUERY_STRING"].must_equal ""
74
+ response["HTTP_X_TEST_HEADER"].must_equal "42"
75
+ response["test.postdata"].must_equal "rack-form-data=23"
67
76
  end
68
77
 
69
- should "support HTTP auth" do
78
+ it "support HTTP auth" do
70
79
  GET("/test", {:user => "ruth", :passwd => "secret"})
71
- response["HTTP_AUTHORIZATION"].should.equal "Basic cnV0aDpzZWNyZXQ="
80
+ response["HTTP_AUTHORIZATION"].must_equal "Basic cnV0aDpzZWNyZXQ="
72
81
  end
73
82
 
74
- should "set status" do
83
+ it "set status" do
75
84
  GET("/test?secret")
76
- status.should.equal 403
77
- response["rack.url_scheme"].should.equal "http"
85
+ status.must_equal 403
86
+ response["rack.url_scheme"].must_equal "http"
78
87
  end
79
88
 
80
- should "set tag for server" do
81
- @server.tag.should.equal 'tag'
89
+ it "set tag for server" do
90
+ @server.tag.must_equal 'tag'
82
91
  end
83
-
84
- @server.stop!
85
- @thread.kill
86
-
87
92
  end
88
93
 
89
94
  rescue LoadError