Sha256: b08d80e6259219cabe6f85c02d09eb3b0f8fc4f95bf580baf3a7054857cff221

Contents?: true

Size: 1.3 KB

Versions: 7

Compression:

Stored size: 1.3 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
      @packer.buffer.should == "\x01"
    end

    it "should track the number of bytes written" do
      @packer.total.should == 1
    end

    it "should be convertable to a String" do
      @packer.to_s.should == "\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

      @buffer.should == ["\x01"]
    end

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

      packer.total.should == 1
    end

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

      @buffer.should == [["\x01", 1]]
    end

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

      packer.to_s.should == nil
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
ffi-msgpack-0.2.1 spec/packer_spec.rb
ffi-msgpack-0.2.0 spec/packer_spec.rb
ffi-msgpack-0.1.4 spec/packer_spec.rb
ffi-msgpack-0.1.3 spec/packer_spec.rb
ffi-msgpack-0.1.2 spec/packer_spec.rb
ffi-msgpack-0.1.1 spec/packer_spec.rb
ffi-msgpack-0.1.0 spec/packer_spec.rb