Sha256: ad310aa16c73566cbd92db1c7e970fd4699b4147b40d2ee5966ea6d1e42a5676

Contents?: true

Size: 1.73 KB

Versions: 70

Compression:

Stored size: 1.73 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

  should 'provide an #each method' do
    Rack::BodyProxy.method_defined?(:each).should.equal true
  end
end

Version data entries

70 entries across 59 versions & 21 rubygems

Version Path
torquebox-console-0.2.5 vendor/bundle/jruby/1.9/gems/rack-1.5.2/test/spec_body_proxy.rb
torquebox-console-0.2.5 vendor/bundle/ruby/1.8/gems/rack-1.5.2/test/spec_body_proxy.rb
vagrant-actionio-0.0.9 vendor/bundle/gems/rack-1.5.2/test/spec_body_proxy.rb
torquebox-console-0.2.4 vendor/bundle/jruby/1.9/gems/rack-1.5.2/test/spec_body_proxy.rb
torquebox-console-0.2.4 vendor/bundle/ruby/1.8/gems/rack-1.5.2/test/spec_body_proxy.rb
torquebox-console-0.2.3 vendor/bundle/jruby/1.9/gems/rack-1.5.2/test/spec_body_proxy.rb
active_mailer-0.0.5 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/test/spec_body_proxy.rb
active_mailer-0.0.4 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/test/spec_body_proxy.rb
active_mailer-0.0.3 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/rack-1.4.5/test/spec_body_proxy.rb
graphael-on-rails-0.5.1 vendor/bundle/gems/rack-1.4.5/test/spec_body_proxy.rb
graphael-on-rails-0.0.1 vendor/bundle/gems/rack-1.4.5/test/spec_body_proxy.rb
challah-0.9.1.beta.3 vendor/bundle/gems/rack-1.4.3/test/spec_body_proxy.rb
rack-1.5.2 test/spec_body_proxy.rb
rack-1.4.5 test/spec_body_proxy.rb
devise_sociable-0.1.0 vendor/bundle/gems/rack-1.5.1/test/spec_body_proxy.rb
devise_sociable-0.1.0 vendor/bundle/gems/rack-1.4.4/test/spec_body_proxy.rb
rack-1.5.1 test/spec_body_proxy.rb
rack-1.5.0 test/spec_body_proxy.rb
backbone-queryparams-rails-0.0.1 vendor/bundle/gems/rack-1.4.4/test/spec_body_proxy.rb
railscast-assets-0.0.2 vendor/bundle/gems/backbone-forms-on-rails-0.10.0/vendor/bundle/gems/rack-1.4.4/test/spec_body_proxy.rb