amq-protocol 1.9.2 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -12,7 +12,7 @@ module AMQ
12
12
  Select.decode("\x01")
13
13
  end
14
14
 
15
- its(:nowait) { should be_true }
15
+ its(:nowait) { should be_truthy }
16
16
  end
17
17
 
18
18
  describe '.encode' do
@@ -20,8 +20,8 @@ module AMQ
20
20
  channel = 1
21
21
  nowait = true
22
22
  method_frame = Select.encode(channel, nowait)
23
- method_frame.payload.should == "\x00U\x00\n\x01"
24
- method_frame.channel.should == 1
23
+ expect(method_frame.payload).to eq("\x00U\x00\n\x01")
24
+ expect(method_frame.channel).to eq(1)
25
25
  end
26
26
  end
27
27
  end
@@ -34,8 +34,8 @@ module AMQ
34
34
  it 'encodes the parameters into a MethodFrame' do
35
35
  channel = 1
36
36
  method_frame = SelectOk.encode(channel)
37
- method_frame.payload.should == "\000U\000\v"
38
- method_frame.channel.should == 1
37
+ expect(method_frame.payload).to eq("\000U\000\v")
38
+ expect(method_frame.channel).to eq(1)
39
39
  end
40
40
  end
41
41
  end
@@ -29,13 +29,13 @@ module AMQ
29
29
  locale = 'en_GB'
30
30
  method_frame = StartOk.encode(client_properties, mechanism, response, locale)
31
31
  # the order of the table parts isn't deterministic in Ruby 1.8
32
- method_frame.payload[0, 8].should == "\x00\n\x00\v\x00\x00\x00x"
33
- method_frame.payload.should include("\bplatformS\x00\x00\x00\nRuby 1.9.2")
34
- method_frame.payload.should include("\aproductS\x00\x00\x00\nAMQ Client")
35
- method_frame.payload.should include("\vinformationS\x00\x00\x00&http://github.com/ruby-amqp/amq-client")
36
- method_frame.payload.should include("\aversionS\x00\x00\x00\x050.2.0")
37
- method_frame.payload[-28, 28].should == "\x05PLAIN\x00\x00\x00\f\x00guest\x00guest\x05en_GB"
38
- method_frame.payload.length.should == 156
32
+ expect(method_frame.payload[0, 8]).to eq("\x00\n\x00\v\x00\x00\x00x")
33
+ expect(method_frame.payload).to include("\bplatformS\x00\x00\x00\nRuby 1.9.2")
34
+ expect(method_frame.payload).to include("\aproductS\x00\x00\x00\nAMQ Client")
35
+ expect(method_frame.payload).to include("\vinformationS\x00\x00\x00&http://github.com/ruby-amqp/amq-client")
36
+ expect(method_frame.payload).to include("\aversionS\x00\x00\x00\x050.2.0")
37
+ expect(method_frame.payload[-28, 28]).to eq("\x05PLAIN\x00\x00\x00\f\x00guest\x00guest\x05en_GB")
38
+ expect(method_frame.payload.length).to eq(156)
39
39
  end
40
40
  end
41
41
  end
@@ -46,7 +46,7 @@ module AMQ
46
46
  Secure.decode("\x00\x00\x00\x03foo")
47
47
  end
48
48
 
49
- its(:challenge) { should == 'foo' }
49
+ its(:challenge) { should eq('foo') }
50
50
  end
51
51
  end
52
52
 
@@ -55,7 +55,7 @@ module AMQ
55
55
  it 'encodes the parameters as a MethodFrame' do
56
56
  response = 'bar'
57
57
  method_frame = SecureOk.encode(response)
58
- method_frame.payload.should == "\x00\x0a\x00\x15\x00\x00\x00\x03bar"
58
+ expect(method_frame.payload).to eq("\x00\x0a\x00\x15\x00\x00\x00\x03bar")
59
59
  end
60
60
  end
61
61
  end
@@ -66,9 +66,9 @@ module AMQ
66
66
  Tune.decode("\x00\x00\x00\x02\x00\x00\x00\x00")
67
67
  end
68
68
 
69
- its(:channel_max) { should == 0 }
70
- its(:frame_max) { should == 131072 }
71
- its(:heartbeat) { should == 0}
69
+ its(:channel_max) { should eq(0) }
70
+ its(:frame_max) { should eq(131072) }
71
+ its(:heartbeat) { should eq(0) }
72
72
  end
73
73
  end
74
74
 
@@ -79,7 +79,7 @@ module AMQ
79
79
  frame_max = 65536
80
80
  heartbeat = 1
81
81
  method_frame = TuneOk.encode(channel_max, frame_max, heartbeat)
