File: body_spec.rb

package info (click to toggle)
ruby-http 0.6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 404 kB
  • ctags: 213
  • sloc: ruby: 2,397; makefile: 7
file content (42 lines) | stat: -rw-r--r-- 1,039 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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