Class: MockSocket

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

Defined Under Namespace

Modules: Assertions

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#inObject

Returns the value of attribute in.



11
12
13
# File 'lib/mocksocket.rb', line 11

def in
  @in
end

#outObject

Returns the value of attribute out.



11
12
13
# File 'lib/mocksocket.rb', line 11

def out
  @out
end

Class Method Details

.pipeObject



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

Returns:

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

Returns:

  • (Boolean)


25
# File 'lib/mocksocket.rb', line 25

def eof?() @in.eof? end

#getsObject



17
18
19
# File 'lib/mocksocket.rb', line 17

def gets()
  Timeout.timeout(1) {@in.gets}
end


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