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
savant-echo-1.0.4 bin/packaging/vendor/ruby/2.2.0/gems/net-ssh-3.2.0/test/start/test_connection.rb
savant-echo-1.0.4 bin/alexa-0.1.2-osx/lib/vendor/ruby/2.2.0/gems/net-ssh-3.2.0/test/start/test_connection.rb
vagrant-unbundled-1.9.1.1 vendor/bundle/ruby/2.4.0/gems/net-ssh-3.0.2/test/start/test_connection.rb
savant-echo-1.0.1 bin/alexa-0.1.2-osx/lib/vendor/ruby/2.2.0/gems/net-ssh-3.2.0/test/start/test_connection.rb
savant-echo-1.0.1 bin/packaging/vendor/ruby/2.2.0/gems/net-ssh-3.2.0/test/start/test_connection.rb
savant-echo-0.1.91 bin/alexa-0.1.2-osx/lib/vendor/ruby/2.2.0/gems/net-ssh-3.2.0/test/start/test_connection.rb
savant-echo-0.1.91 bin/packaging/vendor/ruby/2.2.0/gems/net-ssh-3.2.0/test/start/test_connection.rb
savant-echo-0.1.9 bin/packaging/vendor/ruby/2.2.0/gems/net-ssh-3.2.0/test/start/test_connection.rb
savant-echo-0.1.9 bin/alexa-0.1.2-osx/lib/vendor/ruby/2.2.0/gems/net-ssh-3.2.0/test/start/test_connection.rb
savant-echo-0.1.6 bin/packaging/vendor/ruby/2.2.0/gems/net-ssh-3.2.0/test/start/test_connection.rb
savant-echo-0.1.6 bin/alexa-0.1.2-osx/lib/vendor/ruby/2.2.0/gems/net-ssh-3.2.0/test/start/test_connection.rb
savant-echo-0.1.5 bin/alexa-0.1.2-osx/lib/vendor/ruby/2.2.0/gems/net-ssh-3.2.0/test/start/test_connection.rb
savant-echo-0.1.5 bin/packaging/vendor/ruby/2.2.0/gems/net-ssh-3.2.0/test/start/test_connection.rb
savant-echo-0.1.4 bin/packaging/vendor/ruby/2.2.0/gems/net-ssh-3.2.0/test/start/test_connection.rb
savant-echo-0.1.4 bin/alexa-0.1.2-osx/lib/vendor/ruby/2.2.0/gems/net-ssh-3.2.0/test/start/test_connection.rb
savant-echo-0.1.3 bin/packaging/vendor/ruby/2.2.0/gems/net-ssh-3.2.0/test/start/test_connection.rb
savant-echo-0.1.3 bin/alexa-0.1.2-osx/lib/vendor/ruby/2.2.0/gems/net-ssh-3.2.0/test/start/test_connection.rb
net-ssh-3.3.0.beta1 test/start/test_connection.rb
vagrant-compose-yaml-0.1.3 vendor/bundle/ruby/2.2.0/gems/net-ssh-3.0.2/test/start/test_connection.rb
vagrant-compose-yaml-0.1.2 vendor/bundle/ruby/2.2.0/gems/net-ssh-3.0.2/test/start/test_connection.rb