Sha256: 1cada5a1cf10065ab17214bf780383ce62099319cfda0ee965e496774551f58c

Contents?: true

Size: 1.63 KB

Versions: 121

Compression:

Stored size: 1.63 KB

Contents

require 'rack/body_proxy'
require 'stringio'

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 'call the passed block on close even if there is an exception' do
    object = Object.new
    def object.close() raise "No!" end
    called = false

    begin
      proxy  = Rack::BodyProxy.new(object) { called = true }
      called.should.equal false
      proxy.close
    rescue RuntimeError => e
    end

    raise "Expected exception to have been raised" unless e
    called.should.equal true
  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 }
    2.times { proxy.close }
    count.should.equal 1
  end

  should 'be closed when the callback is triggered' do
    closed = false
    proxy = Rack::BodyProxy.new([]) { closed = proxy.closed? }
    proxy.close
    closed.should.equal true
  end
end

Version data entries

121 entries across 102 versions & 13 rubygems

Version Path
classiccms-0.7.5 vendor/bundle/gems/rack-1.4.1/test/spec_body_proxy.rb
classiccms-0.7.4 vendor/bundle/gems/rack-1.4.1/test/spec_body_proxy.rb
classiccms-0.7.3 vendor/bundle/gems/rack-1.4.1/test/spec_body_proxy.rb
classiccms-0.7.2 vendor/bundle/gems/rack-1.4.1/test/spec_body_proxy.rb
classiccms-0.7.1 vendor/bundle/gems/rack-1.4.1/test/spec_body_proxy.rb
classiccms-0.7.0 vendor/bundle/gems/rack-1.4.1/test/spec_body_proxy.rb
sunrise-cms-0.5.0.rc1 vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/test/spec_body_proxy.rb
challah-0.9.0 vendor/bundle/gems/rack-1.4.1/test/spec_body_proxy.rb
classiccms-0.6.9 vendor/bundle/gems/rack-1.4.1/test/spec_body_proxy.rb
jquery_regex-0.0.3 vendor/bundle/gems/jquery_regex-0.0.3/vendor/bundle/gems/jquery_regex-0.0.2/vendor/bundle/gems/jquery_regex-0.0.1/vendor/bundle/gems/rack-1.4.1/test/spec_body_proxy.rb
jquery_regex-0.0.3 vendor/bundle/gems/jquery_regex-0.0.2/vendor/bundle/gems/jquery_regex-0.0.1/vendor/bundle/gems/rack-1.4.1/test/spec_body_proxy.rb
jquery_regex-0.0.3 vendor/bundle/gems/jquery_regex-0.0.2/vendor/bundle/gems/rack-1.4.1/test/spec_body_proxy.rb
jquery_regex-0.0.3 vendor/bundle/gems/rack-1.4.1/test/spec_body_proxy.rb
jquery_regex-0.0.3 vendor/bundle/gems/jquery_regex-0.0.1/vendor/bundle/gems/rack-1.4.1/test/spec_body_proxy.rb
jquery_regex-0.0.3 vendor/bundle/gems/jquery_regex-0.0.3/vendor/bundle/gems/jquery_regex-0.0.1/vendor/bundle/gems/rack-1.4.1/test/spec_body_proxy.rb
jquery_regex-0.0.3 vendor/bundle/gems/jquery_regex-0.0.3/vendor/bundle/gems/jquery_regex-0.0.2/vendor/bundle/gems/rack-1.4.1/test/spec_body_proxy.rb
jquery_regex-0.0.3 vendor/bundle/gems/jquery_regex-0.0.3/vendor/bundle/gems/rack-1.4.1/test/spec_body_proxy.rb
jquery_regex-0.0.1 vendor/bundle/gems/rack-1.4.1/test/spec_body_proxy.rb
challah-rolls-0.2.0 vendor/bundle/gems/challah-0.8.0.pre/vendor/bundle/gems/rack-1.4.1/test/spec_body_proxy.rb
challah-rolls-0.2.0 vendor/bundle/gems/challah-0.8.3/vendor/bundle/gems/rack-1.4.1/test/spec_body_proxy.rb