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 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
|
require File.join(File.dirname(__FILE__), %w[spec_helper])
module ZMQ
describe Message do
context "when initializing with an argument" do
it "calls zmq_msg_init_data()" do
expect(LibZMQ).to receive(:zmq_msg_init_data)
message = Message.new "text"
end
it "should *not* define a finalizer on this object" do
expect(ObjectSpace).not_to receive(:define_finalizer)
Message.new "text"
end
end # context initializing with arg
context "when initializing *without* an argument" do
it "calls zmq_msg_init()" do
expect(LibZMQ).to receive(:zmq_msg_init).and_return(0)
message = Message.new
end
it "should *not* define a finalizer on this object" do
expect(ObjectSpace).not_to receive(:define_finalizer)
Message.new "text"
end
end # context initializing with arg
context "#copy_in_string" do
it "calls zmq_msg_init_data()" do
message = Message.new "text"
expect(LibZMQ).to receive(:zmq_msg_init_data)
message.copy_in_string("new text")
end
it "correctly finds the length of binary data by ignoring encoding" do
message = Message.new
message.copy_in_string("\x83\x6e\x04\x00\x00\x44\xd1\x81")
expect(message.size).to eq(8)
end
end
context "#copy" do
it "calls zmq_msg_copy()" do
message = Message.new "text"
copy = Message.new
expect(LibZMQ).to receive(:zmq_msg_copy)
copy.copy(message)
end
end # context copy
context "#move" do
it "calls zmq_msg_move()" do
message = Message.new "text"
copy = Message.new
expect(LibZMQ).to receive(:zmq_msg_move)
copy.move(message)
end
end # context move
context "#size" do
it "calls zmq_msg_size()" do
message = Message.new "text"
expect(LibZMQ).to receive(:zmq_msg_size)
message.size
end
end # context size
context "#data" do
it "calls zmq_msg_data()" do
message = Message.new "text"
expect(LibZMQ).to receive(:zmq_msg_data)
message.data
end
end # context data
context "#close" do
it "calls zmq_msg_close() the first time" do
message = Message.new "text"
expect(LibZMQ).to receive(:zmq_msg_close)
message.close
end
it "*does not* call zmq_msg_close() on subsequent invocations" do
message = Message.new "text"
message.close
expect(LibZMQ).not_to receive(:zmq_msg_close)
message.close
end
end # context close
end # describe Message
describe ManagedMessage do
context "when initializing with an argument" do
it "should define a finalizer on this object" do
expect(ObjectSpace).to receive(:define_finalizer)
ManagedMessage.new "text"
end
end # context initializing
end # describe ManagedMessage
end # module ZMQ
|