82
- method_frame.payload.should == "\x00\n\x00\x1F\x00\x00\x00\x01\x00\x00\x00\x01"
82
+ expect(method_frame.payload).to eq("\x00\n\x00\x1F\x00\x00\x00\x01\x00\x00\x00\x01")
83
83
  end
84
84
  end
85
85
  end
@@ -89,7 +89,7 @@ module AMQ
89
89
  it 'encodes the parameters into a MethodFrame' do
90
90
  vhost = '/test'
91
91
  method_frame = Open.encode(vhost)
92
- method_frame.payload.should == "\x00\n\x00(\x05/test\x00\x00"
92
+ expect(method_frame.payload).to eq("\x00\n\x00(\x05/test\x00\x00")
93
93
  end
94
94
  end
95
95
  end
@@ -100,7 +100,7 @@ module AMQ
100
100
  OpenOk.decode("\x00")
101
101
  end
102
102
 
103
- its(:known_hosts) { should == '' }
103
+ its(:known_hosts) { should eq('') }
104
104
  end
105
105
  end
106
106
 
@@ -111,10 +111,10 @@ module AMQ
111
111
  Close.decode("\x00\xc8\x07KTHXBAI\x00\x05\x00\x06")
112
112
  end
113
113
 
114
- its(:reply_code) { should == 200 }
115
- its(:reply_text) { should == 'KTHXBAI' }
116
- its(:class_id) { should == 5 }
117
- its(:method_id) { should == 6 }
114
+ its(:reply_code) { should eq(200) }
115
+ its(:reply_text) { should eq('KTHXBAI') }
116
+ its(:class_id) { should eq(5) }
117
+ its(:method_id) { should eq(6) }
118
118
  end
119
119
 
120
120
  context 'with an error code' do
@@ -131,7 +131,7 @@ module AMQ
131
131
  class_id = 0
132
132
  method_id = 0
133
133
  method_frame = Close.encode(reply_code, reply_text, class_id, method_id)
134
- method_frame.payload.should == "\x00\x0a\x002\x02\x1c\x0fNOT_IMPLEMENTED\x00\x00\x00\x00"
134
+ expect(method_frame.payload).to eq("\x00\x0a\x002\x02\x1c\x0fNOT_IMPLEMENTED\x00\x00\x00\x00")
135
135
  end
136
136
  end
137
137
  end
@@ -140,7 +140,7 @@ module AMQ
140
140
  describe '.encode' do
141
141
  it 'encodes a MethodFrame' do
142
142
  method_frame = CloseOk.encode
143
- method_frame.payload.should == "\x00\n\x003"
143
+ expect(method_frame.payload).to eq("\x00\n\x003")
144
144
  end
145
145
  end
146
146
  end
@@ -2,13 +2,13 @@
2
2
 
3
3
  require File.expand_path('../../../spec_helper', __FILE__)
4
4
 
5
- describe "(Some)", AMQ::Protocol, "constants" do
5
+ describe "(Some) AMQ::Protocol constants" do
6
6
  it "include regular port" do
7
- AMQ::Protocol::DEFAULT_PORT.should == 5672
7
+ expect(AMQ::Protocol::DEFAULT_PORT).to eq(5672)
8
8
  end
9
9
 
10
10
  it "provides TLS/SSL port" do
11
- AMQ::Protocol::TLS_PORT.should == 5671
12
- AMQ::Protocol::SSL_PORT.should == 5671
11
+ expect(AMQ::Protocol::TLS_PORT).to eq(5671)
12
+ expect(AMQ::Protocol::SSL_PORT).to eq(5671)
13
13
  end
14
14
  end
@@ -19,8 +19,8 @@ module AMQ
19
19
  nowait = false
20
20
  arguments = nil
21
21
  method_frame = Declare.encode(channel, exchange, type, passive, durable, auto_delete, internal, nowait, arguments)
22
- method_frame.payload.should == "\x00(\x00\n\x00\x00\x1Famqclient.adapters.em.exchange1\x06fanout\x00\x00\x00\x00\x00"
23
- method_frame.channel.should == 1
22
+ expect(method_frame.payload).to eq("\x00(\x00\n\x00\x00\x1Famqclient.adapters.em.exchange1\x06fanout\x00\x00\x00\x00\x00")
23
+ expect(method_frame.channel).to eq(1)
24
24
  end
25
25
  end
26
26
  end
@@ -38,8 +38,8 @@ module AMQ
38
38
  nowait = false
39
39
  arguments = nil
40
40
  method_frame = Declare.encode(channel, exchange, type, passive, durable, auto_delete, internal, nowait, arguments)
