cql-rb 1.0.0.pre5 → 1.0.0.pre6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,11 +7,11 @@ module Cql
7
7
  module Io
8
8
  describe IoReactor do
9
9
  let :host do
10
- Socket.gethostname
10
+ '127.0.0.1'
11
11
  end
12
12
 
13
13
  let :port do
14
- 34535
14
+ 2**15 + rand(2**15)
15
15
  end
16
16
 
17
17
  let :server do
@@ -143,7 +143,7 @@ module Cql
143
143
  io_reactor.add_connection(host, port).get
144
144
  io_reactor.queue_request(Cql::Protocol::StartupRequest.new)
145
145
  await { server.received_bytes.bytesize > 0 }
146
- server.received_bytes[3, 1].should == "\x01"
146
+ server.received_bytes.to_s[3, 1].should == "\x01"
147
147
  end
148
148
 
149
149
  it 'can be called before the reactor is started' do
@@ -183,22 +183,19 @@ module Cql
183
183
  request = Cql::Protocol::StartupRequest.new
184
184
  response = "\x81\x00\x00\x02\x00\x00\x00\x00"
185
185
 
186
- io_reactor.start.on_complete do
187
- io_reactor.add_connection(host, port).on_complete do |c1_id|
188
- io_reactor.add_connection(host, port).on_complete do |c2_id|
189
- q1_future = io_reactor.queue_request(request, c2_id)
190
- q2_future = io_reactor.queue_request(request, c1_id)
191
-
192
- Future.combine(q1_future, q2_future).on_complete do |(_, q1_id), (_, q2_id)|
193
- future.complete!([c1_id, c2_id, q1_id, q2_id])
194
- end
186
+ io_reactor.start.get
187
+ c1_id = io_reactor.add_connection(host, port).get
188
+ c2_id = io_reactor.add_connection(host, port).get
189
+ q1_future = io_reactor.queue_request(request, c2_id)
190
+ q2_future = io_reactor.queue_request(request, c1_id)
195
191
 
196
- server.await_connects!(2)
197
- server.broadcast!(response.dup)
198
- end
199
- end
192
+ Future.combine(q1_future, q2_future).on_complete do |(_, q1_id), (_, q2_id)|
193
+ future.complete!([c1_id, c2_id, q1_id, q2_id])
200
194
  end
201
195
 
196
+ server.await_connects!(2)
197
+ server.broadcast!(response.dup)
198
+
202
199
  connection1_id, connection2_id, query1_id, query2_id = future.value
203
200
 
204
201
  connection1_id.should_not be_nil
@@ -8,7 +8,7 @@ module Cql
8
8
  describe Decoding do
9
9
  describe '#read_byte!' do
10
10
  let :buffer do
11
- "\xab"
11
+ ByteBuffer.new("\xab")
12
12
  end
13
13
 
14
14
  it 'decodes a raw byte' do
@@ -21,47 +21,51 @@ module Cql
21
21
  end
22
22
 
23
23
  it 'raises an error when there is no byte available' do
24
- expect { Decoding.read_byte!('') }.to raise_error(DecodingError)
24
+ expect { Decoding.read_byte!(ByteBuffer.new) }.to raise_error(DecodingError)
25
25
  end
26
26
  end
27
27
 
28
28
  describe '#read_varint!' do
29
29
  it 'decodes a variable length integer' do
30
- Decoding.read_varint!("\x03\x9EV \x15\f\x03\x9DK\x18\xCDI\\$?\a[", 17).should == 1231312312331283012830129382342342412123
30
+ buffer = ByteBuffer.new("\x03\x9EV \x15\f\x03\x9DK\x18\xCDI\\$?\a[")
31
+ Decoding.read_varint!(buffer, 17).should == 1231312312331283012830129382342342412123
31
32
  end
32
33
 
33
34
  it 'decodes a negative variable length integer' do
