Sha256: 2f76a0e2b03cb1ecdd78549757855e9c3fa07cb684afa3e83f3df2648526f35f

Contents?: true

Size: 1.33 KB

Versions: 1

Compression:

Stored size: 1.33 KB

Contents

require 'spec_helper'
require 'ffi/msgpack/packer'

describe MsgPack::Packer do
  context "buffer" do
    before(:each) do
      @packer = MsgPack::Packer.create
      @packer << 1
    end

    it "should write packed messages to a buffer" do
      expect(@packer.buffer).to eq("\x01")
    end

    it "should track the number of bytes written" do
      expect(@packer.total).to eq(1)
    end

    it "should be convertable to a String" do
      expect(@packer.to_s).to eq("\x01")
    end
  end

  context "callback" do
    before(:each) do
      @buffer = []
    end

    it "should write packed messages using a callback" do
      packer = MsgPack::Packer.create do |packed|
        @buffer << packed
      end
      packer << 1

      expect(@buffer).to eq(["\x01"])
    end

    it "should track the number of bytes written" do
      packer = MsgPack::Packer.create do |packed|
        @buffer << packed
      end
      packer << 1

      expect(packer.total).to eq(1)
    end

    it "should accept a secondary length argument" do
      packer = MsgPack::Packer.create do |packed,length|
        @buffer << [packed, length]
      end
      packer << 1

      expect(@buffer).to eq([["\x01", 1]])
    end

    it "should not be convertable to a String" do
      packer = MsgPack::Packer.create { |packed| }

      expect(packer.to_s).to eq(nil)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ffi-msgpack-0.2.2 spec/packer_spec.rb