diff options
-rw-r--r-- | lib/rack/body_proxy.rb | 11 | ||||
-rw-r--r-- | test/spec_body_proxy.rb | 16 |
2 files changed, 19 insertions, 8 deletions
diff --git a/lib/rack/body_proxy.rb b/lib/rack/body_proxy.rb index b35167c8..95a74626 100644 --- a/lib/rack/body_proxy.rb +++ b/lib/rack/body_proxy.rb @@ -4,14 +4,9 @@ module Rack @body, @block, @closed = body, block, false end - def respond_to?(method_name) - case method_name - when :to_ary - return false - when String - return false if /^to_ary$/ =~ method_name - end - super or @body.respond_to?(method_name) + def respond_to?(*args) + return false if args.first.to_s =~ /^to_ary$/ + super or @body.respond_to?(*args) end def close diff --git a/test/spec_body_proxy.rb b/test/spec_body_proxy.rb index c65e10d2..8b6e6a5e 100644 --- a/test/spec_body_proxy.rb +++ b/test/spec_body_proxy.rb @@ -1,5 +1,6 @@ require 'rack/body_proxy' require 'stringio' +require 'ostruct' describe Rack::BodyProxy do should 'call each on the wrapped body' do @@ -49,6 +50,21 @@ describe Rack::BodyProxy do called.should.equal true end + should 'allow multiple arguments in respond_to?' do + body = [] + proxy = Rack::BodyProxy.new(body) { } + proc { proxy.respond_to?(:foo, false) }.should.not.raise + end + + should 'not respond to :to_ary' do + body = OpenStruct.new(:to_ary => true) + body.respond_to?(:to_ary).should.equal true + + proxy = Rack::BodyProxy.new(body) { } + proxy.respond_to?(:to_ary).should.equal false + proxy.respond_to?("to_ary").should.equal false + end + should 'not close more than one time' do count = 0 proxy = Rack::BodyProxy.new([]) { count += 1; raise "Block invoked more than 1 time!" if count > 1 } |