ffi-rzmq 2.0.0 → 2.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: a406c4de564eef119c3f303a386546d6bfda94fd
4
- data.tar.gz: 4ef6371ae1029809d302dc7911d0a5a056328428
2
+ SHA256:
3
+ metadata.gz: 403a3126661f6dc781b72e58f03a2c6b84e38c8d72e9f4b25115c44731aef8e7
4
+ data.tar.gz: 86bd066c1eddd598e67387144e21e45875e2fd79e8a57c6d38c56f04a11b2f19
5
5
  SHA512:
6
- metadata.gz: 801813a1a358e60fc0906369c1da88638bdb2c91588da12c50adf2b5869b8542690baa14b3d6098f2ba34e74fcb9468631c5f23ac21dba216782be21a654406d
7
- data.tar.gz: 88e1a7bdc0500f6703e94ace2c145f96420fafa89b0bd39927edd5f4a396ca36a4a0bbb543d57b517b115eae5ffb9c55288b1b568fc4ae11f8acee903ceaa1b1
6
+ metadata.gz: 8704b9f4d77c7a3dba2381dfea0a8cc96604b453c4e042162c0410371bea0207433b8348b954398c5855427e6f4efc8b51a437a7abe4582f4de1d73e42ed17c1
7
+ data.tar.gz: a4df109b2adcc9b18ea2f772bac5d1130b33b7066a8c1160706cc201c0aa08f58acbef56b44c53a9151c38f9bcb553ccb2ede46182bfdaf9d79bccf85a7b4b08
data/.travis.yml CHANGED
@@ -1,15 +1,14 @@
1
- before_install: sudo apt-get install libzmq3-dev
2
- script: bundle exec rspec
1
+ script: ./travis_build_script.sh
3
2
  language: ruby
4
3
  rvm:
5
- - 1.9.3
6
- - 2.0.0
4
+ - 2.6.0
7
5
  - ruby-head
8
- - jruby-19mode
6
+ - jruby
9
7
  - jruby-head
10
- - rbx-2.1.1
8
+ - rbx-3
11
9
 
12
10
  matrix:
13
11
  allow_failures:
14
12
  - rvm: ruby-head
15
13
  - rvm: jruby-head
14
+ - rvm: rbx-3
data/AUTHORS.txt CHANGED
@@ -32,4 +32,6 @@ Paul Chechetin, github: paulche
32
32
 
33
33
  Michael Zaccari, github: mzaccari
34
34
 
