Module: Net::SSH::Test

### Home Classes Methods

### In Files

- lib/net/ssh/test.rb
- lib/net/ssh/test/channel.rb
- lib/net/ssh/test/extensions.rb
- lib/net/ssh/test/kex.rb
- lib/net/ssh/test/local_packet.rb
- lib/net/ssh/test/packet.rb
- lib/net/ssh/test/remote_packet.rb
- lib/net/ssh/test/script.rb
- lib/net/ssh/test/socket.rb

### Namespace

- MODULE Net::SSH::Test::Extensions
- CLASS Net::SSH::Test::Channel
- CLASS Net::SSH::Test::Kex
- CLASS Net::SSH::Test::LocalPacket
- CLASS Net::SSH::Test::Packet
- CLASS Net::SSH::Test::RemotePacket
- CLASS Net::SSH::Test::Script
- CLASS Net::SSH::Test::Socket

### Methods

- #assert_scripted
- #connection
- #socket
- #story
- #transport

### Files

- README.rdoc

### Class/Module Index

Quicksearch

- Net
- Net::SSH
- Net::SSH::Authentication
- Net::SSH::Authentication::Agent
- Net::SSH::Authentication::Agent::Comment
- Net::SSH::Authentication::AgentError
- Net::SSH::Authentication::AgentNotAvailable
- Net::SSH::Authentication::Constants
- Net::SSH::Authentication::DisallowedMethod
- Net::SSH::Authentication::KeyManager
- Net::SSH::Authentication::KeyManagerError
- Net::SSH::Authentication::Methods
- Net::SSH::Authentication::Methods::Abstract
- Net::SSH::Authentication::Methods::Hostbased
- Net::SSH::Authentication::Methods::KeyboardInteractive
- Net::SSH::Authentication::Methods::None
- Net::SSH::Authentication::Methods::Password
- Net::SSH::Authentication::Methods::Publickey
- Net::SSH::Authentication::Session
- Net::SSH::AuthenticationFailed
- Net::SSH::Buffer
- Net::SSH::ChannelOpenFailed
- Net::SSH::ChannelRequestFailed
- Net::SSH::Compat
- Net::SSH::Config
- Net::SSH::Connection
- Net::SSH::Connection::Channel
- Net::SSH::Connection::Constants
- Net::SSH::Connection::Keepalive
- Net::SSH::Connection::Session
- Net::SSH::Connection::Session::NilChannel
- Net::SSH::Connection::Term
- Net::SSH::ConnectionTimeout
- Net::SSH::Disconnect
- Net::SSH::Exception
- Net::SSH::HostKeyError
- Net::SSH::HostKeyMismatch
- Net::SSH::HostKeyUnknown
- Net::SSH::KeyFactory
- Net::SSH::KnownHosts
- Net::SSH::Loggable
- Net::SSH::Packet
- Net::SSH::PromptMethods
- Net::SSH::PromptMethods::Clear
- Net::SSH::PromptMethods::Highline
- Net::SSH::PromptMethods::Termios
- Net::SSH::Proxy
- Net::SSH::Proxy::Command
- Net::SSH::Proxy::ConnectError
- Net::SSH::Proxy::Error
- Net::SSH::Proxy::HTTP
- Net::SSH::Proxy::SOCKS4
- Net::SSH::Proxy::SOCKS5
- Net::SSH::Proxy::UnauthorizedError
- Net::SSH::Test
- Net::SSH::Test::Channel
- Net::SSH::Test::Extensions
- Net::SSH::Test::Extensions::BufferedIo
- Net::SSH::Test::Extensions::Channel
- Net::SSH::Test::Extensions::IO
- Net::SSH::Test::Extensions::IO::ClassMethods
- Net::SSH::Test::Extensions::PacketStream
- Net::SSH::Test::Kex
- Net::SSH::Test::LocalPacket
- Net::SSH::Test::Packet
- Net::SSH::Test::RemotePacket
- Net::SSH::Test::Script
- Net::SSH::Test::Socket
- Net::SSH::Timeout
- Net::SSH::Transport
- Net::SSH::Transport::Algorithms
- Net::SSH::Transport::CTR
- Net::SSH::Transport::CipherFactory
- Net::SSH::Transport::Constants
- Net::SSH::Transport::HMAC
- Net::SSH::Transport::HMAC::Abstract
- Net::SSH::Transport::HMAC::MD5
- Net::SSH::Transport::HMAC::MD5_96
- Net::SSH::Transport::HMAC::None
- Net::SSH::Transport::HMAC::RIPEMD160
- Net::SSH::Transport::HMAC::SHA1
- Net::SSH::Transport::HMAC::SHA1_96
- Net::SSH::Transport::HMAC::SHA2_256
- Net::SSH::Transport::HMAC::SHA2_256_96
- Net::SSH::Transport::HMAC::SHA2_512
- Net::SSH::Transport::HMAC::SHA2_512_96
- Net::SSH::Transport::IdentityCipher
- Net::SSH::Transport::Kex
- Net::SSH::Transport::Kex::DiffieHellmanGroup14SHA1
- Net::SSH::Transport::Kex::DiffieHellmanGroup1SHA1
- Net::SSH::Transport::Kex::DiffieHellmanGroupExchangeSHA1
- Net::SSH::Transport::Kex::DiffieHellmanGroupExchangeSHA256
- Net::SSH::Transport::Kex::EcdhSHA2NistP256
- Net::SSH::Transport::Kex::EcdhSHA2NistP384
- Net::SSH::Transport::Kex::EcdhSHA2NistP521
- Net::SSH::Transport::KeyExpander
- Net::SSH::Transport::PacketStream
- Net::SSH::Transport::ServerVersion
- Net::SSH::Transport::Session
- Net::SSH::Transport::State
- Net::SSH::Verifiers
- Net::SSH::Verifiers::Lenient
- Net::SSH::Verifiers::Null
- Net::SSH::Verifiers::Secure
- Net::SSH::Verifiers::Strict
- Net::SSH::Version
- OpenSSL
- OpenSSL::BN
- OpenSSL::PKey
- OpenSSL::PKey::DH
- OpenSSL::PKey::DSA
- OpenSSL::PKey::EC
- OpenSSL::PKey::OpenSSL
- OpenSSL::PKey::OpenSSL::PKey
- OpenSSL::PKey::OpenSSL::PKey::OpenSSL
- OpenSSL::PKey::OpenSSL::PKey::OpenSSL::PKey
- OpenSSL::PKey::OpenSSL::PKey::OpenSSL::PKey::ECError
- OpenSSL::PKey::PKey
- OpenSSL::PKey::RSA
- String

