1
0
Fork 0
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:
Jamis Buck 2007-03-04 21:34:35 +00:00
parent b8a1698d39
commit 3b79481659
7 changed files with 44 additions and 7 deletions

View file

@ -18,6 +18,8 @@ module Capistrano
# Using the options build when the command-line was parsed, instantiate # Using the options build when the command-line was parsed, instantiate
# a new Capistrano configuration, initialize it, and execute the # a new Capistrano configuration, initialize it, and execute the
# requested actions. # requested actions.
#
# Returns the Configuration instance used, if successful.
def execute! def execute!
config = instantiate_configuration config = instantiate_configuration
config.logger.level = options[:verbose] config.logger.level = options[:verbose]
@ -26,6 +28,8 @@ module Capistrano
load_recipes(config) load_recipes(config)
execute_requested_actions(config) execute_requested_actions(config)
config
rescue Exception => error rescue Exception => error
handle_error(error) handle_error(error)
end end

View file

@ -89,7 +89,7 @@ module Capistrano
if !task_already_defined if !task_already_defined
metaclass = class << self; self; end 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
end end

View file

@ -89,6 +89,10 @@ class CLIExecuteTest < Test::Unit::TestCase
@cli.execute! @cli.execute!
end end
def test_execute_should_return_config_instance
assert_equal @config, @cli.execute!
end
def test_instantiate_configuration_should_return_new_configuration_instance def test_instantiate_configuration_should_return_new_configuration_instance
assert_instance_of Capistrano::Configuration, MockCLI.new.instantiate_configuration assert_instance_of Capistrano::Configuration, MockCLI.new.instantiate_configuration
end end

View file

@ -2,11 +2,16 @@ require "#{File.dirname(__FILE__)}/utils"
require 'capistrano/cli' require 'capistrano/cli'
class CLI_Test < Test::Unit::TestCase class CLI_Test < Test::Unit::TestCase
def setup def test_options_ui_and_help_modules_should_integrate_successfully_with_configuration
@cli = Capistrano::CLI.new([]) cli = Capistrano::CLI.parse(%w(-T))
cli.expects(:puts).at_least_once
cli.execute!
end end
def test_flunk def test_options_and_execute_modules_should_integrate_successfully_with_configuration
flunk 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
end end

View file

@ -120,6 +120,12 @@ class ConfigurationNamespacesDSLTest < Test::Unit::TestCase
assert @config.methods.include?("original") assert @config.methods.include?("original")
end 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 def test_role_inside_namespace_should_raise_error
assert_raises(NotImplementedError) do assert_raises(NotImplementedError) do
@config.namespace(:outer) do @config.namespace(:outer) do

View file

@ -10,7 +10,20 @@ class ConfigurationTest < Test::Unit::TestCase
@config = Capistrano::Configuration.new @config = Capistrano::Configuration.new
end end
def test_flunk def test_connections_execution_loading_namespaces_roles_and_variables_modules_should_integrate_correctly
flunk 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
end end

5
test/fixtures/cli_integration.rb vendored Normal file
View file

@ -0,0 +1,5 @@
role :test, "www.capistrano.test"
task :testing, :roles => :test do
set :testing_occurred, true
end