Sha256: eb1e461c47bda5cde5713dd06b218da91ed46cfa3ce252745ed450b95e9563f4

Contents?: true

Size: 1.59 KB

Versions: 1

Compression:

Stored size: 1.59 KB

Contents

require 'spec_helper'

describe Net::SSH::SessionCommand do
  describe '#initialize' do
    it 'assigns attributes' do
      cmd = Net::SSH::SessionCommand.new('cmd', 'output', '128', 1.5)

      cmd.command.should be_a String
      cmd.output.should be_a String
      cmd.exit_code.should be_a Fixnum
      cmd.duration.should be_a Float
    end

    it 'sets exit code to 1 on invalid value' do
      cmd = Net::SSH::SessionCommand.new('cmd', 'output', 'ohai')
      cmd.exit_code.should eq(1)
    end
  end

  describe '#success?' do
    it 'returns true for successful exit codes' do
      cmd = Net::SSH::SessionCommand.new('cmd', 'output', '0')
      cmd.success?.should be_true
    end

    it 'returns false for failed exit codes' do
      cmd = Net::SSH::SessionCommand.new('cmd', 'output', '1')
      cmd.success?.should be_false

      cmd = Net::SSH::SessionCommand.new('cmd', 'output', '128')
      cmd.success?.should be_false
    end
  end

  describe '#failure?' do
    it 'returns true for non-zero exit codes' do
      cmd = Net::SSH::SessionCommand.new('cmd', 'output', '1')
      cmd.failure?.should be_true

      cmd = Net::SSH::SessionCommand.new('cmd', 'output', '128')
      cmd.failure?.should be_true
    end

    it 'returns false for successful exit codes' do
      cmd = Net::SSH::SessionCommand.new('cmd', 'output', '0')
      cmd.failure?.should be_false
    end
  end

  describe '#to_s' do
    it 'returns command string representation' do
      cmd = Net::SSH::SessionCommand.new('cmd', 'output', '0', 1.234)
      cmd.to_s.should eq("[cmd] => 0, 6 bytes, 1.234 seconds")
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
net-ssh-session-0.1.0 spec/session_command_spec.rb