35
- Jason Roelofs, github: jasonroelofs
35
+ Jason Roelofs, github: jasonroelofs
36
+
37
+ Cédric Boutillier, github: boutil
data/History.txt CHANGED
@@ -1,3 +1,63 @@
1
+ == 2.0.7
2
+ * Fix Issue #130
3
+ Fix to better support Zeromq 3.x users when performing context termination.
4
+ Support library ffi-rzmq-core was updated to handle this support, so
5
+ we now have a minimum dependency of ffi-rzmq-core 1.0.7 on this gem.
6
+
7
+ * Fix Issue #131
8
+ Update the OpenSSL key and certificate files. Original files were 1024 bits
9
+ but this causes problems on some modern Linux (e.g. Debian) which complains
10
+ about the key length. Updated to 4096 bits. Copied the key and cert
11
+ generation scripts from the Debian repository with attribution. Thanks to
12
+ @boutil for the helper script and the bug report.
13
+
14
+ == 2.0.6
15
+ * Fix for uncaught exception. Strange case... somehow calling
16
+ `zmq_ctx_term` was returning nil, so when checking the result code it
17
+ would fail. No overrides a nil value with 0 so check passes.
18
+
19
+ * Update some JRuby-specific code to fetch a file descriptor value. API
20
+ changed from earlier versions, so code is updated to use new API. All
21
+ specs pass.
22
+
23
+ == 2.0.5
24
+ * Fix issue #123. Bundled gems were a bit outdated so upgraded to latest
25
+ rspec gem.
26
+
27
+ * Fix issue #124. Newer releases of libzmq are not exporting all symbols
28
+ to the global namespace so some lazy loading performed by FFI was
29
+ failing. Now force all symbols into global namespace.
30
+
31
+ * Fix "::Fixnum has been deprecated" warnings from MRI 2.4.x+.
32
+
33
+ * Force ffi-rzmq-core 1.0.6 or later as dependency.
34
+
35
+ == 2.0.4
36
+ * Screwed up the release managment. Had wrong version in version.rb. Fixed.
37
+
38
+ == 2.0.3
39
+ * Updated specs to use RSpec 3.x syntax. Never again... if they change it
40
+ then I'm dumping rspec.
41
+
42
+ * Now loading version.rb during startup so that ZMQ::VERSION returns a string.
43
+
44
+ * Modified README to point most people to the Ruby gem that wraps the CZMQ
45
+ library. It's a much higher-level library that makes writing zeromq apps
46
+ very easy. This gem is for writing low-level code which most people don't
47
+ want or need to do. This gem is going into maintenance mode only.
48
+
49
+
50
+ == 2.0.2
51
+
52
+ * Updated README to make it clearer which versions of libzmq are supported.
53
+
54
+ * Updated README to use a newer example.
55
+
56
+ == 2.0.1 / 20140122
57
+ * Fix setsockopt with string parameters for options that have very strict
58
+ requirements (like CURVE_SECRETKEY) (37aed3c)
59
+
60
+ * Provide a wrapper for zmq_curve_keypair for ZeroMQ4
1
61
 
2
62
  == 2.0.0 / 20140108
3
63
  * Split out all of the FFI code to its own gem so other projects can use
data/README.rdoc CHANGED
@@ -2,6 +2,22 @@ ffi-rzmq
2
2
  by Chuck Remes
3
3
  http://www.zeromq.org/bindings:ruby-ffi
4
4
 
5
+ == FUTURE SUPPORT
6
+
7
+ Most people writing Zeromq applications in Ruby should be using the rbczmq
8
+ project. It wraps the CZMQ binding which is a much higher-level library
9
+ for writing Zeromq code. Find the Ruby gem here:
10
+
11
+ http://github.com/methodmissing/rbczmq
12
+
13
+ Few projects need to write the low-level zeromq code that this gem allows.
14
+ With the release of ffi-rzmq 2.0.3, this library is going into permanent
15
+ maintenance mode. As new versions of libzmq are released, interested parties
16
+ should send pull requests to this project or its related project
17
+ ffi-rzmq-core to support new features.
18
+
19
+ The original README text follows...
20
+
5
21
  == DESCRIPTION:
6
22
 
7
23
  This gem wraps the ZeroMQ networking library using the ruby FFI (foreign
@@ -9,11 +25,18 @@ function interface). It's a pure ruby wrapper so this gem can be loaded
9
25
  and run by any ruby runtime that supports FFI. That's all of them:
10
26
  MRI 1.9.x, Rubinius and JRuby.
11
27
 
12
- This single gem supports 0mq 2.2.x and 3.2.x 0mq APIs. The 0mq project started
28
+ The Ruby API provided by this gem is *NOT* very Ruby-like. It very closely
29
+ tracks the libzmq C API. However, the contributors to this project have
30
+ done all of the hard work to wrap up all of libzmq and make it accessible
31
+ from Ruby. If you want it to be more Ruby-like (e.g. raise Exceptions instead
32
+ of returning integer codes) then *wrap this library* with your own and release
33
+ it as a gem. We will all be grateful!
34
+
35
+ This single gem supports 0mq 3.2.x and 4.x APIs. The 0mq project started
13
36
  making backward-incompatible changes to the API with the 3.1.x release.
14
37
  The gem auto-configures itself to expose the API conforming to the loaded
15
- C library. 0mq API 3.0 is *not* supported; the 0mq community voted to
16
- abandon it.
38
+ C library. 0mq 2.x is no longer supported. 0mq API 3.0 is *not* supported;
39
+ the 0mq community voted to abandon it.
17
40
 