34
- Decoding.read_varint!("\xC9v\x8D:\x86", 5).should == -234234234234
35
+ buffer = ByteBuffer.new("\xC9v\x8D:\x86")
36
+ Decoding.read_varint!(buffer, 5).should == -234234234234
35
37
  end
36
38
 
37
39
  it 'decodes an unsigned variable length integer' do
38
- Decoding.read_varint!("\xC9v\x8D:\x86", 5, false).should == 865277393542
40
+ buffer = ByteBuffer.new("\xC9v\x8D:\x86")
41
+ Decoding.read_varint!(buffer, 5, false).should == 865277393542
39
42
  end
40
43
 
41
44
  it 'consumes the bytes' do
42
- buffer = "\x03\x9EV \x15\f\x03\x9DK\x18\xCDI\\$?\a[\x01\x02\x03"
45
+ buffer = ByteBuffer.new("\x03\x9EV \x15\f\x03\x9DK\x18\xCDI\\$?\a[\x01\x02\x03")
43
46
  Decoding.read_varint!(buffer, 17)
44
- buffer.should == "\x01\x02\x03"
47
+ buffer.should eql_bytes("\x01\x02\x03")
45
48
  end
46
49
 
47
50
  it 'raises an error when there is not enough bytes available' do
48
- expect { Decoding.read_varint!("\xC9v\x8D:", 7) }.to raise_error(DecodingError)
51
+ buffer = ByteBuffer.new("\xC9v\x8D:")
52
+ expect { Decoding.read_varint!(buffer, 7) }.to raise_error(DecodingError)
49
53
  end
50
54
  end
51
55
 
52
56
  describe '#read_decimal!' do
53
57
  let :buffer do
54
- "\x00\x00\x00\x12\r'\xFDI\xAD\x80f\x11g\xDCfV\xAA"
58
+ ByteBuffer.new("\x00\x00\x00\x12\r'\xFDI\xAD\x80f\x11g\xDCfV\xAA")
55
59
  end
56
60
 
57
61
  it 'decodes a decimal to a BigDecimal' do
58
- Decoding.read_decimal!(buffer, buffer.length).should == BigDecimal.new('1042342234234.123423435647768234')
62
+ Decoding.read_decimal!(buffer).should == BigDecimal.new('1042342234234.123423435647768234')
59
63
  end
60
64
 
61
65
  it 'consumes the bytes' do
62
66
  buffer << 'HELLO'
63
67
  Decoding.read_decimal!(buffer, buffer.length - 5)
64
- buffer.should == 'HELLO'
68
+ buffer.should eql_bytes('HELLO')
65
69
  end
66
70
 
67
71
  it 'defaults to using the buffer length' do
@@ -69,61 +73,68 @@ module Cql
69
73
  end
70
74
 
71
75
  it 'raises an error when there is not enough bytes available' do
72
- expect { Decoding.read_decimal!(buffer[0, 3], 7) }.to raise_error(DecodingError)
76
+ b = ByteBuffer.new(buffer.read(3))
77
+ expect { Decoding.read_decimal!(b, 7) }.to raise_error(DecodingError)
73
78
  end
74
79
  end
75
80
 
76
81
  describe '#read_long!' do
77
82
  it 'decodes a long' do
78
- Decoding.read_long!("\x00\x00\xca\xfe\xba\xbe\x00\x00").should == 0x0000cafebabe0000
83
+ buffer = ByteBuffer.new("\x00\x00\xca\xfe\xba\xbe\x00\x00")
84
+ Decoding.read_long!(buffer).should == 0x0000cafebabe0000
79
85
  end
80
86
 
81
87
  it 'consumes the bytes' do
82
- buffer = "\xca\xfe\xba\xbe\xca\xfe\xba\xbe\xca\xfe\xba\xbe"
88
+ buffer = ByteBuffer.new("\xca\xfe\xba\xbe\xca\xfe\xba\xbe\xca\xfe\xba\xbe")
83
89
  Decoding.read_long!(buffer)
