Class: MockSocket
- Inherits:
-
Object
- Object
- MockSocket
- Defined in:
- lib/mocksocket.rb
Defined Under Namespace
Modules: Assertions
Instance Attribute Summary collapse
-
#in ⇒ Object
Returns the value of attribute in.
-
#out ⇒ Object
Returns the value of attribute out.
Class Method Summary collapse
Instance Method Summary collapse
- #empty? ⇒ Boolean
- #eof? ⇒ Boolean
- #gets ⇒ Object
- #print(m) ⇒ Object
- #puts(m) ⇒ Object
- #read(length = nil) ⇒ Object
Instance Attribute Details
#in ⇒ Object
Returns the value of attribute in.
11 12 13 |
# File 'lib/mocksocket.rb', line 11 def in @in end |
#out ⇒ Object
Returns the value of attribute out.
11 12 13 |
# File 'lib/mocksocket.rb', line 11 def out @out end |
Class Method Details
.pipe ⇒ Object
4 5 6 7 8 9 |
# File 'lib/mocksocket.rb', line 4 def self.pipe socket1, socket2 = new, new socket1.in, socket2.out = IO.pipe socket2.in, socket1.out = IO.pipe [socket1, socket2] end |
Instance Method Details
#empty? ⇒ Boolean
27 28 29 30 31 32 33 34 |
# File 'lib/mocksocket.rb', line 27 def empty? begin @in.read_nonblock(1) false rescue Errno::EAGAIN true end end |
#eof? ⇒ Boolean
25 |
# File 'lib/mocksocket.rb', line 25 def eof?() @in.eof? end |
#gets ⇒ Object
17 18 19 |
# File 'lib/mocksocket.rb', line 17 def gets() Timeout.timeout(1) {@in.gets} end |
#print(m) ⇒ Object
15 |
# File 'lib/mocksocket.rb', line 15 def print(m) @out.print(m) end |
#puts(m) ⇒ Object
13 |
# File 'lib/mocksocket.rb', line 13 def puts(m) @out.puts(m) end |
#read(length = nil) ⇒ Object
21 22 23 |
# File 'lib/mocksocket.rb', line 21 def read(length=nil) Timeout.timeout(1) {@in.read(length)} end |