Sha256: 8338e7d384ac9332389d780ac85e5ab5bd063bd5cbbd338e24d9f16b4cf72970

Contents?: true

Size: 1.86 KB

Versions: 17

Compression:

Stored size: 1.86 KB

Contents

# encoding: binary

require File.expand_path('../../../spec_helper', __FILE__)


module AMQ
  module Protocol
    describe Method do
      describe '.split_headers' do
        it 'splits user defined headers into properties and headers' do
          input = {:delivery_mode => 2, :content_type => 'application/octet-stream', :foo => 'bar'}
          properties, headers = Method.split_headers(input)
          properties.should == {:delivery_mode => 2, :content_type => 'application/octet-stream'}
          headers.should == {:foo => 'bar'}
        end
      end
      
      describe '.encode_body' do
        context 'when the body fits in a single frame' do
          it 'encodes a body into a BodyFrame' do
            body_frames = Method.encode_body('Hello world', 1, 131072)
            body_frames.first.payload.should == 'Hello world'
            body_frames.first.channel.should == 1
            body_frames.should have(1).item
          end
        end

        context 'when the body is to big to fit in a single frame' do
          it 'encodes a body into a list of BodyFrames that each fit within the frame size' do
            lipsum = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.'
            frame_size = 100
            expected_payload_size = 93
            body_frames = Method.encode_body(lipsum, 1, frame_size)
            body_frames.map(&:payload).should == lipsum.split('').each_slice(expected_payload_size).map(&:join)
          end
        end
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
amq-protocol-1.0.0.pre1 spec/amq/protocol/method_spec.rb
amq-protocol-0.9.0 spec/amq/protocol/method_spec.rb
amq-protocol-0.8.4 spec/amq/protocol/method_spec.rb
amq-protocol-0.8.3 spec/amq/protocol/method_spec.rb
amq-protocol-0.8.1 spec/amq/protocol/method_spec.rb
amq-protocol-0.8.0 spec/amq/protocol/method_spec.rb
amq-protocol-0.7.0 spec/amq/protocol/method_spec.rb
amq-protocol-0.7.0.beta2 spec/amq/protocol/method_spec.rb
amq-protocol-0.7.0.beta1 spec/amq/protocol/method_spec.rb
amq-protocol-0.7.0.alpha7 spec/amq/protocol/method_spec.rb
amq-protocol-0.7.0.alpha6 spec/amq/protocol/method_spec.rb
amq-protocol-0.7.0.alpha5 spec/amq/protocol/method_spec.rb
amq-protocol-0.7.0.alpha4 spec/amq/protocol/method_spec.rb
amq-protocol-0.7.0.alpha2 spec/amq/protocol/method_spec.rb
amq-protocol-0.7.0.alpha1 spec/amq/protocol/method_spec.rb
amq-protocol-0.6.0.pre spec/amq/protocol/method_spec.rb
amq-protocol-0.5.0 spec/amq/protocol/method_spec.rb