84
- buffer.should == "\xca\xfe\xba\xbe"
90
+ buffer.should eql_bytes("\xca\xfe\xba\xbe")
85
91
  end
86
92
 
87
93
  it 'raises an error when there is not enough bytes available' do
88
- expect { Decoding.read_long!("\xca\xfe\xba\xbe\x00") }.to raise_error(DecodingError)
94
+ buffer = ByteBuffer.new("\xca\xfe\xba\xbe\x00")
95
+ expect { Decoding.read_long!(buffer) }.to raise_error(DecodingError)
89
96
  end
90
97
  end
91
98
 
92
99
  describe '#read_double!' do
93
100
  it 'decodes a double' do
94
- Decoding.read_double!("@\xC3\x88\x0F\xC2\x7F\x9DU").should == 10000.123123123
101
+ buffer = ByteBuffer.new("@\xC3\x88\x0F\xC2\x7F\x9DU")
102
+ Decoding.read_double!(buffer).should == 10000.123123123
95
103
  end
96
104
 
97
105
  it 'consumes the bytes' do
98
- buffer = "@\xC3\x88\x0F\xC2\x7F\x9DUxyz"
106
+ buffer = ByteBuffer.new("@\xC3\x88\x0F\xC2\x7F\x9DUxyz")
99
107
  Decoding.read_double!(buffer)
100
- buffer.should == 'xyz'
108
+ buffer.should eql_bytes('xyz')
101
109
  end
102
110
 
103
111
  it 'raises an error when there is not enough bytes available' do
104
- expect { Decoding.read_double!("@\xC3\x88\x0F") }.to raise_error(DecodingError)
112
+ buffer = ByteBuffer.new("@\xC3\x88\x0F")
113
+ expect { Decoding.read_double!(buffer) }.to raise_error(DecodingError)
105
114
  end
106
115
  end
107
116
 
108
117
  describe '#read_float!' do
109
118
  it 'decodes a float' do
110
- Decoding.read_float!("AB\x14{").should be_within(0.00001).of(12.13)
119
+ buffer = ByteBuffer.new("AB\x14{")
120
+ Decoding.read_float!(buffer).should be_within(0.00001).of(12.13)
111
121
  end
112
122
 
113
123
  it 'consumes the bytes' do
114
- buffer = "AB\x14{xyz"
124
+ buffer = ByteBuffer.new("AB\x14{xyz")
115
125
  Decoding.read_float!(buffer)
116
- buffer.should == 'xyz'
126
+ buffer.should eql_bytes('xyz')
117
127
  end
118
128
 
119
129
  it 'raises an error when there is not enough bytes available' do
120
- expect { Decoding.read_float!("\x0F") }.to raise_error(DecodingError)
130
+ buffer = ByteBuffer.new("\x0F")
131
+ expect { Decoding.read_float!(buffer) }.to raise_error(DecodingError)
121
132
  end
122
133
  end
123
134
 
124
135
  describe '#read_int!' do
125
136
  let :buffer do
126
- "\x00\xff\x00\xff"
137
+ ByteBuffer.new("\x00\xff\x00\xff")
127
138
  end
128
139
 
129
140
  it 'decodes an int' do
@@ -133,17 +144,18 @@ module Cql
133
144
  it 'consumes the bytes' do
134
145
  buffer << "\xab\xcd"
135
146
  Decoding.read_int!(buffer)
136
- buffer.should == "\xab\xcd"
147
+ buffer.should eql_bytes("\xab\xcd")
137
148
  end
138
149
 
139
150
  it 'raises an error when there are not enough bytes in the buffer' do
140
- expect { Decoding.read_int!("\x01\xab") }.to raise_error(DecodingError)
151
+ buffer = ByteBuffer.new("\x01\xab")
152
+ expect { Decoding.read_int!(buffer) }.to raise_error(DecodingError)
141
153
  end
