Class Net::SSH::Test::LocalPacket

  1. lib/net/ssh/test/local_packet.rb

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.

Methods

public class

  1. new

public instance

  1. local?
  2. process

Attributes

init [R]

Public class methods

new (type, *args, &block)

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.

[show source]
    # File lib/net/ssh/test/local_packet.rb, line 16
16:     def initialize(type, *args, &block)
17:       super(type, *args)
18:       @init = block
19:     end

Public instance methods

local? ()

Returns true; this is a local packet.

[show source]
    # File lib/net/ssh/test/local_packet.rb, line 22
22:     def local?
23:       true
24:     end
process (packet)

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.

[show source]
    # File lib/net/ssh/test/local_packet.rb, line 31
31:     def process(packet)
32:       @init.call(Net::SSH::Packet.new(packet.to_s)) if @init
33:       type = packet.read_byte
34:       raise "expected #{@type}, but got #{type}" if @type != type
35: 
36:       @data.zip(types).each do |expected, type|
37:         type ||= case expected
38:           when nil then break
39:           when Numeric then :long
40:           when String then :string
41:           when TrueClass, FalseClass then :bool
42:           end
43: 
44:         actual = packet.send("read_#{type}")
45:         next if expected.nil?
46:         raise "expected #{type} #{expected.inspect} but got #{actual.inspect}" unless expected == actual
47:       end
48:     end