41
- method_frame.payload.should == "\x00(\x00\n\x00\x00\texchange2\x06fanout\x00\x00\x00\x00\x00"
42
- method_frame.channel.should == 1
41
+ expect(method_frame.payload).to eq("\x00(\x00\n\x00\x00\texchange2\x06fanout\x00\x00\x00\x00\x00")
42
+ expect(method_frame.channel).to eq(1)
43
43
  end
44
44
  end
45
45
  end
@@ -52,8 +52,8 @@ module AMQ
52
52
  if_unused = false
53
53
  nowait = false
54
54
  method_frame = Delete.encode(channel, exchange, if_unused, nowait)
55
- method_frame.payload.should == "\x00(\x00\x14\x00\x00\x1Eamqclient.adapters.em.exchange\x00"
56
- method_frame.channel.should == 1
55
+ expect(method_frame.payload).to eq("\x00(\x00\x14\x00\x00\x1Eamqclient.adapters.em.exchange\x00")
56
+ expect(method_frame.channel).to eq(1)
57
57
  end
58
58
  end
59
59
  end
@@ -73,8 +73,8 @@ module AMQ
73
73
  nowait = false
74
74
  arguments = nil
75
75
  method_frame = Bind.encode(channel, destination, source, routing_key, nowait, arguments)
76
- method_frame.payload.should == "\x00(\x00\x1E\x00\x00\x03foo\x03bar\x03xyz\x00\x00\x00\x00\x00"
77
- method_frame.channel.should == 1
76
+ expect(method_frame.payload).to eq("\x00(\x00\x1E\x00\x00\x03foo\x03bar\x03xyz\x00\x00\x00\x00\x00")
77
+ expect(method_frame.channel).to eq(1)
78
78
  end
79
79
  end
80
80
  end
@@ -94,8 +94,8 @@ module AMQ
94
94
  nowait = false
95
95
  arguments = nil
96
96
  method_frame = Unbind.encode(channel, destination, source, routing_key, nowait, arguments)
97
- method_frame.payload.should == "\x00(\x00(\x00\x00\x03foo\x03bar\x03xyz\x00\x00\x00\x00\x00"
98
- method_frame.channel.should == 1
97
+ expect(method_frame.payload).to eq("\x00(\x00(\x00\x00\x03foo\x03bar\x03xyz\x00\x00\x00\x00\x00")
98
+ expect(method_frame.channel).to eq(1)
99
99
  end
100
100
  end
101
101
  end
@@ -1,4 +1,4 @@
1
- # encoding: binary
1
+ # encoding: utf-8
2
2
 
3
3
  require File.expand_path('../../../spec_helper', __FILE__)
4
4
 
@@ -8,7 +8,7 @@ module AMQ
8
8
  describe Frame do
9
9
  describe ".encode" do
10
10
  it "should raise FrameTypeError if type isn't one of: [:method, :header, :body, :heartbeat]" do
11
- lambda { Frame.encode(nil, "", 0) }.should raise_error(FrameTypeError)
11
+ expect { Frame.encode(nil, "", 0) }.to raise_error(FrameTypeError)
12
12
  end
13
13
 
14
14
  it "should raise FrameTypeError if type isn't valid (when type is a symbol)" do
@@ -20,35 +20,35 @@ module AMQ
20
20
  end
21
21
 
22
22
  it "should raise RuntimeError if channel isn't 0 or an integer in range 1..65535" do
23
- lambda { Frame.encode(:method, "", -1) }.should raise_error(RuntimeError, /^Channel has to be 0 or an integer in range 1\.\.65535/)
24
- lambda { Frame.encode(:method, "", 65536) }.should raise_error(RuntimeError, /^Channel has to be 0 or an integer in range 1\.\.65535/)
25
- lambda { Frame.encode(:method, "", 65535) }.should_not raise_error(RuntimeError, /^Channel has to be 0 or an integer in range 1\.\.65535/)
26
- lambda { Frame.encode(:method, "", 0) }.should_not raise_error(RuntimeError, /^Channel has to be 0 or an integer in range 1\.\.65535/)
27
- lambda { Frame.encode(:method, "", 1) }.should_not raise_error(RuntimeError, /^Channel has to be 0 or an integer in range 1\.\.65535/)
23
+ expect { Frame.encode(:method, "", -1) }.to raise_error(RuntimeError, /^Channel has to be 0 or an integer in range 1\.\.65535/)
24
+ expect { Frame.encode(:method, "", 65536) }.to raise_error(RuntimeError, /^Channel has to be 0 or an integer in range 1\.\.65535/)
25
+ expect { Frame.encode(:method, "", 65535) }.not_to raise_error
26
+ expect { Frame.encode(:method, "", 0) }.not_to raise_error
27
+ expect { Frame.encode(:method, "", 1) }.not_to raise_error
28
28
  end
