mocksocket 0.2 → 0.2.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/mocksocket.rb +13 -4
- data/mocksocket.gemspec +1 -1
- metadata +1 -1
data/lib/mocksocket.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'timeout'
|
2
2
|
|
3
3
|
class MockSocket
|
4
|
+
TIMEOUT = 1
|
5
|
+
|
4
6
|
def self.pipe
|
5
7
|
socket1, socket2 = new, new
|
6
8
|
socket1.in, socket2.out = IO.pipe
|
@@ -14,15 +16,17 @@ class MockSocket
|
|
14
16
|
|
15
17
|
def print(m) @out.print(m) end
|
16
18
|
|
17
|
-
def gets
|
18
|
-
|
19
|
+
def gets
|
20
|
+
timeout {@in.gets}
|
19
21
|
end
|
20
22
|
|
21
23
|
def read(length=nil)
|
22
|
-
|
24
|
+
timeout {@in.read(length)}
|
23
25
|
end
|
24
26
|
|
25
|
-
def eof?
|
27
|
+
def eof?
|
28
|
+
timeout {@in.eof?}
|
29
|
+
end
|
26
30
|
|
27
31
|
def empty?
|
28
32
|
begin
|
@@ -32,4 +36,9 @@ class MockSocket
|
|
32
36
|
true
|
33
37
|
end
|
34
38
|
end
|
39
|
+
|
40
|
+
private
|
41
|
+
def timeout(&block)
|
42
|
+
Timeout.timeout(TIMEOUT) {block.call}
|
43
|
+
end
|
35
44
|
end
|
data/mocksocket.gemspec
CHANGED