Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Introduce a new DSL and deprecate the old one

  • Loading branch information...
commit bd5a6aa678571dcff648a283442a0e6a641c4b00 1 parent aff7772
@njonsson authored
Showing with 3,357 additions and 153 deletions.
  1. +38 −9 README.markdown
  2. +63 −0 features/dsl/mirror_rake_tasks/with_cd.feature
  3. +27 −0 features/dsl/mirror_rake_tasks/with_cd_and_environment_variables.feature
  4. +43 −0 features/dsl/mirror_rake_tasks/with_defined_task_and_cd.feature
  5. +46 −0 features/dsl/mirror_rake_tasks/with_defined_task_and_cd_and_environment_variables.feature
  6. +50 −2 features/dsl/mirror_rake_tasks/with_defined_task_and_environment_variables.feature
  7. +47 −0 features/dsl/mirror_rake_tasks/with_defined_task_and_rename.feature
  8. +49 −0 features/dsl/mirror_rake_tasks/with_defined_task_and_rename_and_cd.feature
  9. +52 −0 features/dsl/mirror_rake_tasks/with_defined_task_and_rename_and_cd_and_environment_variables.feature
  10. +50 −0 features/dsl/mirror_rake_tasks/with_defined_task_and_rename_and_environment_variables.feature
  11. +49 −0 features/dsl/mirror_rake_tasks/with_defined_task_and_rename_and_valid_options.feature
  12. +51 −0 features/dsl/mirror_rake_tasks/with_defined_task_and_rename_and_valid_options_and_cd.feature
  13. +54 −0 ...l/mirror_rake_tasks/with_defined_task_and_rename_and_valid_options_and_cd_and_environment_variables.feature
  14. +52 −0 ...ures/dsl/mirror_rake_tasks/with_defined_task_and_rename_and_valid_options_and_environment_variables.feature
  15. +49 −2 features/dsl/mirror_rake_tasks/with_defined_task_and_valid_options.feature
  16. +45 −0 features/dsl/mirror_rake_tasks/with_defined_task_and_valid_options_and_cd.feature
  17. +48 −0 features/dsl/mirror_rake_tasks/with_defined_task_and_valid_options_and_cd_and_environment_variables.feature
  18. +56 −2 features/dsl/mirror_rake_tasks/with_defined_task_and_valid_options_and_environment_variables.feature
  19. +58 −1 features/dsl/mirror_rake_tasks/with_environment_variables.feature
  20. +27 −0 features/dsl/mirror_rake_tasks/with_rename.feature
  21. +28 −0 features/dsl/mirror_rake_tasks/with_rename_and_cd.feature
  22. +30 −0 features/dsl/mirror_rake_tasks/with_rename_and_cd_and_environment_variables.feature
  23. +29 −0 features/dsl/mirror_rake_tasks/with_rename_and_environment_variables.feature
  24. +28 −0 features/dsl/mirror_rake_tasks/with_rename_and_valid_options.feature
  25. +29 −0 features/dsl/mirror_rake_tasks/with_rename_and_valid_options_and_cd.feature
  26. +31 −0 features/dsl/mirror_rake_tasks/with_rename_and_valid_options_and_cd_and_environment_variables.feature
  27. +30 −0 features/dsl/mirror_rake_tasks/with_rename_and_valid_options_and_environment_variables.feature
  28. +24 −1 features/dsl/mirror_rake_tasks/with_valid_options.feature
  29. +26 −0 features/dsl/mirror_rake_tasks/with_valid_options_and_cd.feature
  30. +28 −0 features/dsl/mirror_rake_tasks/with_valid_options_and_cd_and_environment_variables.feature
  31. +26 −1 features/dsl/mirror_rake_tasks/with_valid_options_and_environment_variables.feature
  32. +40 −0 features/step_definitions.rb
  33. +1 −0  lib/cape.rb
  34. +59 −32 lib/cape/capistrano.rb
  35. +165 −0 lib/cape/capistrano_deprecated.rb
  36. +12 −0 lib/cape/deprecation.rb
  37. +59 −0 lib/cape/deprecation/base.rb
  38. +168 −0 lib/cape/deprecation/capistrano_deprecated_define_rake_wrapper.rb
  39. +145 −0 lib/cape/deprecation/dsl_deprecated_mirror_rake_tasks.rb
  40. +48 −60 lib/cape/dsl.rb
  41. +157 −0 lib/cape/dsl_deprecated.rb
  42. +103 −0 lib/cape/recipe_definition.rb
  43. +41 −0 lib/cape/recipe_definition_deprecated.rb
  44. +326 −0 lib/cape/xterm.rb
  45. +18 −0 spec/cape/deprecation/base_sharedspec.rb
  46. +157 −0 spec/cape/deprecation/capistrano_deprecated_define_rake_wrapper_spec.rb
  47. +153 −0 spec/cape/deprecation/dsl_deprecated_mirror_rake_tasks_spec.rb
  48. +307 −0 spec/cape/dsl_deprecated_spec.rb
  49. +10 −43 spec/cape/dsl_spec.rb
  50. +53 −0 spec/cape/recipe_definition_spec.rb
  51. +72 −0 spec/cape/xterm_spec.rb