142
154
  end
143
155
 
144
156
  describe '#read_short!' do
145
157
  let :buffer do
146
- "\x00\x02"
158
+ ByteBuffer.new("\x00\x02")
147
159
  end
148
160
 
149
161
  it 'decodes a short' do
@@ -153,17 +165,18 @@ module Cql
153
165
  it 'consumes the bytes' do
154
166
  buffer << "\xff\xff"
155
167
  Decoding.read_short!(buffer)
156
- buffer.should == "\xff\xff"
168
+ buffer.should eql_bytes("\xff\xff")
157
169
  end
158
170
 
159
171
  it 'raises an error when there are not enough bytes in the buffer' do
160
- expect { Decoding.read_short!("\x01") }.to raise_error(DecodingError)
172
+ buffer = ByteBuffer.new("\x01")
173
+ expect { Decoding.read_short!(buffer) }.to raise_error(DecodingError)
161
174
  end
162
175
  end
163
176
 
164
177
  describe '#read_string!' do
165
178
  let :buffer do
166
- "\x00\x0bhej och hå"
179
+ ByteBuffer.new("\x00\x0bhej och hå")
167
180
  end
168
181
 
169
182
  it 'decodes a string' do
@@ -175,23 +188,25 @@ module Cql
175
188
  end
176
189
 
177
190
  it 'decodes an empty string' do
178
- Decoding.read_string!("\x00\x00").should be_empty
191
+ buffer = ByteBuffer.new("\x00\x00")
192
+ Decoding.read_string!(buffer).should be_empty
179
193
  end
180
194
 
181
195
  it 'consumes the bytes' do
182
196
  buffer << "\xff\xff"
183
197
  Decoding.read_string!(buffer)
184
- buffer.should == "\xff\xff"
198
+ buffer.should eql_bytes("\xff\xff")
185
199
  end
186
200
 
187
201
  it 'raises an error when there are not enough bytes in the buffer' do
188
- expect { Decoding.read_string!(buffer.slice(0, 5)) }.to raise_error(DecodingError)
202
+ b = ByteBuffer.new(buffer.read(5))
203
+ expect { Decoding.read_string!(b) }.to raise_error(DecodingError)
189
204
  end
190
205
  end
191
206
 
192
207
  describe '#read_long_string!' do
193
208
  let :buffer do
194
- "\x00\x01\x00\00" << ('x' * 0x10000)
209
+ ByteBuffer.new("\x00\x01\x00\00" << ('x' * 0x10000))
195
210
  end
196
211
 
197
212
  it 'decodes a string' do
@@ -206,17 +221,18 @@ module Cql
206
221
  it 'consumes the bytes' do
207
222
  buffer << "\xff\xff"
208
223
  Decoding.read_long_string!(buffer)
209
- buffer.should == "\xff\xff"
224
+ buffer.should eql_bytes("\xff\xff")
210
225
  end
211
226
 
212
227
  it 'raises an error when there are not enough bytes in the buffer' do
213
- expect { Decoding.read_long_string!(buffer.slice(0, 246)) }.to raise_error(DecodingError)
228
+ b = ByteBuffer.new(buffer.read(246))
229
+ expect { Decoding.read_long_string!(b) }.to raise_error(DecodingError)
214
230
  end
215
231
  end
216
232
 
217
233
  describe '#read_uuid!' do
218
234
  let :buffer do
219
- "\xA4\xA7\t\x00$\xE1\x11\xDF\x89$\x00\x1F\xF3Y\x17\x11"
235
+ ByteBuffer.new("\xA4\xA7\t\x00$\xE1\x11\xDF\x89$\x00\x1F\xF3Y\x17\x11")
220
236
  end
221
237
 
222
238
  it 'decodes a UUID' do
@@ -229,13 +245,14 @@ module Cql
229
245
  end
230
246
 