18
41
  The impetus behind this library was to provide support for ZeroMQ in
19
42
  JRuby which has native threads. Unlike MRI, which has a GIL, JRuby and
@@ -36,7 +59,7 @@ than using a C extension.
36
59
  == FEATURES/PROBLEMS:
37
60
 
38
61
  This gem needs more tests. This gem has been battle tested by myself
39
- and others for over a year, so I am fairly confident that it is solid.
62
+ and others for years, so I am fairly confident that it is solid.
40
63
  However, it is inevitable that there will be bugs, so please open
41
64
  issues for them here or fork this project, fix them, and send me a pull
42
65
  request.
@@ -46,6 +69,14 @@ on that gem to load and run this code, then this project also no longer
46
69
  supports MRI 1.8.x. I recommend JRuby for the best performance and
47
70
  stability.
48
71
 
72
+ The `Socket` and `Context` classes have finalizers which will
73
+ be called by the garbage collector when there are no more references.
74
+ However, these finalizers should not be relied upon to orderly close
75
+ your sockets and then the context. Finalizers run in a non-determinant
76
+ order, so the `Context` finalizer may run first which will hang the
77
+ program. To avoid this, make sure to close all sockets before the
78
+ program exits.
79
+
49
80
  All features are implemented.
50
81
 
51
82
  == BUILD STATUS:
@@ -56,62 +87,71 @@ All features are implemented.
56
87
 
57
88
  == SYNOPSIS:
58
89
 
59
- 0mq API v2 client code:
90
+ 0mq API v3.2-4 client code:
60
91
 
61
92
  require 'rubygems'
62
93
  require 'ffi-rzmq'
63
94
 
64
95
  if ARGV.length < 3
65
- puts "usage: local_lat <connect-to> <message-size> <roundtrip-count>"
96
+ puts "usage: ruby local_lat.rb <connect-to> <message-size> <roundtrip-count>"
66
97
  exit
67
98
  end
68
-
99
+
69
100
  bind_to = ARGV[0]
70
101
  message_size = ARGV[1].to_i
71
102
  roundtrip_count = ARGV[2].to_i
72
103
 
73
104
  ctx = ZMQ::Context.new
74
- s = ctx.socket ZMQ::REP
75
- rc = s.setsockopt(ZMQ::HWM, 100)
76
- rc = s.bind(bind_to)
105
+ s = ctx.socket ZMQ::REP
106
+ rc = s.setsockopt(ZMQ::SNDHWM, 100)
107
+ rc = s.setsockopt(ZMQ::RCVHWM, 100)
108
+ rc = s.bind(bind_to)
77
109
 
78
- msg = ""
79
110
  roundtrip_count.times do
80
- rc = s.recv_string msg
111
+ msg = ""
112
+ rc = s.recv_string msg
81
113
  raise "Message size doesn't match, expected [#{message_size}] but received [#{msg.size}]" if message_size != msg.size
82
- rc = s.send_string msg, 0
114
+ rc = s.send_string msg, 0
83
115
  end
84
116
 
85
-
86
- 0mq API v2 server code:
117
+ 0mq API v3.2-4 server code:
87
118
 
88
119
  require 'rubygems'
89
120
  require 'ffi-rzmq'
90
121
 
91
122
  if ARGV.length < 3
92
- puts "usage: remote_lat <connect-to> <message-size> <roundtrip-count>"
123
+ puts "usage: ruby remote_lat.rb <connect-to> <message-size> <roundtrip-count>"
93
124
  exit
94
125
  end
95
-
126
+
127
+ def assert(rc)
128
+ raise "Last API call failed at #{caller(1)}" unless rc >= 0
129
+ end
130
+
96
131
  connect_to = ARGV[0]
97
132
  message_size = ARGV[1].to_i
98
133
  roundtrip_count = ARGV[2].to_i
99
134
 