29
29
 
30
30
  it "should raise RuntimeError if payload is nil" do
31
- lambda { Frame.encode(:method, nil, 0) }.should raise_error(RuntimeError, "Payload can't be nil")
31
+ expect { Frame.encode(:method, nil, 0) }.to raise_error(RuntimeError, "Payload can't be nil")
32
32
  end
33
33
 
34
34
  it "should encode type" do
35
- Frame.encode(:body, "", 0).unpack("c").first.should eql(3)
35
+ expect(Frame.encode(:body, "", 0).unpack("c").first).to eql(3)
36
36
  end
37
37
 
38
38
  it "should encode channel" do
39
- Frame.encode(:body, "", 12).unpack("cn").last.should eql(12)
39
+ expect(Frame.encode(:body, "", 12).unpack("cn").last).to eql(12)
40
40
  end
41
41
 
42
42
  it "should encode size" do
43
- Frame.encode(:body, "test", 12).unpack("cnN").last.should eql(4)
43
+ expect(Frame.encode(:body, "test", 12).unpack("cnN").last).to eql(4)
44
44
  end
45
45
 
46
46
  it "should include payload" do
47
- Frame.encode(:body, "test", 12)[7..-2].should eql("test")
47
+ expect(Frame.encode(:body, "test", 12)[7..-2]).to eql("test")
48
48
  end
49
49
 
50
50
  it "should include final octet" do
51
- Frame.encode(:body, "test", 12).should =~ /\xCE$/
51
+ expect(Frame.encode(:body, "test", 12).each_byte.to_a.last).to eq("CE".hex)
52
52
  end
53
53
 
54
54
  it "should encode unicode strings" do
@@ -76,20 +76,20 @@ module AMQ
76
76
  subject { HeaderFrame.new("\x00<\x00\x00\x00\x00\x00\x00\x00\x00\x00\n\x98\x00\x18application/octet-stream\x02\x00", nil) }
77
77
 
78
78
  it "should decode body_size from payload" do
79
- subject.body_size.should == 10
79
+ expect(subject.body_size).to eq(10)
80
80
  end
81
81
 
82
82
  it "should decode klass_id from payload" do
83
- subject.klass_id.should == 60
83
+ expect(subject.klass_id).to eq(60)
84
84
  end
85
85
 
86
86
  it "should decode weight from payload" do
87
- subject.weight.should == 0
87
+ expect(subject.weight).to eq(0)
88
88
  end
89
89
 
90
90
  it "should decode properties from payload" do
91
- subject.properties[:delivery_mode].should == 2
92
- subject.properties[:priority].should == 0
91
+ expect(subject.properties[:delivery_mode]).to eq(2)
92
+ expect(subject.properties[:priority]).to eq(0)
93
93
  end
94
94
  end
95
95
  end
@@ -10,8 +10,8 @@ module AMQ
10
10
  it 'splits user defined headers into properties and headers' do
11
11
  input = {:delivery_mode => 2, :content_type => 'application/octet-stream', :foo => 'bar'}
12
12
  properties, headers = Method.split_headers(input)
13
- properties.should == {:delivery_mode => 2, :content_type => 'application/octet-stream'}
14
- headers.should == {:foo => 'bar'}
13
+ expect(properties).to eq({:delivery_mode => 2, :content_type => 'application/octet-stream'})
14
+ expect(headers).to eq({:foo => 'bar'})
15
15
  end
16
16
  end
17
17
 
@@ -19,9 +19,9 @@ module AMQ
19
19
  context 'when the body fits in a single frame' do
20
20
  it 'encodes a body into a BodyFrame' do
21
21
  body_frames = Method.encode_body('Hello world', 1, 131072)
22
- body_frames.first.payload.should == 'Hello world'
23
- body_frames.first.channel.should == 1
24
- body_frames.should have(1).item
22
+ expect(body_frames.first.payload).to eq('Hello world')
23
+ expect(body_frames.first.channel).to eq(1)
24
+ expect(body_frames.size).to eq(1)
25
25
  end
26
26
  end
27
27
 
@@ -31,15 +31,15 @@ module AMQ
31
31
  frame_size = 100
32
32
  expected_payload_size = 92
33
33
  body_frames = Method.encode_body(lipsum, 1, frame_size)
34
- body_frames.map(&:payload).should == lipsum.split('').each_slice(expected_payload_size).map(&:join)
34
+ expect(body_frames.map(&:payload)).to eq(lipsum.split('').each_slice(expected_payload_size).map(&:join))
35
35
  end
36
36
  end
37
37
 
38
38
  context 'when the body fits perfectly in a single frame' do
39
39
  it 'encodes a body into a single BodyFrame' do
