ffi-rzmq 2.0.1 → 2.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -40,25 +40,25 @@ module ZMQ
40
40
 
41
41
  it "should receive an exact string copy of the string message sent" do
42
42
  rc, received_message = send_ping(string)
43
- received_message.should == string
43
+ expect(received_message).to eq(string)
44
44
  end
45
45
 
46
46
  it "should generate a EFSM error when sending via the REQ socket twice in a row without an intervening receive operation" do
47
47
  send_ping(string)
48
48
  rc = @ping.send_string(string)
49
- rc.should == -1
50
- Util.errno.should == ZMQ::EFSM
49
+ expect(rc).to eq(-1)
50
+ expect(Util.errno).to eq(ZMQ::EFSM)
51
51
  end
52
52
 
53
53
  it "should receive an exact copy of the sent message using Message objects directly" do
54
54
  received_message = Message.new
55
55
 
56
56
  rc = @ping.sendmsg(Message.new(string))
57
- rc.should == string.size
57
+ expect(rc).to eq(string.size)
58
58
  rc = @pong.recvmsg received_message
59
- rc.should == string.size
59
+ expect(rc).to eq(string.size)
60
60
 
61
- received_message.copy_out_string.should == string
61
+ expect(received_message.copy_out_string).to eq(string)
62
62
  end
63
63
 
64
64
  it "should receive an exact copy of the sent message using Message objects directly in non-blocking mode" do
@@ -67,13 +67,13 @@ module ZMQ
67
67
 
68
68
  poll_it_for_read(@pong) do
69
69
  rc = @ping.sendmsg(Message.new(string), ZMQ::DONTWAIT)
70
- rc.should == string.size
70
+ expect(rc).to eq(string.size)
71
71
  end
72
72
 
73
73
  rc = @pong.recvmsg received_message, ZMQ::DONTWAIT
74
- rc.should == string.size
74
+ expect(rc).to eq(string.size)
75
75
 
76
- received_message.copy_out_string.should == string
76
+ expect(received_message.copy_out_string).to eq(string)
77
77
  end
78
78
 
79
79
  end # context ping-pong
@@ -16,21 +16,21 @@ module ZMQ
16
16
 
17
17
 
18
18
  it "should raise an error for a nil context" do
19
- lambda { Socket.new(FFI::Pointer.new(0), ZMQ::REQ) }.should raise_exception(ZMQ::ContextError)
19
+ expect { Socket.new(FFI::Pointer.new(0), ZMQ::REQ) }.to raise_exception(ZMQ::ContextError)
20
20
  end
21
21
 
22
22
  it "works with a Context#pointer as the context_ptr" do
23
- lambda do
23
+ expect do
24
24
  s = Socket.new(@ctx.pointer, ZMQ::REQ)
25
25
  s.close
26
- end.should_not raise_exception
26
+ end.not_to raise_exception
27
27
  end
28
28
 
29
29
  it "works with a Context instance as the context_ptr" do
30
- lambda do
30
+ expect do
31
31
  s = Socket.new(@ctx, ZMQ::SUB)
32
32
  s.close
33
- end.should_not raise_exception
33
+ end.not_to raise_exception
34
34
  end
35
35
 
36
36
 
@@ -38,22 +38,22 @@ module ZMQ
38
38
 
39
39
  it "should not raise an error for a [#{ZMQ::SocketTypeNameMap[socket_type]}] socket type" do
40
40
  sock = nil
41
- lambda { sock = Socket.new(@ctx.pointer, socket_type) }.should_not raise_error
41
+ expect { sock = Socket.new(@ctx.pointer, socket_type) }.not_to raise_error
42
42
  sock.close
43
43
  end
44
44
  end # each socket_type
45
45
 
46
46
  it "should set the :socket accessor to the raw socket allocated by libzmq" do
47
47
  socket = double('socket')
48
- socket.stub(:null? => false)
49
- LibZMQ.should_receive(:zmq_socket).and_return(socket)
48
+ allow(socket).to receive(:null?).and_return(false)
49
+ expect(LibZMQ).to receive(:zmq_socket).and_return(socket)
50
50
 
51
51
  sock = Socket.new(@ctx.pointer, ZMQ::REQ)
52
- sock.socket.should == socket
52
+ expect(sock.socket).to eq(socket)
53
53
  end
54
54
 