231
247
  it 'raises an error when there a not enough bytes in the buffer' do
232
- expect { Decoding.read_uuid!(buffer[2, 5]) }.to raise_error(DecodingError)
248
+ b = ByteBuffer.new(buffer.discard(2).read(5))
249
+ expect { Decoding.read_uuid!(b) }.to raise_error(DecodingError)
233
250
  end
234
251
  end
235
252
 
236
253
  describe '#read_string_list!' do
237
254
  let :buffer do
238
- "\x00\x02\x00\x05hello\x00\x05world"
255
+ ByteBuffer.new("\x00\x02\x00\x05hello\x00\x05world")
239
256
  end
240
257
 
241
258
  it 'decodes a string list' do
@@ -243,87 +260,88 @@ module Cql
243
260
  end
244
261
 
245
262
  it 'decodes an empty string list' do
246
- Decoding.read_string_list!("\x00\x00").should == []
263
+ buffer = ByteBuffer.new("\x00\x00")
264
+ Decoding.read_string_list!(buffer).should == []
247
265
  end
248
266
 
249
267
  it 'consumes the bytes' do
250
268
  buffer << "\xff\xff"
251
269
  Decoding.read_string_list!(buffer)
252
- buffer.should == "\xff\xff"
270
+ buffer.should eql_bytes("\xff\xff")
253
271
  end
254
272
 
255
273
  it 'raises an error when there are not enough bytes in the buffer' do
256
- expect { Decoding.read_string_list!(buffer.slice(0, 13)) }.to raise_error(DecodingError)
274
+ b = ByteBuffer.new(buffer.read(13))
275
+ expect { Decoding.read_string_list!(b) }.to raise_error(DecodingError)
257
276
  end
258
277
  end
259
278
 
260
279
  describe '#read_bytes!' do
261
280
  let :buffer do
262
- "\x00\x01\x00\x00" << ("\x42" * 0x10000)
281
+ ByteBuffer.new("\x00\x01\x00\x00" << ("\x42" * 0x10000))
263
282
  end
264
283
 
265
284
  it 'decodes a byte array' do
266
- Decoding.read_bytes!(buffer).should == ("\x42" * 0x10000)
285
+ Decoding.read_bytes!(buffer).should eql_bytes("\x42" * 0x10000)
267
286
  end
268
287
 
269
288
  it 'decodes an empty byte array' do
270
- Decoding.read_bytes!("\x00\x00\x00\x00").should == ''
271
- end
272
-
273
- it 'returns an ASCII-8BIT encoded string' do
274
- Decoding.read_bytes!("\x00\x00\x00\x01\xaa").encoding.should == ::Encoding::BINARY
289
+ buffer = ByteBuffer.new("\x00\x00\x00\x00")
290
+ Decoding.read_bytes!(buffer).should be_empty
275
291
  end
276
292
 
277
293
  it 'decodes null' do
278
- Decoding.read_bytes!("\x80\x00\x00\x00").should be_nil
294
+ buffer = ByteBuffer.new("\x80\x00\x00\x00")
295
+ Decoding.read_bytes!(buffer).should be_nil
279
296
  end
280
297
 
281
298
  it 'consumes the bytes' do
282
299
  buffer << "\xab\xcd"
283
300
  Decoding.read_bytes!(buffer)
284
- buffer.should == "\xab\xcd"
301
+ buffer.should eql_bytes("\xab\xcd")
285
302
  end
286
303
 
287
304
  it 'raises an error when there are not enough bytes in the buffer' do
288
- expect { Decoding.read_bytes!(buffer[0, 10]) }.to raise_error(DecodingError)
305
+ b = ByteBuffer.new(buffer.read(10))
306
+ expect { Decoding.read_bytes!(b) }.to raise_error(DecodingError)
289
307
  end
290
308
  end
291
309
 
292
310
  describe '#read_short_bytes!' do
293
311
  let :buffer do
