summaryrefslogtreecommitdiff
path: root/test/spec_builder.rb
diff options
context:
space:
mode:
authorLars Gierth <lars.gierth@gmail.com>2011-12-18 06:48:47 +0100
committerJames Tucker <jftucker@gmail.com>2011-12-21 05:33:43 -0800
commit484bcfd4931e3cbdb0b3759aa0e5e8c8113cc575 (patch)
treeb502aa26b44e3726ee957d7e1e3ca437d7abe58a /test/spec_builder.rb
parent39582c24cd829c8e2413a76f2c982d0c9166fb81 (diff)
downloadrack-484bcfd4931e3cbdb0b3759aa0e5e8c8113cc575.tar.gz
Wrap test apps in Rack::Lint (first pass)
Update tests for Auth::Basic, Auth::Digest, Builder, Casecase, Handler::CGI, Chunked, CommonLogger and ConditionalGet.
Diffstat (limited to 'test/spec_builder.rb')
-rw-r--r--test/spec_builder.rb51
1 files changed, 31 insertions, 20 deletions
diff --git a/test/spec_builder.rb b/test/spec_builder.rb
index d3e7261d..f3a18b83 100644
--- a/test/spec_builder.rb
+++ b/test/spec_builder.rb
@@ -1,4 +1,5 @@
require 'rack/builder'
+require 'rack/lint'
require 'rack/mock'
require 'rack/showexceptions'
require 'rack/urlmap'
@@ -18,38 +19,46 @@ class NothingMiddleware
end
describe Rack::Builder do
+ def builder(&block)
+ Rack::Lint.new Rack::Builder.new(&block)
+ end
+
+ def builder_to_app(&block)
+ Rack::Lint.new Rack::Builder.new(&block).to_app
+ end
+
it "supports mapping" do
- app = Rack::Builder.new do
+ app = builder_to_app do
map '/' do |outer_env|
- run lambda { |inner_env| [200, {}, ['root']] }
+ run lambda { |inner_env| [200, {"Content-Type" => "text/plain"}, ['root']] }
end
map '/sub' do
- run lambda { |inner_env| [200, {}, ['sub']] }
+ run lambda { |inner_env| [200, {"Content-Type" => "text/plain"}, ['sub']] }
end
- end.to_app
+ end
Rack::MockRequest.new(app).get("/").body.to_s.should.equal 'root'
Rack::MockRequest.new(app).get("/sub").body.to_s.should.equal 'sub'
end
it "doesn't dupe env even when mapping" do
- app = Rack::Builder.new do
+ app = builder_to_app do
use NothingMiddleware
map '/' do |outer_env|
run lambda { |inner_env|
inner_env['new_key'] = 'new_value'
- [200, {}, ['root']]
+ [200, {"Content-Type" => "text/plain"}, ['root']]
}
end
- end.to_app
+ end
Rack::MockRequest.new(app).get("/").body.to_s.should.equal 'root'
NothingMiddleware.env['new_key'].should.equal 'new_value'
end
it "chains apps by default" do
- app = Rack::Builder.new do
+ app = builder_to_app do
use Rack::ShowExceptions
run lambda { |env| raise "bzzzt" }
- end.to_app
+ end
Rack::MockRequest.new(app).get("/").should.be.server_error
Rack::MockRequest.new(app).get("/").should.be.server_error
@@ -57,7 +66,7 @@ describe Rack::Builder do
end
it "has implicit #to_app" do
- app = Rack::Builder.new do
+ app = builder do
use Rack::ShowExceptions
run lambda { |env| raise "bzzzt" }
end
@@ -68,13 +77,13 @@ describe Rack::Builder do
end
it "supports blocks on use" do
- app = Rack::Builder.new do
+ app = builder do
use Rack::ShowExceptions
use Rack::Auth::Basic do |username, password|
'secret' == password
end
- run lambda { |env| [200, {}, ['Hi Boss']] }
+ run lambda { |env| [200, {"Content-Type" => "text/plain"}, ['Hi Boss']] }
end
response = Rack::MockRequest.new(app).get("/")
@@ -89,7 +98,7 @@ describe Rack::Builder do
end
it "has explicit #to_app" do
- app = Rack::Builder.app do
+ app = builder do
use Rack::ShowExceptions
run lambda { |env| raise "bzzzt" }
end
@@ -100,9 +109,11 @@ describe Rack::Builder do
end
it "can mix map and run for endpoints" do
- app = Rack::Builder.app do
- map('/sub') { run lambda { |inner_env| [200, {}, ['sub']] }}
- run lambda { |inner_env| [200, {}, ['root']] }
+ app = builder do
+ map '/sub' do
+ run lambda { |inner_env| [200, {"Content-Type" => "text/plain"}, ['sub']] }
+ end
+ run lambda { |inner_env| [200, {"Content-Type" => "text/plain"}, ['root']] }
end
Rack::MockRequest.new(app).get("/").body.to_s.should.equal 'root'
@@ -110,7 +121,7 @@ describe Rack::Builder do
end
it "accepts middleware-only map blocks" do
- app = Rack::Builder.app do
+ app = builder do
map('/foo') { use Rack::ShowExceptions }
run lambda { |env| raise "bzzzt" }
end
@@ -120,7 +131,7 @@ describe Rack::Builder do
end
should "initialize apps once" do
- app = Rack::Builder.new do
+ app = builder do
class AppClass
def initialize
@called = 0
@@ -141,7 +152,7 @@ describe Rack::Builder do
end
it "allows use after run" do
- app = Rack::Builder.app do
+ app = builder do
run lambda { |env| raise "bzzzt" }
use Rack::ShowExceptions
end
@@ -153,7 +164,7 @@ describe Rack::Builder do
it 'complains about a missing run' do
proc do
- Rack::Builder.app { use Rack::ShowExceptions }
+ Rack::Lint.new Rack::Builder.app { use Rack::ShowExceptions }
end.should.raise(RuntimeError)
end