Skip to content

Commit

Permalink
block should not be called if IOError raised
Browse files Browse the repository at this point in the history
Signed-off-by: Konstantin Haase <konstantin.mailinglists@googlemail.com>
  • Loading branch information
Jan Xie authored and rkh committed Jun 14, 2011
1 parent 4856607 commit 9d53fb9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
10 changes: 6 additions & 4 deletions lib/rack/body_proxy.rb
Expand Up @@ -10,10 +10,12 @@ def respond_to?(*args)


def close def close
raise IOError, "closed stream" if @closed raise IOError, "closed stream" if @closed
@body.close if @body.respond_to? :close begin
ensure @body.close if @body.respond_to? :close
@block.call ensure
@closed = true @block.call
@closed = true
end
end end


def closed? def closed?
Expand Down
3 changes: 2 additions & 1 deletion test/spec_body_proxy.rb
Expand Up @@ -33,7 +33,8 @@
end end


should 'not close more than one time' do should 'not close more than one time' do
proxy = Rack::BodyProxy.new([]) { } count = 0
proxy = Rack::BodyProxy.new([]) { count += 1; raise "Block invoked more than 1 time!" if count > 1 }
proxy.close proxy.close
lambda { lambda {
proxy.close proxy.close
Expand Down

0 comments on commit 9d53fb9

Please sign in to comment.