1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
|
$: << "." # added for ruby 1.9.2 compatibilty; it doesn't include the current directory on the load path anymore
require File.join(File.dirname(__FILE__), %w[spec_helper])
module ZMQ
describe Context do
context "when initializing with factory method #create" do
include APIHelper
it "should return nil for negative io threads" do
expect(Context.create(-1)).to eq(nil)
end
it "should default to requesting 1 i/o thread when no argument is passed" do
ctx = Context.create
expect(ctx.io_threads).to eq(1)
end
it "should set the :pointer accessor to non-nil" do
ctx = Context.create
expect(ctx.pointer).not_to be_nil
end
it "should set the :context accessor to non-nil" do
ctx = Context.create
expect(ctx.context).not_to be_nil
end
it "should set the :pointer and :context accessors to the same value" do
ctx = Context.create
expect(ctx.pointer).to eq(ctx.context)
end
it "should define a finalizer on this object" do
expect(ObjectSpace).to receive(:define_finalizer)
ctx = Context.create
end
end # context initializing
context "when initializing with #new" do
include APIHelper
it "should raise a ContextError exception for negative io threads" do
expect { Context.new(-1) }.to raise_exception(ZMQ::ContextError)
end
it "should default to requesting 1 i/o thread when no argument is passed" do
ctx = Context.new
expect(ctx.io_threads).to eq(1)
end
it "should set the :pointer accessor to non-nil" do
ctx = Context.new
expect(ctx.pointer).not_to be_nil
end
it "should set the :context accessor to non-nil" do
ctx = Context.new
expect(ctx.context).not_to be_nil
end
it "should set the :pointer and :context accessors to the same value" do
ctx = Context.new
expect(ctx.pointer).to eq(ctx.context)
end
it "should define a finalizer on this object" do
expect(ObjectSpace).to receive(:define_finalizer)
Context.new 1
end
end # context initializing
context "when terminating" do
it "should set the context to nil when terminating the library's context" do
ctx = Context.new # can't use a shared context here because we are terminating it!
ctx.terminate
expect(ctx.pointer).to be_nil
end
it "should call the correct library function to terminate the context" do
ctx = Context.new
expect(LibZMQ).to receive(:terminate_context).with(ctx.pointer).and_return(0)
ctx.terminate
end
end # context terminate
context "when allocating a socket" do
it "should return nil when allocation fails" do
ctx = Context.new
allow(LibZMQ).to receive(:zmq_socket).and_return(nil)
expect(ctx.socket(ZMQ::REQ)).to be_nil
end
end # context socket
end # describe Context
end # module ZMQ
|