100
135
  ctx = ZMQ::Context.new
101
- s = ctx.socket ZMQ::REQ
102
- rc = s.connect(connect_to)
136
+ s = ctx.socket ZMQ::REQ
137
+ rc = s.connect(connect_to)
103
138
 
104
139
  msg = "#{ '3' * message_size }"
105
140
 
106
- start_time = Time.now
141
+ time_start = Time.now
107
142
 
108
- msg = ""
109
143
  roundtrip_count.times do
110
- rc = s.send_string msg, 0
111
- rc = s.recv_string msg
144
+ assert(s.send_string(msg, 0))
145
+
146
+ msg = ''
147
+ assert(s.recv_string(msg, 0))
148
+
112
149
  raise "Message size doesn't match, expected [#{message_size}] but received [#{msg.size}]" if message_size != msg.size
113
150
  end
114
151
 
152
+ time_end = Time.now
153
+ puts "Time #{( time_end - time_start )}"
154
+
115
155
  == Better Examples
116
156
 
117
157
  I highly recommend visiting the Learn Ruby 0mq project for a bunch of good code examples.
@@ -139,7 +179,7 @@ It will crash randomly and you will be sad.
139
179
 
140
180
  == INSTALL:
141
181
 
142
- Make sure the ZeroMQ library is already installed on your system.
182
+ Make sure the ZeroMQ library is already installed on your system. We recommend 'brew' or 'macports' to get it.
143
183
 
144
184
  % gem install ffi-rzmq # should grab the latest release
145
185
 
@@ -161,7 +201,7 @@ that activity. That DLL also requires that you copy libstdc++-6.dll and libgcc_s
161
201
 
162
202
  (The MIT License)
163
203
 
164
- Copyright (c) 2013 Chuck Remes
204
+ Copyright (c) 2013-2017 Chuck Remes
165
205
 
166
206
  Permission is hereby granted, free of charge, to any person obtaining
167
207
  a copy of this software and associated documentation files (the
data/Rakefile CHANGED
@@ -4,3 +4,18 @@ require 'rspec/core/rake_task'
4
4
  RSpec::Core::RakeTask.new
5
5
 
6
6
  task :default => :spec
7
+
8
+ task :console do
9
+ require 'irb'
10
+ require 'irb/completion'
11
+ require 'ffi-rzmq'
12
+ ARGV.clear
13
+ IRB.start
14
+ end
15
+
16
+ task :pryconsole do
17
+ require 'pry'
18
+ require 'ffi-rzmq'
19
+ ARGV.clear
20
+ Pry.start
21
+ end
@@ -0,0 +1,60 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'ffi-rzmq')
2
+
3
+ # This example shows the basics of a CURVE-secured REP/REQ setup between
4
+ # a Server and Client. This is the minimal required setup for authenticating
5
+ # a connection between a Client and a Server. For validating the Client's authentication
6
+ # once the initial connection has succeeded, you'll need a ZAP handler on the Server.
7
+
8
+ # Build the Server's keys
9
+ server_public_key, server_private_key = ZMQ::Util.curve_keypair
10
+
11
+ # Build the Client's keys
12
+ client_public_key, client_private_key = ZMQ::Util.curve_keypair
13
+
14
+ context = ZMQ::Context.new
15
+ bind_point = "tcp://127.0.0.1:4455"
16
+
17
+ ##
18
+ # Configure the Server
19
+ ##
20
+ server = context.socket ZMQ::REP
21
+
22
+ server.setsockopt(ZMQ::CURVE_SERVER, 1)
23
+ server.setsockopt(ZMQ::CURVE_SECRETKEY, server_private_key)
24
+
25
+ server.bind(bind_point)
26
+
27
+ ##
28
+ # Configure the Client to talk to the Server
29
+ ##
30
+ client = context.socket ZMQ::REQ
31
+
32
+ client.setsockopt(ZMQ::CURVE_SERVERKEY, server_public_key)
33
+ client.setsockopt(ZMQ::CURVE_PUBLICKEY, client_public_key)
34
+ client.setsockopt(ZMQ::CURVE_SECRETKEY, client_private_key)
35
+
36
+ client.connect(bind_point)
37
+
38
+ ##
39
+ # Show that communication still works
40
+ ##
41
+
42
+ client_message = "Hello Server!"
43
+ server_response = "Hello Client!"
44
+
45
+ puts "Client sending: #{client_message}"
46
+ client.send_string client_message
47
+
48
+ server.recv_string(server_message = '')
49
+ puts "Server received: #{server_message}, replying with #{server_response}"
50
+
51
+ server.send_string(server_response)
52
+
53
+ client.recv_string(response = '')
54
+ puts "Client has received: #{response}"
55
+
56
+ puts "Finished"
57
+
58
+ client.close
59
+ server.close
60
+ context.terminate
data/ffi-rzmq.gemspec CHANGED
@@ -21,7 +21,7 @@ and run by any ruby runtime that supports FFI. That's all of the major ones - MR
21
21
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
22
22
  s.require_paths = ["lib"]