View
47 README.markdown
@@ -166,9 +166,9 @@ Cape lets you filter the Rake tasks to be mirrored. Note that Cape statements mu
mirror_rake_tasks :foo
end
-### Mirror Rake tasks that require Capistrano recipe options and/or environment variables
+### Mirror Rake tasks that require renaming, Capistrano recipe options, path switching, and/or environment variables
-Cape lets you specify options used for defining Capistrano recipes. You can also specify remote environment variables to be set when executing Rake tasks. Note that Cape statements must be contained in a `Cape` block.
+Cape lets you customize mirrored Rake tasks to suit your needs. Note that Cape statements must be contained in a `Cape` block, and references to Capistrano variables such as `rails_env` and `release_path` must be contained in an inner block, lambda, or other callable object.
# config/deploy.rb
@@ -176,13 +176,37 @@ Cape lets you specify options used for defining Capistrano recipes. You can also
Cape do
# Display defined Rails routes on application server remote machines only.
- mirror_rake_tasks :routes, :roles => :app
+ mirror_rake_tasks :routes do |recipes|
+ recipes.options[:roles] = :app
+ end
# Execute database migration on application server remote machines only,
# and set the 'RAILS_ENV' environment variable to the value of the
# Capistrano variable 'rails_env'.
- mirror_rake_tasks 'db:migrate', :roles => :app do |env|
- env['RAILS_ENV'] = rails_env
+ mirror_rake_tasks 'db:migrate' do |recipes|
+ recipes.options[:roles] = :app
+ recipes.env['RAILS_ENV'] = lambda { rails_env }
+ end
+
+ # Support a Rake task that must be run on application server remote
+ # machines only, and in the remote directory 'release_path' instead of the
+ # default, 'current_path'.
+ before 'deploy:symlink', :spec
+ mirror_rake_tasks :spec do |recipes|
+ recipes.cd { release_path }
+ recipes.options[:roles] = :app
+ end
+
+ # Avoid collisions with the existing Ruby method #test, run tests on
+ # application server remote machines only, and set the 'RAILS_ENV'
+ # environment variable to the value of the Capistrano variable
+ # 'rails_env'.
+ mirror_rake_tasks :test do |recipes|
+ recipes.rename do |rake_task_name|
+ "#{rake_task_name}_task"
+ end
+ recipes.options[:roles] = :app
+ recipes.env['RAILS_ENV'] = lambda { rails_env }
end
end
@@ -215,6 +239,15 @@ The above is equivalent to the following manually-defined Capistrano recipes.
end
end
+ before 'deploy:symlink', :spec
+ task :spec, :roles => :app do
+ run "cd #{release_path} && #{RAKE} routes"
+ end
+
+ task :test_task, :roles => :app do
+ run "cd #{current_path} && #{RAKE} test RAILS_ENV=#{rails_env}"
+ end
+
### Mirror Rake tasks into a Capistrano namespace
Cape plays friendly with the Capistrano DSL for organizing Rake tasks in Capistrano namespaces. Note that Cape statements must be contained in a `Cape` block.
@@ -286,10 +319,6 @@ Note that Cape statements must be contained in a `Cape` block.
gem 'rake', '>= 0.9.3'
-**A Rake task whose name collides with a Ruby method cannot be mirrored.** For example, the name of [Rails](http://rubyonrails.org)’s _db:fixtures:load_ task collides with the Ruby Core Library’s [_Kernel::load_ method](http://ruby-doc.org/core/Kernel.html#method-i-load) because that method is mixed into all objects. If you try to mirror _db:fixtures:load_, Capistrano will raise an exception. There is [a questionable workaround](http://github.com/njonsson/cape/issues/7#issuecomment-5632718 "Comment on Cape issue #7 (“defining a task named ‘load’ would shadow an existing method with that name (ArgumentError)”)") for this.
-
-**A Rake task is always executed in the Capistrano deployment’s _current_path_.** You may need to execute a task under _release_path_ or another remote filesystem location, but this is not possible at present. [Discuss](http://github.com/njonsson/cape/issues/9 "Cape issue #9 (“Cape Always Runs the Mirrorred Rake Tasks Under $current_path”)") this.
-
## Contributing
Report defects and feature requests on [GitHub Issues](http://github.com/njonsson/cape/issues).
View
63 features/dsl/mirror_rake_tasks/with_cd.feature
@@ -0,0 +1,63 @@
+Feature: The #mirror_rake_tasks DSL method with a different directory
+
+ In order to include Rake tasks with descriptions in my Capistrano recipes,
+ As a developer using Cape,
+ I want to use the Cape DSL.
+
+ Scenario: mirror a Rake task with its implementation, using a Capistrano variable inside a lambda
+ Given a full-featured Rakefile
+ And a Capfile with:
+ """
+ set :release_path, '/release/path'
+
+ Cape do
+ mirror_rake_tasks do |recipes|
+ recipes.cd lambda { release_path }
+ end
+ end
+ """
+ When I run `cap with_period`
+ Then the output should contain:
+ """
+ * executing `with_period'
+ * executing "cd /release/path && /usr/bin/env `/usr/bin/env bundle check >/dev/null 2>&1; case $? in 0|1 ) echo bundle exec ;; esac` rake with_period"
+ `with_period' is only run for servers matching {}, but no servers matched
+ """
+
+ Scenario: mirror a Rake task with its implementation, using a Capistrano variable inside a block
+ Given a full-featured Rakefile
+ And a Capfile with:
+ """
+ set :release_path, '/release/path'
+
+ Cape do
+ mirror_rake_tasks do |recipes|
+ recipes.cd { release_path }
+ end
+ end
+ """
+ When I run `cap with_period`
+ Then the output should contain:
+ """
+ * executing `with_period'
+ * executing "cd /release/path && /usr/bin/env `/usr/bin/env bundle check >/dev/null 2>&1; case $? in 0|1 ) echo bundle exec ;; esac` rake with_period"
+ `with_period' is only run for servers matching {}, but no servers matched
+ """
+
+ Scenario: mirror a Rake task with its implementation, using a string
+ Given a full-featured Rakefile
+ And a Capfile with:
+ """
+ Cape do
+ mirror_rake_tasks do |recipes|
+ recipes.cd '/release/path'
+ end
+ end
+ """
+ When I run `cap with_period`
+ Then the output should contain:
+ """
+ * executing `with_period'
+ * executing "cd /release/path && /usr/bin/env `/usr/bin/env bundle check >/dev/null 2>&1; case $? in 0|1 ) echo bundle exec ;; esac` rake with_period"
+ `with_period' is only run for servers matching {}, but no servers matched
+ """
View
27 features/dsl/mirror_rake_tasks/with_cd_and_environment_variables.feature
@@ -0,0 +1,27 @@
+Feature: The #mirror_rake_tasks DSL method with a different directory and environment variables
+
+ In order to include Rake tasks with descriptions in my Capistrano recipes,
+ As a developer using Cape,
+ I want to use the Cape DSL.
+
+ Scenario: mirror a Rake task with its implementation
+ Given a full-featured Rakefile
+ And a Capfile with:
+ """
+ set :release_path, '/release/path'
+ set :rails_env, 'rails-env'
+
+ Cape do
+ mirror_rake_tasks do |recipes|
+ recipes.cd { release_path }
+ recipes.env['RAILS_ENV'] = lambda { rails_env }
+ end
+ end
+ """
+ When I run `cap with_period`
+ Then the output should contain:
+ """
+ * executing `with_period'
+ * executing "cd /release/path && /usr/bin/env `/usr/bin/env bundle check >/dev/null 2>&1; case $? in 0|1 ) echo bundle exec ;; esac` rake with_period RAILS_ENV=\"rails-env\""
+ `with_period' is only run for servers matching {}, but no servers matched
+ """
View
43 features/dsl/mirror_rake_tasks/with_defined_task_and_cd.feature
@@ -0,0 +1,43 @@
+Feature: The #mirror_rake_tasks DSL method with a defined task and a different directory
+
+ In order to include Rake tasks with descriptions in my Capistrano recipes,
+ As a developer using Cape,
+ I want to use the Cape DSL.
+
+ Scenario: mirror only the matching Rake task
+ Given a full-featured Rakefile
+ And a Capfile with:
+ """
+ Cape do
+ mirror_rake_tasks :with_period do |recipes|
+ recipes.cd { release_path }
+ end
+ end
+ """
+ When I run `cap -vT`
+ Then the output should contain:
+ """
+ cap with_period # Ends with period.
+ """
+ And the output should not contain "without_period"
+ And the output should not contain "my_namespace"
+
+ Scenario: mirror the matching Rake task with its implementation
+ Given a full-featured Rakefile
+ And a Capfile with:
+ """
+ set :release_path, '/release/path'
+
+ Cape do
+ mirror_rake_tasks :with_period do |recipes|
+ recipes.cd { release_path }
+ end
+ end
+ """
+ When I run `cap with_period`
+ Then the output should contain:
+ """
+ * executing `with_period'
+ * executing "cd /release/path && /usr/bin/env `/usr/bin/env bundle check >/dev/null 2>&1; case $? in 0|1 ) echo bundle exec ;; esac` rake with_period"
+ `with_period' is only run for servers matching {}, but no servers matched
+ """
View
46 features/dsl/mirror_rake_tasks/with_defined_task_and_cd_and_environment_variables.feature
@@ -0,0 +1,46 @@
+Feature: The #mirror_rake_tasks DSL method with a defined task, a different directory, and environment variables
+
+ In order to include Rake tasks with descriptions in my Capistrano recipes,
+ As a developer using Cape,
+ I want to use the Cape DSL.
+
+ Scenario: mirror only the matching Rake task
+ Given a full-featured Rakefile
+ And a Capfile with:
+ """
+ Cape do
+ mirror_rake_tasks :with_period do |recipes|
+ recipes.cd { release_path }
+ recipes.env['RAILS_ENV'] = lambda { rails_env }
+ end
+ end
+ """
+ When I run `cap -vT`
+ Then the output should contain:
+ """
+ cap with_period # Ends with period.
+ """
+ And the output should not contain "without_period"
+ And the output should not contain "my_namespace"
+
+ Scenario: mirror the matching Rake task with its implementation
+ Given a full-featured Rakefile
+ And a Capfile with:
+ """
+ set :release_path, '/release/path'
+ set :rails_env, 'rails-env'
+
+ Cape do
+ mirror_rake_tasks :with_period do |recipes|
+ recipes.cd { release_path }
+ recipes.env['RAILS_ENV'] = lambda { rails_env }
+ end
+ end
+ """
+ When I run `cap with_period`
+ Then the output should contain:
+ """
+ * executing `with_period'
+ * executing "cd /release/path && /usr/bin/env `/usr/bin/env bundle check >/dev/null 2>&1; case $? in 0|1 ) echo bundle exec ;; esac` rake with_period RAILS_ENV=\"rails-env\""
+ `with_period' is only run for servers matching {}, but no servers matched
+ """
View
52 features/dsl/mirror_rake_tasks/with_defined_task_and_environment_variables.feature
@@ -4,7 +4,8 @@ Feature: The #mirror_rake_tasks DSL method with a defined task and environment v
As a developer using Cape,
I want to use the Cape DSL.
- Scenario: mirror only the matching Rake task
+ @deprecated
+ Scenario: mirror only the matching Rake task (deprecated)
Given a full-featured Rakefile
And a Capfile with:
"""
@@ -21,8 +22,32 @@ Feature: The #mirror_rake_tasks DSL method with a defined task and environment v
"""
And the output should not contain "without_period"
And the output should not contain "my_namespace"
+ And the output should contain:
+ """
+ *** DEPRECATED: Referencing Capistrano variables from Cape without wrapping them in a block, a lambda, or another callable object
+ """
- Scenario: mirror the matching Rake task with its implementation
+ Scenario: mirror only the matching Rake task
+ Given a full-featured Rakefile
+ And a Capfile with:
+ """
+ Cape do
+ mirror_rake_tasks :with_period do |recipes|
+ recipes.env['RAILS_ENV'] = lambda { rails_env }
+ end
+ end
+ """
+ When I run `cap -vT`
+ Then the output should contain:
+ """
+ cap with_period # Ends with period.
+ """
+ And the output should not contain "without_period"
+ And the output should not contain "my_namespace"
+ And the output should not contain "DEPRECATED"
+
+ @deprecated
+ Scenario: mirror the matching Rake task with its implementation (deprecated)
Given a full-featured Rakefile
And a Capfile with:
"""
@@ -38,7 +63,30 @@ Feature: The #mirror_rake_tasks DSL method with a defined task and environment v
When I run `cap with_period`
Then the output should contain:
"""
+ *** DEPRECATED: `mirror_rake_tasks("with_period") { |env| env["RAILS_ENV"] = "rails-env" }`. Use this instead: `mirror_rake_tasks("with_period") { |recipes| recipes.env["RAILS_ENV"] = "rails-env" }`
+ * executing `with_period'
+ * executing "cd /current/path && /usr/bin/env `/usr/bin/env bundle check >/dev/null 2>&1; case $? in 0|1 ) echo bundle exec ;; esac` rake with_period RAILS_ENV=\"rails-env\""
+ `with_period' is only run for servers matching {}, but no servers matched
+ """
+
+ Scenario: mirror the matching Rake task with its implementation
+ Given a full-featured Rakefile
+ And a Capfile with:
+ """
+ set :current_path, '/current/path'
+ set :rails_env, 'rails-env'
+
+ Cape do
+ mirror_rake_tasks 'with_period' do |recipes|
+ recipes.env['RAILS_ENV'] = lambda { rails_env }
+ end
+ end
+ """
+ When I run `cap with_period`
+ Then the output should contain:
+ """
* executing `with_period'
* executing "cd /current/path && /usr/bin/env `/usr/bin/env bundle check >/dev/null 2>&1; case $? in 0|1 ) echo bundle exec ;; esac` rake with_period RAILS_ENV=\"rails-env\""
`with_period' is only run for servers matching {}, but no servers matched
"""
+ And the output should not contain "DEPRECATED"
View
47 features/dsl/mirror_rake_tasks/with_defined_task_and_rename.feature
@@ -0,0 +1,47 @@
+Feature: The #mirror_rake_tasks DSL method with a defined task and renaming logic
+
+ In order to include Rake tasks with descriptions in my Capistrano recipes,
+ As a developer using Cape,
+ I want to use the Cape DSL.
+
+ Scenario: mirror only the matching Rake task
+ Given a full-featured Rakefile defining a Ruby-method-shadowing task
+ And a Capfile with:
+ """
+ Cape do
+ mirror_rake_tasks :load do |recipes|
+ recipes.rename do |task_name|
+ "do_#{task_name}"
+ end
+ end
+ end
+ """
+ When I run `cap -vT`
+ Then the output should contain:
+ """
+ cap do_load # A task that shadows a Ruby method.
+ """
+ And the output should not contain "period"
+ And the output should not contain "my_namespace"
+
+ Scenario: mirror the matching Rake task with its implementation
+ Given a full-featured Rakefile defining a Ruby-method-shadowing task
+ And a Capfile with:
+ """
+ set :current_path, '/current/path'
+
+ Cape do
+ mirror_rake_tasks :load do |recipes|
+ recipes.rename do |task_name|
+ "do_#{task_name}"
+ end
+ end
+ end
+ """
+ When I run `cap do_load`
+ Then the output should contain:
+ """
+ * executing `do_load'
+ * executing "cd /current/path && /usr/bin/env `/usr/bin/env bundle check >/dev/null 2>&1; case $? in 0|1 ) echo bundle exec ;; esac` rake load"
+ `do_load' is only run for servers matching {}, but no servers matched
+ """
View
49 features/dsl/mirror_rake_tasks/with_defined_task_and_rename_and_cd.feature
@@ -0,0 +1,49 @@
+Feature: The #mirror_rake_tasks DSL method with a defined task, renaming logic, and a different directory
+
+ In order to include Rake tasks with descriptions in my Capistrano recipes,
+ As a developer using Cape,
+ I want to use the Cape DSL.
+
+ Scenario: mirror only the matching Rake task
+ Given a full-featured Rakefile defining a Ruby-method-shadowing task
+ And a Capfile with:
+ """
+ Cape do
+ mirror_rake_tasks :load do |recipes|
+ recipes.rename do |task_name|
+ "do_#{task_name}"
+ end
+ recipes.cd { release_path }
+ end
+ end
+ """
+ When I run `cap -vT`
+ Then the output should contain:
+ """
+ cap do_load # A task that shadows a Ruby method.
+ """
+ And the output should not contain "period"
+ And the output should not contain "my_namespace"
+
+ Scenario: mirror the matching Rake task with its implementation
+ Given a full-featured Rakefile defining a Ruby-method-shadowing task
+ And a Capfile with:
+ """
+ set :release_path, '/release/path'
+
+ Cape do
+ mirror_rake_tasks :load do |recipes|
+ recipes.rename do |task_name|
+ "do_#{task_name}"
+ end
+ recipes.cd { release_path }
+ end
+ end
+ """
+ When I run `cap do_load`
+ Then the output should contain:
+ """
+ * executing `do_load'
+ * executing "cd /release/path && /usr/bin/env `/usr/bin/env bundle check >/dev/null 2>&1; case $? in 0|1 ) echo bundle exec ;; esac` rake load"
+ `do_load' is only run for servers matching {}, but no servers matched
+ """
View
52 features/dsl/mirror_rake_tasks/with_defined_task_and_rename_and_cd_and_environment_variables.feature
@@ -0,0 +1,52 @@
+Feature: The #mirror_rake_tasks DSL method with a defined task, renaming logic, a different directory, and environment variables
+
+ In order to include Rake tasks with descriptions in my Capistrano recipes,
+ As a developer using Cape,
+ I want to use the Cape DSL.
+
+ Scenario: mirror only the matching Rake task
+ Given a full-featured Rakefile defining a Ruby-method-shadowing task
+ And a Capfile with:
+ """
+ Cape do
+ mirror_rake_tasks :load do |recipes|
+ recipes.rename do |task_name|
+ "do_#{task_name}"
+ end
+ recipes.cd { release_path }
+ recipes.env['RAILS_ENV'] = lambda { rails_env }
+ end
+ end
+ """
+ When I run `cap -vT`
+ Then the output should contain:
+ """
+ cap do_load # A task that shadows a Ruby method.
+ """
+ And the output should not contain "period"
+ And the output should not contain "my_namespace"
+
+ Scenario: mirror the matching Rake task with its implementation
+ Given a full-featured Rakefile defining a Ruby-method-shadowing task
+ And a Capfile with:
+ """
+ set :release_path, '/release/path'
+ set :rails_env, 'rails-env'
+
+ Cape do
+ mirror_rake_tasks :load do |recipes|
+ recipes.rename do |task_name|
+ "do_#{task_name}"
+ end
+ recipes.cd { release_path }
+ recipes.env['RAILS_ENV'] = lambda { rails_env }
+ end
+ end
+ """
+ When I run `cap do_load`
+ Then the output should contain:
+ """
+ * executing `do_load'
+ * executing "cd /release/path && /usr/bin/env `/usr/bin/env bundle check >/dev/null 2>&1; case $? in 0|1 ) echo bundle exec ;; esac` rake load RAILS_ENV=\"rails-env\""
+ `do_load' is only run for servers matching {}, but no servers matched
+ """
View
50 features/dsl/mirror_rake_tasks/with_defined_task_and_rename_and_environment_variables.feature
@@ -0,0 +1,50 @@
+Feature: The #mirror_rake_tasks DSL method with a defined task, renaming logic, and environment variables
+
+ In order to include Rake tasks with descriptions in my Capistrano recipes,
+ As a developer using Cape,
+ I want to use the Cape DSL.
+
+ Scenario: mirror only the matching Rake task
+ Given a full-featured Rakefile defining a Ruby-method-shadowing task
+ And a Capfile with:
+ """
+ Cape do
+ mirror_rake_tasks :load do |recipes|
+ recipes.rename do |task_name|
+ "do_#{task_name}"
+ end
+ recipes.env['RAILS_ENV'] = lambda { rails_env }
+ end
+ end
+ """
+ When I run `cap -vT`
+ Then the output should contain:
+ """
+ cap do_load # A task that shadows a Ruby method.
+ """
+ And the output should not contain "period"
+ And the output should not contain "my_namespace"
+
+ Scenario: mirror the matching Rake task with its implementation
+ Given a full-featured Rakefile defining a Ruby-method-shadowing task
+ And a Capfile with:
+ """
+ set :current_path, '/current/path'
+ set :rails_env, 'rails-env'
+
+ Cape do
+ mirror_rake_tasks :load do |recipes|
+ recipes.rename do |task_name|
+ "do_#{task_name}"
+ end
+ recipes.env['RAILS_ENV'] = lambda { rails_env }
+ end
+ end
+ """
+ When I run `cap do_load`
+ Then the output should contain:
+ """
+ * executing `do_load'
+ * executing "cd /current/path && /usr/bin/env `/usr/bin/env bundle check >/dev/null 2>&1; case $? in 0|1 ) echo bundle exec ;; esac` rake load RAILS_ENV=\"rails-env\""
+ `do_load' is only run for servers matching {}, but no servers matched
+ """
View
49 features/dsl/mirror_rake_tasks/with_defined_task_and_rename_and_valid_options.feature
@@ -0,0 +1,49 @@
+Feature: The #mirror_rake_tasks DSL method with a defined task, renaming logic, and valid options
+
+ In order to include Rake tasks with descriptions in my Capistrano recipes,
+ As a developer using Cape,
+ I want to use the Cape DSL.
+
+ Scenario: mirror only the matching Rake task
+ Given a full-featured Rakefile defining a Ruby-method-shadowing task
+ And a Capfile with:
+ """
+ Cape do
+ mirror_rake_tasks :load do |recipes|
+ recipes.rename do |task_name|
+ "do_#{task_name}"
+ end
+ recipes.options[:roles] = :app
+ end
+ end
+ """
+ When I run `cap -vT`
+ Then the output should contain:
+ """
+ cap do_load # A task that shadows a Ruby method.
+ """
+ And the output should not contain "period"
+ And the output should not contain "my_namespace"
+
+ Scenario: mirror the matching Rake task with its implementation
+ Given a full-featured Rakefile defining a Ruby-method-shadowing task
+ And a Capfile with:
+ """
+ set :current_path, '/current/path'
+
+ Cape do
+ mirror_rake_tasks :load do |recipes|
+ recipes.rename do |task_name|
+ "do_#{task_name}"
+ end
+ recipes.options[:roles] = :app
+ end
+ end
+ """
+ When I run `cap do_load`
+ Then the output should contain:
+ """
+ * executing `do_load'
+ * executing "cd /current/path && /usr/bin/env `/usr/bin/env bundle check >/dev/null 2>&1; case $? in 0|1 ) echo bundle exec ;; esac` rake load"
+ `do_load' is only run for servers matching {:roles=>:app}, but no servers matched
+ """
View
51 features/dsl/mirror_rake_tasks/with_defined_task_and_rename_and_valid_options_and_cd.feature
@@ -0,0 +1,51 @@
+Feature: The #mirror_rake_tasks DSL method with a defined task, renaming logic, valid options, and a different directory
+
+ In order to include Rake tasks with descriptions in my Capistrano recipes,
+ As a developer using Cape,
+ I want to use the Cape DSL.
+
+ Scenario: mirror only the matching Rake task
+ Given a full-featured Rakefile defining a Ruby-method-shadowing task
+ And a Capfile with:
+ """
+ Cape do
+ mirror_rake_tasks :load do |recipes|
+ recipes.rename do |task_name|
+ "do_#{task_name}"
+ end
+ recipes.options[:roles] = :app
+ recipes.cd { release_path }
+ end
+ end
+ """
+ When I run `cap -vT`
+ Then the output should contain:
+ """
+ cap do_load # A task that shadows a Ruby method.
+ """
+ And the output should not contain "period"
+ And the output should not contain "my_namespace"
+
+ Scenario: mirror the matching Rake task with its implementation
+ Given a full-featured Rakefile defining a Ruby-method-shadowing task
+ And a Capfile with:
+ """
+ set :release_path, '/release/path'
+
+ Cape do
+ mirror_rake_tasks :load do |recipes|
+ recipes.rename do |task_name|
+ "do_#{task_name}"
+ end
+ recipes.options[:roles] = :app
+ recipes.cd { release_path }
+ end
+ end
+ """
+ When I run `cap do_load`
+ Then the output should contain:
+ """
+ * executing `do_load'
+ * executing "cd /release/path && /usr/bin/env `/usr/bin/env bundle check >/dev/null 2>&1; case $? in 0|1 ) echo bundle exec ;; esac` rake load"
+ `do_load' is only run for servers matching {:roles=>:app}, but no servers matched
+ """
View
54 ...irror_rake_tasks/with_defined_task_and_rename_and_valid_options_and_cd_and_environment_variables.feature
@@ -0,0 +1,54 @@
+Feature: The #mirror_rake_tasks DSL method with a defined task, renaming logic, valid options, a different directory, and environment variables
+
+ In order to include Rake tasks with descriptions in my Capistrano recipes,
+ As a developer using Cape,
+ I want to use the Cape DSL.
+
+ Scenario: mirror only the matching Rake task
+ Given a full-featured Rakefile defining a Ruby-method-shadowing task
+ And a Capfile with:
+ """
+ Cape do
+ mirror_rake_tasks :load do |recipes|
+ recipes.rename do |task_name|
+ "do_#{task_name}"
+ end
+ recipes.options[:roles] = :app
+ recipes.cd { release_path }
+ recipes.env['RAILS_ENV'] = lambda { rails_env }
+ end
+ end
+ """
+ When I run `cap -vT`
+ Then the output should contain:
+ """
+ cap do_load # A task that shadows a Ruby method.
+ """
+ And the output should not contain "period"
+ And the output should not contain "my_namespace"
+
+ Scenario: mirror the matching Rake task with its implementation
+ Given a full-featured Rakefile defining a Ruby-method-shadowing task
+ And a Capfile with:
+ """
+ set :release_path, '/release/path'
+ set :rails_env, 'rails-env'
+
+ Cape do
+ mirror_rake_tasks :load do |recipes|
+ recipes.rename do |task_name|
+ "do_#{task_name}"
+ end
+ recipes.options[:roles] = :app
+ recipes.cd { release_path }
+ recipes.env['RAILS_ENV'] = lambda { rails_env }
+ end
+ end
+ """
+ When I run `cap do_load`
+ Then the output should contain:
+ """
+ * executing `do_load'
+ * executing "cd /release/path && /usr/bin/env `/usr/bin/env bundle check >/dev/null 2>&1; case $? in 0|1 ) echo bundle exec ;; esac` rake load RAILS_ENV=\"rails-env\""
+ `do_load' is only run for servers matching {:roles=>:app}, but no servers matched
+ """
View
52 ...s/dsl/mirror_rake_tasks/with_defined_task_and_rename_and_valid_options_and_environment_variables.feature
@@ -0,0 +1,52 @@
+Feature: The #mirror_rake_tasks DSL method with a defined task, renaming logic, valid options, and environment variables
+
+ In order to include Rake tasks with descriptions in my Capistrano recipes,
+ As a developer using Cape,
+ I want to use the Cape DSL.
+
+ Scenario: mirror only the matching Rake task
+ Given a full-featured Rakefile defining a Ruby-method-shadowing task
+ And a Capfile with:
+ """
+ Cape do
+ mirror_rake_tasks :load do |recipes|
+ recipes.rename do |task_name|
+ "do_#{task_name}"
+ end
+ recipes.options[:roles] = :app
+ recipes.env['RAILS_ENV'] = lambda { rails_env }
+ end
+ end
+ """
+ When I run `cap -vT`
+ Then the output should contain:
+ """
+ cap do_load # A task that shadows a Ruby method.
+ """
+ And the output should not contain "period"
+ And the output should not contain "my_namespace"
+
+ Scenario: mirror the matching Rake task with its implementation
+ Given a full-featured Rakefile defining a Ruby-method-shadowing task
+ And a Capfile with:
+ """
+ set :current_path, '/current/path'
+ set :rails_env, 'rails-env'
+
+ Cape do
+ mirror_rake_tasks :load do |recipes|
+ recipes.rename do |task_name|
+ "do_#{task_name}"
+ end
+ recipes.options[:roles] = :app
+ recipes.env['RAILS_ENV'] = lambda { rails_env }
+ end
+ end
+ """
+ When I run `cap do_load`
+ Then the output should contain:
+ """
+ * executing `do_load'
+ * executing "cd /current/path && /usr/bin/env `/usr/bin/env bundle check >/dev/null 2>&1; case $? in 0|1 ) echo bundle exec ;; esac` rake load RAILS_ENV=\"rails-env\""
+ `do_load' is only run for servers matching {:roles=>:app}, but no servers matched
+ """
View
51 features/dsl/mirror_rake_tasks/with_defined_task_and_valid_options.feature
@@ -4,7 +4,8 @@ Feature: The #mirror_rake_tasks DSL method with a defined task and valid options
As a developer using Cape,
I want to use the Cape DSL.
- Scenario: mirror only the matching Rake task
+ @deprecated
+ Scenario: mirror only the matching Rake task (deprecated)
Given a full-featured Rakefile
And a Capfile with:
"""
@@ -19,8 +20,32 @@ Feature: The #mirror_rake_tasks DSL method with a defined task and valid options
"""
And the output should not contain "without_period"
And the output should not contain "my_namespace"
+ And the output should contain:
+ """
+ *** DEPRECATED: `mirror_rake_tasks :with_period, :roles => :app`. Use this instead: `mirror_rake_tasks(:with_period) { |recipes| recipes.options[:roles] = :app }`
+ """
- Scenario: mirror the matching Rake task with its implementation
+ Scenario: mirror only the matching Rake task
+ Given a full-featured Rakefile
+ And a Capfile with:
+ """
+ Cape do
+ mirror_rake_tasks :with_period do |recipes|
+ recipes.options[:roles] = :app
+ end
+ end
+ """
+ When I run `cap -vT`
+ Then the output should contain:
+ """
+ cap with_period # Ends with period.
+ """
+ And the output should not contain "without_period"
+ And the output should not contain "my_namespace"
+ And the output should not contain "DEPRECATED"
+
+ @deprecated
+ Scenario: mirror the matching Rake task with its implementation (deprecated)
Given a full-featured Rakefile
And a Capfile with:
"""
@@ -33,7 +58,29 @@ Feature: The #mirror_rake_tasks DSL method with a defined task and valid options
When I run `cap with_period`
Then the output should contain:
"""
+ *** DEPRECATED: `mirror_rake_tasks "with_period", :roles => :app`. Use this instead: `mirror_rake_tasks("with_period") { |recipes| recipes.options[:roles] = :app }`
+ * executing `with_period'
+ * executing "cd /current/path && /usr/bin/env `/usr/bin/env bundle check >/dev/null 2>&1; case $? in 0|1 ) echo bundle exec ;; esac` rake with_period"
+ `with_period' is only run for servers matching {:roles=>:app}, but no servers matched
+ """
+
+ Scenario: mirror the matching Rake task with its implementation
+ Given a full-featured Rakefile
+ And a Capfile with:
+ """
+ set :current_path, '/current/path'
+
+ Cape do
+ mirror_rake_tasks 'with_period' do |recipes|
+ recipes.options[:roles] = :app
+ end
+ end
+ """
+ When I run `cap with_period`
+ Then the output should contain:
+ """
* executing `with_period'
* executing "cd /current/path && /usr/bin/env `/usr/bin/env bundle check >/dev/null 2>&1; case $? in 0|1 ) echo bundle exec ;; esac` rake with_period"
`with_period' is only run for servers matching {:roles=>:app}, but no servers matched
"""
+ And the output should not contain "DEPRECATED"
View
45 features/dsl/mirror_rake_tasks/with_defined_task_and_valid_options_and_cd.feature
@@ -0,0 +1,45 @@
+Feature: The #mirror_rake_tasks DSL method with a defined task, valid options, and a different directory
+
+ In order to include Rake tasks with descriptions in my Capistrano recipes,
+ As a developer using Cape,
+ I want to use the Cape DSL.
+
+ Scenario: mirror only the matching Rake task
+ Given a full-featured Rakefile
+ And a Capfile with:
+ """
+ Cape do
+ mirror_rake_tasks :with_period do |recipes|
+ recipes.options[:roles] = :app
+ recipes.cd { release_path }
+ end
+ end
+ """
+ When I run `cap -vT`
+ Then the output should contain:
+ """
+ cap with_period # Ends with period.
+ """
+ And the output should not contain "without_period"
+ And the output should not contain "my_namespace"
+
+ Scenario: mirror the matching Rake task with its implementation
+ Given a full-featured Rakefile
+ And a Capfile with:
+ """
+ set :release_path, '/release/path'
+
+ Cape do
+ mirror_rake_tasks :with_period do |recipes|
+ recipes.options[:roles] = :app
+ recipes.cd { release_path }
+ end
+ end
+ """
+ When I run `cap with_period`
+ Then the output should contain:
+ """
+ * executing `with_period'
+ * executing "cd /release/path && /usr/bin/env `/usr/bin/env bundle check >/dev/null 2>&1; case $? in 0|1 ) echo bundle exec ;; esac` rake with_period"
+ `with_period' is only run for servers matching {:roles=>:app}, but no servers matched
+ """
View
48 features/dsl/mirror_rake_tasks/with_defined_task_and_valid_options_and_cd_and_environment_variables.feature
@@ -0,0 +1,48 @@
+Feature: The #mirror_rake_tasks DSL method with a defined task, valid options, a different directory, and environment variables
+
+ In order to include Rake tasks with descriptions in my Capistrano recipes,
+ As a developer using Cape,
+ I want to use the Cape DSL.
+
+ Scenario: mirror only the matching Rake task
+ Given a full-featured Rakefile
+ And a Capfile with:
+ """
+ Cape do
+ mirror_rake_tasks :with_period do |recipes|
+ recipes.options[:roles] = :app
+ recipes.cd { release_path }
+ recipes.env['RAILS_ENV'] = lambda { rails_env }
+ end
+ end
+ """
+ When I run `cap -vT`
+ Then the output should contain:
+ """
+ cap with_period # Ends with period.
+ """
+ And the output should not contain "without_period"
+ And the output should not contain "my_namespace"
+
+ Scenario: mirror the matching Rake task with its implementation
+ Given a full-featured Rakefile
+ And a Capfile with:
+ """
+ set :release_path, '/release/path'
+ set :rails_env, 'rails-env'
+
+ Cape do
+ mirror_rake_tasks :with_period do |recipes|
+ recipes.options[:roles] = :app
+ recipes.cd { release_path }
+ recipes.env['RAILS_ENV'] = lambda { rails_env }
+ end
+ end
+ """
+ When I run `cap with_period`
+ Then the output should contain:
+ """
+ * executing `with_period'
+ * executing "cd /release/path && /usr/bin/env `/usr/bin/env bundle check >/dev/null 2>&1; case $? in 0|1 ) echo bundle exec ;; esac` rake with_period RAILS_ENV=\"rails-env\""
+ `with_period' is only run for servers matching {:roles=>:app}, but no servers matched
+ """
View
58 features/dsl/mirror_rake_tasks/with_defined_task_and_valid_options_and_environment_variables.feature
@@ -4,7 +4,8 @@ Feature: The #mirror_rake_tasks DSL method with a defined task, valid options, a
As a developer using Cape,
I want to use the Cape DSL.
- Scenario: mirror only the matching Rake task
+ @deprecated
+ Scenario: mirror only the matching Rake task (deprecated)
Given a full-featured Rakefile
And a Capfile with:
"""
@@ -21,8 +22,37 @@ Feature: The #mirror_rake_tasks DSL method with a defined task, valid options, a
"""
And the output should not contain "without_period"
And the output should not contain "my_namespace"
+ And the output should contain:
+ """
+ *** DEPRECATED: `mirror_rake_tasks :with_period, :roles => :app`. Use this instead: `mirror_rake_tasks(:with_period) { |recipes| recipes.options[:roles] = :app }`
+ """
+ And the output should contain:
+ """
+ *** DEPRECATED: Referencing Capistrano variables from Cape without wrapping them in a block, a lambda, or another callable object
+ """
- Scenario: mirror the matching Rake task with its implementation
+ Scenario: mirror only the matching Rake task
+ Given a full-featured Rakefile
+ And a Capfile with:
+ """
+ Cape do
+ mirror_rake_tasks :with_period do |recipes|
+ recipes.options[:roles] = :app
+ recipes.env['RAILS_ENV'] = lambda { rails_env }
+ end
+ end
+ """
+ When I run `cap -vT`
+ Then the output should contain:
+ """
+ cap with_period # Ends with period.
+ """
+ And the output should not contain "without_period"
+ And the output should not contain "my_namespace"
+ And the output should not contain "DEPRECATED"
+
+ @deprecated
+ Scenario: mirror the matching Rake task with its implementation (deprecated)
Given a full-featured Rakefile
And a Capfile with:
"""
@@ -38,7 +68,31 @@ Feature: The #mirror_rake_tasks DSL method with a defined task, valid options, a
When I run `cap with_period`
Then the output should contain:
"""
+ *** DEPRECATED: `mirror_rake_tasks("with_period", :roles => :app) { |env| env["RAILS_ENV"] = "rails-env" }`. Use this instead: `mirror_rake_tasks("with_period") { |recipes| recipes.options[:roles] = :app; recipes.env["RAILS_ENV"] = "rails-env" }`
+ * executing `with_period'
+ * executing "cd /current/path && /usr/bin/env `/usr/bin/env bundle check >/dev/null 2>&1; case $? in 0|1 ) echo bundle exec ;; esac` rake with_period RAILS_ENV=\"rails-env\""
+ `with_period' is only run for servers matching {:roles=>:app}, but no servers matched
+ """
+
+ Scenario: mirror the matching Rake task with its implementation
+ Given a full-featured Rakefile
+ And a Capfile with:
+ """
+ set :current_path, '/current/path'
+ set :rails_env, 'rails-env'
+
+ Cape do
+ mirror_rake_tasks 'with_period' do |recipes|
+ recipes.options[:roles] = :app
+ recipes.env['RAILS_ENV'] = lambda { rails_env }
+ end
+ end
+ """
+ When I run `cap with_period`
+ Then the output should contain:
+ """
* executing `with_period'
* executing "cd /current/path && /usr/bin/env `/usr/bin/env bundle check >/dev/null 2>&1; case $? in 0|1 ) echo bundle exec ;; esac` rake with_period RAILS_ENV=\"rails-env\""
`with_period' is only run for servers matching {:roles=>:app}, but no servers matched
"""
+ And the output should not contain "DEPRECATED"
View
59 features/dsl/mirror_rake_tasks/with_environment_variables.feature
@@ -4,7 +4,38 @@ Feature: The #mirror_rake_tasks DSL method with environment variables
As a developer using Cape,
I want to use the Cape DSL.
- Scenario: mirror a Rake task with its implementation
+ @deprecated
+ Scenario: mirror only the matching Rake task (deprecated)
+ Given a full-featured Rakefile
+ And a Capfile with:
+ """
+ Cape do
+ mirror_rake_tasks do |env|
+ env['RAILS_ENV'] = rails_env
+ end
+ end
+ """
+ When I run `cap -vT`
+ And the output should contain:
+ """
+ *** DEPRECATED: Referencing Capistrano variables from Cape without wrapping them in a block, a lambda, or another callable object
+ """
+
+ Scenario: mirror only the matching Rake task
+ Given a full-featured Rakefile
+ And a Capfile with:
+ """
+ Cape do
+ mirror_rake_tasks do |recipes|
+ recipes.env['RAILS_ENV'] = lambda { rails_env }
+ end
+ end
+ """
+ When I run `cap -vT`
+ And the output should not contain "DEPRECATED"
+
+ @deprecated
+ Scenario: mirror a Rake task with its implementation (deprecated)
Given a full-featured Rakefile
And a Capfile with:
"""
@@ -23,7 +54,33 @@ Feature: The #mirror_rake_tasks DSL method with environment variables
When I run `cap with_period`
Then the output should contain:
"""
+ *** DEPRECATED: `mirror_rake_tasks { |env| env["RAILS_ENV"] = "rails-env"; env[nil] = "foo"; env["FOO"] = nil; env["SOME_OTHER"] = "var" }`. Use this instead: `mirror_rake_tasks { |recipes| recipes.env["RAILS_ENV"] = "rails-env"; recipes.env[nil] = "foo"; recipes.env["FOO"] = nil; recipes.env["SOME_OTHER"] = "var" }`
+ * executing `with_period'
+ * executing "cd /current/path && /usr/bin/env `/usr/bin/env bundle check >/dev/null 2>&1; case $? in 0|1 ) echo bundle exec ;; esac` rake with_period RAILS_ENV=\"rails-env\" SOME_OTHER=\"var\""
+ `with_period' is only run for servers matching {}, but no servers matched
+ """
+
+ Scenario: mirror a Rake task with its implementation
+ Given a full-featured Rakefile
+ And a Capfile with:
+ """
+ set :current_path, '/current/path'
+ set :rails_env, 'rails-env'
+
+ Cape do
+ mirror_rake_tasks do |recipes|
+ recipes.env['RAILS_ENV'] = lambda { rails_env }
+ recipes.env[nil] = 'foo'
+ recipes.env['FOO'] = nil
+ recipes.env['SOME_OTHER'] = 'var'
+ end
+ end
+ """
+ When I run `cap with_period`
+ Then the output should contain:
+ """
* executing `with_period'
* executing "cd /current/path && /usr/bin/env `/usr/bin/env bundle check >/dev/null 2>&1; case $? in 0|1 ) echo bundle exec ;; esac` rake with_period RAILS_ENV=\"rails-env\" SOME_OTHER=\"var\""
`with_period' is only run for servers matching {}, but no servers matched
"""
+ And the output should not contain "DEPRECATED"
View
27 features/dsl/mirror_rake_tasks/with_rename.feature
@@ -0,0 +1,27 @@
+Feature: The #mirror_rake_tasks DSL method with renaming logic
+
+ In order to include Rake tasks with descriptions in my Capistrano recipes,
+ As a developer using Cape,
+ I want to use the Cape DSL.
+
+ Scenario: mirror a Ruby-method-shadowing Rake task with its implementation
+ Given a full-featured Rakefile defining a Ruby-method-shadowing task
+ And a Capfile with:
+ """
+ set :current_path, '/current/path'
+
+ Cape do
+ mirror_rake_tasks do |recipes|
+ recipes.rename do |task_name|
+ "do_#{task_name}"
+ end
+ end
+ end
+ """
+ When I run `cap do_load`
+ Then the output should contain:
+ """
+ * executing `do_load'
+ * executing "cd /current/path && /usr/bin/env `/usr/bin/env bundle check >/dev/null 2>&1; case $? in 0|1 ) echo bundle exec ;; esac` rake load"
+ `do_load' is only run for servers matching {}, but no servers matched
+ """
View
28 features/dsl/mirror_rake_tasks/with_rename_and_cd.feature
@@ -0,0 +1,28 @@
+Feature: The #mirror_rake_tasks DSL method with renaming logic and a different directory
+
+ In order to include Rake tasks with descriptions in my Capistrano recipes,
+ As a developer using Cape,
+ I want to use the Cape DSL.
+
+ Scenario: mirror a Ruby-method-shadowing Rake task with its implementation
+ Given a full-featured Rakefile defining a Ruby-method-shadowing task
+ And a Capfile with:
+ """
+ set :release_path, '/release/path'
+
+ Cape do
+ mirror_rake_tasks do |recipes|
+ recipes.rename do |task_name|
+ "do_#{task_name}"
+ end
+ recipes.cd { release_path }
+ end
+ end
+ """
+ When I run `cap do_load`
+ Then the output should contain:
+ """
+ * executing `do_load'
+ * executing "cd /release/path && /usr/bin/env `/usr/bin/env bundle check >/dev/null 2>&1; case $? in 0|1 ) echo bundle exec ;; esac` rake load"
+ `do_load' is only run for servers matching {}, but no servers matched
+ """
View
30 features/dsl/mirror_rake_tasks/with_rename_and_cd_and_environment_variables.feature
@@ -0,0 +1,30 @@
+Feature: The #mirror_rake_tasks DSL method with renaming logic, a different directory, and environment variables
+
+ In order to include Rake tasks with descriptions in my Capistrano recipes,
+ As a developer using Cape,
+ I want to use the Cape DSL.
+
+ Scenario: mirror a Ruby-method-shadowing Rake task with its implementation
+ Given a full-featured Rakefile defining a Ruby-method-shadowing task
+ And a Capfile with:
+ """
+ set :release_path, '/release/path'
+ set :rails_env, 'rails-env'
+
+ Cape do
+ mirror_rake_tasks do |recipes|
+ recipes.rename do |task_name|
+ "do_#{task_name}"
+ end
+ recipes.cd { release_path }
+ recipes.env['RAILS_ENV'] = lambda { rails_env }
+ end
+ end
+ """
+ When I run `cap do_load`
+ Then the output should contain:
+ """
+ * executing `do_load'
+ * executing "cd /release/path && /usr/bin/env `/usr/bin/env bundle check >/dev/null 2>&1; case $? in 0|1 ) echo bundle exec ;; esac` rake load RAILS_ENV=\"rails-env\""
+ `do_load' is only run for servers matching {}, but no servers matched
+ """
View
29 features/dsl/mirror_rake_tasks/with_rename_and_environment_variables.feature
@@ -0,0 +1,29 @@
+Feature: The #mirror_rake_tasks DSL method with renaming logic and environment variables
+
+ In order to include Rake tasks with descriptions in my Capistrano recipes,
+ As a developer using Cape,
+ I want to use the Cape DSL.
+
+ Scenario: mirror a Ruby-method-shadowing Rake task with its implementation
+ Given a full-featured Rakefile defining a Ruby-method-shadowing task
+ And a Capfile with:
+ """
+ set :current_path, '/current/path'
+ set :rails_env, 'rails-env'
+
+ Cape do
+ mirror_rake_tasks do |recipes|
+ recipes.rename do |task_name|
+ "do_#{task_name}"
+ end
+ recipes.env['RAILS_ENV'] = lambda { rails_env }
+ end
+ end
+ """
+ When I run `cap do_load`
+ Then the output should contain:
+ """
+ * executing `do_load'
+ * executing "cd /current/path && /usr/bin/env `/usr/bin/env bundle check >/dev/null 2>&1; case $? in 0|1 ) echo bundle exec ;; esac` rake load RAILS_ENV=\"rails-env\""
+ `do_load' is only run for servers matching {}, but no servers matched
+ """
View
28 features/dsl/mirror_rake_tasks/with_rename_and_valid_options.feature
@@ -0,0 +1,28 @@
+Feature: The #mirror_rake_tasks DSL method with renaming logic and valid options
+
+ In order to include Rake tasks with descriptions in my Capistrano recipes,
+ As a developer using Cape,
+ I want to use the Cape DSL.
+
+ Scenario: mirror a Ruby-method-shadowing Rake task with its implementation
+ Given a full-featured Rakefile defining a Ruby-method-shadowing task
+ And a Capfile with:
+ """
+ set :current_path, '/current/path'
+
+ Cape do
+ mirror_rake_tasks do |recipes|
+ recipes.rename do |task_name|
+ "do_#{task_name}"
+ end
+ recipes.options[:roles] = :app
+ end
+ end
+ """
+ When I run `cap do_load`
+ Then the output should contain:
+ """
+ * executing `do_load'
+ * executing "cd /current/path && /usr/bin/env `/usr/bin/env bundle check >/dev/null 2>&1; case $? in 0|1 ) echo bundle exec ;; esac` rake load"
+ `do_load' is only run for servers matching {:roles=>:app}, but no servers matched
+ """
View
29 features/dsl/mirror_rake_tasks/with_rename_and_valid_options_and_cd.feature
@@ -0,0 +1,29 @@
+Feature: The #mirror_rake_tasks DSL method with renaming logic, valid options, and a different directory
+
+ In order to include Rake tasks with descriptions in my Capistrano recipes,
+ As a developer using Cape,
+ I want to use the Cape DSL.
+
+ Scenario: mirror a Ruby-method-shadowing Rake task with its implementation
+ Given a full-featured Rakefile defining a Ruby-method-shadowing task
+ And a Capfile with:
+ """
+ set :release_path, '/release/path'
+
+ Cape do
+ mirror_rake_tasks do |recipes|
+ recipes.rename do |task_name|
+ "do_#{task_name}"
+ end
+ recipes.options[:roles] = :app
+ recipes.cd { release_path }
+ end
+ end
+ """
+ When I run `cap do_load`
+ Then the output should contain:
+ """
+ * executing `do_load'
+ * executing "cd /release/path && /usr/bin/env `/usr/bin/env bundle check >/dev/null 2>&1; case $? in 0|1 ) echo bundle exec ;; esac` rake load"
+ `do_load' is only run for servers matching {:roles=>:app}, but no servers matched
+ """
View
31 features/dsl/mirror_rake_tasks/with_rename_and_valid_options_and_cd_and_environment_variables.feature
@@ -0,0 +1,31 @@
+Feature: The #mirror_rake_tasks DSL method with renaming logic, valid options, a different directory, and enviroment variables
+
+ In order to include Rake tasks with descriptions in my Capistrano recipes,
+ As a developer using Cape,
+ I want to use the Cape DSL.
+
+ Scenario: mirror a Ruby-method-shadowing Rake task with its implementation
+ Given a full-featured Rakefile defining a Ruby-method-shadowing task
+ And a Capfile with:
+ """
+ set :release_path, '/release/path'
+ set :rails_env, 'rails-env'
+
+ Cape do
+ mirror_rake_tasks do |recipes|
+ recipes.rename do |task_name|
+ "do_#{task_name}"
+ end
+ recipes.options[:roles] = :app
+ recipes.cd { release_path }
+ recipes.env['RAILS_ENV'] = lambda { rails_env }
+ end
+ end
+ """
+ When I run `cap do_load`
+ Then the output should contain:
+ """
+ * executing `do_load'
+ * executing "cd /release/path && /usr/bin/env `/usr/bin/env bundle check >/dev/null 2>&1; case $? in 0|1 ) echo bundle exec ;; esac` rake load RAILS_ENV=\"rails-env\""
+ `do_load' is only run for servers matching {:roles=>:app}, but no servers matched
+ """
View
30 features/dsl/mirror_rake_tasks/with_rename_and_valid_options_and_environment_variables.feature
@@ -0,0 +1,30 @@
+Feature: The #mirror_rake_tasks DSL method with renaming logic, valid options, and enviroment variables
+
+ In order to include Rake tasks with descriptions in my Capistrano recipes,
+ As a developer using Cape,
+ I want to use the Cape DSL.
+
+ Scenario: mirror a Ruby-method-shadowing Rake task with its implementation
+ Given a full-featured Rakefile defining a Ruby-method-shadowing task
+ And a Capfile with:
+ """
+ set :current_path, '/current/path'
+ set :rails_env, 'rails-env'
+
+ Cape do
+ mirror_rake_tasks do |recipes|
+ recipes.rename do |task_name|
+ "do_#{task_name}"
+ end
+ recipes.options[:roles] = :app
+ recipes.env['RAILS_ENV'] = lambda { rails_env }
+ end
+ end
+ """
+ When I run `cap do_load`
+ Then the output should contain:
+ """
+ * executing `do_load'
+ * executing "cd /current/path && /usr/bin/env `/usr/bin/env bundle check >/dev/null 2>&1; case $? in 0|1 ) echo bundle exec ;; esac` rake load RAILS_ENV=\"rails-env\""
+ `do_load' is only run for servers matching {:roles=>:app}, but no servers matched
+ """
View
25 features/dsl/mirror_rake_tasks/with_valid_options.feature
@@ -4,7 +4,8 @@ Feature: The #mirror_rake_tasks DSL method with valid options
As a developer using Cape,
I want to use the Cape DSL.
- Scenario: mirror a Rake task with its implementation
+ @deprecated
+ Scenario: mirror a Rake task with its implementation (deprecated)
Given a full-featured Rakefile
And a Capfile with:
"""
@@ -17,7 +18,29 @@ Feature: The #mirror_rake_tasks DSL method with valid options
When I run `cap with_period`
Then the output should contain:
"""
+ *** DEPRECATED: `mirror_rake_tasks :roles => :app`. Use this instead: `mirror_rake_tasks { |recipes| recipes.options[:roles] = :app }`
+ * executing `with_period'
+ * executing "cd /current/path && /usr/bin/env `/usr/bin/env bundle check >/dev/null 2>&1; case $? in 0|1 ) echo bundle exec ;; esac` rake with_period"
+ `with_period' is only run for servers matching {:roles=>:app}, but no servers matched
+ """
+
+ Scenario: mirror a Rake task with its implementation
+ Given a full-featured Rakefile
+ And a Capfile with:
+ """
+ set :current_path, '/current/path'
+
+ Cape do
+ mirror_rake_tasks do |recipes|
+ recipes.options[:roles] = :app
+ end
+ end
+ """
+ When I run `cap with_period`
+ Then the output should contain:
+ """
* executing `with_period'
* executing "cd /current/path && /usr/bin/env `/usr/bin/env bundle check >/dev/null 2>&1; case $? in 0|1 ) echo bundle exec ;; esac` rake with_period"
`with_period' is only run for servers matching {:roles=>:app}, but no servers matched
"""
+ And the output should not contain "DEPRECATED"
View
26 features/dsl/mirror_rake_tasks/with_valid_options_and_cd.feature
@@ -0,0 +1,26 @@
+Feature: The #mirror_rake_tasks DSL method with valid options and a different directory
+
+ In order to include Rake tasks with descriptions in my Capistrano recipes,
+ As a developer using Cape,
+ I want to use the Cape DSL.
+
+ Scenario: mirror a Rake task with its implementation
+ Given a full-featured Rakefile
+ And a Capfile with:
+ """
+ set :release_path, '/release/path'
+
+ Cape do
+ mirror_rake_tasks do |recipes|
+ recipes.options[:roles] = :app
+ recipes.cd { release_path }
+ end
+ end
+ """
+ When I run `cap with_period`
+ Then the output should contain:
+ """
+ * executing `with_period'
+ * executing "cd /release/path && /usr/bin/env `/usr/bin/env bundle check >/dev/null 2>&1; case $? in 0|1 ) echo bundle exec ;; esac` rake with_period"
+ `with_period' is only run for servers matching {:roles=>:app}, but no servers matched
+ """
View
28 features/dsl/mirror_rake_tasks/with_valid_options_and_cd_and_environment_variables.feature
@@ -0,0 +1,28 @@
+Feature: The #mirror_rake_tasks DSL method with valid options, a different directory, and environment variables
+
+ In order to include Rake tasks with descriptions in my Capistrano recipes,
+ As a developer using Cape,
+ I want to use the Cape DSL.
+
+ Scenario: mirror the matching Rake task with its implementation
+ Given a full-featured Rakefile
+ And a Capfile with:
+ """
+ set :release_path, '/release/path'
+ set :rails_env, 'rails-env'
+
+ Cape do
+ mirror_rake_tasks do |recipes|
+ recipes.options[:roles] = :app
+ recipes.cd { release_path }
+ recipes.env['RAILS_ENV'] = lambda { rails_env }
+ end
+ end
+ """
+ When I run `cap with_period`
+ Then the output should contain:
+ """
+ * executing `with_period'
+ * executing "cd /release/path && /usr/bin/env `/usr/bin/env bundle check >/dev/null 2>&1; case $? in 0|1 ) echo bundle exec ;; esac` rake with_period RAILS_ENV=\"rails-env\""
+ `with_period' is only run for servers matching {:roles=>:app}, but no servers matched
+ """
View
27 features/dsl/mirror_rake_tasks/with_valid_options_and_environment_variables.feature
@@ -4,7 +4,8 @@ Feature: The #mirror_rake_tasks DSL method with valid options and environment va
As a developer using Cape,
I want to use the Cape DSL.
- Scenario: mirror a Rake task with its implementation
+ @deprecated
+ Scenario: mirror the matching Rake task with its implementation (deprecated)
Given a full-featured Rakefile
And a Capfile with:
"""
@@ -20,7 +21,31 @@ Feature: The #mirror_rake_tasks DSL method with valid options and environment va
When I run `cap with_period`
Then the output should contain:
"""
+ *** DEPRECATED: `mirror_rake_tasks(:roles => :app) { |env| env["RAILS_ENV"] = "rails-env" }`. Use this instead: `mirror_rake_tasks { |recipes| recipes.options[:roles] = :app; recipes.env["RAILS_ENV"] = "rails-env" }`
* executing `with_period'
* executing "cd /current/path && /usr/bin/env `/usr/bin/env bundle check >/dev/null 2>&1; case $? in 0|1 ) echo bundle exec ;; esac` rake with_period RAILS_ENV=\"rails-env\""
`with_period' is only run for servers matching {:roles=>:app}, but no servers matched
"""
+
+ Scenario: mirror the matching Rake task with its implementation
+ Given a full-featured Rakefile
+ And a Capfile with:
+ """
+ set :current_path, '/current/path'
+ set :rails_env, 'rails-env'
+
+ Cape do
+ mirror_rake_tasks do |recipes|
+ recipes.options[:roles] = :app
+ recipes.env['RAILS_ENV'] = lambda { rails_env }
+ end
+ end
+ """
+ When I run `cap with_period`
+ Then the output should contain:
+ """
+ * executing `with_period'
+ * executing "cd /current/path && /usr/bin/env `/usr/bin/env bundle check >/dev/null 2>&1; case $? in 0|1 ) echo bundle exec ;; esac` rake with_period RAILS_ENV=\"rails-env\""
+ `with_period' is only run for servers matching {:roles=>:app}, but no servers matched
+ """
+ And the output should not contain "DEPRECATED"
View
40 features/step_definitions.rb
@@ -43,3 +43,43 @@
task :hidden_task
end_step
end
+
+Given 'a full-featured Rakefile defining a Ruby-method-shadowing task' do
+ step 'a file named "Rakefile" with:', <<-end_step
+ desc 'A task that shadows a Ruby method'
+ task :load
+
+ desc 'Ends with period.'
+ task :with_period
+
+ desc 'Ends without period'
+ task :without_period
+
+ desc 'My long task -- it has a very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very long description'
+ task :long
+
+ desc 'My task with one argument'
+ task :with_one_arg, [:the_arg]
+
+ desc 'A task that shadows a namespace'
+ task :my_namespace
+
+ namespace :my_namespace do
+ desc 'My task in a namespace'
+ task :in_a_namespace
+
+ namespace :my_nested_namespace do
+ desc 'My task in a nested namespace'
+ task :in_a_nested_namespace
+ end
+ end
+
+ desc 'My task with two arguments'
+ task :with_two_args, [:my_arg1, :my_arg2]
+
+ desc 'My task with three arguments'
+ task :with_three_args, [:an_arg1, :an_arg2, :an_arg3]
+
+ task :hidden_task
+ end_step
+end
View
1  lib/cape.rb
@@ -6,6 +6,7 @@
module Cape
extend DSL
+ extend DSLDeprecated
end
View
91 lib/cape/capistrano.rb
@@ -1,5 +1,5 @@
-require 'cape/hash_list'
require 'cape/rake'
+require 'cape/recipe_definition'
require 'cape/util'
module Cape
@@ -17,14 +17,13 @@ def initialize(attributes={})
attributes.each do |name, value|
send "#{name}=", value
end
- self.rake ||= Rake.new
+ self.rake ||= new_rake
end
# Defines a wrapper in Capistrano around the specified Rake _task_.
#
# @param [Hash] task metadata for a Rake task
- # @param [Hash] named_arguments named arguments, including options to pass to
- # the Capistrano +task+ method
+ # @param [Hash] named_arguments
#
# @option task [String] :name the name of the Rake task
# @option task [Array of String, nil] :parameters the names of the Rake
@@ -32,33 +31,28 @@ def initialize(attributes={})
# @option task [String] :description documentation for the Rake
# task
#
- # @option named_arguments [Binding] :binding the Binding of your
- # Capistrano recipes
- # file
+ # @option named_arguments [Binding] :binding the Binding of your Capistrano
+ # recipes file
#
- # @yield [env] a block that defines environment variables for the Rake task;
- # optional
- # @yieldparam [Hash] env the environment variables to set before executing
- # the Rake task
+ # @yield [recipes] a block that customizes the Capistrano recipe(s)
+ # generated for the Rake task(s); optional
+ # @yieldparam [RecipeDefinition] recipes an interface for customizing the
+ # Capistrano recipe(s) generated for
+ # the Rake task(s)
#
# @return [Capistrano] the object
#
# @raise [ArgumentError] +named_arguments[:binding]+ is missing
#
# @note Any parameters that the Rake task has are integrated via environment variables, since Capistrano does not support recipe parameters per se.
- #
- # @see http://github.com/capistrano/capistrano/blob/master/lib/capistrano/configuration/actions/invocation.rb#L99-L144 Valid Capistrano ‘task’ method options
def define_rake_wrapper(task, named_arguments, &block)
unless (binding = named_arguments[:binding])
raise ::ArgumentError, ':binding named argument is required'
end
capistrano_context = binding.eval('self', __FILE__, __LINE__)
- options = named_arguments.reject do |key, value|
- key == :binding
- end
describe task, capistrano_context
- implement(task, capistrano_context, options, &block)
+ implement(task, capistrano_context, &block)
end
private
@@ -88,6 +82,11 @@ def build_capistrano_description(task)
description.join
end
+ def capture_recipe_definition(recipe_definition, &recipe_definition_block)
+ recipe_definition_block.call(recipe_definition) if recipe_definition_block
+ true
+ end
+
def describe(task, capistrano_context)
if (description = build_capistrano_description(task))
capistrano_context.desc description
@@ -95,13 +94,18 @@ def describe(task, capistrano_context)
self
end
- def implement(task, capistrano_context, options, &env_block)
- name_tokens = task[:name].split(':')
- name_tokens << 'default' if task[:default]
+ def implement(task, capistrano_context, &recipe_definition_block)
+ name_tokens = tokenize_name(task)
+ recipe_definition = new_recipe_definition
+ capture_recipe_definition(recipe_definition, &recipe_definition_block)
+ env = nil
rake = self.rake
- # Define the recipe.
block = lambda { |context|
- context.task name_tokens.last, options do
+ recipe_name = name_tokens.last
+ if recipe_definition.rename
+ recipe_name = recipe_definition.rename.call(name_tokens.last)
+ end
+ context.task recipe_name, recipe_definition.options do
arguments = Array(task[:parameters]).collect do |a|
if (value = ENV[a.upcase])
value = value.inspect
@@ -113,17 +117,26 @@ def implement(task, capistrano_context, options, &env_block)
else
arguments = "[#{arguments.join ','}]"
end
- env_hash = HashList.new
- env_block.call(env_hash) if env_block
- env_hash.reject! do |var_name, var_value|
- var_name.nil? || var_value.nil?
- end
- env_strings = env_hash.collect do |var_name, var_value|
- "#{var_name}=#{var_value.inspect}"
+
+ unless env
+ env_strings = recipe_definition.env.collect do |var_name, var_value|
+ if var_name.nil? || var_value.nil?
+ nil
+ else
+ if var_value.is_a?(Proc)
+ var_value = context.instance_eval do
+ var_value.call
+ end
+ end
+ "#{var_name}=#{var_value.inspect}"
+ end
+ end.compact
+ env = env_strings.empty? ? nil : (' ' + env_strings.join(' '))
end
- env = env_strings.empty? ? nil : (' ' + env_strings.join(' '))
- command = "cd #{context.current_path} && " +
- "#{rake.remote_executable} " +
+
+ path = recipe_definition.cd || context.current_path
+ path = path.call if path.respond_to?(:call)
+ command = "cd #{path} && #{rake.remote_executable} " +
"#{task[:name]}#{arguments}#{env}"
context.run command
end
@@ -139,6 +152,20 @@ def implement(task, capistrano_context, options, &env_block)
self
end
+ def new_rake(*arguments)
+ Rake.new(*arguments)
+ end
+
+ def new_recipe_definition(*arguments)
+ RecipeDefinition.new(*arguments)
+ end
+
+ def tokenize_name(task)
+ task[:name].split(':').tap do |result|
+ result << 'default' if task[:default]
+ end
+ end
+
end
end
View
165 lib/cape/capistrano_deprecated.rb
@@ -0,0 +1,165 @@
+require 'cape/capistrano'
+require 'cape/deprecation/capistrano_deprecated_define_rake_wrapper'
+require 'cape/recipe_definition_deprecated'
+require 'cape/xterm'
+
+module Cape
+
+ # Implements {Capistrano} with deprecated methods.
+ #
+ # @api private
+ class CapistranoDeprecated < Capistrano
+
+ # Defines a wrapper in Capistrano around the specified Rake _task_.
+ #
+ # @deprecated Use {Capistrano#define_rake_wrapper} instead.
+ #
+ # @param [Hash] task metadata for a Rake task
+ # @param [Hash] named_arguments named arguments, including options to pass to
+ # the Capistrano +task+ method
+ #
+ # @option task [String] :name the name of the Rake task
+ # @option task [Array of String, nil] :parameters the names of the Rake
+ # task's parameters, if any
+ # @option task [String] :description documentation for the Rake
+ # task
+ #
+ # @option named_arguments [Binding] :binding the Binding of your
+ # Capistrano recipes
+ # file
+ #
+ # @yield [env] a block that defines environment variables for the Rake task;
+ # optional
+ # @yieldparam [Hash] env the environment variables to set before executing
+ # the Rake task
+ #
+ # @return [CapistranoDeprecated] the object
+ #
+ # @raise [ArgumentError] +named_arguments[:binding]+ is missing
+ #
+ # @note Any parameters that the Rake task has are integrated via environment variables, since Capistrano does not support recipe parameters per se.
+ #
+ # @see http://github.com/capistrano/capistrano/blob/master/lib/capistrano/configuration/actions/invocation.rb#L99-L144 Valid Capistrano 'task' method options
+ #
+ # @api public
+ def define_rake_wrapper(task, named_arguments, &block)
+ unless (binding = named_arguments[:binding])
+ raise ::ArgumentError, ':binding named argument is required'
+ end
+
+ deprecation.task = task
+ deprecation.named_arguments = named_arguments
+
+ capistrano_context = binding.eval('self', __FILE__, __LINE__)
+ options = named_arguments.reject do |key, value|
+ key == :binding
+ end
+ describe task, capistrano_context
+ implement(task, capistrano_context, options, &block)
+ end
+
+ # The object in which deprecated API usage is recorded.
+ #
+ # @return [Deprecation::Base]
+ def deprecation
+ @deprecation ||= Deprecation::CapistranoDeprecatedDefineRakeWrapper.new
+ end
+
+ private
+
+ def capture_recipe_definition(recipe_definition, &recipe_definition_block)
+ begin
+ super
+ rescue NoMethodError
+ unless @warned
+ deprecation.stream.puts XTerm.bold_and_foreground_red('*** DEPRECATED:') +
+ ' ' +
+ XTerm.bold('Referencing Capistrano variables ' +
+ 'from Cape without wrapping them in ' +
+ 'a block, a lambda, or another ' +
+ 'callable object')
+ @warned = true
+ end
+ return false
+ end
+ true
+ end
+
+ def implement(task, capistrano_context, options, &env_block)
+ return super(task, capistrano_context, &env_block) if options.empty?
+
+ name_tokens = tokenize_name(task)
+ recipe_definition = new_recipe_definition(deprecation)
+ env = nil
+ if capture_recipe_definition(recipe_definition, &env_block)
+ env_strings = recipe_definition.env.collect do |var_name, var_value|
+ if var_name.nil? || var_value.nil?
+ nil
+ else
+ var_value = var_value.call if var_value.is_a?(Proc)
+ "#{var_name}=#{var_value.inspect}"
+ end
+ end.compact
+ env = env_strings.empty? ? nil : (' ' + env_strings.join(' '))
+ end
+ this = env ? nil : self
+ rake = self.rake
+ block = lambda { |context|
+ recipe_name = name_tokens.last
+ if recipe_definition.rename
+ recipe_name = recipe_definition.rename.call(name_tokens.last)
+ end
+ context.task recipe_name, options do
+ arguments = Array(task[:parameters]).collect do |a|
+ if (value = ENV[a.upcase])
+ value = value.inspect
+ end
+ value
+ end
+ if arguments.empty?
+ arguments = nil
+ else
+ arguments = "[#{arguments.join ','}]"
+ end
+
+ unless env
+ if this.instance_eval { capture_recipe_definition(recipe_definition, &env_block) }
+ env_strings = recipe_definition.env.collect do |var_name, var_value|
+ if var_name.nil? || var_value.nil?
+ nil
+ else
+ var_value = var_value.call if var_value.is_a?(Proc)
+ "#{var_name}=#{var_value.inspect}"
+ end
+ end.compact
+ env = env_strings.empty? ? nil : (' ' + env_strings.join(' '))
+ this = nil
+ end
+ end
+
+ path = recipe_definition.cd || context.current_path
+ path = path.call if path.respond_to?(:call)
+ command = "cd #{path} && #{rake.remote_executable} " +
+ "#{task[:name]}#{arguments}#{env}"
+ context.run command
+ end
+ }
+ # Nest the recipe inside its containing namespaces.
+ name_tokens[0...-1].reverse.each do |namespace_token|
+ inner_block = block
+ block = lambda { |context|
+ context.namespace(namespace_token, &inner_block)
+ }
+ end
+ block.call capistrano_context
+ self
+ end
+
+ def new_recipe_definition(*arguments)
+ arguments << deprecation if arguments.empty?
+ RecipeDefinitionDeprecated.new(*arguments)
+ end
+
+ end
+
+end
View
12 lib/cape/deprecation.rb
@@ -0,0 +1,12 @@
+::Dir.glob(::File.expand_path('../deprecation/*.rb', __FILE__)) do |f|
+ require "cape/deprecation/#{::File.basename f, '.rb'}"
+end
+
+module Cape
+
+ # Contains implementations of deprecation stream printers.
+ #
+ # @api private
+ module Deprecation; end
+
+end
View
59 lib/cape/deprecation/base.rb
@@ -0,0 +1,59 @@
+require 'cape/xterm'
+
+module Cape
+
+ module Deprecation
+
+ # Prints to a stream a message related to deprecated API usage.
+ #
+ # @abstract
+ class Base
+
+ # Sets the value of {#stream}.
+ #
+ # @param [IO] value a new value for {#stream}
+ #
+ # @return [IO] _value_
+ attr_writer :stream
+
+ # Formats {#message_content} for display.
+ #
+ # @return [String] the full message
+ def formatted_message
+ [].tap do |fragments|
+ fragments << XTerm.bold_and_foreground_red('*** DEPRECATED:')
+ fragments << ' '
+ fragments << XTerm.bold(message_content)
+ end.join
+ end
+
+ # Prepares a message based on deprecated API usage.
+ #
+ # @raise [NotImplementedError]
+ #
+ # @abstract
+ def message_content
+ raise ::NotImplementedError
+ end
+
+ # The stream to which deprecation messages are printed. Defaults to
+ # $stderr.
+ #
+ # @return [IO]
+ def stream
+ @stream ||= $stderr
+ end
+
+ # Writes {#formatted_message} to {#stream}.
+ #
+ # @return [Base] the object
+ def write_formatted_message_to_stream
+ stream.puts formatted_message
+ self
+ end
+
+ end
+
+ end
+
+end
View
168 lib/cape/deprecation/capistrano_deprecated_define_rake_wrapper.rb
@@ -0,0 +1,168 @@
+require 'cape/deprecation/base'
+require 'cape/hash_list'
+
+module Cape
+
+ module Deprecation
+
+ # Prints to a stream a message related to deprecated usage of
+ # {CapistranoDeprecated#define_rake_wrapper}.
+ class CapistranoDeprecatedDefineRakeWrapper < Base
+
+ # The _task_ argument to {CapistranoDeprecated#define_rake_wrapper}.
+ #
+ # @return [Symbol, String]
+ attr_accessor :task
+
+ # Environment variable names and values set in a call to
+ # {CapistranoDeprecated#define_rake_wrapper}.
+ #
+ # @return [HashList]
+ def env
+ @env ||= HashList.new
+ end
+
+ # Prepares a message based on deprecated usage of
+ # {CapistranoDeprecated#define_rake_wrapper}.
+ #
+ # @return [String] a deprecation message
+ def message_content
+ [].tap do |fragments|
+ fragments << message_content_actual
+ fragments << '. '
+ fragments << message_content_expected
+ end.join
+ end
+
+ # The _named_arguments_ argument to
+ # {CapistranoDeprecated#define_rake_wrapper}.
+ #
+ # @return [HashList]
+ def named_arguments
+ @named_arguments ||= HashList.new
+ end
+
+ # Sets the value of {#named_arguments}.
+ #
+ # @param [Hash] value a new value for {#named_arguments}
+ #
+ # @return [HashList] _value_
+ def named_arguments=(value)
+ @named_arguments = HashList.new(value)
+ end
+
+ private
+
+ def binding_named_arguments
+ named_arguments.select do |name, value|
+ name == :binding
+ end
+ end
+
+ def message_content_env_actual
+ [].tap do |fragments|
+ env_entries = env.collect do |name, value|
+ "env[#{name.inspect}] = #{value.inspect}"
+ end
+ unless env_entries.empty?
+ fragments << ' { |env| '
+ fragments << env_entries.join('; ')
+ fragments << ' }'
+ end
+ end.join
+ end
+
+ def message_content_options_and_env_expected
+ [].tap do |fragments|
+ unless named_arguments.empty? && env.empty?
+ fragments << ' { |recipes| '
+
+ options_entries = options.collect do |name, value|
+ "recipes.options[#{name.inspect}] = #{value.inspect}"
+ end
+ env_entries = env.collect do |name, value|
+ "recipes.env[#{name.inspect}] = #{value.inspect}"
+ end
+ fragments << (options_entries + env_entries).join('; ')
+
+ fragments << ' }'
+ end
+ end.join
+ end
+
+ def message_content_actual
+ [].tap do |fragments|
+ fragments << '`'
+ fragments << message_content_method_name
+ fragments << message_content_task_and_named_arguments_actual
+ fragments << message_content_env_actual
+ fragments << '`'
+ end.join
+ end
+
+ def message_content_expected
+ [].tap do |fragments|
+ fragments << 'Use this instead: '
+ fragments << '`'
+ fragments << message_content_method_name
+ fragments << message_content_task_and_named_arguments_expected
+ fragments << message_content_options_and_env_expected
+ fragments << '`'
+ end.join
+ end
+
+ def message_content_method_name
+ 'define_rake_wrapper'
+ end
+
+ def message_content_task_and_named_arguments_actual
+ [].tap do |fragments|
+ arguments = []
+ arguments << task.inspect unless task.nil?
+ named_arguments_entries = named_arguments.collect do |name, value|
+ "#{name.inspect} => #{value.inspect}"
+ end
+ unless named_arguments_entries.empty?
+ arguments << named_arguments_entries.join(', ')
+ end
+ unless arguments.empty?
+ if env.empty?
+ fragments << " #{arguments.join ', '}"
+ else
+ fragments << "(#{arguments.join ', '})"
+ end
+ end
+ end.join
+ end
+
+ def message_content_task_and_named_arguments_expected
+ [].tap do |fragments|
+ arguments = []
+ arguments << task.inspect unless task.nil?
+ binding_named_arguments_entries = binding_named_arguments.collect do |name, value|
+ "#{name.inspect} => #{value.inspect}"
+ end
+ unless binding_named_arguments_entries.empty?
+ arguments << binding_named_arguments_entries.join(', ')
+ end
+ unless arguments.empty?
+ if options.empty? && env.empty?
+ fragments << " #{arguments.join ', '}"
+ else
+ fragments << "(#{arguments.join ', '})"
+ end
+ end
+ end.join
+ end
+
+ def options
+ named_arguments.reject do |name, value|
+ name == :binding
+ end
+ end
+
+ end
+
+ end
+
+end
View
145 lib/cape/deprecation/dsl_deprecated_mirror_rake_tasks.rb
@@ -0,0 +1,145 @@
+require 'cape/deprecation/base'
+require 'cape/hash_list'
+
+module Cape
+
+ module Deprecation
+
+ # Prints to a stream a message related to deprecated usage of
+ # {DSLDeprecated#mirror_rake_tasks}.
+ class DSLDeprecatedMirrorRakeTasks < Base
+
+ # The _task_expression_ argument to {DSLDeprecated#mirror_rake_tasks}.
+ #
+ # @return [Symbol, String]
+ attr_accessor :task_expression
+
+ # Environment variable names and values set in a call to
+ # {DSLDeprecated#mirror_rake_tasks}.
+ #
+ # @return [HashList]
+ def env
+ @env ||= HashList.new
+ end
+
+ # Prepares a message based on deprecated usage of
+ # {DSLDeprecated#mirror_rake_tasks}.
+ #
+ # @return [String] a deprecation message
+ def message_content
+ [].tap do |fragments|
+ fragments << message_content_actual
+ fragments << '. '
+ fragments << message_content_expected
+ end.join
+ end
+
+ # The _options_ argument to {DSLDeprecated#mirror_rake_tasks}.
+ #
+ # @return [HashList]
+ def options
+ @options ||= HashList.new
+ end
+
+ # Sets the value of {#options}.
+ #
+ # @param [Hash] value a new value for {#options}
+ #
+ # @return [HashList] _value_
+ def options=(value)
+ @options = HashList.new(value)
+ end
+
+ private
+
+ def message_content_env_actual
+ [].tap do |fragments|
+ env_entries = env.collect do |name, value|
+ "env[#{name.inspect}] = #{value.inspect}"
+ end
+ unless env_entries.empty?
+ fragments << ' { |env| '
+ fragments << env_entries.join('; ')
+ fragments << ' }'
+ end
+ end.join
+ end
+
+ def message_content_options_and_env_expected
+ [].tap do |fragments|
+ unless options.empty? && env.empty?
+ fragments << ' { |recipes| '
+
+ options_entries = options.collect do |name, value|
+ "recipes.options[#{name.inspect}] = #{value.inspect}"
+ end
+ env_entries = env.collect do |name, value|
+ "recipes.env[#{name.inspect}] = #{value.inspect}"
+ end
+ fragments << (options_entries + env_entries).join('; ')
+
+ fragments << ' }'
+ end
+ end.join
+ end
+
+ def message_content_actual
+ [].tap do |fragments|
+ fragments << '`'
+ fragments << message_content_method_name
+ fragments << message_content_task_expression_and_options_actual
+ fragments << message_content_env_actual
+ fragments << '`'
+ end.join
+ end
+
+ def message_content_expected
+ [].tap do |fragments|
+ fragments << 'Use this instead: '
+ fragments << '`'
+ fragments << message_content_method_name
+ fragments << message_content_task_expression_expected
+ fragments << message_content_options_and_env_expected
+ fragments << '`'
+ end.join
+ end
+
+ def message_content_method_name
+ 'mirror_rake_tasks'
+ end
+
+ def message_content_task_expression_and_options_actual
+ [].tap do |fragments|
+ arguments = []
+ arguments << task_expression.inspect unless task_expression.nil?
+ options_entries = options.collect do |name, value|
+ "#{name.inspect} => #{value.inspect}"
+ end
+ arguments << options_entries.join(', ') unless options_entries.empty?
+ unless arguments.empty?
+ if env.empty?
+ fragments << " #{arguments.join ', '}"
+ else
+ fragments << "(#{arguments.join ', '})"
+ end
+ end
+ end.join
+ end
+
+ def message_content_task_expression_expected
+ [].tap do |fragments|
+ unless task_expression.nil?
+ if options.empty? && env.empty?
+ fragments << " #{task_expression.inspect}"
+ else
+ fragments << "(#{task_expression.inspect})"
+ end
+ end
+ end.join
+ end
+
+ end
+
+ end
+
+end
View
108 lib/cape/dsl.rb