Skip to content

Commit

Permalink
let Rack::BodyProxy raise an IOError (like IO and StringIO do) when c…
Browse files Browse the repository at this point in the history
…alling #close twice. Related to rack#191.
  • Loading branch information
rkh committed Jun 14, 2011
1 parent 9f803f2 commit c02443d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
12 changes: 5 additions & 7 deletions lib/rack/body_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
8 changes: 4 additions & 4 deletions test/spec_body_proxy.rb
Original file line number Diff line number Diff line change
@@ -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 c02443d

Please sign in to comment.