Skip to content

Commit

Permalink
Make sure 'desc' applies to the next defined task, in any namespace.
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.rubyonrails.org/rails/tools/capistrano@6697 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
jamis committed May 8, 2007
1 parent 7c4d877 commit 845f0d2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
2 changes: 2 additions & 0 deletions 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]
Expand Down
13 changes: 10 additions & 3 deletions lib/capistrano/configuration/namespaces.rb
Expand Up @@ -29,7 +29,6 @@ def initialize_with_namespaces(*args) #:nodoc:
initialize_without_namespaces(*args)
@tasks = {}
@namespaces = {}
@next_description = nil
end
private :initialize_with_namespaces

Expand All @@ -46,6 +45,14 @@ def desc(text)
@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.
Expand Down Expand Up @@ -84,8 +91,7 @@ def task(name, options={}, &block)
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
Expand Down Expand Up @@ -177,6 +183,7 @@ def method_missing(sym, *args, &block)
end

include Capistrano::Configuration::Namespaces
undef :desc, :next_description
end
end
end
Expand Down
20 changes: 6 additions & 14 deletions test/configuration/namespace_dsl_test.rb
Expand Up @@ -54,20 +54,6 @@ def test_namespace_within_namespace_should_define_task_within_nested_namespace
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" }
Expand All @@ -76,6 +62,12 @@ def test_pending_desc_should_apply_only_to_immediately_subsequent_task
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)
Expand Down

0 comments on commit 845f0d2

Please sign in to comment.