diff --git a/CHANGELOG b/CHANGELOG index 7af0e97f..35f8bf74 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Make sure 'desc' applies to the next defined task, in any namespace. [Jamis Buck] + * Fix shell so that servers for a task are correctly discovered. [Jamis Buck] * Added before(), after(), and on() callback creation methods. [Jamis Buck] diff --git a/lib/capistrano/configuration/namespaces.rb b/lib/capistrano/configuration/namespaces.rb index 8eb38ccf..3f00248e 100644 --- a/lib/capistrano/configuration/namespaces.rb +++ b/lib/capistrano/configuration/namespaces.rb @@ -29,7 +29,6 @@ module Capistrano initialize_without_namespaces(*args) @tasks = {} @namespaces = {} - @next_description = nil end private :initialize_with_namespaces @@ -46,6 +45,14 @@ module Capistrano @next_description = text end + # Returns the value set by the last, pending "desc" call. If +reset+ is + # not false, the value will be reset immediately afterwards. + def next_description(reset=false) + @next_description + ensure + @next_description = nil if reset + end + # Open a namespace in which to define new tasks. If the namespace was # defined previously, it will be reopened, otherwise a new namespace # will be created for the given name. @@ -84,8 +91,7 @@ module Capistrano raise ArgumentError, "defining a task named `#{name}' would shadow an existing #{thing} with that name" end - tasks[name] = TaskDefinition.new(name, self, {:desc => @next_description}.merge(options), &block) - @next_description = nil + tasks[name] = TaskDefinition.new(name, self, {:desc => next_description(:reset)}.merge(options), &block) if !task_already_defined metaclass = class << self; self; end @@ -177,6 +183,7 @@ module Capistrano end include Capistrano::Configuration::Namespaces + undef :desc, :next_description end end end diff --git a/test/configuration/namespace_dsl_test.rb b/test/configuration/namespace_dsl_test.rb index 1268c37a..4d475ea2 100644 --- a/test/configuration/namespace_dsl_test.rb +++ b/test/configuration/namespace_dsl_test.rb @@ -54,20 +54,6 @@ class ConfigurationNamespacesDSLTest < Test::Unit::TestCase assert @config.namespaces[:outer].namespaces[:inner].tasks.key?(:nested) end - def test_pending_desc_should_disappear_when_enclosing_namespace_terminates - @config.namespace :outer do - desc "Something to say" - end - - @config.namespace :outer do - task :testing do - puts "testing" - end - end - - assert_nil @config.namespaces[:outer].tasks[:testing].options[:desc] - end - def test_pending_desc_should_apply_only_to_immediately_subsequent_task @config.desc "A description" @config.task(:testing) { puts "foo" } @@ -76,6 +62,12 @@ class ConfigurationNamespacesDSLTest < Test::Unit::TestCase assert_nil @config.tasks[:another].options[:desc] end + def test_pending_desc_should_apply_only_to_next_task_in_any_namespace + @config.desc "A description" + @config.namespace(:outer) { task(:testing) { puts "foo" } } + assert_equal "A description", @config.namespaces[:outer].tasks[:testing].options[:desc] + end + def test_defining_task_without_block_should_raise_error assert_raises(ArgumentError) do @config.task(:testing)