55
55
  it "should define a finalizer on this object" do
56
- ObjectSpace.should_receive(:define_finalizer).at_least(1)
56
+ expect(ObjectSpace).to receive(:define_finalizer).at_least(1)
57
57
  sock = Socket.new(@ctx.pointer, ZMQ::REQ)
58
58
  sock.close
59
59
  end
@@ -77,7 +77,7 @@ module ZMQ
77
77
  sock = Socket.new @ctx.pointer, ZMQ::REQ
78
78
  raw_socket = sock.socket
79
79
 
80
- LibZMQ.should_receive(:close).with(raw_socket)
80
+ expect(LibZMQ).to receive(:close).with(raw_socket)
81
81
  sock.close
82
82
  sock.close
83
83
  LibZMQ.close raw_socket # *really close it otherwise the context will block indefinitely
@@ -94,7 +94,7 @@ module ZMQ
94
94
  sock = Socket.new @ctx.pointer, ZMQ::REQ
95
95
 
96
96
  sock.identity = ('a' * 256)
97
- sock.identity.should == ''
97
+ expect(sock.identity).to eq('')
98
98
  sock.close
99
99
  end
100
100
 
@@ -102,7 +102,7 @@ module ZMQ
102
102
  sock = Socket.new @ctx.pointer, ZMQ::REQ
103
103
 
104
104
  sock.identity = ''
105
- sock.identity.should == ''
105
+ expect(sock.identity).to eq('')
106
106
  sock.close
107
107
  end
108
108
 
@@ -110,7 +110,7 @@ module ZMQ
110
110
  sock = Socket.new @ctx.pointer, ZMQ::REQ
111
111
 
112
112
  sock.identity = 'a'
113
- sock.identity.should == 'a'
113
+ expect(sock.identity).to eq('a')
114
114
  sock.close
115
115
  end
116
116
 
@@ -118,7 +118,7 @@ module ZMQ
118
118
  sock = Socket.new @ctx.pointer, ZMQ::REQ
119
119
 
120
120
  sock.identity = ('a' * 255)
121
- sock.identity.should == ('a' * 255)
121
+ expect(sock.identity).to eq('a' * 255)
122
122
  sock.close
123
123
  end
124
124
 
@@ -126,7 +126,7 @@ module ZMQ
126
126
  sock = Socket.new @ctx.pointer, ZMQ::REQ
127
127
 
128
128
  sock.identity = 7
129
- sock.identity.should == '7'
129
+ expect(sock.identity).to eq('7')
130
130
  sock.close
131
131
  end
132
132
  end # context identity=
@@ -157,8 +157,8 @@ module ZMQ
157
157
 
158
158
  array = []
159
159
  rc = socket.getsockopt(ZMQ::IDENTITY, array)
160
- rc.should == 0
161
- array[0].should == identity
160
+ expect(rc).to eq(0)
161
+ expect(array[0]).to eq(identity)
162
162
  end
163
163
  end
164
164
 
@@ -166,7 +166,7 @@ module ZMQ
166
166
  identity = 'a' * 256
167
167
  array = []
168
168
  rc = socket.setsockopt(ZMQ::IDENTITY, identity)
169
- rc.should == -1
169
+ expect(rc).to eq(-1)
170
170
  end
171
171
  end # context using option ZMQ::IDENTITY
172
172
 
@@ -176,28 +176,28 @@ module ZMQ
176
176
  socket.setsockopt ZMQ::IPV4ONLY, value
177
177
  array = []
178
178
  rc = socket.getsockopt(ZMQ::IPV4ONLY, array)
179
- rc.should == 0
180
- array[0].should == value
179
+ expect(rc).to eq(0)
180
+ expect(array[0]).to eq(value)
181
181
  end
182
182
 
183
183
  it "should default to a value of 1" do
184
184
  value = 1
185
185
  array = []
186
186
  rc = socket.getsockopt(ZMQ::IPV4ONLY, array)
187
- rc.should == 0
188
- array[0].should == value
187
+ expect(rc).to eq(0)
188
+ expect(array[0]).to eq(value)
189
189
  end
190
190
 
191
191
  it "returns -1 given a negative value" do
192
192
  value = -1
193
193
  rc = socket.setsockopt ZMQ::IPV4ONLY, value
194
- rc.should == -1
194
+ expect(rc).to eq(-1)
195
195
  end
