Sha256: bd52c518e0323d1250500d53867366bf1cfcf2f439214f2ba0790c2fdbe9fdb9

Contents?: true

Size: 1.68 KB

Versions: 1

Compression:

Stored size: 1.68 KB

Contents

require 'spec_helper'

describe DeltaCapistrano::Configuration::Actions::RunInShell do

  let(:config) do
    Class.new { include DeltaCapistrano::Configuration::Actions::RunInShell }.new
  end
  
  it "should su to the supplied user" do
    user = "the_user" 
    config.should_receive(:sudo).with do |cmd|
      cmd.should =~ /^su - the_user/
    end
    
    config.in_a_shell_as(user)
  end

  it "should exec command in a new shell" do
    expected_command = "a command"
    
    config.should_receive(:sudo).with do |cmd|
      cmd.should == "su - user sh -c '#{expected_command}'"
    end

    config.in_a_shell_as("user", expected_command)
  end


  describe "" do

    before do
      @cmd = nil
      
      config.stub(:sudo).with do |cmd, sudo_conf|
        @cmd = cmd.scan(/sh -c '([^"]*)'/).flatten.first
      end
    end
    
    example "executes command given as argument" do
      config.in_a_shell_as("u", "from argument")
      @cmd.should == "from argument"
    end
  
    example "executes command from block" do
      config.in_a_shell_as("u") do |shell|
        shell.run "from block"
      end

      @cmd.should == "from block"
    end

    example" executes several commands from block" do
     config.in_a_shell_as("u") do |shell|
        shell.run "from block once"
        shell.run "from block twice"
      end

      @cmd.should == "from block once; from block twice"
    end

    example "executes command from argument before commands in block" do
      config.in_a_shell_as("u", "from argument") do |shell|
        shell.run "from block once"
        shell.run "from block twice"
      end

      @cmd.should == "from argument; from block once; from block twice"
    end
    
  end
  
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
delta-capistrano-0.2.0 spec/delta_capistrano/configuration/actions/run_in_shell_spec.rb