294
- "\x01\x00" << ("\x42" * 0x100)
312
+ ByteBuffer.new("\x01\x00" << ("\x42" * 0x100))
295
313
  end
296
314
 
297
315
  it 'decodes a byte array' do
298
- Decoding.read_short_bytes!(buffer).should == ("\x42" * 0x100)
316
+ Decoding.read_short_bytes!(buffer).should eql_bytes("\x42" * 0x100)
299
317
  end
300
318
 
301
319
  it 'decodes an empty byte array' do
302
- Decoding.read_short_bytes!("\x00\x00\x00\x00").should == ''
303
- end
304
-
305
- it 'returns an ASCII-8BIT encoded string' do
306
- Decoding.read_short_bytes!("\x00\x00\x00\x01\xaa").encoding.should == ::Encoding::BINARY
320
+ buffer = ByteBuffer.new("\x00\x00\x00\x00")
321
+ Decoding.read_short_bytes!(buffer).should be_empty
307
322
  end
308
323
 
309
324
  it 'decodes null' do
310
- Decoding.read_short_bytes!("\x80\x00").should be_nil
325
+ buffer = ByteBuffer.new("\x80\x00")
326
+ Decoding.read_short_bytes!(buffer).should be_nil
311
327
  end
312
328
 
313
329
  it 'consumes the bytes' do
314
330
  buffer << "\xab\xcd"
315
331
  Decoding.read_short_bytes!(buffer)
316
- buffer.should == "\xab\xcd"
332
+ buffer.should eql_bytes("\xab\xcd")
317
333
  end
318
334
 
319
335
  it 'raises an error when there are not enough bytes in the buffer' do
320
- expect { Decoding.read_short_bytes!(buffer[0, 10]) }.to raise_error(DecodingError)
336
+ b = ByteBuffer.new(buffer.read(10))
337
+ expect { Decoding.read_short_bytes!(b) }.to raise_error(DecodingError)
321
338
  end
322
339
  end
323
340
 
324
341
  describe '#read_option!' do
325
342
  it 'decodes an option ID and value with instructions from a block' do
326
- id, value = Decoding.read_option!("\x00\x01\x00\x03foo") do |id, buffer|
343
+ buffer = ByteBuffer.new("\x00\x01\x00\x03foo")
344
+ id, value = Decoding.read_option!(buffer) do |id, buffer|
327
345
  Decoding.read_string!(buffer)
328
346
  end
329
347
  id.should == 1
@@ -331,90 +349,105 @@ module Cql
331
349
  end
332
350
 
333
351
  it 'decodes an option ID and nil value when there is no block' do
334
- id, value = Decoding.read_option!("\xaa\xbb")
352
+ buffer = ByteBuffer.new("\xaa\xbb")
353
+ id, value = Decoding.read_option!(buffer)
335
354
  id.should == 0xaabb
336
355
  value.should be_nil
337
356
  end
338
357
 
339
358
  it 'consumes the bytes' do
340
- buffer = "\x00\x01\x00\x03\xab"
359
+ buffer = ByteBuffer.new("\x00\x01\x00\x03\xab")
341
360
  id, value = Decoding.read_option!(buffer) do |id, buffer|
342
361
  Decoding.read_short!(buffer)
343
362
  end
344
- buffer.should == "\xab"
363
+ buffer.should eql_bytes("\xab")
345
364
  end
346
365
 
347
366
  it 'raises an error when there are not enough bytes in the buffer' do
348
- expect { Decoding.read_option!("\xaa") }.to raise_error(DecodingError)
367
+ buffer = ByteBuffer.new("\xaa")
368
+ expect { Decoding.read_option!(buffer) }.to raise_error(DecodingError)
349
369
  end
350
370
  end
351
371
 
352
372
  describe '#read_inet!' do
353
373
  it 'decodes an IPv4 + port pair' do
