Permalink
Browse files

Rip out Bacon examples, see spec/amqp/buffer_spec.rb

  • Loading branch information...
michaelklishin committed Jan 6, 2011
1 parent c56fe18 commit ecab3d97e04bbbca91b0849bb45c8dad38e68bbd
Showing with 0 additions and 125 deletions.
  1. +0 −125 lib/amqp/buffer.rb
View
@@ -268,128 +268,3 @@ def _write data, pack = nil
end
end
end
-
-if $0 =~ /bacon/ or $0 == __FILE__
- require 'bacon'
- include AMQP
-
- describe Buffer do
- before do
- @buf = Buffer.new
- end
-
- should 'have contents' do
- @buf.contents.should == ''
- end
-
- should 'initialize with data' do
- @buf = Buffer.new('abc')
- @buf.contents.should == 'abc'
- end
-
- should 'append raw data' do
- @buf << 'abc'
- @buf << 'def'
- @buf.contents.should == 'abcdef'
- end
-
- should 'append other buffers' do
- @buf << Buffer.new('abc')
- @buf.data.should == 'abc'
- end
-
- should 'have a position' do
- @buf.pos.should == 0
- end
-
- should 'have a length' do
- @buf.length.should == 0
- @buf << 'abc'
- @buf.length.should == 3
- end
-
- should 'know the end' do
- @buf.empty?.should == true
- end
-
- should 'read and write data' do
- @buf._write('abc')
- @buf.rewind
- @buf._read(2).should == 'ab'
- @buf._read(1).should == 'c'
- end
-
- should 'raise on overflow' do
- lambda{ @buf._read(1) }.should.raise Buffer::Overflow
- end
-
- should 'raise on invalid types' do
- lambda{ @buf.read(:junk) }.should.raise Buffer::InvalidType
- lambda{ @buf.write(:junk, 1) }.should.raise Buffer::InvalidType
- end
-
- { :octet => 0b10101010,
- :short => 100,
- :long => 100_000_000,
- :longlong => 666_555_444_333_222_111,
- :shortstr => 'hello',
- :longstr => 'bye'*500,
- :timestamp => time = Time.at(Time.now.to_i),
- :table => { :this => 'is', :a => 'hash', :with => {:nested => 123, :and => time, :also => 123.456} },
- :bit => true
- }.each do |type, value|
-
- should "read and write a #{type}" do
- @buf.write(type, value)
- @buf.rewind
- @buf.read(type).should == value
- @buf.should.be.empty
- end
-
- end
-
- should 'read and write multiple bits' do
- bits = [true, false, false, true, true, false, false, true, true, false]
- @buf.write(:bit, bits)
- @buf.write(:octet, 100)
-
- @buf.rewind
-
- bits.map do
- @buf.read(:bit)
- end.should == bits
- @buf.read(:octet).should == 100
- end
-
- should 'read and write properties' do
- properties = ([
- [:octet, 1],
- [:shortstr, 'abc'],
- [:bit, true],
- [:bit, false],
- [:shortstr, nil],
- [:timestamp, nil],
- [:table, { :a => 'hash' }],
- ]*5).sort_by{rand}
-
- @buf.write(:properties, properties)
- @buf.rewind
- @buf.read(:properties, *properties.map{|type,_| type }).should == properties.map{|_,value| value }
- @buf.should.be.empty
- end
-
- should 'do transactional reads with #extract' do
- @buf.write :octet, 8
- orig = @buf.to_s
-
- @buf.rewind
- @buf.extract do |b|
- b.read :octet
- b.read :short
- end
-
- @buf.pos.should == 0
- @buf.data.should == orig
- end
- end
-end

0 comments on commit ecab3d9

Please sign in to comment.