mirror of
https://github.com/capistrano/capistrano
synced 2023-03-27 23:21:18 -04:00
Make sure the CLI components integrate nicely. Make sure the Configuration components integrate nicely.
git-svn-id: http://svn.rubyonrails.org/rails/tools/capistrano@6321 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
b8a1698d39
commit
3b79481659
7 changed files with 44 additions and 7 deletions
|
@ -18,6 +18,8 @@ module Capistrano
|
|||
# Using the options build when the command-line was parsed, instantiate
|
||||
# a new Capistrano configuration, initialize it, and execute the
|
||||
# requested actions.
|
||||
#
|
||||
# Returns the Configuration instance used, if successful.
|
||||
def execute!
|
||||
config = instantiate_configuration
|
||||
config.logger.level = options[:verbose]
|
||||
|
@ -26,6 +28,8 @@ module Capistrano
|
|||
load_recipes(config)
|
||||
|
||||
execute_requested_actions(config)
|
||||
|
||||
config
|
||||
rescue Exception => error
|
||||
handle_error(error)
|
||||
end
|
||||
|
|
|
@ -89,7 +89,7 @@ module Capistrano
|
|||
|
||||
if !task_already_defined
|
||||
metaclass = class << self; self; end
|
||||
metaclass.send(:define_method, name) { execute_task(name, self) }
|
||||
metaclass.send(:define_method, name) { execute_task(tasks[name]) }
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -89,6 +89,10 @@ class CLIExecuteTest < Test::Unit::TestCase
|
|||
@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 Capistrano::Configuration, MockCLI.new.instantiate_configuration
|
||||
end
|
||||
|
|
|
@ -2,11 +2,16 @@ require "#{File.dirname(__FILE__)}/utils"
|
|||
require 'capistrano/cli'
|
||||
|
||||
class CLI_Test < Test::Unit::TestCase
|
||||
def setup
|
||||
@cli = Capistrano::CLI.new([])
|
||||
def test_options_ui_and_help_modules_should_integrate_successfully_with_configuration
|
||||
cli = Capistrano::CLI.parse(%w(-T))
|
||||
cli.expects(:puts).at_least_once
|
||||
cli.execute!
|
||||
end
|
||||
|
||||
def test_flunk
|
||||
flunk
|
||||
def test_options_and_execute_modules_should_integrate_successfully_with_configuration
|
||||
path = "#{File.dirname(__FILE__)}/fixtures/cli_integration.rb"
|
||||
cli = Capistrano::CLI.parse(%W(-q -f #{path} testing))
|
||||
config = cli.execute!
|
||||
assert config[:testing_occurred]
|
||||
end
|
||||
end
|
||||
|
|
|
@ -120,6 +120,12 @@ class ConfigurationNamespacesDSLTest < Test::Unit::TestCase
|
|||
assert @config.methods.include?("original")
|
||||
end
|
||||
|
||||
def test_calling_defined_task_should_delegate_to_execute_task
|
||||
@config.task(:original) { puts "foo" }
|
||||
@config.expects(:execute_task).with(@config.tasks[:original])
|
||||
@config.original
|
||||
end
|
||||
|
||||
def test_role_inside_namespace_should_raise_error
|
||||
assert_raises(NotImplementedError) do
|
||||
@config.namespace(:outer) do
|
||||
|
|
|
@ -10,7 +10,20 @@ class ConfigurationTest < Test::Unit::TestCase
|
|||
@config = Capistrano::Configuration.new
|
||||
end
|
||||
|
||||
def test_flunk
|
||||
flunk
|
||||
def test_connections_execution_loading_namespaces_roles_and_variables_modules_should_integrate_correctly
|
||||
Capistrano::SSH.expects(:connect).with { |s,c| s.host == "www.capistrano.test" && c == @config }.returns(:session)
|
||||
Capistrano::Command.expects(:process).with("echo 'hello world'", [:session], :logger => @config.logger)
|
||||
|
||||
@config.load do
|
||||
role :test, "www.capistrano.test"
|
||||
set :message, "hello world"
|
||||
namespace :testing do
|
||||
task :example, :roles => :test do
|
||||
run "echo '#{message}'"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@config.testing.example
|
||||
end
|
||||
end
|
||||
|
|
5
test/fixtures/cli_integration.rb
vendored
Normal file
5
test/fixtures/cli_integration.rb
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
role :test, "www.capistrano.test"
|
||||
|
||||
task :testing, :roles => :test do
|
||||
set :testing_occurred, true
|
||||
end
|
Loading…
Reference in a new issue