Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tag: v2-1-0
Fetching contributors…

Cannot retrieve contributors at this time

file 64 lines (54 sloc) 2.098 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
require "#{File.dirname(__FILE__)}/utils"
require 'capistrano/configuration'
require 'capistrano/shell'

class ShellTest < Test::Unit::TestCase
  def setup
    @config = Capistrano::Configuration.new
    @shell = Capistrano::Shell.new(@config)
    @shell.stubs(:puts)
  end

  def test_readline_fallback_prompt_should_write_to_stdout_and_read_from_stdin
    STDOUT.expects(:print).with("prompt> ")
    STDOUT.expects(:flush)
    STDIN.expects(:gets).returns("hi\n")
    assert_equal "hi\n", Capistrano::Shell::ReadlineFallback.readline("prompt> ")
  end

  def test_question_mark_as_input_should_trigger_help
    @shell.expects(:read_line).returns("?")
    @shell.expects(:help)
    assert @shell.read_and_execute
  end

  def test_help_as_input_should_trigger_help
    @shell.expects(:read_line).returns("help")
    @shell.expects(:help)
    assert @shell.read_and_execute
  end

  def test_quit_as_input_should_cause_read_and_execute_to_return_false
    @shell.expects(:read_line).returns("quit")
    assert !@shell.read_and_execute
  end

  def test_exit_as_input_should_cause_read_and_execute_to_return_false
    @shell.expects(:read_line).returns("exit")
    assert !@shell.read_and_execute
  end

  def test_set_should_parse_flag_and_value_and_call_set_option
    @shell.expects(:read_line).returns("set -v 5")
    @shell.expects(:set_option).with("v", "5")
    assert @shell.read_and_execute
  end

  def test_text_without_with_or_on_gets_processed_verbatim
    @shell.expects(:read_line).returns("hello world")
    @shell.expects(:process_command).with(nil, nil, "hello world")
    assert @shell.read_and_execute
  end

  def test_text_with_with_gets_processed_with_with # lol
    @shell.expects(:read_line).returns("with app,db hello world")
    @shell.expects(:process_command).with("with", "app,db", "hello world")
    assert @shell.read_and_execute
  end

  def test_text_with_on_gets_processed_with_on
    @shell.expects(:read_line).returns("on app,db hello world")
    @shell.expects(:process_command).with("on", "app,db", "hello world")
    assert @shell.read_and_execute
  end
end
Something went wrong with that request. Please try again.