public
Description: Remote multi-server automation tool
Homepage: http://www.capify.org
Clone URL: git://github.com/jamis/capistrano.git
capistrano / test / shell_test.rb
100644 91 lines (74 sloc) 2.757 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
require "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
  
  def test_task_command_with_bang_gets_processed_by_exec_tasks
    while_testing_post_exec_commands do
      @shell.expects(:read_line).returns("!deploy")
      @shell.expects(:exec_tasks).with(["deploy"])
      assert @shell.read_and_execute
    end
  end
  
  def test_normal_command_gets_processed_by_exec_command
    while_testing_post_exec_commands do
      @shell.expects(:read_line).returns("uptime")
      @shell.expects(:exec_command).with("uptime",nil)
      @shell.expects(:connect)
      assert @shell.read_and_execute
    end
  end
  
  
  private
  
  def while_testing_post_exec_commands(&block)
    @shell.instance_variable_set(:@mutex,Mutex.new)
    yield
  end
  
end