Permalink
Browse files

Wrap test apps in Rack::Lint and fix uncovered errors (seventh pass)

Update tests for ShowExceptions, ShowStatus, Static and URLMap.
  • Loading branch information...
1 parent d072f02 commit dab9742552d12b45a12756717bc12bf8dc1db1fb @lgierth lgierth committed with lgierth Dec 28, 2011
Showing with 39 additions and 24 deletions.
  1. +9 −4 test/spec_showexceptions.rb
  2. +10 −5 test/spec_showstatus.rb
  3. +10 −5 test/spec_static.rb
  4. +10 −10 test/spec_urlmap.rb
@@ -1,12 +1,17 @@
require 'rack/showexceptions'
+require 'rack/lint'
require 'rack/mock'
describe Rack::ShowExceptions do
+ def show_exceptions(app)
+ Rack::Lint.new Rack::ShowExceptions.new(app)
+ end
+
it "catches exceptions" do
res = nil
req = Rack::MockRequest.new(
- Rack::ShowExceptions.new(
+ show_exceptions(
lambda{|env| raise RuntimeError }
))
@@ -25,7 +30,7 @@
res = nil
req = Rack::MockRequest.new(
- Rack::ShowExceptions.new(
+ show_exceptions(
lambda{|env| raise RuntimeError, "It was never supposed to work" }
))
@@ -46,7 +51,7 @@
res = nil
req = Rack::MockRequest.new(
- Rack::ShowExceptions.new(
+ show_exceptions(
lambda{|env| raise RuntimeError, "It was never supposed to work" }
))
@@ -68,7 +73,7 @@
res = nil
req = Rack::MockRequest.new(
- Rack::ShowExceptions.new(
+ show_exceptions(
lambda{|env| raise RuntimeError, "", [] }
)
)
View
@@ -1,10 +1,15 @@
require 'rack/showstatus'
+require 'rack/lint'
require 'rack/mock'
describe Rack::ShowStatus do
+ def show_status(app)
+ Rack::Lint.new Rack::ShowStatus.new(app)
+ end
+
should "provide a default status message" do
req = Rack::MockRequest.new(
- Rack::ShowStatus.new(lambda{|env|
+ show_status(lambda{|env|
[404, {"Content-Type" => "text/plain", "Content-Length" => "0"}, []]
}))
@@ -19,7 +24,7 @@
should "let the app provide additional information" do
req = Rack::MockRequest.new(
- Rack::ShowStatus.new(
+ show_status(
lambda{|env|
env["rack.showstatus.detail"] = "gone too meta."
[404, {"Content-Type" => "text/plain", "Content-Length" => "0"}, []]
@@ -37,7 +42,7 @@
should "not replace existing messages" do
req = Rack::MockRequest.new(
- Rack::ShowStatus.new(
+ show_status(
lambda{|env|
[404, {"Content-Type" => "text/plain", "Content-Length" => "4"}, ["foo!"]]
}))
@@ -52,15 +57,15 @@
headers = {"WWW-Authenticate" => "Basic blah"}
req = Rack::MockRequest.new(
- Rack::ShowStatus.new(lambda{|env| [401, headers, []] }))
+ show_status(lambda{|env| [401, headers, []] }))
res = req.get("/", :lint => true)
res["WWW-Authenticate"].should.equal("Basic blah")
end
should "replace existing messages if there is detail" do
req = Rack::MockRequest.new(
- Rack::ShowStatus.new(
+ show_status(
lambda{|env|
env["rack.showstatus.detail"] = "gone too meta."
[404, {"Content-Type" => "text/plain", "Content-Length" => "4"}, ["foo!"]]
View
@@ -1,22 +1,27 @@
require 'rack/static'
+require 'rack/lint'
require 'rack/mock'
class DummyApp
def call(env)
- [200, {}, ["Hello World"]]
+ [200, {"Content-Type" => "text/plain"}, ["Hello World"]]
end
end
describe Rack::Static do
+ def static(app, *args)
+ Rack::Lint.new Rack::Static.new(app, *args)
+ end
+
root = File.expand_path(File.dirname(__FILE__))
OPTIONS = {:urls => ["/cgi"], :root => root}
STATIC_OPTIONS = {:urls => [""], :root => "#{root}/static", :index => 'index.html'}
HASH_OPTIONS = {:urls => {"/cgi/sekret" => 'cgi/test'}, :root => root}
- @request = Rack::MockRequest.new(Rack::Static.new(DummyApp.new, OPTIONS))
- @static_request = Rack::MockRequest.new(Rack::Static.new(DummyApp.new, STATIC_OPTIONS))
- @hash_request = Rack::MockRequest.new(Rack::Static.new(DummyApp.new, HASH_OPTIONS))
+ @request = Rack::MockRequest.new(static(DummyApp.new, OPTIONS))
+ @static_request = Rack::MockRequest.new(static(DummyApp.new, STATIC_OPTIONS))
+ @hash_request = Rack::MockRequest.new(static(DummyApp.new, HASH_OPTIONS))
it "serves files" do
res = @request.get("/cgi/test")
@@ -67,7 +72,7 @@ def call(env)
it "supports serving fixed cache-control" do
opts = OPTIONS.merge(:cache_control => 'public')
- request = Rack::MockRequest.new(Rack::Static.new(DummyApp.new, opts))
+ request = Rack::MockRequest.new(static(DummyApp.new, opts))
res = request.get("/cgi/test")
res.should.be.ok
res.headers['Cache-Control'].should == 'public'
View
@@ -10,11 +10,11 @@
'Content-Type' => 'text/plain'
}, [""]]
}
- map = Rack::URLMap.new({
+ map = Rack::Lint.new(Rack::URLMap.new({
'http://foo.org/bar' => app,
'/foo' => app,
'/foo/bar' => app
- })
+ }))
res = Rack::MockRequest.new(map).get("/")
res.should.be.not_found
@@ -66,7 +66,7 @@
it "dispatches hosts correctly" do
- map = Rack::URLMap.new("http://foo.org/" => lambda { |env|
+ map = Rack::Lint.new(Rack::URLMap.new("http://foo.org/" => lambda { |env|
[200,
{ "Content-Type" => "text/plain",
"X-Position" => "foo.org",
@@ -90,7 +90,7 @@
"X-Position" => "default.org",
"X-Host" => env["HTTP_HOST"] || env["SERVER_NAME"],
}, [""]]}
- )
+ ))
res = Rack::MockRequest.new(map).get("/")
res.should.be.ok
@@ -124,7 +124,7 @@
end
should "be nestable" do
- map = Rack::URLMap.new("/foo" =>
+ map = Rack::Lint.new(Rack::URLMap.new("/foo" =>
Rack::URLMap.new("/bar" =>
Rack::URLMap.new("/quux" => lambda { |env|
[200,
@@ -133,7 +133,7 @@
"X-PathInfo" => env["PATH_INFO"],
"X-ScriptName" => env["SCRIPT_NAME"],
}, [""]]}
- )))
+ ))))
res = Rack::MockRequest.new(map).get("/foo/bar")
res.should.be.not_found
@@ -146,7 +146,7 @@
end
should "route root apps correctly" do
- map = Rack::URLMap.new("/" => lambda { |env|
+ map = Rack::Lint.new(Rack::URLMap.new("/" => lambda { |env|
[200,
{ "Content-Type" => "text/plain",
"X-Position" => "root",
@@ -160,7 +160,7 @@
"X-PathInfo" => env["PATH_INFO"],
"X-ScriptName" => env["SCRIPT_NAME"]
}, [""]]}
- )
+ ))
res = Rack::MockRequest.new(map).get("/foo/bar")
res.should.be.ok
@@ -188,7 +188,7 @@
end
should "not squeeze slashes" do
- map = Rack::URLMap.new("/" => lambda { |env|
+ map = Rack::Lint.new(Rack::URLMap.new("/" => lambda { |env|
[200,
{ "Content-Type" => "text/plain",
"X-Position" => "root",
@@ -202,7 +202,7 @@
"X-PathInfo" => env["PATH_INFO"],
"X-ScriptName" => env["SCRIPT_NAME"]
}, [""]]}
- )
+ ))
res = Rack::MockRequest.new(map).get("/http://example.org/bar")
res.should.be.ok

0 comments on commit dab9742

Please sign in to comment.