Something went wrong. Try again.
A simplified fork of old Capistrano 2.x - a tool for deploying Ruby applications to a server
Something went wrong. Try again.
4.4 kB · 130 lines
Ruby
at master
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131require "utils"require 'minestrone/cli'
class CLIExecuteTest < Test::Unit::TestCase class MockCLI < Minestrone::CLI attr_reader :options
def initialize @options = {} end end
def setup @cli = MockCLI.new @logger = stub_everything @config = stub(:logger => @logger, :debug= => nil, :dry_run= => nil) @config.stubs(:set) @config.stubs(:load) @config.stubs(:trigger) @cli.stubs(:instantiate_configuration).returns(@config) end
def test_execute_should_set_logger_verbosity @cli.options[:verbose] = 7 @logger.expects(:level=).with(7) @cli.execute! end
def test_execute_should_set_password @cli.options[:password] = "nosoup4u" @config.expects(:set).with(:password, "nosoup4u") @cli.execute! end
def test_execute_should_set_prevars_before_loading @config.expects(:load).never @config.expects(:set).with(:environment, "foobar") @config.expects(:load).with("standard") @cli.options[:pre_vars] = { :environment => "foobar" } @cli.execute! end
def test_execute_should_load_sysconf_if_sysconf_set_and_exists @cli.options[:sysconf] = "/etc/minestrone.conf" @config.expects(:load).with("/etc/minestrone.conf") File.expects(:file?).with("/etc/minestrone.conf").returns(true) @cli.execute! end
def test_execute_should_not_load_sysconf_when_sysconf_set_and_not_exists @cli.options[:sysconf] = "/etc/minestrone.conf" File.expects(:file?).with("/etc/minestrone.conf").returns(false) @cli.execute! end
def test_execute_should_load_dotfile_if_dotfile_set_and_exists @cli.options[:dotfile] = "/home/jamis/.caprc" @config.expects(:load).with("/home/jamis/.caprc") File.expects(:file?).with("/home/jamis/.caprc").returns(true) @cli.execute! end
def test_execute_should_not_load_dotfile_when_dotfile_set_and_not_exists @cli.options[:dotfile] = "/home/jamis/.caprc" File.expects(:file?).with("/home/jamis/.caprc").returns(false) @cli.execute! end
def test_execute_should_load_recipes_when_recipes_are_given @cli.options[:recipes] = %w(config/deploy path/to/extra) @config.expects(:load).with("config/deploy") @config.expects(:load).with("path/to/extra") @cli.execute! end
def test_execute_should_set_vars_and_execute_tasks @cli.options[:vars] = { :foo => "bar", :baz => "bang" } @cli.options[:actions] = %w(first second) @config.expects(:set).with(:foo, "bar") @config.expects(:set).with(:baz, "bang") @config.expects(:find_and_execute_task).with("first", :before => :start, :after => :finish) @config.expects(:find_and_execute_task).with("second", :before => :start, :after => :finish) @cli.execute! end
def test_execute_should_call_load_and_exit_triggers @cli.options[:actions] = %w(first second) @config.expects(:find_and_execute_task).with("first", :before => :start, :after => :finish) @config.expects(:find_and_execute_task).with("second", :before => :start, :after => :finish) @config.expects(:trigger).never @config.expects(:trigger).with(:load) @config.expects(:trigger).with(:exit) @cli.execute! end
def test_execute_should_call_handle_error_when_exceptions_occur @config.expects(:load).raises(Exception, "boom") @cli.expects(:handle_error).with { |e,| Exception === e } @cli.execute! end
def test_execute_should_return_config_instance assert_equal @config, @cli.execute! end
def test_instantiate_configuration_should_return_new_configuration_instance assert_instance_of Minestrone::Configuration, MockCLI.new.instantiate_configuration end
def test_handle_error_with_auth_error_should_abort_with_message_including_user_name @cli.expects(:abort).with { |s| s.include?("jamis") } @cli.handle_error(Net::SSH::AuthenticationFailed.new("jamis")) end
def test_handle_error_with_cap_error_should_abort_with_message @cli.expects(:abort).with("Wish you were here") @cli.handle_error(Minestrone::Error.new("Wish you were here")) end
def test_handle_error_with_other_errors_should_reraise_error other_error = Class.new(RuntimeError) assert_raises(other_error) { @cli.handle_error(other_error.new("boom")) } end
def test_class_execute_method_should_call_parse_and_execute_with_ARGV cli = mock(:execute! => nil) MockCLI.expects(:parse).with(ARGV).returns(cli) MockCLI.execute endend