40
40
  body_frames = Method.encode_body('*' * 131064, 1, 131072)
41
- body_frames.first.payload.should == '*' * 131064
42
- body_frames.should have(1).item
41
+ expect(body_frames.first.payload).to eq('*' * 131064)
42
+ expect(body_frames.size).to eq(1)
43
43
  end
44
44
  end
45
45
  end
@@ -18,8 +18,8 @@ module AMQ
18
18
  nowait = false
19
19
  arguments = nil
20
20
  method_frame = Declare.encode(channel, queue, passive, durable, exclusive, auto_delete, nowait, arguments)
21
- method_frame.payload.should == "\x002\x00\n\x00\x00\vhello.world\x0E\x00\x00\x00\x00"
22
- method_frame.channel.should == 1
21
+ expect(method_frame.payload).to eq("\x002\x00\n\x00\x00\vhello.world\x0E\x00\x00\x00\x00")
22
+ expect(method_frame.channel).to eq(1)
23
23
  end
24
24
  end
25
25
  end
@@ -30,9 +30,9 @@ module AMQ
30
30
  DeclareOk.decode(" amq.gen-KduGSqQrpeUo1otnU0TWSA==\x00\x00\x00\x00\x00\x00\x00\x00")
31
31
  end
32
32
 
33
- its(:queue) { should == 'amq.gen-KduGSqQrpeUo1otnU0TWSA==' }
34
- its(:message_count) { should == 0 }
35
- its(:consumer_count) { should == 0 }
33
+ its(:queue) { should eq('amq.gen-KduGSqQrpeUo1otnU0TWSA==') }
34
+ its(:message_count) { should eq(0) }
35
+ its(:consumer_count) { should eq(0) }
36
36
  end
37
37
  end
38
38
 
@@ -46,8 +46,8 @@ module AMQ
46
46
  nowait = false
47
47
  arguments = nil
48
48
  method_frame = Bind.encode(channel, queue, exchange, routing_key, nowait, arguments)
49
- method_frame.payload.should == "\x002\x00\x14\x00\x00\vhello.world\afoo.bar\x03xyz\x00\x00\x00\x00\x00"
50
- method_frame.channel.should == 1
49
+ expect(method_frame.payload).to eq("\x002\x00\x14\x00\x00\vhello.world\afoo.bar\x03xyz\x00\x00\x00\x00\x00")
50
+ expect(method_frame.channel).to eq(1)
51
51
  end
52
52
  end
53
53
  end
@@ -64,8 +64,8 @@ module AMQ
64
64
  queue = 'hello.world'
65
65
  nowait = false
66
66
  method_frame = Purge.encode(channel, queue, nowait)
67
- method_frame.payload.should == "\x002\x00\x1E\x00\x00\vhello.world\x00"
68
- method_frame.channel.should == 1
67
+ expect(method_frame.payload).to eq("\x002\x00\x1E\x00\x00\vhello.world\x00")
68
+ expect(method_frame.channel).to eq(1)
69
69
  end
70
70
  end
71
71
  end
@@ -76,7 +76,7 @@ module AMQ
76
76
  PurgeOk.decode("\x00\x00\x00\x02")
77
77
  end
78
78
 
79
- its(:message_count) { should == 2 }
79
+ its(:message_count) { should eq(2) }
80
80
  end
81
81
  end
82
82
 
@@ -89,8 +89,8 @@ module AMQ
89
89
  if_empty = false
90
90
  nowait = false
91
91
  method_frame = Delete.encode(channel, queue, if_unused, if_empty, nowait)
92
- method_frame.payload.should == "\x002\x00(\x00\x00\vhello.world\x00"
93
- method_frame.channel.should == 1
92
+ expect(method_frame.payload).to eq("\x002\x00(\x00\x00\vhello.world\x00")
93
+ expect(method_frame.channel).to eq(1)
94
94
  end
95
95
  end
96
96
  end
@@ -101,7 +101,7 @@ module AMQ
101
101
  DeleteOk.decode("\x00\x00\x00\x02")
102
102
  end
103
103
 
104
- its(:message_count) { should == 2 }
104
+ its(:message_count) { should eq(2) }
105
105
  end
106
106
  end
107
107
 
@@ -114,8 +114,8 @@ module AMQ
114
114
  routing_key = 'xyz'
115
115
  arguments = nil
116
116
  method_frame = Unbind.encode(channel, queue, exchange, routing_key, arguments)
117
- method_frame.payload.should == "\x002\x002\x00\x00\vhello.world\afoo.bar\x03xyz\x00\x00\x00\x00"
118
- method_frame.channel.should == 1
117
+ expect(method_frame.payload).to eq("\x002\x002\x00\x00\vhello.world\afoo.bar\x03xyz\x00\x00\x00\x00")
118
+ expect(method_frame.channel).to eq(1)
119
119
  end
