diff --git a/lib/capistrano/configuration/servers.rb b/lib/capistrano/configuration/servers.rb index b32e0e2d..20b066b8 100644 --- a/lib/capistrano/configuration/servers.rb +++ b/lib/capistrano/configuration/servers.rb @@ -39,6 +39,9 @@ module Capistrano # # returns the given hosts, translated to ServerDefinition objects # servers = find_servers :hosts => "jamis@example.host.com" def find_servers(options={}) + return [] if options.key?(:hosts) && (options[:hosts].nil? || options[:hosts] == []) + return [] if options.key?(:roles) && (options[:roles].nil? || options[:roles] == []) + hosts = server_list_from(ENV['HOSTS'] || options[:hosts]) if hosts.any? diff --git a/test/configuration/servers_test.rb b/test/configuration/servers_test.rb index 6cfc404b..51018878 100644 --- a/test/configuration/servers_test.rb +++ b/test/configuration/servers_test.rb @@ -155,4 +155,15 @@ class ConfigurationServersTest < Test::Unit::TestCase assert_equal %w(app1 app2 app3), @config.find_servers(:roles => lambda { :app }).map { |s| s.host }.sort assert_equal %w(app2 file), @config.find_servers(:roles => lambda { [:report, :file] }).map { |s| s.host }.sort end + + def test_find_servers_with_hosts_nil_or_empty + assert_equal [], @config.find_servers(:hosts => nil) + assert_equal [], @config.find_servers(:hosts => []) + end + + def test_find_servers_with_rolees_nil_or_empty + assert_equal [], @config.find_servers(:roles => nil) + assert_equal [], @config.find_servers(:roles => []) + end + end