Permalink
Browse files

Added specification for Rack::Request memoization.

  • Loading branch information...
1 parent 3873269 commit 552f7b0718ee8cd79c185cd72413690f0da72402 @mtodd mtodd committed Dec 25, 2008
Showing with 16 additions and 0 deletions.
  1. +16 −0 test/spec_rack_request.rb
@@ -433,4 +433,20 @@
res.body.should == '212.212.212.212'
end
+
+ specify "memoizes itself to reduce the cost of repetitive initialization" do
+ env = Rack::MockRequest.env_for("http://example.com:8080/")
+ env['rack.request'].should.be.nil
+
+ req1 = Rack::Request.new(env)
+ env['rack.request'].should.not.be.nil
+ req1.should.equal env['rack.request']
+
+ rack_request_object_id = env['rack.request'].object_id
+
+ req2 = Rack::Request.new(env)
+ env['rack.request'].should.not.be.nil
+ rack_request_object_id.should.be.equal env['rack.request'].object_id
+ req2.should.equal env['rack.request']
+ end
end

0 comments on commit 552f7b0

Please sign in to comment.