Class: MockSocket

Inherits:
Object
  • Object
show all
Defined in:
lib/mocksocket.rb

Defined Under Namespace

Modules: Assertions

Constant Summary collapse

TIMEOUT =
1

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#inObject

Returns the value of attribute in.



13
14
15
# File 'lib/mocksocket.rb', line 13

def in
  @in
end

#outObject

Returns the value of attribute out.



13
14
15
# File 'lib/mocksocket.rb', line 13

def out
  @out
end

Class Method Details

.pipeObject



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

Returns:

  • (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

Returns:

  • (Boolean)


27
28
29
# File 'lib/mocksocket.rb', line 27

def eof?
  timeout {@in.eof?}
end

#getsObject



19
20
21
# File 'lib/mocksocket.rb', line 19

def gets
  timeout {@in.gets}
end


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