Sha256: 0d2b625703687b534c7a54ff2d24318813ce166cec186197c8f9ba6b851743dd

Contents?: true

Size: 1.65 KB

Versions: 65

Compression:

Stored size: 1.65 KB

Contents

require 'common'
require 'net/ssh'

module NetSSH
  class TestConnection < Test::Unit::TestCase
    attr_reader :connection_session
    
    def setup
      authentication_session = mock('authentication_session')
      authentication_session.stubs(:authenticate).returns(true)
      Net::SSH::Authentication::Session.stubs(:new).returns(authentication_session)
      Net::SSH::Transport::Session.stubs(:new).returns(mock('transport_session'))
      @connection_session = mock('connection_session')
      Net::SSH::Connection::Session.expects(:new => connection_session)
    end
    
    def test_close_connection_on_exception
      @connection_session.expects(:closed?).returns(false)
      @connection_session.expects(:close).once
      
      begin
        Net::SSH.start('localhost', 'testuser') { raise "error" }
      rescue RuntimeError
        # We aren't interested in the exception
      end
    end

    def test_close_connection_on_exception_only_if_still_open
      conn_open = states('conn').starts_as(true)
      @connection_session.expects(:close).then(conn_open.is(false)).once
      @connection_session.expects(:closed?).when(conn_open.is(false)).returns(true)
      
      begin
        Net::SSH.start('localhost', 'testuser') do |ssh|
          ssh.close
          raise "error"
        end
      rescue RuntimeError
        # We aren't interested in the exception
      end
    end
    
    def test_return_value_is_returned
      @connection_session.expects(:closed?).returns(false)
      @connection_session.expects(:close).once
      
      val = 1
      retval = Net::SSH.start('localhost', 'testuser') { val }
      assert_equal(val, retval)
    end
  end
end

Version data entries

65 entries across 55 versions & 8 rubygems

Version Path
net-ssh-2.9.2.beta test/start/test_connection.rb
vagrant-tiktalik-0.0.3 vendor/bundle/ruby/2.0.0/gems/net-ssh-2.9.1/test/start/test_connection.rb
net-ssh-2.9.1 test/start/test_connection.rb
net-ssh-2.9.0 test/start/test_connection.rb
net-ssh-2.8.0 test/start/test_connection.rb