196
196
 
197
197
  it "returns -1 given a value > 1" do
198
198
  value = 2
199
199
  rc = socket.setsockopt ZMQ::IPV4ONLY, value
200
- rc.should == -1
200
+ expect(rc).to eq(-1)
201
201
  end
202
202
  end # context using option ZMQ::IPV4ONLY
203
203
 
@@ -206,10 +206,10 @@ module ZMQ
206
206
  random_port = bind_to_random_tcp_port(socket, max_tries = 500)
207
207
  array = []
208
208
  rc = socket.getsockopt(ZMQ::LAST_ENDPOINT, array)
209
- ZMQ::Util.resultcode_ok?(rc).should == true
209
+ expect(ZMQ::Util.resultcode_ok?(rc)).to eq(true)
210
210
  endpoint_regex = %r{\Atcp://(.*):(\d+)\0\z}
211
- array[0].should =~ endpoint_regex
212
- Integer(array[0][endpoint_regex, 2]).should == random_port
211
+ expect(array[0]).to match(endpoint_regex)
212
+ expect(Integer(array[0][endpoint_regex, 2])).to eq(random_port)
213
213
  end
214
214
  end
215
215
 
@@ -217,12 +217,12 @@ module ZMQ
217
217
  if ZMQ::SUB == socket_type
218
218
  it "returns 0 for a SUB socket" do
219
219
  rc = socket.setsockopt(ZMQ::SUBSCRIBE, "topic.string")
220
- rc.should == 0
220
+ expect(rc).to eq(0)
221
221
  end
222
222
  else
223
223
  it "returns -1 for non-SUB sockets" do
224
224
  rc = socket.setsockopt(ZMQ::SUBSCRIBE, "topic.string")
225
- rc.should == -1
225
+ expect(rc).to eq(-1)
226
226
  end
227
227
  end
228
228
  end # context using option ZMQ::SUBSCRIBE
@@ -233,13 +233,13 @@ module ZMQ
233
233
  it "returns 0 given a topic string that was previously subscribed" do
234
234
  socket.setsockopt ZMQ::SUBSCRIBE, "topic.string"
235
235
  rc = socket.setsockopt(ZMQ::UNSUBSCRIBE, "topic.string")
236
- rc.should == 0
236
+ expect(rc).to eq(0)
237
237
  end
238
238
 
239
239
  else
240
240
  it "returns -1 for non-SUB sockets" do
241
241
  rc = socket.setsockopt(ZMQ::UNSUBSCRIBE, "topic.string")
242
- rc.should == -1
242
+ expect(rc).to eq(-1)
243
243
  end
244
244
  end
245
245
  end # context using option ZMQ::UNSUBSCRIBE
@@ -251,8 +251,8 @@ module ZMQ
251
251
  socket.setsockopt ZMQ::AFFINITY, affinity
252
252
  array = []
253
253
  rc = socket.getsockopt(ZMQ::AFFINITY, array)
254
- rc.should == 0
255
- array[0].should == affinity
254
+ expect(rc).to eq(0)
255
+ expect(array[0]).to eq(affinity)
256
256
  end
257
257
  end # context using option ZMQ::AFFINITY
258
258
 
@@ -263,14 +263,14 @@ module ZMQ
263
263
  socket.setsockopt ZMQ::RATE, rate
264
264
  array = []
265
265
  rc = socket.getsockopt(ZMQ::RATE, array)
266
- rc.should == 0
267
- array[0].should == rate
266
+ expect(rc).to eq(0)
267
+ expect(array[0]).to eq(rate)
268
268
  end
269
269
 
270
270
  it "returns -1 given a negative value" do
271
271
  rate = -200
272
272
  rc = socket.setsockopt ZMQ::RATE, rate
273
- rc.should == -1
273
+ expect(rc).to eq(-1)
274
274
  end
275
275
  end # context using option ZMQ::RATE
276
276
 
@@ -281,14 +281,14 @@ module ZMQ
281
281
  socket.setsockopt ZMQ::RECOVERY_IVL, rate
282
282
  array = []
283
283
  rc = socket.getsockopt(ZMQ::RECOVERY_IVL, array)
284
- rc.should == 0
285
- array[0].should == rate
284
+ expect(rc).to eq(0)
285
+ expect(array[0]).to eq(rate)
286
286
  end
287
287
 
288
288
  it "returns -1 given a negative value" do
289
289
  rate = -200
290
290
  rc = socket.setsockopt ZMQ::RECOVERY_IVL, rate
291
- rc.should == -1
291
+ expect(rc).to eq(-1)
292
292
  end
293
293
  end # context using option ZMQ::RECOVERY_IVL
294
294
 
@@ -299,8 +299,8 @@ module ZMQ
299
299
  socket.setsockopt ZMQ::SNDBUF, size
300
300
  array = []
301
301
  rc = socket.getsockopt(ZMQ::SNDBUF, array)
302
- rc.should == 0
303
- array[0].should == size
302
+ expect(rc).to eq(0)
303
+ expect(array[0]).to eq(size)
304
304
  end
305
305
  end # context using option ZMQ::SNDBUF
306
306
 
@@ -311,8 +311,8 @@ module ZMQ
311
311
  socket.setsockopt ZMQ::RCVBUF, size
312
312
  array = []
313
313
  rc = socket.getsockopt(ZMQ::RCVBUF, array)
314
- rc.should == 0
315
- array[0].should == size
314
+ expect(rc).to eq(0)
315
+ expect(array[0]).to eq(size)
316
316
  end
317
317
  end # context using option ZMQ::RCVBUF
318
318
 
@@ -323,8 +323,8 @@ module ZMQ
323
323
  socket.setsockopt ZMQ::LINGER, value
324
324
  array = []
325
325
  rc = socket.getsockopt(ZMQ::LINGER, array)
326
- rc.should == 0
327
- array[0].should == value
326
+ expect(rc).to eq(0)
327
+ expect(array[0]).to eq(value)
328
328
  end
329
329
 
330
330
  it "should set the socket message linger option to 0 for dropping packets" do
@@ -332,16 +332,16 @@ module ZMQ
332
332
  socket.setsockopt ZMQ::LINGER, value
333
333
  array = []
334
334
  rc = socket.getsockopt(ZMQ::LINGER, array)
335
- rc.should == 0
336
- array[0].should == value
335
+ expect(rc).to eq(0)
336
+ expect(array[0]).to eq(value)
337
337
  end
338
338
 
339
339
  it "should default to a value of 0" do
340
340
  value = [SUB, XSUB].include?(socket_type) ? 0 : -1
341
341
  array = []
342
342
  rc = socket.getsockopt(ZMQ::LINGER, array)
343
- rc.should == 0
344
- array[0].should == value
343
+ expect(rc).to eq(0)
344
+ expect(array[0]).to eq(value)
345
345
  end
346
346
  end # context using option ZMQ::LINGER
347
347
 
@@ -352,16 +352,16 @@ module ZMQ
352
352
  socket.setsockopt ZMQ::RECONNECT_IVL, value
353
353
  array = []
354
354
  rc = socket.getsockopt(ZMQ::RECONNECT_IVL, array)
355
- rc.should == 0
356
- array[0].should == value
355
+ expect(rc).to eq(0)
356
+ expect(array[0]).to eq(value)
357
357
  end
358
358
 
359
359
  it "should default to a value of 100" do
360
360
  value = 100
361
361
  array = []
362
362
  rc = socket.getsockopt(ZMQ::RECONNECT_IVL, array)
363
- rc.should == 0
364
- array[0].should == value
363
+ expect(rc).to eq(0)
364
+ expect(array[0]).to eq(value)
365
365
  end
366
366
  end # context using option ZMQ::RECONNECT_IVL
367
367
 
@@ -370,19 +370,19 @@ module ZMQ
370
370
  it "should set the maximum number of pending socket connections given a positive value" do
371
371
  value = 200
372
372
  rc = socket.setsockopt ZMQ::BACKLOG, value
373
- rc.should == 0
373
+ expect(rc).to eq(0)
374
374
  array = []
375
375
  rc = socket.getsockopt(ZMQ::BACKLOG, array)
376
- rc.should == 0
377
- array[0].should == value
376
+ expect(rc).to eq(0)
377
+ expect(array[0]).to eq(value)
378
378
  end
379
379
 
380
380
  it "should default to a value of 100" do
381
381
  value = 100
382
382
  array = []
383
383
  rc = socket.getsockopt(ZMQ::BACKLOG, array)
384
- rc.should == 0
385
- array[0].should == value
384
+ expect(rc).to eq(0)
385
+ expect(array[0]).to eq(value)
386
386
  end
387
387
  end # context using option ZMQ::BACKLOG
388
388
 
@@ -408,8 +408,8 @@ module ZMQ
408
408
  it "should return an FD as a positive integer" do
409
409
  array = []
410
410
  rc = socket.getsockopt(ZMQ::FD, array)
411
- rc.should == 0
412
- array[0].should > 0
411
+ expect(rc).to eq(0)
412
+ expect(array[0]).to be > 0
413
413
  end
414
414
 
415
415
  it "returns a valid FD that is accepted by the system poll() function" do
@@ -434,7 +434,7 @@ module ZMQ
434
434
 
435
435
  array = []
436
436
  rc = socket.getsockopt(ZMQ::FD, array)
437
- rc.should be_zero
437
+ expect(rc).to eq(0)
438
438
  fd = array[0]
439
439
 
440
440
  # setup the BSD poll_fd struct
@@ -444,7 +444,7 @@ module ZMQ
444
444
  pollfd[:revents] = 0
445
445
 
446
446
  rc = LibSocket.poll(pollfd, 1, 0)
447
- rc.should be_zero
447
+ expect(rc).to eq(0)
448
448
  end
449
449
  end
450
450
 
@@ -454,8 +454,8 @@ module ZMQ
454
454
  it "should return a mask of events as a Fixnum" do
455
455
  array = []
456
456
  rc = socket.getsockopt(ZMQ::EVENTS, array)
457
- rc.should == 0
458
- array[0].should be_a(Fixnum)
457
+ expect(rc).to eq(0)
458
+ expect(array[0]).to be_a(Fixnum)
459
459
  end
460
460
  end
461
461
 
@@ -463,8 +463,8 @@ module ZMQ
463
463
  it "should return the socket type" do
464
464
  array = []
465
465
  rc = socket.getsockopt(ZMQ::TYPE, array)
466
- rc.should == 0
467
- array[0].should == socket_type
466
+ expect(rc).to eq(0)
467
+ expect(array[0]).to eq(socket_type)
468
468
  end
469
469
  end
470
470
  end # context #getsockopt
@@ -479,29 +479,29 @@ module ZMQ
479
479
  it "SUB socket that received a message always has POLLIN set" do
480
480
  events = []
481
481
  rc = @sub.getsockopt(ZMQ::EVENTS, events)
482
- rc.should == 0
483
- events[0].should == ZMQ::POLLIN
482
+ expect(rc).to eq(0)
483
+ expect(events[0]).to eq ZMQ::POLLIN
484
484
  end
485
485
 
486
486
  it "PUB socket always has POLLOUT set" do
487
487
  events = []
488
488
  rc = @pub.getsockopt(ZMQ::EVENTS, events)
489
- rc.should == 0
490
- events[0].should == ZMQ::POLLOUT
489
+ expect(rc).to eq(0)
490
+ expect(events[0]).to eq ZMQ::POLLOUT
491
491
  end
492
492
 
493
493
  it "PUB socket never has POLLIN set" do
494
494
  events = []
495
495
  rc = @pub.getsockopt(ZMQ::EVENTS, events)
496
- rc.should == 0
497
- events[0].should_not == ZMQ::POLLIN
496
+ expect(rc).to eq(0)
497
+ expect(events[0]).not_to eq ZMQ::POLLIN
498
498
  end
499
499
 
500
500
  it "SUB socket never has POLLOUT set" do
501
501
  events = []
502
502
  rc = @sub.getsockopt(ZMQ::EVENTS, events)
503
- rc.should == 0
504
- events[0].should_not == ZMQ::POLLOUT
503
+ expect(rc).to eq(0)
504
+ expect(events[0]).not_to eq ZMQ::POLLOUT
505
505
  end
506
506
  end # shared example for pubsub
507
507
 
@@ -514,7 +514,7 @@ module ZMQ
514
514
  endpoint = "inproc://socket_test"
515
515
  @sub = @ctx.socket ZMQ::SUB
516
516
  rc = @sub.setsockopt ZMQ::SUBSCRIBE, ''
517
- rc.should == 0
517
+ expect(rc).to eq(0)
518
518
 
519
519
  @pub = @ctx.socket ZMQ::PUB
520
520
  @sub.bind(endpoint)