mojombo-bertrpc 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/bertrpc.gemspec +1 -1
- data/lib/bertrpc/fun.rb +4 -1
- data/test/fun_test.rb +23 -0
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
data/bertrpc.gemspec
CHANGED
data/lib/bertrpc/fun.rb
CHANGED
@@ -19,8 +19,11 @@ module BERTRPC
|
|
19
19
|
sock = TCPSocket.new(@svc.host, @svc.port)
|
20
20
|
sock.write([bert_request.length].pack("N"))
|
21
21
|
sock.write(bert_request)
|
22
|
-
|
22
|
+
lenheader = sock.read(4)
|
23
|
+
raise ProtocolError.new("Unable to read length header from server.") unless lenheader
|
24
|
+
len = lenheader.unpack('N').first
|
23
25
|
bert_response = sock.read(len)
|
26
|
+
raise ProtocolError.new("Unable to read data from server.") unless bert_response
|
24
27
|
sock.close
|
25
28
|
bert_response
|
26
29
|
end
|
data/test/fun_test.rb
CHANGED
@@ -77,6 +77,29 @@ class FunTest < Test::Unit::TestCase
|
|
77
77
|
TCPSocket.expects(:new).returns(io)
|
78
78
|
assert_equal "bar", @fun.sync_request("foo")
|
79
79
|
end
|
80
|
+
|
81
|
+
should "raise a ProxyError when the length is invalid" do
|
82
|
+
io = stub()
|
83
|
+
io.expects(:write).with("\000\000\000\003")
|
84
|
+
io.expects(:write).with("foo")
|
85
|
+
io.expects(:read).with(4).returns(nil)
|
86
|
+
TCPSocket.expects(:new).returns(io)
|
87
|
+
assert_raises(BERTRPC::ProtocolError) do
|
88
|
+
@fun.sync_request("foo")
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
should "raise a ProxyError when the data is invalid" do
|
93
|
+
io = stub()
|
94
|
+
io.expects(:write).with("\000\000\000\003")
|
95
|
+
io.expects(:write).with("foo")
|
96
|
+
io.expects(:read).with(4).returns("\000\000\000\003")
|
97
|
+
io.expects(:read).with(3).returns(nil)
|
98
|
+
TCPSocket.expects(:new).returns(io)
|
99
|
+
assert_raises(BERTRPC::ProtocolError) do
|
100
|
+
@fun.sync_request("foo")
|
101
|
+
end
|
102
|
+
end
|
80
103
|
end
|
81
104
|
|
82
105
|
context "ruby request encoder" do
|