mirror of
https://github.com/capistrano/capistrano
synced 2023-03-27 23:21:18 -04:00
Ticket #193 - alias_task first implementation
This commit is contained in:
parent
2fd9180125
commit
1b002e6394
4 changed files with 85 additions and 2 deletions
|
@ -1,5 +1,6 @@
|
|||
require 'capistrano/logger'
|
||||
|
||||
require 'capistrano/configuration/alias_task'
|
||||
require 'capistrano/configuration/callbacks'
|
||||
require 'capistrano/configuration/connections'
|
||||
require 'capistrano/configuration/execution'
|
||||
|
@ -33,7 +34,7 @@ module Capistrano
|
|||
|
||||
# The includes must come at the bottom, since they may redefine methods
|
||||
# defined in the base class.
|
||||
include Connections, Execution, Loading, Namespaces, Roles, Servers, Variables
|
||||
include AliasTask, Connections, Execution, Loading, Namespaces, Roles, Servers, Variables
|
||||
|
||||
# Mix in the actions
|
||||
include Actions::FileTransfer, Actions::Inspect, Actions::Invocation
|
||||
|
|
19
lib/capistrano/configuration/alias_task.rb
Normal file
19
lib/capistrano/configuration/alias_task.rb
Normal file
|
@ -0,0 +1,19 @@
|
|||
module Capistrano
|
||||
class Configuration
|
||||
module AliasTask
|
||||
# Attempts to find the task at the given fully-qualified path, and
|
||||
# alias it. If arguments don't have correct task names, an ArgumentError
|
||||
# wil be raised. If no such task exists, a Capistrano::NoSuchTaskError
|
||||
# will be raised.
|
||||
def alias_task(new_name, old_name)
|
||||
if !new_name.respond_to?(:to_sym) or !old_name.respond_to?(:to_sym)
|
||||
raise ArgumentError, "expected a valid task name"
|
||||
end
|
||||
|
||||
task = find_task(old_name) or raise NoSuchTaskError, "the task `#{old_name}' does not exist"
|
||||
|
||||
task(new_name, task.options, &task.body)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
63
test/configuration/alias_task_test.rb
Normal file
63
test/configuration/alias_task_test.rb
Normal file
|
@ -0,0 +1,63 @@
|
|||
require 'utils'
|
||||
require 'capistrano/configuration/alias_task'
|
||||
require 'capistrano/configuration/execution'
|
||||
require 'capistrano/configuration/namespaces'
|
||||
require 'capistrano/task_definition'
|
||||
|
||||
class AliasTaskTest < Test::Unit::TestCase
|
||||
class MockConfig
|
||||
attr_reader :options
|
||||
attr_accessor :logger
|
||||
|
||||
def initialize(options={})
|
||||
@options = {}
|
||||
@logger = options.delete(:logger)
|
||||
end
|
||||
|
||||
include Capistrano::Configuration::AliasTask
|
||||
include Capistrano::Configuration::Execution
|
||||
include Capistrano::Configuration::Namespaces
|
||||
end
|
||||
|
||||
def setup
|
||||
@config = MockConfig.new( :logger => stub(:debug => nil, :info => nil, :important => nil) )
|
||||
end
|
||||
|
||||
def test_makes_a_copy_of_the_task
|
||||
@config.task(:foo) { 42 }
|
||||
@config.alias_task 'new_foo', 'foo'
|
||||
|
||||
assert @config.tasks.key?(:new_foo)
|
||||
end
|
||||
|
||||
def test_aliased_task_do_the_same
|
||||
@config.task(:foo) { 42 }
|
||||
@config.alias_task 'new_foo', 'foo'
|
||||
|
||||
assert_equal 42, @config.find_and_execute_task('new_foo')
|
||||
end
|
||||
|
||||
def test_raise_exception_when_task_doesnt_exist
|
||||
assert_raises(Capistrano::NoSuchTaskError) { @config.alias_task 'non_existant_task', 'fail_miserably' }
|
||||
end
|
||||
|
||||
def test_convert_task_names_using_to_str
|
||||
@config.task(:foo, :role => :app) { 42 }
|
||||
|
||||
@config.alias_task 'one', 'foo'
|
||||
@config.alias_task :two, 'foo'
|
||||
@config.alias_task 'three', :foo
|
||||
@config.alias_task :four, :foo
|
||||
|
||||
assert @config.tasks.key?(:one)
|
||||
assert @config.tasks.key?(:two)
|
||||
assert @config.tasks.key?(:three)
|
||||
assert @config.tasks.key?(:four)
|
||||
end
|
||||
|
||||
def test_raise_an_exception_when_task_names_can_not_be_converted
|
||||
@config.task(:foo, :role => :app) { 42 }
|
||||
|
||||
assert_raises(ArgumentError) { @config.alias_task mock('x'), :foo }
|
||||
end
|
||||
end
|
Loading…
Add table
Reference in a new issue