From d558838408f425a029b4d2fd158d362dc60f9fd3 Mon Sep 17 00:00:00 2001 From: Jamis Buck Date: Sat, 6 Sep 2008 16:11:16 -0600 Subject: [PATCH] tests all pass under Ruby 1.9 --- CHANGELOG.rdoc | 5 +++++ lib/capistrano/configuration/namespaces.rb | 4 ++-- lib/capistrano/extensions.rb | 2 +- lib/capistrano/logger.rb | 2 +- lib/capistrano/recipes/deploy/remote_dependency.rb | 3 ++- lib/capistrano/recipes/deploy/scm/cvs.rb | 4 ++-- lib/capistrano/recipes/deploy/scm/mercurial.rb | 6 +++--- test/cli/options_test.rb | 5 +++-- test/configuration/loading_test.rb | 2 +- test/configuration/namespace_dsl_test.rb | 4 ++-- test/configuration/servers_test.rb | 6 +++--- test/role_test.rb | 2 +- 12 files changed, 26 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.rdoc b/CHANGELOG.rdoc index 14840dbf..5b56c1f3 100644 --- a/CHANGELOG.rdoc +++ b/CHANGELOG.rdoc @@ -1,3 +1,8 @@ +== (unreleased) + +* Ruby 1.9 compatibility [Jamis Buck] + + == 2.5.0 / August 28, 2008 * Allow :gateway to be set to an array, in which case a chain of tunnels is created [Kerry Buckley] diff --git a/lib/capistrano/configuration/namespaces.rb b/lib/capistrano/configuration/namespaces.rb index 12dc36fa..838dc3d7 100644 --- a/lib/capistrano/configuration/namespaces.rb +++ b/lib/capistrano/configuration/namespaces.rb @@ -67,7 +67,7 @@ module Capistrano raise ArgumentError, "expected a block" unless block_given? namespace_already_defined = namespaces.key?(name) - if all_methods.include?(name.to_s) && !namespace_already_defined + if all_methods.any? { |m| m.to_sym == name } && !namespace_already_defined thing = tasks.key?(name) ? "task" : "method" raise ArgumentError, "defining a namespace named `#{name}' would shadow an existing #{thing} with that name" end @@ -92,7 +92,7 @@ module Capistrano raise ArgumentError, "expected a block" unless block_given? task_already_defined = tasks.key?(name) - if all_methods.include?(name.to_s) && !task_already_defined + if all_methods.any? { |m| m.to_sym == name } && !task_already_defined thing = namespaces.key?(name) ? "namespace" : "method" raise ArgumentError, "defining a task named `#{name}' would shadow an existing #{thing} with that name" end diff --git a/lib/capistrano/extensions.rb b/lib/capistrano/extensions.rb index c4147ff3..650893e1 100644 --- a/lib/capistrano/extensions.rb +++ b/lib/capistrano/extensions.rb @@ -25,7 +25,7 @@ module Capistrano Capistrano::Configuration.protected_instance_methods + Capistrano::Configuration.private_instance_methods - if methods.include?(name.to_s) + if methods.any? { |m| m.to_sym == name } raise Capistrano::Error, "registering a plugin named `#{name}' would shadow a method on Capistrano::Configuration with the same name" end diff --git a/lib/capistrano/logger.rb b/lib/capistrano/logger.rb index 52fbd7d5..0aa9602f 100644 --- a/lib/capistrano/logger.rb +++ b/lib/capistrano/logger.rb @@ -30,7 +30,7 @@ module Capistrano def log(level, message, line_prefix=nil) if level <= self.level indent = "%*s" % [MAX_LEVEL, "*" * (MAX_LEVEL - level)] - message.each do |line| + (RUBY_VERSION >= "1.9" ? message.lines : message).each do |line| if line_prefix device.puts "#{indent} [#{line_prefix}] #{line.strip}\n" else diff --git a/lib/capistrano/recipes/deploy/remote_dependency.rb b/lib/capistrano/recipes/deploy/remote_dependency.rb index e135b83a..540f1db0 100644 --- a/lib/capistrano/recipes/deploy/remote_dependency.rb +++ b/lib/capistrano/recipes/deploy/remote_dependency.rb @@ -9,6 +9,7 @@ module Capistrano def initialize(configuration) @configuration = configuration @success = true + @hosts = nil end def directory(path, options={}) @@ -83,7 +84,7 @@ module Capistrano def message s = @message.dup - s << " (#{@hosts})" if @hosts && @hosts.any? + s << " (#{@hosts})" if @hosts s end diff --git a/lib/capistrano/recipes/deploy/scm/cvs.rb b/lib/capistrano/recipes/deploy/scm/cvs.rb index 12a4ac14..6424444c 100644 --- a/lib/capistrano/recipes/deploy/scm/cvs.rb +++ b/lib/capistrano/recipes/deploy/scm/cvs.rb @@ -123,9 +123,9 @@ module Capistrano def cvs_revision(rev) revision = "" revision << case revision_type(rev) - when :date: + when :date "-D \"#{rev}\"" if revision_type(rev) == :date - when :revision: + when :revision "-r #{rev}" else "-r #{head}" diff --git a/lib/capistrano/recipes/deploy/scm/mercurial.rb b/lib/capistrano/recipes/deploy/scm/mercurial.rb index cb4b88d0..257013cb 100644 --- a/lib/capistrano/recipes/deploy/scm/mercurial.rb +++ b/lib/capistrano/recipes/deploy/scm/mercurial.rb @@ -119,9 +119,9 @@ module Capistrano # verbosity configuration grokking :) def verbose case variable(:scm_verbose) - when nil: nil - when false: "--quiet" - else "--verbose" + when nil then nil + when false then "--quiet" + else "--verbose" end end diff --git a/test/cli/options_test.rb b/test/cli/options_test.rb index 3ce076a2..634d1316 100644 --- a/test/cli/options_test.rb +++ b/test/cli/options_test.rb @@ -261,7 +261,8 @@ class CLIOptionsTest < Test::Unit::TestCase assert_equal "world", ENV["HELLO"] assert_equal "value", ENV["ANOTHER"] ensure - ENV["HELLO"] = ENV["ANOTHER"] = nil + ENV.delete("HELLO") + ENV.delete("ANOTHER") end def test_remaining_args_should_be_added_to_actions_list @@ -269,7 +270,7 @@ class CLIOptionsTest < Test::Unit::TestCase @cli.parse_options! assert_equal %w(something else), @cli.args ensure - ENV["HELLO"] = nil + ENV.delete("HELLO") end def test_search_for_default_recipe_file_should_look_for_Capfile diff --git a/test/configuration/loading_test.rb b/test/configuration/loading_test.rb index 3caa0675..eb4e2e4b 100644 --- a/test/configuration/loading_test.rb +++ b/test/configuration/loading_test.rb @@ -23,7 +23,7 @@ class ConfigurationLoadingTest < Test::Unit::TestCase def teardown MockConfig.instance = nil - $".delete "#{File.dirname(__FILE__)}/../fixtures/custom.rb" + $LOADED_FEATURES.delete_if { |a| a =~ /fixtures\/custom\.rb$/ } end def test_initialize_should_init_collections diff --git a/test/configuration/namespace_dsl_test.rb b/test/configuration/namespace_dsl_test.rb index 517ed6f1..17d15109 100644 --- a/test/configuration/namespace_dsl_test.rb +++ b/test/configuration/namespace_dsl_test.rb @@ -108,9 +108,9 @@ class ConfigurationNamespacesDSLTest < Test::Unit::TestCase end def test_defining_ask_should_add_task_as_method - assert !@config.methods.include?("original") + assert !@config.methods.any? { |m| m.to_sym == :original } @config.task(:original) { puts "foo" } - assert @config.methods.include?("original") + assert @config.methods.any? { |m| m.to_sym == :original } end def test_calling_defined_task_should_delegate_to_execute_task diff --git a/test/configuration/servers_test.rb b/test/configuration/servers_test.rb index 71e4ce38..ebdd39ac 100644 --- a/test/configuration/servers_test.rb +++ b/test/configuration/servers_test.rb @@ -59,7 +59,7 @@ class ConfigurationServersTest < Test::Unit::TestCase task = new_task(:testing) assert_equal %w(app1 app2 app3 file).sort, @config.find_servers_for_task(task).map { |s| s.host }.sort ensure - ENV['ROLES'] = nil + ENV.delete('ROLES') end def test_task_with_hosts_as_environment_variable_should_apply_only_to_those_hosts @@ -67,7 +67,7 @@ class ConfigurationServersTest < Test::Unit::TestCase task = new_task(:testing) assert_equal %w(foo bar).sort, @config.find_servers_for_task(task).map { |s| s.host }.sort ensure - ENV['HOSTS'] = nil + ENV.delete('HOSTS') end def test_task_with_hosts_as_environment_variable_should_not_inspect_roles_at_all @@ -75,7 +75,7 @@ class ConfigurationServersTest < Test::Unit::TestCase task = new_task(:testing, @config, :roles => :bogus) assert_equal %w(foo bar).sort, @config.find_servers_for_task(task).map { |s| s.host }.sort ensure - ENV['HOSTS'] = nil + ENV.delete('HOSTS') end def test_task_with_only_should_apply_only_to_matching_tasks diff --git a/test/role_test.rb b/test/role_test.rb index 84ab4941..98447b4b 100644 --- a/test/role_test.rb +++ b/test/role_test.rb @@ -3,7 +3,7 @@ require 'capistrano/role' class RoleTest < Test::Unit::TestCase def test_clearing_a_populated_role_should_yield_no_servers - role = Capistrano::Role.new("app1.capistrano.test", lambda { "app2.capistrano.test" }) + role = Capistrano::Role.new("app1.capistrano.test", lambda { |o| "app2.capistrano.test" }) assert_equal 2, role.servers.size role.clear assert role.servers.empty?