Sha256: 2504d8e686541e3ae8901752611dcf65bdb8ddf6bdfca060e71f7ca7c15de1ac

Contents?: true

Size: 1.4 KB

Versions: 3

Compression:

Stored size: 1.4 KB

Contents

require "test_helper"

class TestSSH < MiniTest::Unit::TestCase

  def test_connect
    connection_mock

    Yads::SSH.new(:host => "example.org", :user => "deploy", :forward_agent => true)
  end

  def test_connect_using_non_standard_port
    connection_mock(nil, :port => 2222)

    Yads::SSH.new(:host => "example.org", :port => 2222, :user => "deploy", :forward_agent => true)
  end

  def test_execute
    session = mock
    session.expects(:exec!).with("mkdir -p /tmp/yads")
    connection_mock(session)

    s = Yads::SSH.new(:host => "example.org", :user => "deploy", :forward_agent => true)
    s.execute("mkdir -p /tmp/yads")
  end

  def test_execute_with_block
    session = mock
    session.expects(:exec).with("echo $PATH").yields(nil, nil, "/usr/bin:/usr/local/bin")
    session.expects(:loop)
    connection_mock(session)

    s = Yads::SSH.new(:host => "example.org", :user => "deploy", :forward_agent => true)
    s.execute("echo $PATH") do |output|
      assert_equal "/usr/bin:/usr/local/bin", output
    end
  end

  def test_close
    session = mock
    session.expects(:close)
    connection_mock(session)

    s = Yads::SSH.new(:host => "example.org", :user => "deploy", :forward_agent => true)
    s.close
  end

  private

  def connection_mock(session = nil, options = {})
    Net::SSH.expects(:start).with("example.org", "deploy", { :forward_agent => true }.merge(options)).returns(session)
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
yads-0.2.0 test/yads/test_ssh.rb
yads-0.1.2 test/yads/test_ssh.rb
yads-0.1.1 test/yads/test_ssh.rb