23
23
 
24
- s.add_runtime_dependency "ffi-rzmq-core", [">= 1.0.1"]
25
- s.add_development_dependency "rspec", ["~> 2.14"]
24
+ s.add_runtime_dependency "ffi-rzmq-core", [">= 1.0.7"]
25
+ s.add_development_dependency "rspec", ["~> 3.7"]
26
26
  s.add_development_dependency "rake"
27
27
  end
@@ -82,9 +82,9 @@ module ZMQ
82
82
  def terminate
83
83
  unless @context.nil? || @context.null?
84
84
  remove_finalizer
85
- rc = LibZMQ.zmq_ctx_destroy(@context)
85
+ rc = LibZMQ.terminate_context(@context)
86
86
  @context = nil
87
- rc
87
+ rc || 0
88
88
  else
89
89
  0
90
90
  end
@@ -129,7 +129,7 @@ module ZMQ
129
129
  end
130
130
 
131
131
  def self.close context, pid
132
- Proc.new { LibZMQ.zmq_term context if !context.null? && Process.pid == pid }
132
+ Proc.new { LibZMQ.zmq_ctx_term context if !context.null? && Process.pid == pid }
133
133
  end
134
134
  end
135
135
 
@@ -13,6 +13,9 @@ module ZMQ
13
13
  end
14
14
  end # call ZeroMQError
15
15
 
16
+ class NotSupportedError < ZeroMQError
17
+ end
18
+
16
19
 
17
20
  class ContextError < ZeroMQError
18
21
  # True when the exception was raised due to the library
@@ -1,5 +1,4 @@
1
1
  require 'forwardable'
2
- require 'io_extensions'
3
2
 
4
3
  module ZMQ
5
4
  class PollItem
@@ -135,15 +135,14 @@ module ZMQ
135
135
  pointer.write_int value
136
136
 
137
137
  elsif 2 == @option_lookup[name]
138
+ # Strings are treated as pointers by FFI so we'll just pass it through
138
139
  length ||= value.size
140
+ pointer = value
139
141
 
140
- # note: not checking errno for failed memory allocations :(
141
- pointer = LibC.malloc length
142
- pointer.write_string value
143
142
  end
144
143
 
145
144
  rc = LibZMQ.zmq_setsockopt @socket, name, pointer, length
146
- LibC.free(pointer) unless pointer.nil? || pointer.null?
145
+ LibC.free(pointer) unless pointer.is_a?(String) || pointer.nil? || pointer.null?
147
146
  rc
148
147
  end
149
148
 
data/lib/ffi-rzmq/util.rb CHANGED
@@ -5,6 +5,23 @@ module ZMQ
5
5
  #
6
6
  class Util
7
7
 
