Sha256: 067fda447cf8ccac2705ed50909ff2a6eab81c2fd242ebdb2257300554aefa4a

Contents?: true

Size: 1.44 KB

Versions: 4

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

4 entries across 4 versions & 1 rubygems

Version Path
datacenter-0.4.4 spec/shell_spec.rb
datacenter-0.4.3 spec/shell_spec.rb
datacenter-0.4.2 spec/shell_spec.rb
datacenter-0.4.0 spec/shell_spec.rb