354
- ip_addr, port = Decoding.read_inet!("\x04\x00\x00\x00\x00\x00\x00#R")
374
+ buffer = ByteBuffer.new("\x04\x00\x00\x00\x00\x00\x00#R")
375
+ ip_addr, port = Decoding.read_inet!(buffer)
355
376
  ip_addr.should == IPAddr.new('0.0.0.0')
356
377
  port.should == 9042
357
378
  end
358
379
 
359
380
  it 'decodes an IPv6 + port pair' do
360
- ip_addr, port = Decoding.read_inet!("\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00#R")
381
+ buffer = ByteBuffer.new("\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00#R")
382
+ ip_addr, port = Decoding.read_inet!(buffer)
361
383
  ip_addr.should == IPAddr.new('::1')
362
384
  port.should == 9042
363
385
  end
364
386
 
365
387
  it 'consumes the bytes' do
366
- buffer = "\x04\x00\x00\x00\x00\x00\x00#R\xff\xaa"
388
+ buffer = ByteBuffer.new("\x04\x00\x00\x00\x00\x00\x00#R\xff\xaa")
367
389
  Decoding.read_inet!(buffer)
368
- buffer.should == "\xff\xaa"
390
+ buffer.should eql_bytes("\xff\xaa")
369
391
  end
370
392
 
371
393
  it 'raises an error when there are not enough bytes in the buffer' do
372
- expect { Decoding.read_inet!("\x04\x00\x00\x00\x00\x00\x00") }.to raise_error(DecodingError)
373
- expect { Decoding.read_inet!("\x04\x00\x00\x00") }.to raise_error(DecodingError)
394
+ buffer1 = ByteBuffer.new("\x04\x00\x00\x00\x00\x00\x00")
395
+ expect { Decoding.read_inet!(buffer1) }.to raise_error(DecodingError)
396
+ buffer2 = ByteBuffer.new("\x04\x00\x00\x00")
397
+ expect { Decoding.read_inet!(buffer2) }.to raise_error(DecodingError)
374
398
  end
375
399
  end
376
400
 
377
401
  describe '#read_consistency!' do
378
402
  it 'decodes ANY' do
379
- Decoding.read_consistency!("\x00\x00").should == :any
403
+ buffer = ByteBuffer.new("\x00\x00")
404
+ Decoding.read_consistency!(buffer).should == :any
380
405
  end
381
406
 
382
407
  it 'decodes ONE' do
383
- Decoding.read_consistency!("\x00\x01").should == :one
408
+ buffer = ByteBuffer.new("\x00\x01")
409
+ Decoding.read_consistency!(buffer).should == :one
384
410
  end
385
411
 
386
412
  it 'decodes TWO' do
387
- Decoding.read_consistency!("\x00\x02").should == :two
413
+ buffer = ByteBuffer.new("\x00\x02")
414
+ Decoding.read_consistency!(buffer).should == :two
388
415
  end
389
416
 
390
417
  it 'decodes THREE' do
391
- Decoding.read_consistency!("\x00\x03").should == :three
418
+ buffer = ByteBuffer.new("\x00\x03")
419
+ Decoding.read_consistency!(buffer).should == :three
392
420
  end
393
421
 
394
422
  it 'decodes QUORUM' do
395
- Decoding.read_consistency!("\x00\x04").should == :quorum
423
+ buffer = ByteBuffer.new("\x00\x04")
424
+ Decoding.read_consistency!(buffer).should == :quorum
396
425
  end
397
426
 
398
427
  it 'decodes ALL' do
399
- Decoding.read_consistency!("\x00\x05").should == :all
428
+ buffer = ByteBuffer.new("\x00\x05")
429
+ Decoding.read_consistency!(buffer).should == :all
400
430
  end
401
431
 
402
432
  it 'decodes LOCAL_QUORUM' do
