class Net::SSH::Test::LocalPacket

This is a specialization of Net::SSH::Test::Packet for representing mock packets that are sent from the local (client) host. These are created automatically by Net::SSH::Test::Script and Net::SSH::Test::Channel by any of the sends_* methods.



Public Class Methods

new(type, *args, &block) click to toggle source

Extend the default Net::SSH::Test::Packet constructor to also accept an optional block, which is used to finalize the initialization of the packet when process is first called.

Calls superclass method
# File lib/net/ssh/test/local_packet.rb, line 16
def initialize(type, *args, &block)
  super(type, *args)
  @init = block

Public Instance Methods

local?() click to toggle source

Returns true; this is a local packet.

# File lib/net/ssh/test/local_packet.rb, line 22
def local?
process(packet) click to toggle source

Called by Net::SSH::Test::Extensions::PacketStream#test_enqueue_packet to mimic remote processing of a locally-sent packet. It compares the packet it was given with the contents of this LocalPacket's data, to see if what was sent matches what was scripted. If it differs in any way, an exception is raised.

# File lib/net/ssh/test/local_packet.rb, line 31
def process(packet) if @init
  type = packet.read_byte
  raise "expected #{@type}, but got #{type}" if @type != type do |expected, _type|
    _type ||= case expected
      when nil then break
      when Numeric then :long
      when String then :string
      when TrueClass, FalseClass then :bool

    actual = packet.send("read_#{_type}")
    next if expected.nil?
    raise "expected #{_type} #{expected.inspect} but got #{actual.inspect}" unless expected == actual