Sha256: d6533bbd17c2e4ead98f08c28128a0381dc52f36cd602aa04662b076998b891e

Contents?: true

Size: 1.28 KB

Versions: 20

Compression:

Stored size: 1.28 KB

Contents

require 'spec_helper'

describe GnipApi::Apis::PowerTrack::Buffer do
  before do
    @buffer = GnipApi::Apis::PowerTrack::Buffer.new(:terminator => '--')
  end
  
  it 'has "--" as terminator char' do
    expect(@buffer.terminator).to eq('--')
  end

  it 'stores string data' do
    expect(@buffer.data.kind_of?(String)).to eq(true)
  end

  describe '#insert!' do
    it 'apends data at the end' do
      @buffer.insert! "asd"
      expect(@buffer.data[-1]).to eq('d')
      @buffer.insert! 'lol'
      expect(@buffer.data[-1]).to eq('l')
    end
  end

  describe '#read!' do
    context 'with partial data' do
      before do
        @buffer.insert! 'asd--qwe--x'
      end
      
      it 'gets complete objects' do
        objects = @buffer.read!
        expect(objects.empty?).to eq(false)
      end

      it 'consumes data from buffer' do
        @buffer.read!
        expect(@buffer.data).to eq('x')
      end
    end

    context 'with complete data' do
      before do
        @buffer.insert! 'asd--qwe--zxc'
      end

      it 'gets complete objects except for last one' do
        objects = @buffer.read!
        expect(objects.size).to eq(2)
      end

      it 'removes the data read' do
        @buffer.read!
        expect(@buffer.data.include?('asd')).to eq(false)
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
gnip_api-1.1.3 spec/gnip_api/apis/power_track/buffer_spec.rb
gnip_api-1.1.2 spec/gnip_api/apis/power_track/buffer_spec.rb
gnip_api-1.1.1 spec/gnip_api/apis/power_track/buffer_spec.rb
gnip_api-1.1.0 spec/gnip_api/apis/power_track/buffer_spec.rb
gnip_api-1.0.6 spec/gnip_api/apis/power_track/buffer_spec.rb
gnip_api-1.0.5 spec/gnip_api/apis/power_track/buffer_spec.rb
gnip_api-1.0.4 spec/gnip_api/apis/power_track/buffer_spec.rb
gnip_api-1.0.3 spec/gnip_api/apis/power_track/buffer_spec.rb
gnip_api-1.0.2 spec/gnip_api/apis/power_track/buffer_spec.rb
gnip_api-1.0.1 spec/gnip_api/apis/power_track/buffer_spec.rb
gnip_api-1.0.0 spec/gnip_api/apis/power_track/buffer_spec.rb
gnip_api-0.0.9 spec/gnip_api/apis/power_track/buffer_spec.rb
gnip_api-0.0.8 spec/gnip_api/apis/power_track/buffer_spec.rb
gnip_api-0.0.7 spec/gnip_api/apis/power_track/buffer_spec.rb
gnip_api-0.0.6 spec/gnip_api/apis/power_track/buffer_spec.rb
gnip_api-0.0.5 spec/gnip_api/apis/power_track/buffer_spec.rb
gnip_api-0.0.4 spec/gnip_api/apis/power_track/buffer_spec.rb
gnip_api-0.0.3 spec/gnip_api/apis/power_track/buffer_spec.rb
gnip_api-0.0.2 spec/gnip_api/apis/power_track/buffer_spec.rb
gnip_api-0.0.1 spec/gnip_api/apis/power_track/buffer_spec.rb