From 29f973c92c848345a3b8eabe5a6123e68a3df7f9 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Fri, 29 Mar 2013 15:31:31 -0700 Subject: Revert "Update Rake tasks to call `rails test` instead" This reverts commit b51673fbd9563bd3ffa22e22255ca1cef80cfb6d. --- railties/lib/rails/test_unit/testing.rake | 80 ++++++++++++++++++++----------- railties/test/application/rake_test.rb | 23 ++++----- 2 files changed, 62 insertions(+), 41 deletions(-) diff --git a/railties/lib/rails/test_unit/testing.rake b/railties/lib/rails/test_unit/testing.rake index de44bf9e4d..44485d9b14 100644 --- a/railties/lib/rails/test_unit/testing.rake +++ b/railties/lib/rails/test_unit/testing.rake @@ -1,7 +1,6 @@ require 'rbconfig' require 'rake/testtask' require 'rails/test_unit/sub_test_task' -require 'active_support/deprecation' TEST_CHANGES_SINCE = Time.now - 600 @@ -48,11 +47,7 @@ task default: :test desc 'Runs test:units, test:functionals, test:integration together' task :test do - if ENV['TEST'] - exec "bundle exec rails test #{ENV['TEST'].inspect}" - else - exec 'bundle exec rails test' - end + Rake::Task[ENV['TEST'] ? 'test:single' : 'test:run'].invoke end namespace :test do @@ -61,8 +56,19 @@ namespace :test do end task :run do - ActiveSupport::Deprecation.warn "`rake test:run` is deprecated. Please use `rails test`." - exec 'bundle exec rails test' + errors = %w(test:units test:functionals test:integration).collect do |task| + begin + Rake::Task[task].invoke + nil + rescue => e + { task: task, exception: e } + end + end.compact + + if errors.any? + puts errors.map { |e| "Errors running #{e[:task]}! #{e[:exception].inspect}" }.join("\n") + abort + end end # Inspired by: http://ngauthier.com/2012/02/quick-tests-with-bash.html @@ -77,13 +83,7 @@ namespace :test do task :db => %w[db:test:prepare test:all] end - # Display deprecation message - task :deprecated do - task_name = ARGV.first - ActiveSupport::Deprecation.warn "`rake #{ARGV.first}` is deprecated with no replacement." - end - - Rake::TestTask.new(recent: ["test:deprecated", "test:prepare"]) do |t| + Rake::TestTask.new(recent: "test:prepare") do |t| since = TEST_CHANGES_SINCE touched = FileList['test/**/*_test.rb'].select { |path| File.mtime(path) > since } + recent_tests('app/models/**/*.rb', 'test/models', since) + @@ -94,9 +94,9 @@ namespace :test do t.libs << 'test' t.test_files = touched.uniq end - Rake::Task['test:recent'].comment = "Deprecated; Test recent changes" + Rake::Task['test:recent'].comment = "Test recent changes" - Rake::TestTask.new(uncommitted: ["test:deprecated", "test:prepare"]) do |t| + Rake::TestTask.new(uncommitted: "test:prepare") do |t| def t.file_list if File.directory?(".svn") changed_since_checkin = silence_stderr { `svn status` }.split.map { |path| path.chomp[7 .. -1] } @@ -118,20 +118,44 @@ namespace :test do t.libs << 'test' end - Rake::Task['test:uncommitted'].comment = "Deprecated; Test changes since last checkin (only Subversion and Git)" + Rake::Task['test:uncommitted'].comment = "Test changes since last checkin (only Subversion and Git)" - desc "Deprecated; Please use `rails test \"#{ENV['TEST']}\"`" - task :single do - ActiveSupport::Deprecation.warn "`rake test:single` is deprecated. Please use `rails test \"#{ENV['TEST']}\"`." - exec "bundle exec rails test #{test_suit_name}" + Rake::TestTask.new(single: "test:prepare") do |t| + t.libs << "test" end - [:models, :helpers, :units, :controllers, :functionals, :integration].each do |test_suit_name| - desc "Deprecated; Please use `rails test #{test_suit_name}`" - task test_suit_name do - ActiveSupport::Deprecation.warn "`rake test:#{test_suit_name}` is deprecated. Please use `rails test #{test_suit_name}`." + Rails::SubTestTask.new(models: "test:prepare") do |t| + t.libs << "test" + t.pattern = 'test/models/**/*_test.rb' + end - exec "bundle exec rails test #{test_suit_name}" - end + Rails::SubTestTask.new(helpers: "test:prepare") do |t| + t.libs << "test" + t.pattern = 'test/helpers/**/*_test.rb' + end + + Rails::SubTestTask.new(units: "test:prepare") do |t| + t.libs << "test" + t.pattern = 'test/{models,helpers,unit}/**/*_test.rb' + end + + Rails::SubTestTask.new(controllers: "test:prepare") do |t| + t.libs << "test" + t.pattern = 'test/controllers/**/*_test.rb' + end + + Rails::SubTestTask.new(mailers: "test:prepare") do |t| + t.libs << "test" + t.pattern = 'test/mailers/**/*_test.rb' + end + + Rails::SubTestTask.new(functionals: "test:prepare") do |t| + t.libs << "test" + t.pattern = 'test/{controllers,mailers,functional}/**/*_test.rb' + end + + Rails::SubTestTask.new(integration: "test:prepare") do |t| + t.libs << "test" + t.pattern = 'test/integration/**/*_test.rb' end end diff --git a/railties/test/application/rake_test.rb b/railties/test/application/rake_test.rb index a9e0e1bcb7..09f2ad1209 100644 --- a/railties/test/application/rake_test.rb +++ b/railties/test/application/rake_test.rb @@ -91,9 +91,19 @@ module ApplicationTests raise 'models' RUBY + app_file "test/controllers/one_controller_test.rb", <<-RUBY + raise 'controllers' + RUBY + + app_file "test/integration/one_integration_test.rb", <<-RUBY + raise 'integration' + RUBY + silence_stderr do output = Dir.chdir(app_path) { `rake test 2>&1` } assert_match 'models', output + assert_match 'controllers', output + assert_match 'integration', output end end @@ -125,19 +135,6 @@ module ApplicationTests end end - def test_rake_test_deprecation_messages - Dir.chdir(app_path){ `rails generate scaffold user name:string` } - Dir.chdir(app_path){ `rake db:migrate` } - - %w(run recent uncommitted models helpers units controllers functionals integration).each do |test_suit_name| - output = Dir.chdir(app_path) { `rake test:#{test_suit_name} 2>&1` } - assert_match /DEPRECATION WARNING: `rake test:#{test_suit_name}` is deprecated/, output - end - - assert_match /DEPRECATION WARNING: `rake test:single` is deprecated/, - Dir.chdir(app_path) { `rake test:single TEST=test/models/user_test.rb 2>&1` } - end - def test_rake_routes_calls_the_route_inspector app_file "config/routes.rb", <<-RUBY AppTemplate::Application.routes.draw do -- cgit v1.2.3