Sha256: 7339a845a10766052d7d6051225f8f045f3722ee91f12630f4b07f3b714a26fe

Contents?: true

Size: 1.44 KB

Versions: 2

Compression:

Stored size: 1.44 KB

Contents

require 'minitest_helper'

describe Datacenter::Shell do
  
  module SharedExpamples

    let(:shell) { shell_class.new(*shell_args) }
    
    it 'Success' do
      filename = File.join '/tmp', Time.now.to_i.to_s
      shell.run "echo \"test file\" > #{filename}"
      shell.run("cat #{filename}").must_equal "test file\n"
    end

    it 'Error' do
      filename = '/invalid_dir/invalid_file'
      error = Proc.new { shell.run "cat #{filename}" }.must_raise Datacenter::Shell::CommandError
      error.message.must_include "cat: #{filename}: No such file or directory"
    end

    it 'Block' do
      shell_class.open(*shell_args) do |shell|
        shell.run('ls /').must_equal `ls /`
      end
    end

    it 'Redirect stdout' do
      out = StringIO.new
      shell.run 'ls /', out: out
      out.rewind
      out.read.must_equal `ls /`
    end

    it 'Redirect stderr' do
      err = StringIO.new
      filename = '/invalid_dir/invalid_file'
      Proc.new { shell.run "cat #{filename}", err: err }.must_raise Datacenter::Shell::CommandError
      err.rewind
      err.read.must_include "cat: #{filename}: No such file or directory"
    end

  end

  describe 'Local' do

    let(:shell_args) { [] }
    let(:shell_class) { Datacenter::Shell::Local }

    include SharedExpamples

  end

  describe 'Remote' do

    let(:shell_args) { ['localhost', `whoami`.strip] }
    let(:shell_class) { Datacenter::Shell::Remote }

    include SharedExpamples

  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
datacenter-0.5.1 spec/shell_spec.rb
datacenter-0.5.0 spec/shell_spec.rb