Permalink
Browse files

Add some more edge-case tests to improve coverage

darcs-hash:20070511145605-4fc50-e3e8e83f7d4bd6fbbbbee59d014dc5b7a549a7a5.gz
  • Loading branch information...
chneukirchen committed May 11, 2007
1 parent 68dd1b9 commit 30a35505f77e02e27b90b1eff91c110bff0f30a1
Showing with 22 additions and 7 deletions.
  1. +4 −0 lib/rack/mock.rb
  2. +3 −0 test/spec_rack_camping.rb
  3. +2 −0 test/spec_rack_mock.rb
  4. +12 −0 test/spec_rack_session_cookie.rb
  5. +1 −7 test/spec_rack_urlmap.rb
View
@@ -32,6 +32,10 @@ def write(warning)
def flush
end
+
+ def string
+ ""
+ end
end
DEFAULT_ENV = {
@@ -1,5 +1,6 @@
require 'test/spec'
require 'stringio'
+require 'uri'
require 'rack/mock'
@@ -12,6 +13,7 @@ module CampApp
module Controllers
class HW < R('/')
def get
+ @headers["X-Served-By"] = URI("http://rack.rubyforge.org")
"Camping works!"
end
@@ -30,6 +32,7 @@ def post
res.should.be.ok
res["Content-Type"].should.equal "text/html"
+ res["X-Served-By"].should.equal "http://rack.rubyforge.org"
res.body.should.equal "Camping works!"
end
View
@@ -126,13 +126,15 @@
res["Content-Type"].should.equal "text/yaml"
res.content_type.should.equal "text/yaml"
res.content_length.should.be.nil
+ res.location.should.be.nil
end
specify "should provide access to the HTTP body" do
res = Rack::MockRequest.new(app).get("")
res.body.should =~ /rack/
res.should =~ /rack/
res.should.match(/rack/)
+ res.should.satisfy { |r| r.match(/rack/) }
end
specify "should provide access to the Rack errors" do
@@ -34,4 +34,16 @@
get("/", "HTTP_COOKIE" => "rack.session=blarghfasel")
res.body.should.equal '{"counter"=>1}'
end
+
+ bigcookie = lambda { |env|
+ env["rack.session"]["cookie"] = "big" * 3000
+ Rack::Response.new(env["rack.session"].inspect).to_a
+ }
+
+ specify "barks on too big cookies" do
+ lambda {
+ Rack::MockRequest.new(Rack::Session::Cookie.new(bigcookie)).
+ get("/", :fatal => true)
+ }.should.raise(Rack::MockRequest::FatalWarning)
+ end
end
View
@@ -17,14 +17,8 @@
{ "Content-Type" => "text/plain",
"X-Position" => "/bar",
"X-PathInfo" => env["PATH_INFO"],
- }, [""]]},
-
- "/foo/bar" => lambda { |env|
- [200,
- { "Content-Type" => "text/plain",
- "X-Position" => "/foo/bar",
- "X-PathInfo" => env["PATH_INFO"],
}, [""]]}
+
)

0 comments on commit 30a3550

Please sign in to comment.