403
- Decoding.read_consistency!("\x00\x06").should == :local_quorum
433
+ buffer = ByteBuffer.new("\x00\x06")
434
+ Decoding.read_consistency!(buffer).should == :local_quorum
404
435
  end
405
436
 
406
437
  it 'decodes EACH_QUORUM' do
407
- Decoding.read_consistency!("\x00\x07").should == :each_quorum
438
+ buffer = ByteBuffer.new("\x00\x07")
439
+ Decoding.read_consistency!(buffer).should == :each_quorum
408
440
  end
409
441
 
410
442
  it 'raises an exception for an unknown consistency' do
411
- expect { Decoding.read_consistency!("\xff\xff") }.to raise_error(DecodingError)
443
+ buffer = ByteBuffer.new("\xff\xff")
444
+ expect { Decoding.read_consistency!(buffer) }.to raise_error(DecodingError)
412
445
  end
413
446
  end
414
447
 
415
448
  describe '#read_string_map!' do
416
449
  let :buffer do
417
- "\x00\x02\x00\x05hello\x00\x05world\x00\x03foo\x00\x03bar"
450
+ ByteBuffer.new("\x00\x02\x00\x05hello\x00\x05world\x00\x03foo\x00\x03bar")
418
451
  end
419
452
 
420
453
  it 'decodes a string multimap' do
@@ -422,23 +455,25 @@ module Cql
422
455
  end
423
456
 
424
457
  it 'decodes an empty string map' do
425
- Decoding.read_string_map!("\x00\x00").should == {}
458
+ buffer = ByteBuffer.new("\x00\x00")
459
+ Decoding.read_string_map!(buffer).should == {}
426
460
  end
427
461
 
428
462
  it 'consumes the bytes' do
429
463
  buffer << "\xff"
430
464
  Decoding.read_string_map!(buffer)
431
- buffer.should == "\xff"
465
+ buffer.should eql_bytes("\xff")
432
466
  end
433
467
 
434
468
  it 'raises an error when there are not enough bytes in the buffer' do
435
- expect { Decoding.read_string_map!(buffer.slice(0, 20)) }.to raise_error(DecodingError)
469
+ b = ByteBuffer.new(buffer.read(20))
470
+ expect { Decoding.read_string_map!(b) }.to raise_error(DecodingError)
436
471
  end
437
472
  end
438
473
 
439
474
  describe '#read_string_multimap!' do
440
475
  let :buffer do
441
- "\x00\x02\x00\x0bCQL_VERSION\x00\x01\x00\x053.0.0\x00\x0bCOMPRESSION\x00\x02\x00\x06snappy\x00\x04gzip"
476
+ ByteBuffer.new("\x00\x02\x00\x0bCQL_VERSION\x00\x01\x00\x053.0.0\x00\x0bCOMPRESSION\x00\x02\x00\x06snappy\x00\x04gzip")
442
477
  end
443
478
 
444
479
  it 'decodes a string multimap' do
@@ -446,17 +481,19 @@ module Cql
446
481
  end
447
482
 
448
483
  it 'decodes an empty string multimap' do
449
- Decoding.read_string_multimap!("\x00\x00").should == {}
484
+ buffer = ByteBuffer.new("\x00\x00")
485
+ Decoding.read_string_multimap!(buffer).should == {}
450
486
  end
451
487
 
452
488
  it 'consumes the bytes' do
453
489
  buffer << "\xff"
454
490
  Decoding.read_string_multimap!(buffer)
455
- buffer.should == "\xff"
491
+ buffer.should eql_bytes("\xff")
456
492
  end
457
493
 
458
494
  it 'raises an error when there are not enough bytes in the buffer' do
459
- expect { Decoding.read_string_multimap!(buffer.slice(0, 40)) }.to raise_error(DecodingError)
495
+ b = ByteBuffer.new(buffer.read(40))
496
+ expect { Decoding.read_string_multimap!(b) }.to raise_error(DecodingError)
460
497
  end
461
498
  end
462
499
  end