Skip to content

Commit

Permalink
Add some more edge-case tests to improve coverage
Browse files Browse the repository at this point in the history
darcs-hash:20070511145605-4fc50-e3e8e83f7d4bd6fbbbbee59d014dc5b7a549a7a5.gz
  • Loading branch information
leahneukirchen committed May 11, 2007
1 parent 68dd1b9 commit 30a3550
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 7 deletions.
4 changes: 4 additions & 0 deletions lib/rack/mock.rb
Expand Up @@ -32,6 +32,10 @@ def write(warning)

def flush
end

def string
""
end
end

DEFAULT_ENV = {
Expand Down
3 changes: 3 additions & 0 deletions test/spec_rack_camping.rb
@@ -1,5 +1,6 @@
require 'test/spec'
require 'stringio'
require 'uri'

require 'rack/mock'

Expand All @@ -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

Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions test/spec_rack_mock.rb
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions test/spec_rack_session_cookie.rb
Expand Up @@ -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
8 changes: 1 addition & 7 deletions test/spec_rack_urlmap.rb
Expand Up @@ -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"],
}, [""]]}

)


Expand Down

0 comments on commit 30a3550

Please sign in to comment.