8
+ # Generate and return a CURVE public/private keypair
9
+ #
10
+ # Raises an error if ZeroMQ is not configured for CURVE connections.
11
+ # Install libsodium if this is the case.
12
+ def self.curve_keypair
13
+ public_key = FFI::MemoryPointer.from_string(' ' * 41)
14
+ private_key = FFI::MemoryPointer.from_string(' ' * 41)
15
+ rc = LibZMQ.zmq_curve_keypair public_key, private_key
16
+
17
+ if rc < 0
18
+ raise NotSupportedError.new "zmq_curve_keypair" , rc, ZMQ::Util.errno,
19
+ "Rebuild zeromq with libsodium to enable CURVE security options."
20
+ end
21
+
22
+ [public_key.read_string, private_key.read_string]
23
+ end
24
+
8
25
  # Returns true when +rc+ is greater than or equal to 0, false otherwise.
9
26
  #
10
27
  # We use the >= test because zmq_poll() returns the number of sockets
@@ -1,3 +1,3 @@
1
1
  module ZMQ
2
- VERSION = "2.0.0"
2
+ VERSION = "2.0.7"
3
3
  end
data/lib/ffi-rzmq.rb CHANGED
@@ -66,6 +66,7 @@ end # module ZMQ
66
66
  require 'ffi-rzmq-core'
67
67
 
68
68
  # the order of files is important
69
- %w(util exceptions context message socket poll_items poll_item poll device).each do |file|
69
+ require ZMQ.libpath(['.', "io_extensions"])
70
+ %w(util exceptions context message socket poll_items poll_item poll device version).each do |file|
70
71
  require ZMQ.libpath(['ffi-rzmq', file])
71
72
  end
data/lib/io_extensions.rb CHANGED
@@ -10,7 +10,7 @@ class IO
10
10
  when STDERR, $stderr
11
11
  2
12
12
  else
13
- JRuby.reference(self).getOpenFile.getMainStream.getDescriptor.getChannel.getFDVal
13
+ JRuby.reference(self).getOpenFile().getFileno
14
14
  end
15
15
  end
16
16
  else
data/spec/context_spec.rb CHANGED
@@ -11,31 +11,31 @@ module ZMQ
11
11
  include APIHelper
12
12
 
13
13
  it "should return nil for negative io threads" do
14
- Context.create(-1).should be_nil
14
+ expect(Context.create(-1)).to eq(nil)
15
15
  end
16
16
 
17
17
  it "should default to requesting 1 i/o thread when no argument is passed" do
18
18
  ctx = Context.create
19
- ctx.io_threads.should == 1
19
+ expect(ctx.io_threads).to eq(1)
20
20
  end
21
21
 
22
22
  it "should set the :pointer accessor to non-nil" do
23
23
  ctx = Context.create
24
- ctx.pointer.should_not be_nil
24
+ expect(ctx.pointer).not_to be_nil
25
25
  end
26
26
 
27
27
  it "should set the :context accessor to non-nil" do
28
28
  ctx = Context.create
29
- ctx.context.should_not be_nil
29
+ expect(ctx.context).not_to be_nil
30
30
  end
31
31
 
32
32
  it "should set the :pointer and :context accessors to the same value" do
33
33
  ctx = Context.create
34
- ctx.pointer.should == ctx.context
34
+ expect(ctx.pointer).to eq(ctx.context)
35
35
  end
36
36
 
37
37
  it "should define a finalizer on this object" do
38
- ObjectSpace.should_receive(:define_finalizer)
38
+ expect(ObjectSpace).to receive(:define_finalizer)
39
39
  ctx = Context.create
40
40
  end
41
41
  end # context initializing
@@ -45,31 +45,31 @@ module ZMQ
45
45
  include APIHelper
46
46
 
47
47
  it "should raise a ContextError exception for negative io threads" do
48
- lambda { Context.new(-1) }.should raise_exception(ZMQ::ContextError)
48
+ expect { Context.new(-1) }.to raise_exception(ZMQ::ContextError)
49
49
  end
50
50
 
51
51
  it "should default to requesting 1 i/o thread when no argument is passed" do
52
52
  ctx = Context.new
