Permalink
Browse files

more tests for Rack::BodyProxy

  • Loading branch information...
1 parent c02443d commit c038a7561526ff85c2c7681b5eb506ad9186678e @rkh rkh committed Jun 14, 2011
Showing with 33 additions and 0 deletions.
  1. +33 −0 test/spec_body_proxy.rb
View
@@ -1,4 +1,37 @@
+require 'rack/body_proxy'
+
describe Rack::BodyProxy do
+ should 'call each on the wrapped body' do
+ called = false
+ proxy = Rack::BodyProxy.new(['foo']) { }
+ proxy.each do |str|
+ called = true
+ str.should.equal 'foo'
+ end
+ called.should.equal true
+ end
+
+ should 'call close on the wrapped body' do
+ body = StringIO.new
+ proxy = Rack::BodyProxy.new(body) { }
+ proxy.close
+ body.should.be.closed
+ end
+
+ should 'only call close on the wrapped body if it responds to close' do
+ body = []
+ proxy = Rack::BodyProxy.new(body) { }
+ proc { proxy.close }.should.not.raise
+ end
+
+ should 'call the passed block on close' do
+ called = false
+ proxy = Rack::BodyProxy.new([]) { called = true }
+ called.should.equal false
+ proxy.close
+ called.should.equal true
+ end
+
should 'not close more than one time' do
proxy = Rack::BodyProxy.new([]) { }
proxy.close

0 comments on commit c038a75

Please sign in to comment.