120
120
  end
121
121
  end
@@ -1,4 +1,4 @@
1
- # encoding: binary
1
+ # -*- coding: utf-8 -*-
2
2
 
3
3
  require File.expand_path('../../../spec_helper', __FILE__)
4
4
  require 'bigdecimal'
@@ -11,63 +11,49 @@ module AMQ
11
11
  timestamp = Time.utc(2010, 12, 31, 23, 58, 59)
12
12
  bigdecimal_1 = BigDecimal.new("1.0")
13
13
  bigdecimal_2 = BigDecimal.new("5E-3")
14
- bigdecimal_3 = BigDecimal.new("-0.01")
15
-
16
-
17
- DATA = if one_point_eight?
18
- {
19
- {} => "\000\000\000\000",
20
- {"test" => 1} => "\000\000\000\n\004testI\000\000\000\001",
21
- {"float" => 1.87} => "\000\000\000\017\005floatd?\375\353\205\036\270Q\354",
22
- {"test" => "string"} => "\000\000\000\020\004testS\000\000\000\006string",
23
- {"test" => {}} => "\000\000\000\n\004testF\000\000\000\000",
24
- {"test" => bigdecimal_1} => "\000\000\000\v\004testD\000\000\000\000\001",
25
- {"test" => bigdecimal_2} => "\000\000\000\v\004testD\003\000\000\000\005",
26
- {"test" => timestamp} => "\000\000\000\016\004testT\000\000\000\000M\036nC"
27
- }
28
- else
29
- {
14
+
15
+
16
+ DATA = {
30
17
  {} => "\x00\x00\x00\x00",
31
- {"test" => 1} => "\x00\x00\x00\n\x04testI\x00\x00\x00\x01",
18
+ {"test" => 1} => "\x00\x00\x00\x0E\x04testl\x00\x00\x00\x00\x00\x00\x00\x01",
32
19
  {"float" => 1.92} => "\x00\x00\x00\x0F\x05floatd?\xFE\xB8Q\xEB\x85\x1E\xB8",
33
20
  {"test" => "string"} => "\x00\x00\x00\x10\x04testS\x00\x00\x00\x06string",
34
21
  {"test" => {}} => "\x00\x00\x00\n\x04testF\x00\x00\x00\x00",
35
22
  {"test" => bigdecimal_1} => "\x00\x00\x00\v\x04testD\x00\x00\x00\x00\x01",
36
23
  {"test" => bigdecimal_2} => "\x00\x00\x00\v\x04testD\x03\x00\x00\x00\x05",
37
24
  {"test" => timestamp} => "\x00\x00\x00\x0e\x04testT\x00\x00\x00\x00M\x1enC"
38
- }
39
- end
25
+ }
40
26
 
41
27
  describe ".encode" do
42
28
  it "should return \"\x00\x00\x00\x00\" for nil" do
43
- encoded_value = if one_point_eight?
44
- "\000\000\000\000"
45
- else
46
- "\x00\x00\x00\x00"
47
- end
29
+ encoded_value = "\x00\x00\x00\x00"
48
30
 
49
- Table.encode(nil).should eql(encoded_value)
31
+ expect(Table.encode(nil)).to eql(encoded_value)
50
32
  end
51
33
 
52
34
  it "should serialize { :test => true }" do
53
- Table.encode(:test => true).should eql("\x00\x00\x00\a\x04testt\x01")
35
+ expect(Table.encode(:test => true)).
36
+ to eql("\x00\x00\x00\a\x04testt\x01".force_encoding(Encoding::ASCII_8BIT))
54
37
  end
55
38
 
56
39
  it "should serialize { :test => false }" do
57
- Table.encode(:test => false).should eql("\x00\x00\x00\a\x04testt\x00")
40
+ expect(Table.encode(:test => false)).
41
+ to eql("\x00\x00\x00\a\x04testt\x00".force_encoding(Encoding::ASCII_8BIT))
58
42
  end
59
43
 
60
44
  it "should serialize { :coordinates => { :latitude => 59.35 } }" do
61
- Table.encode(:coordinates => { :latitude => 59.35 }).should eql("\x00\x00\x00#\vcoordinatesF\x00\x00\x00\x12\blatituded@M\xAC\xCC\xCC\xCC\xCC\xCD")
45
+ expect(Table.encode(:coordinates => { :latitude => 59.35 })).
46
+ to eql("\x00\x00\x00#\vcoordinatesF\x00\x00\x00\x12\blatituded@M\xAC\xCC\xCC\xCC\xCC\xCD".force_encoding(Encoding::ASCII_8BIT))
62
47
  end
