Sha256: c19d95cd9f3089eedc8cc71b810af364af22afda4386d47bc54bede8a2f5475c

Contents?: true

Size: 613 Bytes

Versions: 6

Compression:

Stored size: 613 Bytes

Contents

require "socket"

module EchoMock
  def self.start(port = 6380)
    server = TCPServer.new("127.0.0.1", port)
    loop do
      session = server.accept
      while line = session.gets
        session.write(line)
        session.write("\r\n")
      end
    end
  end

  module Helper
    def echo_mock
      begin
        pid = fork do
          trap("TERM") { exit }
          EchoMock.start
        end
        sleep 1 # Give time for the socket to start listening.
        yield
      ensure
        if pid
          Process.kill("TERM", pid)
          Process.wait(pid)
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
zmachine-0.4.3 spec/support/echo_mock.rb
zmachine-0.4.2 spec/support/echo_mock.rb
zmachine-0.4.1 spec/support/echo_mock.rb
zmachine-0.4.0 spec/support/echo_mock.rb
zmachine-0.3.2 spec/support/echo_mock.rb
zmachine-0.3.0 spec/support/echo_mock.rb