Sha256: e738cd1b17d75c883049c29a543ab7b17b4e8051b71c75356239fdbd51c1b5f3

Contents?: true

Size: 1.37 KB

Versions: 7

Compression:

Stored size: 1.37 KB

Contents

context ShellCommand do

  context 'run' do
    it 'executes a command successfully.' do
      command = ShellCommand.run "echo -n Hi!"
      command.success?.must_equal(true)
    end

    it 'gives access to the standard output of a command.' do
      command = ShellCommand.run "echo -n Hi!"
      command.stdout.must_equal("Hi!")
    end

    it 'gives access to the standard error output of a command.' do
      command = ShellCommand.run "ls /i_do_not_exist"
      command.stderr.empty?.must_equal(false)
    end

    it 'calls a block, if given.' do
      mock = MiniTest::Mock.new
      mock.expect(:ok, nil)

      ShellCommand.run "ls" do |command|
        mock.ok
      end

      mock.verify
    end

    it "yields a parameter, if given." do
      ShellCommand.run "ls" do |command|
        command.must_be_instance_of(ShellCommand::Command)
      end
    end

    it 'raises an ArgumentError if given no arguments.' do
      proc {
        ShellCommand.run
      }.must_raise(ArgumentError)
    end
  end

  context 'run!' do
    it 'raises ShellCommand::Exception when a command fails.' do
      proc {
        ShellCommand.run! "ls /opskddiofjfsiodjf"
      }.must_raise(ShellCommand::Exception)
    end

    it 'gives a ShellCommand::Command when a command is successful.' do
      command = ShellCommand.run! "ls"
      command.must_be_instance_of(ShellCommand::Command)
    end
  end

end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
shell_command-0.2.6 test/test_shell_command.rb
shell_command-0.2.5 test/test_shell_command.rb
shell_command-0.2.4 test/test_shell_command.rb
shell_command-0.2.3 test/test_shell_command.rb
shell_command-0.2.2 test/test_shell_command.rb
shell_command-0.2.1 test/test_shell_command.rb
shell_command-0.2.0 test/test_shell_command.rb