From 51d5d1ecd9231222c12cc3f18bae8579d400e96f Mon Sep 17 00:00:00 2001 From: Kir Shatrov Date: Thu, 17 Oct 2013 12:38:48 +0200 Subject: [PATCH] Warn developers that :all is a meta role Fix for #705 --- lib/capistrano/configuration.rb | 4 ++++ lib/capistrano/templates/stage.rb.erb | 1 + spec/integration/dsl_spec.rb | 8 ++++++++ 3 files changed, 13 insertions(+) diff --git a/lib/capistrano/configuration.rb b/lib/capistrano/configuration.rb index 40637737..979cff3c 100644 --- a/lib/capistrano/configuration.rb +++ b/lib/capistrano/configuration.rb @@ -34,6 +34,10 @@ module Capistrano end def role(name, hosts, options={}) + if name == :all + raise ArgumentError.new("#{name} reserved name for role. Please choose another name") + end + servers.add_role(name, hosts, options) end diff --git a/lib/capistrano/templates/stage.rb.erb b/lib/capistrano/templates/stage.rb.erb index 19fbcf7a..65b86dd3 100644 --- a/lib/capistrano/templates/stage.rb.erb +++ b/lib/capistrano/templates/stage.rb.erb @@ -5,6 +5,7 @@ set :stage, :<%= stage %> # Supports bulk-adding hosts to roles, the primary # server in each group is considered to be the first # unless any hosts have the primary property set. +# Don't declare `role :all`, it's a meta role role :app, %w{deploy@example.com} role :web, %w{deploy@example.com} role :db, %w{deploy@example.com} diff --git a/spec/integration/dsl_spec.rb b/spec/integration/dsl_spec.rb index d99a8657..36af5d5b 100644 --- a/spec/integration/dsl_spec.rb +++ b/spec/integration/dsl_spec.rb @@ -70,6 +70,14 @@ describe Capistrano::DSL do end + describe 'when defining role with reserved name' do + it 'fails with ArgumentError' do + expect { + dsl.role :all, %w{example1.com} + }.to raise_error(ArgumentError, "all reserved name for role. Please choose another name") + end + end + describe 'when defining hosts using the `role` syntax' do before do dsl.role :web, %w{example1.com example2.com example3.com}