Class: MockSocket
- Inherits:
-
Object
- Object
- MockSocket
- Defined in:
- lib/mocksocket.rb
Defined Under Namespace
Modules: Assertions
Constant Summary collapse
- TIMEOUT =
1
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.
13 14 15 |
# File 'lib/mocksocket.rb', line 13 def in @in end |
#out ⇒ Object
Returns the value of attribute out.
13 14 15 |
# File 'lib/mocksocket.rb', line 13 def out @out end |
Class Method Details
.pipe ⇒ Object
6 7 8 9 10 11 |
# File 'lib/mocksocket.rb', line 6 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
31 32 33 34 35 36 37 38 |
# File 'lib/mocksocket.rb', line 31 def empty? begin @in.read_nonblock(1) false rescue Errno::EAGAIN true end end |
#eof? ⇒ Boolean
27 28 29 |
# File 'lib/mocksocket.rb', line 27 def eof? timeout {@in.eof?} end |
#gets ⇒ Object
19 20 21 |
# File 'lib/mocksocket.rb', line 19 def gets timeout {@in.gets} end |
#print(m) ⇒ Object
17 |
# File 'lib/mocksocket.rb', line 17 def print(m) @out.print(m) end |
#puts(m) ⇒ Object
15 |
# File 'lib/mocksocket.rb', line 15 def puts(m) @out.puts(m) end |
#read(length = nil) ⇒ Object
23 24 25 |
# File 'lib/mocksocket.rb', line 23 def read(length=nil) timeout {@in.read(length)} end |