Permalink
Browse files

Add Rack::Response#empty?

darcs-hash:20070418131558-4fc50-f700034bd3b8cfa1fe85c9b2f2f020a4419ed438.gz
  • Loading branch information...
1 parent cbfe671 commit 04f2bdf2ed9b851cec65bab0dd40bd00caca8196 @chneukirchen committed Apr 18, 2007
Showing with 22 additions and 0 deletions.
  1. +5 −0 lib/rack/response.rb
  2. +17 −0 test/spec_rack_response.rb
View
@@ -22,6 +22,7 @@ def initialize(body=[], status=200, header={}, &block)
merge(header))
@writer = lambda { |x| @body << x }
+ @block = nil
@body = []
@@ -110,5 +111,9 @@ def write(str)
@writer.call str.to_s
str
end
+
+ def empty?
+ @block == nil && @body.empty?
+ end
end
end
View
@@ -107,4 +107,21 @@
}.should.raise(TypeError).
message.should =~ /stringable or iterable required/
end
+
+ specify "knows if it's empty" do
+ r = Rack::Response.new
+ r.should.be.empty
+ r.write "foo"
+ r.should.not.be.empty
+
+ r = Rack::Response.new
+ r.should.be.empty
+ r.finish
+ r.should.be.empty
+
+ r = Rack::Response.new
+ r.should.be.empty
+ r.finish { }
+ r.should.not.be.empty
+ end
end

0 comments on commit 04f2bdf

Please sign in to comment.