Permalink
Browse files

let Rack::BodyProxy raise an IOError (like IO and StringIO do) when c…

…alling #close twice. Related to #191.
  • Loading branch information...
1 parent 81a2a75 commit 00503bebcaf72f2313ad021f0663a5f39592144e @rkh rkh committed Jun 14, 2011
Showing with 9 additions and 11 deletions.
  1. +5 −7 lib/rack/body_proxy.rb
  2. +4 −4 test/spec_body_proxy.rb
View
@@ -9,13 +9,11 @@ def respond_to?(*args)
end
def close
- return if closed?
- begin
- @body.close if @body.respond_to? :close
- ensure
- @block.call
- @closed = true
- end
+ raise IOError, "closed stream" if @closed
+ @body.close if @body.respond_to? :close
+ ensure
+ @block.call
+ @closed = true
end
def closed?
View
@@ -1,9 +1,9 @@
describe Rack::BodyProxy do
should 'not close more than one time' do
- count = 0
- proxy = Rack::BodyProxy.new([]) { count += 1 }
+ proxy = Rack::BodyProxy.new([]) { }
proxy.close
- proxy.close
- count.should == 1
+ lambda {
+ proxy.close
+ }.should.raise(IOError)
end
end

0 comments on commit 00503be

Please sign in to comment.