63
48
 
64
49
  it "should serialize { :coordinates => { :longitude => 18.066667 } }" do
65
- Table.encode(:coordinates => { :longitude => 18.066667 }).should eql("\x00\x00\x00$\vcoordinatesF\x00\x00\x00\x13\tlongituded@2\x11\x11\x16\xA8\xB8\xF1")
50
+ expect(Table.encode(:coordinates => { :longitude => 18.066667 })).
51
+ to eql("\x00\x00\x00$\vcoordinatesF\x00\x00\x00\x13\tlongituded@2\x11\x11\x16\xA8\xB8\xF1".force_encoding(Encoding::ASCII_8BIT))
66
52
  end
67
53
 
68
54
  DATA.each do |data, encoded|
69
55
  it "should return #{encoded.inspect} for #{data.inspect}" do
70
- Table.encode(data).should eql(encoded)
56
+ expect(Table.encode(data)).to eql(encoded.force_encoding(Encoding::ASCII_8BIT))
71
57
  end
72
58
  end
73
59
  end
@@ -75,114 +61,121 @@ module AMQ
75
61
  describe ".decode" do
76
62
  DATA.each do |data, encoded|
77
63
  it "should return #{data.inspect} for #{encoded.inspect}" do
78
- Table.decode(encoded).should eql(data)
64
+ expect(Table.decode(encoded)).to eql(data)
79
65
  end
80
66
 
81
67
  it "is capable of decoding what it encodes" do
82
- Table.decode(Table.encode(data)).should == data
68
+ expect(Table.decode(Table.encode(data))).to eq(data)
83
69
  end
84
70
  end # DATA.each
85
71
 
86
72
 
87
73
  it "is capable of decoding boolean table values" do
88
74
  input1 = { "boolval" => true }
89
- Table.decode(Table.encode(input1)).should == input1
75
+ expect(Table.decode(Table.encode(input1))).to eq(input1)
90
76
 
91
77
 
92
78
  input2 = { "boolval" => false }
93
- Table.decode(Table.encode(input2)).should == input2
79
+ expect(Table.decode(Table.encode(input2))).to eq(input2)
94
80
  end
95
81
 
96
82
 
97
83
  it "is capable of decoding nil table values" do
98
84
  input = { "nilval" => nil }
99
- Table.decode(Table.encode(input)).should == input
85
+ expect(Table.decode(Table.encode(input))).to eq(input)
100
86
  end
101
87
 
102
88
  it "is capable of decoding nil table in nested hash/map values" do
103
89
  input = { "hash" => {"nil" => nil} }
104
- Table.decode(Table.encode(input)).should == input
90
+ expect(Table.decode(Table.encode(input))).to eq(input)
105
91
  end
106
92
 
107
93
  it "is capable of decoding string table values" do
108
94
  input = { "stringvalue" => "string" }
109
- Table.decode(Table.encode(input)).should == input
95
+ expect(Table.decode(Table.encode(input))).to eq(input)
110
96
  end
111
97
 
112
98
  it "is capable of decoding string table values with UTF-8 characters" do
113
- input = { "строка" => "значение" }
114
- Table.decode(Table.encode(input)).should == input
99
+ input = {
100
+ "строка".force_encoding(::Encoding::ASCII_8BIT) => "значение".force_encoding(::Encoding::ASCII_8BIT)
101
+ }
102
+ expect(Table.decode(Table.encode(input))).to eq(input)
115
103
  end
116
104
 
117
105
 
118
106
  it "is capable of decoding integer table values" do
119
107
  input = { "intvalue" => 10 }
120
- Table.decode(Table.encode(input)).should == input
108
+ expect(Table.decode(Table.encode(input))).to eq(input)
121
109
  end
122
110
 
123
111
 
112
+ it "is capable of decoding signed integer table values" do
113
+ input = { "intvalue" => -10 }
114
+ expect(Table.decode(Table.encode(input))).to eq(input)
115
+ end
116
+
124
117
 
125
118
  it "is capable of decoding long table values" do
126
119
  input = { "longvalue" => 912598613 }
127
- Table.decode(Table.encode(input)).should == input
120
+ expect(Table.decode(Table.encode(input))).to eq(input)
128
121
  end
129
122
 
130
123
 
131
124
 
132
125
  it "is capable of decoding float table values" do
133
126
  input = { "floatvalue" => 100.0 }
134
- Table.decode(Table.encode(input)).should == input
127
+ expect(Table.decode(Table.encode(input))).to eq(input)
135
128
  end
136
129
 
137
130
 
138
131
 
139
132
  it "is capable of decoding time table values" do
140
133
  input = { "intvalue" => Time.parse("2011-07-14 01:17:46 +0400") }
