Project

mockets

0.0
No commit activity in last 3 years
No release in over 3 years
Mock socket library for testing network applications
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.3
>= 0
>= 0
 Project Readme

mockets

Mock socket library for testing network applications

Reset all mock sockets to default of connection refused

Mocket.reset!
Mocket.open('10.10.10.10', 25)
Exception: Errno:ECONNREFUSED

Set a host/port to host unreachable

Mocket.hostunreachable('10.10.10.20', 25)
Mocket.open('10.10.10.20', 25)
Exception: Errno::EHOSTUNREACH

Set a host/port to connection timed out

Mocket.timeout('10.10.20.20', 25)
Mocket.open('10.10.20.20', 25)
Exception: Errno::ETIMEDOUT

Set a host/port to return an open mocket

Mocket.listen('10.10.10.30', 25)
mocket = Mocket.open('10.10.10.30', 25)
number_bytes_written = mocket.write('some message here')
mocket.close

Use SocketAdapter to interchange sockets with mockets on the fly

class SocketClient
  attr_accessor :adapter
  delegate :open, :setstate, to: :adapter
  
  def initialize
    self.adapter = SocketAdapter.new
  end
end

# Connecting to a socket
client = SocketClient.new
client.setstate(:live)
server = TCPServer.open(4000)
socket = client.open('127.0.0.1', 4000)
socket.write('message...')
socket.close
server.close

# Connecting to a mocket
client = SocketClient.new
client.setstate(:test)
Mocket.listen('172.31.33.7', 5000)
socket = client.open('172.131.33.7', 5000)
socket.write('message...')
socket.close
Mocket.reset!