Sha256: 32bafb430f0694c2e64bc3147c614b5638439d0128fee7e3ece15315dc122d4f

Contents?: true

Size: 1.01 KB

Versions: 4

Compression:

Stored size: 1.01 KB

Contents

require 'spec_helper'

describe HTTP::Response::Body do
  let(:client)   { double }
  let(:chunks)   { ['Hello, ', 'World!'] }

  before         { allow(client).to receive(:readpartial) { chunks.shift } }

  subject(:body) { described_class.new client }

  it 'streams bodies from responses' do
    expect(subject.to_s).to eq 'Hello, World!'
  end

  context 'when body empty' do
    let(:chunks) { [''] }

    it 'returns responds to empty? with true' do
      expect(subject).to be_empty
    end
  end

  describe '#readpartial' do
    context 'with size given' do
      it 'passes value to underlying client' do
        expect(client).to receive(:readpartial).with(42)
        body.readpartial 42
      end
    end

    context 'without size given' do
      it 'does not blows up' do
        expect { body.readpartial }.to_not raise_error
      end

      it 'calls underlying client readpartial without specific size' do
        expect(client).to receive(:readpartial).with no_args
        body.readpartial
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
http-0.6.4 spec/http/response/body_spec.rb
http-0.6.3 spec/http/response/body_spec.rb
http-0.6.2 spec/http/response/body_spec.rb
http-0.6.1 spec/http/response/body_spec.rb