141
- Table.decode(Table.encode(input)).should == input
134
+ expect(Table.decode(Table.encode(input))).to eq(input)
142
135
  end
143
136
 
144
137
 
145
138
 
146
139
  it "is capable of decoding empty hash table values" do
147
140
  input = { "hashvalue" => Hash.new }
148
- Table.decode(Table.encode(input)).should == input
141
+ expect(Table.decode(Table.encode(input))).to eq(input)
149
142
  end
150
143
 
151
144
 
152
145
 
153
146
  it "is capable of decoding empty array table values" do
154
147
  input = { "arrayvalue" => Array.new }
155
- Table.decode(Table.encode(input)).should == input
148
+ expect(Table.decode(Table.encode(input))).to eq(input)
156
149
  end
157
150
 
158
151
 
159
152
  it "is capable of decoding single string value array table values" do
160
153
  input = { "arrayvalue" => ["amq-protocol"] }
161
- Table.decode(Table.encode(input)).should == input
154
+ expect(Table.decode(Table.encode(input))).to eq(input)
162
155
  end
163
156
 
164
157
 
165
158
 
166
159
  it "is capable of decoding simple nested hash table values" do
167
160
  input = { "hashvalue" => { "a" => "b" } }
168
- Table.decode(Table.encode(input)).should == input
161
+ expect(Table.decode(Table.encode(input))).to eq(input)
169
162
  end
170
163
 
171
164
 
172
165
 
173
166
  it "is capable of decoding nil table values" do
174
167
  input = { "nil" => nil }
175
- Table.decode(Table.encode(input)).should == input
168
+ expect(Table.decode(Table.encode(input))).to eq(input)
176
169
  end
177
170
 
178
171
  it 'is capable of decoding 8bit signed integers' do
179
172
  output = TableValueDecoder.decode_byte("\xC0",0).first
180
- output.should == 192
173
+ expect(output).to eq(192)
181
174
  end
182
175
 
183
176
  it 'is capable of decoding 16bit signed integers' do
184
177
  output = TableValueDecoder.decode_short("\x06\x8D", 0).first
185
- output.should == 1677
178
+ expect(output).to eq(1677)
186
179
  end
187
180
 
188
181
  it "is capable of decoding tables" do
@@ -195,7 +188,7 @@ module AMQ
195
188
  "longval" => 912598613,
196
189
  "hashval" => { "protocol" => "AMQP091", "true" => true, "false" => false, "nil" => nil }
197
190
  }
198
- Table.decode(Table.encode(input)).should == input
191
+ expect(Table.decode(Table.encode(input))).to eq(input)
199
192
  end
200
193
 
201
194
 
@@ -210,7 +203,7 @@ module AMQ
210
203
  "rev" => 1.0,
211
204
  "spec" => {
212
205
  "url" => "http://bit.ly/hw2ELX",
213
- "utf8" => "à bientôt"
206
+ "utf8" => "à bientôt".force_encoding(::Encoding::ASCII_8BIT)
214
207
  }
215
208
  },
216
209
  "true" => true,
@@ -218,7 +211,7 @@ module AMQ
218
211
  "nil" => nil
219
212
  }
220
213
  }
221
- Table.decode(Table.encode(input)).should == input
214
+ expect(Table.decode(Table.encode(input))).to eq(input)
222
215
  end
223
216
 
224
217
 
@@ -228,7 +221,7 @@ module AMQ
228
221
  "arrayval1" => [198, 3, 77, 8.0, ["inner", "array", { "oh" => "well", "it" => "should work", "3" => 6 }], "two", { "a" => "value", "is" => nil }],
229
222
  "arrayval2" => [198, 3, 77, "two", { "a" => "value", "is" => nil }, 8.0, ["inner", "array", { "oh" => "well", "it" => "should work", "3" => 6 }]]
230
223
  }
231
- Table.decode(Table.encode(input1)).should == input1
224
+ expect(Table.decode(Table.encode(input1))).to eq(input1)
232
225
 
233
226
  now = Time.now
234
227
  input2 = {
@@ -244,10 +237,10 @@ module AMQ
244
237
  "ary_field" => ["one", 2.0, 3]
245
238
  }
246
239
 
247
- Table.decode(Table.encode(input2)).should == input2
240
+ expect(Table.decode(Table.encode(input2))).to eq(input2)
248
241
 
249
242
  input3 = { "timely" => { "now" => now } }
250
- Table.decode(Table.encode(input3))["timely"]["now"].to_i.should == now.to_i
243
+ expect(Table.decode(Table.encode(input3))["timely"]["now"].to_i).to eq(now.to_i)
251
244
  end
252
245
 
253
246
  end # describe