Permalink
Browse files

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

Update tests for Sendfile, Session::Cookie, Session::Memcache and Session::Pool.
  • Loading branch information...
1 parent 8f39d33 commit d072f0245b070a1369bca1e8d56c1d7b545c7ecf @lgierth lgierth committed Dec 28, 2011
Showing with 40 additions and 26 deletions.
  1. +8 −5 test/spec_sendfile.rb
  2. +9 −3 test/spec_session_cookie.rb
  3. +10 −8 test/spec_session_memcache.rb
  4. +13 −10 test/spec_session_pool.rb
View
@@ -1,3 +1,5 @@
+require 'fileutils'
+require 'rack/lint'
require 'rack/sendfile'
require 'rack/mock'
@@ -9,8 +11,9 @@
describe Rack::Sendfile do
def sendfile_body
+ FileUtils.touch "/tmp/rack_sendfile"
res = ['Hello World']
- def res.to_path ; "/tmp/hello.txt" ; end
+ def res.to_path ; "/tmp/rack_sendfile" ; end
res
end
@@ -19,7 +22,7 @@ def simple_app(body=sendfile_body)
end
def sendfile_app(body=sendfile_body)
- Rack::Sendfile.new(simple_app(body))
+ Rack::Lint.new Rack::Sendfile.new(simple_app(body))
end
@request = Rack::MockRequest.new(sendfile_app)
@@ -41,7 +44,7 @@ def request(headers={})
response.should.be.ok
response.body.should.be.empty
response.headers['Content-Length'].should == '0'
- response.headers['X-Sendfile'].should.equal '/tmp/hello.txt'
+ response.headers['X-Sendfile'].should.equal '/tmp/rack_sendfile'
end
end
@@ -50,7 +53,7 @@ def request(headers={})
response.should.be.ok
response.body.should.be.empty
response.headers['Content-Length'].should == '0'
- response.headers['X-Lighttpd-Send-File'].should.equal '/tmp/hello.txt'
+ response.headers['X-Lighttpd-Send-File'].should.equal '/tmp/rack_sendfile'
end
end
@@ -63,7 +66,7 @@ def request(headers={})
response.should.be.ok
response.body.should.be.empty
response.headers['Content-Length'].should == '0'
- response.headers['X-Accel-Redirect'].should.equal '/foo/bar/hello.txt'
+ response.headers['X-Accel-Redirect'].should.equal '/foo/bar/rack_sendfile'
end
end
@@ -1,4 +1,5 @@
require 'rack/session/cookie'
+require 'rack/lint'
require 'rack/mock'
describe Rack::Session::Cookie do
@@ -9,7 +10,7 @@
hash.delete("session_id")
Rack::Response.new(hash.inspect).to_a
end
-
+
session_id = lambda do |env|
Rack::Response.new(env["rack.session"].to_hash.inspect).to_a
end
@@ -45,10 +46,15 @@
def response_for(options={})
request_options = options.fetch(:request, {})
- request_options["HTTP_COOKIE"] = options[:cookie].is_a?(Rack::Response) ?
- options[:cookie]["Set-Cookie"] : options[:cookie]
+ cookie = if options[:cookie].is_a?(Rack::Response)
+ options[:cookie]["Set-Cookie"]
+ else
+ options[:cookie]
+ end
+ request_options["HTTP_COOKIE"] = cookie || ""
app_with_cookie = Rack::Session::Cookie.new(*options[:app])
+ app_with_cookie = Rack::Lint.new(app_with_cookie)
Rack::MockRequest.new(app_with_cookie).get("/", request_options)
end
@@ -1,5 +1,6 @@
begin
require 'rack/session/memcache'
+ require 'rack/lint'
require 'rack/mock'
require 'thread'
@@ -11,22 +12,23 @@
env["rack.session"]["counter"] += 1
Rack::Response.new(env["rack.session"].inspect).to_a
end
- drop_session = proc do |env|
+ drop_session = Rack::Lint.new(proc do |env|
env['rack.session.options'][:drop] = true
incrementor.call(env)
- end
- renew_session = proc do |env|
+ end)
+ renew_session = Rack::Lint.new(proc do |env|
env['rack.session.options'][:renew] = true
incrementor.call(env)
- end
- defer_session = proc do |env|
+ end)
+ defer_session = Rack::Lint.new(proc do |env|
env['rack.session.options'][:defer] = true
incrementor.call(env)
- end
- skip_session = proc do |env|
+ end)
+ skip_session = Rack::Lint.new(proc do |env|
env['rack.session.options'][:skip] = true
incrementor.call(env)
- end
+ end)
+ incrementor = Rack::Lint.new(incrementor)
# test memcache connection
Rack::Session::Memcache.new(incrementor)
View
@@ -1,4 +1,5 @@
require 'thread'
+require 'rack/lint'
require 'rack/mock'
require 'rack/session/pool'
@@ -12,28 +13,30 @@
Rack::Response.new(env["rack.session"].inspect).to_a
end
- session_id = lambda do |env|
+ session_id = Rack::Lint.new(lambda do |env|
Rack::Response.new(env["rack.session"].inspect).to_a
- end
+ end)
- nothing = lambda do |env|
+ nothing = Rack::Lint.new(lambda do |env|
Rack::Response.new("Nothing").to_a
- end
+ end)
- drop_session = lambda do |env|
+ drop_session = Rack::Lint.new(lambda do |env|
env['rack.session.options'][:drop] = true
incrementor.call(env)
- end
+ end)
- renew_session = lambda do |env|
+ renew_session = Rack::Lint.new(lambda do |env|
env['rack.session.options'][:renew] = true
incrementor.call(env)
- end
+ end)
- defer_session = lambda do |env|
+ defer_session = Rack::Lint.new(lambda do |env|
env['rack.session.options'][:defer] = true
incrementor.call(env)
- end
+ end)
+
+ incrementor = Rack::Lint.new(incrementor)
it "creates a new cookie" do
pool = Rack::Session::Pool.new(incrementor)

0 comments on commit d072f02

Please sign in to comment.