53
- ctx.io_threads.should == 1
53
+ expect(ctx.io_threads).to eq(1)
54
54
  end
55
55
 
56
56
  it "should set the :pointer accessor to non-nil" do
57
57
  ctx = Context.new
58
- ctx.pointer.should_not be_nil
58
+ expect(ctx.pointer).not_to be_nil
59
59
  end
60
60
 
61
61
  it "should set the :context accessor to non-nil" do
62
62
  ctx = Context.new
63
- ctx.context.should_not be_nil
63
+ expect(ctx.context).not_to be_nil
64
64
  end
65
65
 
66
66
  it "should set the :pointer and :context accessors to the same value" do
67
67
  ctx = Context.new
68
- ctx.pointer.should == ctx.context
68
+ expect(ctx.pointer).to eq(ctx.context)
69
69
  end
70
70
 
71
71
  it "should define a finalizer on this object" do
72
- ObjectSpace.should_receive(:define_finalizer)
72
+ expect(ObjectSpace).to receive(:define_finalizer)
73
73
  Context.new 1
74
74
  end
75
75
  end # context initializing
@@ -79,13 +79,13 @@ module ZMQ
79
79
  it "should set the context to nil when terminating the library's context" do
80
80
  ctx = Context.new # can't use a shared context here because we are terminating it!
81
81
  ctx.terminate
82
- ctx.pointer.should be_nil
82
+ expect(ctx.pointer).to be_nil
83
83
  end
84
84
 
85
85
  it "should call the correct library function to terminate the context" do
86
86
  ctx = Context.new
87
87
 
88
- LibZMQ.should_receive(:zmq_ctx_destroy).with(ctx.pointer).and_return(0)
88
+ expect(LibZMQ).to receive(:terminate_context).with(ctx.pointer).and_return(0)
89
89
  ctx.terminate
90
90
  end
91
91
  end # context terminate
@@ -94,8 +94,8 @@ module ZMQ
94
94
  context "when allocating a socket" do
95
95
  it "should return nil when allocation fails" do
96
96
  ctx = Context.new
97
- LibZMQ.stub(:zmq_socket => nil)
98
- ctx.socket(ZMQ::REQ).should be_nil
97
+ allow(LibZMQ).to receive(:zmq_socket).and_return(nil)
98
+ expect(ctx.socket(ZMQ::REQ)).to be_nil
99
99
  end
100
100
  end # context socket
101
101
 
data/spec/device_spec.rb CHANGED
@@ -26,9 +26,9 @@ module ZMQ
26
26
  front = @ctx.socket(ZMQ::PUSH)
27
27
  front.bind(@front_endpoint)
28
28
  @mutex.synchronize { @device_thread = true }
29
- puts "create streamer device and running..."
29
+ puts "create streamer device and running..." if $DEBUG
30
30
  Device.new(back, front)
31
- puts "device exited"
31
+ puts "device exited" if $DEBUG
32
32
  back.close
33
33
  front.close
34
34
  end
@@ -40,7 +40,7 @@ module ZMQ
40
40
 
41
41
  break if can_break
42
42
  end
43
- puts "broke out of wait_for_device loop"
43
+ puts "broke out of wait_for_device loop" if $DEBUG
44
44
  end
45
45
 
46
46
  it "should create a device without error given valid opts" do
@@ -63,16 +63,16 @@ module ZMQ
63
63
 
64
64
  res = ''
65
65
  rc = puller.recv_string(res, ZMQ::DONTWAIT)
66
- res.should == "hello"
66
+ expect(res).to eq("hello")
67
67
 
68
68
  pusher.close
69
69
  puller.close
70
70
  end
71
71
 
72
72
  it "should raise an ArgumentError when trying to pass non-socket objects into the device" do
73
- lambda {
73
+ expect {
74
74
  Device.new(1,2)
75
- }.should raise_exception(ArgumentError)
75
+ }.to raise_exception(ArgumentError)
76
76
  end
77
77
  end
78
78
  end