No matching classes.

# Net::SSH::Test

This module may be used in unit tests, for when you want to test that your SSH state machines are really doing what you expect they are doing. You will typically include this module in your unit test class, and then build a "story" of expected sends and receives:

    require 'test/unit'
    require 'net/ssh/test'

    class MyTest < Test::Unit::TestCase
      include Net::SSH::Test

      def test_exec_via_channel_works
        story do |session|
          channel = session.opens_channel
          channel.sends_exec "ls"
          channel.gets_data "result of ls"
          channel.gets_close
          channel.sends_close
        end

        assert_scripted do
          result = nil

          connection.open_channel do |ch|
            ch.exec("ls") do |success|
              ch.on_data { |c, data| result = data }
              ch.on_close { |c| c.close }
            end
          end

          connection.loop
          assert_equal "result of ls", result
        end
      end
    end

See Net::SSH::Test::Channel and Net::SSH::Test::Script for more options.

Note that the Net::SSH::Test system is rather finicky yet, and can be kind of frustrating to get working. Any suggestions for improvement will be welcome!

### Public Instance Methods

assert_scripted() click to toggle source

First asserts that a story has been described (see story). Then yields, and then asserts that all items described in the script have been processed. Typically, this is called immediately after a story has been built, and the SSH commands being tested are then executed within the block passed to this assertion.

    # File lib/net/ssh/test.rb, line 82
    def assert_scripted
      raise "there is no script to be processed" if socket.script.events.empty?
      yield
      assert socket.script.events.empty?, "there should not be any remaining scripted events, but there are still #{socket.script.events.length} pending"
    end

connection(options={}) click to toggle source

Returns the connection session (Net::SSH::Connection::Session) for use in these tests. It is a fully functional SSH session, operating over a mock socket (socket).

    # File lib/net/ssh/test.rb, line 66
    def connection(options={})
      @connection ||= Net::SSH::Connection::Session.new(transport(options), options)
    end

socket(options={}) click to toggle source

Returns the test socket instance to use for these tests (see Net::SSH::Test::Socket).

    # File lib/net/ssh/test.rb, line 59
    def socket(options={})
      @socket ||= Net::SSH::Test::Socket.new
    end

story() click to toggle source

If a block is given, yields the script for the test socket (socket). Otherwise, simply returns the socket's script. See Net::SSH::Test::Script.

    # File lib/net/ssh/test.rb, line 52
    def story
      yield socket.script if block_given?
      return socket.script
    end

transport(options={}) click to toggle source

Returns the transport session (Net::SSH::Transport::Session) for use in these tests. It is a fully functional SSH transport session, operating over a mock socket (socket).

    # File lib/net/ssh/test.rb, line 73
    def transport(options={})
      @transport ||= Net::SSH::Transport::Session.new(options[:host] || "localhost", options.merge(:kex => "test", :host_key => "ssh-rsa", :paranoid => false, :proxy => socket(options)))
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.